86 if (frame->isEmpty()) {
87 log_->warning(
"Empty frame received on transport input");
93 std::lock_guard<std::mutex> lock(tranMtx_);
95 buff = *(frame->beginBuffer());
97 size = buff->getPayload();
100 if (frame->getError() ||
101 (frame->bufferCount() != 1) ||
103 ((size & 0x7) > 0) ||
104 ((data[0] & 0xF) != 0x2)) {
105 log_->warning(
"Dropping frame due to contents: error=0x%" PRIx8
", payload=%" PRIu32
", buffers=%" PRIu32
106 ", Version=0x%" PRIx8,
109 frame->bufferCount(),
121 tmpCount =
static_cast<uint32_t
>(data[4]) << 0;
122 tmpCount |=
static_cast<uint32_t
>(data[5]) << 8;
123 tmpSof = ((data[7] & 0x80) ?
true :
false);
126 tmpLuser = data[size - 8];
127 tmpEof = ((data[size - 7] & 0x1) ?
true :
false);
128 last =
static_cast<uint32_t
>(data[size - 6]);
132 tmpCrc =
static_cast<uint32_t
>(data[size - 1]) << 0;
133 tmpCrc |=
static_cast<uint32_t
>(data[size - 2]) << 8;
134 tmpCrc |=
static_cast<uint32_t
>(data[size - 3]) << 16;
135 tmpCrc |=
static_cast<uint32_t
>(data[size - 4]) << 24;
143 crcErr = (tmpCrc != crc_[tmpDest]);
148 log_->debug(
"transportRx: Raw header: 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
149 ", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8,
158 log_->debug(
"transportRx: Raw footer: 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
159 ", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8,
168 log_->debug(
"transportRx: Got frame: Fuser=0x%" PRIx8
", Dest=0x%" PRIx8
", Id=0x%" PRIx8
", Count=%" PRIu32
169 ", Sof=%" PRIu8
", Luser=0x%" PRIx8
", Eof=%" PRIu8
", Last=%" PRIu32
", crcErr=%" PRIu8,
182 buff->adjustPayload(-8 + (
static_cast<int32_t
>(last) - 8));
185 buff->adjustHeader(8);
189 if ((transSof_[tmpDest] != tmpSof) || crcErr || tmpCount != tranCount_[tmpDest]) {
190 log_->warning(
"Dropping frame: gotDest=%" PRIu8
", gotSof=%" PRIu8
", crcErr=%" PRIu8
", expCount=%" PRIu32
191 ", gotCount=%" PRIu32,
198 transSof_[tmpDest] =
true;
199 tranCount_[tmpDest] = 0;
200 tranFrame_[tmpDest].reset();
205 if (transSof_[tmpDest]) {
206 transSof_[tmpDest] =
false;
207 if ((tranCount_[tmpDest] != 0) || !tmpSof || crcErr) {
208 log_->warning(
"Dropping frame: gotDest=%" PRIu8
", gotSof=%" PRIu8
", crcErr=%" PRIu8
", expCount=%" PRIu32
209 ", gotCount=%" PRIu32,
216 transSof_[tmpDest] =
true;
217 tranCount_[tmpDest] = 0;
218 tranFrame_[tmpDest].reset();
222 tranFrame_[tmpDest] = ris::Frame::create();
223 tranCount_[tmpDest] = 0;
225 tranFrame_[tmpDest]->setFirstUser(tmpFuser);
228 tranFrame_[tmpDest]->appendBuffer(buff);
233 tranFrame_[tmpDest]->setLastUser(tmpLuser);
234 transSof_[tmpDest] =
true;
235 tranCount_[tmpDest] = 0;
238 if (enSsi_ & (tmpLuser & 0x1)) tranFrame_[tmpDest]->setError(0x80);
241 app_[tmpDest]->pushFrame(tranFrame_[tmpDest]);
243 tranFrame_[tmpDest].reset();
245 tranCount_[tmpDest] = (tranCount_[tmpDest] + 1) & 0xFFFF;
251 ris::Frame::BufferIterator it;
259 struct timeval startTime;
260 struct timeval currTime;
261 struct timeval endTime;
263 gettimeofday(&startTime, NULL);
264 timeradd(&startTime, &timeout_, &endTime);
266 if (frame->isEmpty()) {
267 log_->warning(
"Empty frame received on application input");
271 if (frame->getError())
return;
275 std::lock_guard<std::mutex> lock(appMtx_);
278 while (tranQueue_.busy()) {
280 gettimeofday(&currTime, NULL);
281 if (timercmp(&currTime, &endTime, >)) {
282 log_->critical(
"ControllerV2::applicationRx: Timeout waiting for outbound queue after %" PRIu32
".%" PRIu32
283 " seconds! May be caused by outbound backpressure.",
286 gettimeofday(&startTime, NULL);
287 timeradd(&startTime, &timeout_, &endTime);
291 fUser = frame->getFirstUser();
292 lUser = frame->getLastUser();
295 if (enSsi_) fUser |= 0x2;
298 for (it = frame->beginBuffer(); it != frame->endBuffer(); ++it) {
302 last = (*it)->getPayload() % 8;
303 if (last == 0) last = 8;
304 (*it)->adjustPayload(8 - last);
307 (*it)->adjustHeader(-8);
308 (*it)->adjustTail(-8);
311 (*it)->adjustPayload(8);
314 data = (*it)->begin();
315 size = (*it)->getPayload();
319 if (enObCrc_) data[0] |= 0x20;
325 data[4] = segment & 0xFF;
326 data[5] = (segment >> 8) & 0xFF;
328 data[7] = (segment == 0) ? 0x80 : 0x0;
331 data[size - 8] = lUser;
332 data[size - 7] = (it == (frame->endBuffer() - 1)) ? 0x1 : 0x0;
333 data[size - 6] = last;
344 data[size - 1] = (crc >> 0) & 0xFF;
345 data[size - 2] = (crc >> 8) & 0xFF;
346 data[size - 3] = (crc >> 16) & 0xFF;
347 data[size - 4] = (crc >> 24) & 0xFF;
356 log_->debug(
"applicationRx: Gen frame: Size=%" PRIu32
", Fuser=0x%" PRIu8
", Dest=0x%" PRIu8
", Count=%" PRIu32
357 ", Sof=%" PRIu8
", Luser=0x%" PRIu8
", Eof=%" PRIu8
", Last=%" PRIu32,
366 log_->debug(
"applicationRx: Raw header: 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
367 ", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8,
376 log_->debug(
"applicationRx: Raw footer: 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8
377 ", 0x%" PRIx8
", 0x%" PRIx8
", 0x%" PRIx8,
387 tFrame->appendBuffer(*it);
388 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).