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 ;)
Revision 3:09fdfec053cd, committed 2013-02-20
- Comitter:
- foxdie
- Date:
- Wed Feb 20 20:10:50 2013 +0000
- Parent:
- 2:1a2cb289f24d
- Child:
- 4:486fec88517e
- Commit message:
- Added basic support for 11-bit frame headers, changing function names to support
Changed in this revision
GMLAN.cpp | Show annotated file Show diff for this revision Revisions of this file |
GMLAN.h | Show annotated file Show diff for this revision Revisions of this file |
--- 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;
--- a/GMLAN.h Tue Feb 19 22:28:25 2013 +0000 +++ b/GMLAN.h Wed Feb 20 20:10:50 2013 +0000 @@ -29,12 +29,24 @@ #define GMLAN_BAUD_HS 500000 class CANHeader { - // Example header packet for Steering Wheel Switches: - // Hexadecimal: 0x10 0x0D 0x00 0x60 - // Binary: 00010000 00001101 00000000 01100000 - // Priority: --- - // Arbitration: -- -------- --- - // Sending ECU: ----- -------- + /* + CANHeader was designed solely for 29-bit frames but supports 11-bit too by just setting the ArbID + + Example 29-bit header packet from Steering Wheel Switches: + + Hexadecimal: 0x10 0x0D 0x00 0x60 + Binary: 00010000 00001101 00000000 01100000 + Priority: --- + Arbitration: -- -------- --- + Sending ECU: ----- -------- + + Example 11-bit header packet from Head Unit: + + Hexadecimal: 0x02 0x44 + Binary: 00000010 01000100 + Identifier: --- -------- + + */ private: int priorityID, arbitrationID, senderID; @@ -42,22 +54,24 @@ public: // Main function CANHeader() { } - - //// 29-bit frames + // Methods for getting / setting priority, both integers int priority(void) { return priorityID; } void priority(int _priority) { priorityID = _priority; } + // Method for getting / setting arbitration id aka arbid, both integers int arbitration(void) { return arbitrationID; } void arbitration(int _arbitration) { arbitrationID = _arbitration; } + // Method for getting / setting sender id, both integers int sender(void) { return senderID; } void sender(int _sender) { senderID = _sender; } - // Function to decode a header packet and store values in respective variables + // Function to decode either an 11-bit or 29-bit header packet and store values in respective variables void decode(int _header); - // Function to encode stored values and return header packet as int - int encode(void); + + // Function to encode stored values as 29-bit header and return header packet as int + int encode29bit(void); }; #endif \ No newline at end of file