78 if (frame->isEmpty()) {
79 log_->warning(
"Empty frame received on transport input");
85 std::lock_guard<std::mutex> lock(tranMtx_);
87 buff = *(frame->beginBuffer());
89 size = buff->getPayload();
92 if (frame->getError() ||
93 (frame->bufferCount() != 1) ||
96 ((data[0] & 0xF) != 0x2)) {
97 log_->warning(
"Dropping frame due to contents: error=0x%" PRIx8
", payload=%" PRIu32
", buffers=%" PRIu32
98 ", Version=0x%" PRIx8,
101 frame->bufferCount(),
113 tmpCount =
static_cast<uint32_t
>(data[4]) << 0;
114 tmpCount |=
static_cast<uint32_t
>(data[5]) << 8;
115 tmpSof = ((data[7] & 0x80) ?
true :
false);
118 tmpLuser = data[size - 8];
119 tmpEof = ((data[size - 7] & 0x1) ?
true :
false);
120 last =
static_cast<uint32_t
>(data[size - 6]);
123 if ((last == 0) || (last > 8)) {
124 log_->warning(
"Dropping frame due to invalid last value: %" PRIu32, last);
131 tmpCrc =
static_cast<uint32_t
>(data[size - 1]) << 0;
132 tmpCrc |=
static_cast<uint32_t
>(data[size - 2]) << 8;
133 tmpCrc |=
static_cast<uint32_t
>(data[size - 3]) << 16;
134 tmpCrc |=
static_cast<uint32_t
>(data[size - 4]) << 24;
142 crcErr = (tmpCrc != crc_[tmpDest]);
147 log_->debug(
"transportRx: Raw header: 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
148 ", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8,
157 log_->debug(
"transportRx: Raw footer: 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
158 ", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8,
167 log_->debug(
"transportRx: Got frame: Fuser=0x%" PRIx8
", Dest=0x%" PRIx8
", Id=0x%" PRIx8
", Count=%" PRIu32
168 ", Sof=%" PRIu8
", Luser=0x%" PRIx8
", Eof=%" PRIu8
", Last=%" PRIu32
", crcErr=%" PRIu8,
181 buff->adjustPayload(-8 + (
static_cast<int32_t
>(last) - 8));
184 buff->adjustHeader(8);
188 if ((transSof_[tmpDest] != tmpSof) || crcErr || tmpCount != tranCount_[tmpDest]) {
189 log_->warning(
"Dropping frame: gotDest=%" PRIu8
", gotSof=%" PRIu8
", crcErr=%" PRIu8
", expCount=%" PRIu32
190 ", gotCount=%" PRIu32,
197 transSof_[tmpDest] =
true;
198 tranCount_[tmpDest] = 0;
199 tranFrame_[tmpDest].reset();
204 if (transSof_[tmpDest]) {
205 transSof_[tmpDest] =
false;
206 if ((tranCount_[tmpDest] != 0) || !tmpSof || crcErr) {
207 log_->warning(
"Dropping frame: gotDest=%" PRIu8
", gotSof=%" PRIu8
", crcErr=%" PRIu8
", expCount=%" PRIu32
208 ", gotCount=%" PRIu32,
215 transSof_[tmpDest] =
true;
216 tranCount_[tmpDest] = 0;
217 tranFrame_[tmpDest].reset();
221 tranFrame_[tmpDest] = ris::Frame::create();
222 tranCount_[tmpDest] = 0;
224 tranFrame_[tmpDest]->setFirstUser(tmpFuser);
227 tranFrame_[tmpDest]->appendBuffer(buff);
232 tranFrame_[tmpDest]->setLastUser(tmpLuser);
233 transSof_[tmpDest] =
true;
234 tranCount_[tmpDest] = 0;
237 if (enSsi_ & (tmpLuser & 0x1)) tranFrame_[tmpDest]->setError(0x80);
240 tranFrame_[tmpDest].reset();
242 tranCount_[tmpDest] = (tranCount_[tmpDest] + 1) & 0xFFFF;
248 ris::Frame::BufferIterator it;
256 struct timeval startTime;
257 struct timeval currTime;
258 struct timeval endTime;
260 gettimeofday(&startTime, NULL);
261 timeradd(&startTime, &timeout_, &endTime);
263 if (frame->isEmpty()) {
264 log_->warning(
"Empty frame received on application input");
268 if (frame->getError())
return;
272 std::lock_guard<std::mutex> lock(appMtx_);
275 while (tranQueue_.busy()) {
277 gettimeofday(&currTime, NULL);
278 if (timercmp(&currTime, &endTime, >)) {
279 log_->critical(
"ControllerV2::applicationRx: Timeout waiting for outbound queue after %" PRIu32
".%" PRIu32
280 " seconds! May be caused by outbound backpressure.",
283 gettimeofday(&startTime, NULL);
284 timeradd(&startTime, &timeout_, &endTime);
288 fUser = frame->getFirstUser();
289 lUser = frame->getLastUser();
292 if (enSsi_) fUser |= 0x2;
295 for (it = frame->beginBuffer(); it != frame->endBuffer(); ++it) {
299 last = (*it)->getPayload() % 8;
300 if (last == 0) last = 8;
301 (*it)->adjustPayload(8 - last);
304 (*it)->adjustHeader(-8);
305 (*it)->adjustTail(-8);
308 (*it)->adjustPayload(8);
311 data = (*it)->begin();
312 size = (*it)->getPayload();
316 if (enObCrc_) data[0] |= 0x20;
322 data[4] = segment & 0xFF;
323 data[5] = (segment >> 8) & 0xFF;
325 data[7] = (segment == 0) ? 0x80 : 0x0;
328 data[size - 8] = lUser;
329 data[size - 7] = (it == (frame->endBuffer() - 1)) ? 0x1 : 0x0;
330 data[size - 6] = last;
341 data[size - 1] = (crc >> 0) & 0xFF;
342 data[size - 2] = (crc >> 8) & 0xFF;
343 data[size - 3] = (crc >> 16) & 0xFF;
344 data[size - 4] = (crc >> 24) & 0xFF;
353 log_->debug(
"applicationRx: Gen frame: Size=%" PRIu32
", Fuser=0x%" PRIu8
", Dest=0x%" PRIu8
", Count=%" PRIu32
354 ", Sof=%" PRIu8
", Luser=0x%" PRIu8
", Eof=%" PRIu8
", Last=%" PRIu32,
363 log_->debug(
"applicationRx: Raw header: 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
364 ", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8,
373 log_->debug(
"applicationRx: Raw footer: 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
374 ", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8,
384 tFrame->appendBuffer(*it);
385 tranQueue_.push(tFrame);
static const Parameters< crcpp_uint32, 32 > & CRC_32()
Returns a set of parameters for CRC-32 (aka CRC-32 ADCCP, CRC-32 PKZip).