MCPcopy Create free account
hub / github.com/Seeed-Studio/Seeed_Arduino_CAN / receiveSingleFrame

Method receiveSingleFrame

src/can-serial.cpp:417–463  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

415}
416
417INT8U Can232::receiveSingleFrame() {
418 INT8U ret = LW232_OK;
419 INT8U idx = 0;
420 if (CAN_OK == readMsgBufID(&lw232CanId, &lw232PacketLen, lw232Buffer)) {
421 if (lw232CanId > 0x1FFFFFFF) {
422 ret = LW232_ERR; // address if totally wrong
423 }
424 else if (checkPassFilter(lw232CanId)) {// do we want to skip some addresses?
425 if (isExtendedFrame()) {
426 Serial.print(LW232_TR29);
427 HexHelper::printFullByte(HIGH_BYTE(HIGH_WORD(lw232CanId)));
428 HexHelper::printFullByte(LOW_BYTE(HIGH_WORD(lw232CanId)));
429 HexHelper::printFullByte(HIGH_BYTE(LOW_WORD(lw232CanId)));
430 HexHelper::printFullByte(LOW_BYTE(LOW_WORD(lw232CanId)));
431 }
432 else {
433 Serial.print(LW232_TR11);
434 HexHelper::printNibble(HIGH_BYTE(LOW_WORD(lw232CanId)));
435 HexHelper::printFullByte(LOW_BYTE(LOW_WORD(lw232CanId)));
436 }
437 //write data len
438 HexHelper::printNibble(lw232PacketLen);
439 //write data
440 for (idx = 0; idx < lw232PacketLen; idx++) {
441 HexHelper::printFullByte(lw232Buffer[idx]);
442 }
443 //write timestamp if needed
444 if (lw232TimeStamp != LW232_TIMESTAMP_OFF) {
445 INT32U time = millis();
446 if (lw232TimeStamp == LW232_TIMESTAMP_ON_NORMAL) {
447 // standard LAWICEL protocol. two bytes.
448 time %= 60000;
449 } else {
450 // non standard protocol - 4 bytes timestamp
451 HexHelper::printFullByte(HIGH_BYTE(HIGH_WORD(time)));
452 HexHelper::printFullByte(LOW_BYTE(HIGH_WORD(time)));
453 }
454 HexHelper::printFullByte(HIGH_BYTE(LOW_WORD(time)));
455 HexHelper::printFullByte(LOW_BYTE(LOW_WORD(time)));
456 }
457 }
458 }
459 else {
460 ret = LW232_ERR;
461 }
462 return ret;
463}
464
465
466INT8U Can232::isExtendedFrame() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected