From ae956e624fa6ba1a3d9bb7b6f47418e8dcbc7fae Mon Sep 17 00:00:00 2001 From: Marius Wensing Date: Wed, 4 Sep 2019 10:32:53 +0200 Subject: [PATCH] changing behaviour of parsePacket: returns -1 if no packet has been received, otherwise the length of the packet this fixes reception of zero-length packets --- examples/CANReceiver/CANReceiver.ino | 2 +- src/CANController.cpp | 2 +- src/ESP32SJA1000.cpp | 2 +- src/MCP2515.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/CANReceiver/CANReceiver.ino b/examples/CANReceiver/CANReceiver.ino index fca49e4..08d7deb 100644 --- a/examples/CANReceiver/CANReceiver.ino +++ b/examples/CANReceiver/CANReceiver.ino @@ -20,7 +20,7 @@ void loop() { // try to parse packet int packetSize = CAN.parsePacket(); - if (packetSize) { + if (packetSize >= 0) { // received a packet Serial.print("Received "); diff --git a/src/CANController.cpp b/src/CANController.cpp index 0890eec..ecc9680 100644 --- a/src/CANController.cpp +++ b/src/CANController.cpp @@ -109,7 +109,7 @@ int CANControllerClass::endPacket() int CANControllerClass::parsePacket() { - return 0; + return -1; } long CANControllerClass::packetId() diff --git a/src/ESP32SJA1000.cpp b/src/ESP32SJA1000.cpp index 3c56fba..cbe62b7 100644 --- a/src/ESP32SJA1000.cpp +++ b/src/ESP32SJA1000.cpp @@ -219,7 +219,7 @@ int ESP32SJA1000Class::parsePacket() { if ((readRegister(REG_SR) & 0x01) != 0x01) { // no packet - return 0; + return -1; } _rxExtended = (readRegister(REG_SFF) & 0x80) ? true : false; diff --git a/src/MCP2515.cpp b/src/MCP2515.cpp index aa46051..93f0d42 100644 --- a/src/MCP2515.cpp +++ b/src/MCP2515.cpp @@ -225,7 +225,7 @@ int MCP2515Class::parsePacket() _rxExtended = false; _rxRtr = false; _rxLength = 0; - return 0; + return -1; } _rxExtended = (readRegister(REG_RXBnSIDL(n)) & FLAG_IDE) ? true : false;