Skip to content

Commit 25ee443

Browse files
committed
Correct extended packet parsing
There were some issues with sign extension
1 parent ef96565 commit 25ee443

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/CAN.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ int CANClass::parsePacket()
280280

281281
_rxExtended = (readRegister(REG_RXBnSIDL(n)) & FLAG_IDE) ? true : false;
282282

283-
uint32_t idA = (readRegister(REG_RXBnSIDH(n)) << 3) | ((readRegister(REG_RXBnSIDL(n)) >> 5) & 0x07);
283+
uint32_t idA = ((readRegister(REG_RXBnSIDH(n)) << 3) & 0xf8) | ((readRegister(REG_RXBnSIDL(n)) >> 5) & 0x07);
284284
if (_rxExtended) {
285-
uint32_t idB = ((uint32_t)(readRegister(REG_RXBnSIDL(n)) & 0x03) << 16) | (readRegister(REG_RXBnEID8(n)) << 8) | readRegister(REG_RXBnEID0(n));
285+
uint32_t idB = (((uint32_t)(readRegister(REG_RXBnSIDL(n)) & 0x03) << 16) & 0x30000) | ((readRegister(REG_RXBnEID8(n)) << 8) & 0xff00) | readRegister(REG_RXBnEID0(n));
286286

287287
_rxId = (idA << 18) | idB;
288288
_rxRtr = (readRegister(REG_RXBnDLC(n)) & FLAG_RTR) ? true : false;

0 commit comments

Comments
 (0)