Libraries to support working with GMLAN - General Motors CAN BUS network in most of their vehicles between 2007-present day. Please note this is a work in progress and not guaranteed to be correct, use at your own risk! Read commit logs / subscribe to see what has been added, it's a work in progress after all ;)
Diff: GMLAN.cpp
- Revision:
- 3:09fdfec053cd
- Parent:
- 0:9266fbfbef88
- Child:
- 4:486fec88517e
--- a/GMLAN.cpp Tue Feb 19 22:28:25 2013 +0000 +++ b/GMLAN.cpp Wed Feb 20 20:10:50 2013 +0000 @@ -19,11 +19,18 @@ #include "GMLAN.h" void CANHeader::decode(int _header) { - priorityID = (_header >> 26) & 0x7; - arbitrationID = (_header >> 13) & 0x1FFF; - senderID = (_header >> 0) & 0x1FFF; + if (_header < 0x800) + { + // 11-bit header + arbitrationID = _header; + } else { + // 29-bit header + priorityID = (_header >> 26) & 0x7; + arbitrationID = (_header >> 13) & 0x1FFF; + senderID = (_header >> 0) & 0x1FFF; + } } -int CANHeader::encode(void) { +int CANHeader::encode29bit(void) { long int buffer = 0; buffer = (buffer << 3) | 0x0; // 3 bit padding buffer = (buffer << 3) | priorityID;