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 ;)
GMLAN.h@3:09fdfec053cd, 2013-02-20 (annotated)
- Committer:
- foxdie
- Date:
- Wed Feb 20 20:10:50 2013 +0000
- Revision:
- 3:09fdfec053cd
- Parent:
- 2:1a2cb289f24d
- Child:
- 4:486fec88517e
Added basic support for 11-bit frame headers, changing function names to support
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
foxdie | 0:9266fbfbef88 | 1 | /* |
foxdie | 0:9266fbfbef88 | 2 | GMLAN.h - Header file for GMLAN Library |
foxdie | 0:9266fbfbef88 | 3 | |
foxdie | 0:9266fbfbef88 | 4 | GMLAN is a Controller Area Network Bus used in General Motors vehicles from |
foxdie | 0:9266fbfbef88 | 5 | roughly 2007-onwards. Its purpose is to allow various Electronic Control Units |
foxdie | 0:9266fbfbef88 | 6 | (aka ECUs) within a modern vehicle to share information and enact procedures. |
foxdie | 0:9266fbfbef88 | 7 | |
foxdie | 0:9266fbfbef88 | 8 | An example of this would be communication between the HU (Head unit) and the |
foxdie | 0:9266fbfbef88 | 9 | DIC (Dashboard Information Cluster), when you adjust the volume up / down, this |
foxdie | 0:9266fbfbef88 | 10 | is reported to the cluster to be displayed. |
foxdie | 0:9266fbfbef88 | 11 | |
foxdie | 0:9266fbfbef88 | 12 | It is the function of this library to "crack open" this world to allow anyone |
foxdie | 0:9266fbfbef88 | 13 | with only as little as a few hours of C++ programming under their belt to get |
foxdie | 0:9266fbfbef88 | 14 | started in what can sometimes seem a daunting world. |
foxdie | 0:9266fbfbef88 | 15 | |
foxdie | 0:9266fbfbef88 | 16 | Jason Gaunt, 18th Feb 2013 |
foxdie | 0:9266fbfbef88 | 17 | */ |
foxdie | 0:9266fbfbef88 | 18 | |
foxdie | 2:1a2cb289f24d | 19 | #include "GMLAN_29bit.h" |
foxdie | 2:1a2cb289f24d | 20 | // #include "GMLAN_11bit.h" |
foxdie | 2:1a2cb289f24d | 21 | |
foxdie | 0:9266fbfbef88 | 22 | #ifndef GMLAN_H |
foxdie | 0:9266fbfbef88 | 23 | #define GMLAN_H |
foxdie | 0:9266fbfbef88 | 24 | |
foxdie | 0:9266fbfbef88 | 25 | /* Baud rates of various services */ |
foxdie | 0:9266fbfbef88 | 26 | #define GMLAN_BAUD_LS_NORMAL 33333 |
foxdie | 0:9266fbfbef88 | 27 | #define GMLAN_BAUD_LS_FAST 83333 |
foxdie | 0:9266fbfbef88 | 28 | #define GMLAN_BAUD_MS 95200 |
foxdie | 0:9266fbfbef88 | 29 | #define GMLAN_BAUD_HS 500000 |
foxdie | 0:9266fbfbef88 | 30 | |
foxdie | 0:9266fbfbef88 | 31 | class CANHeader { |
foxdie | 3:09fdfec053cd | 32 | /* |
foxdie | 3:09fdfec053cd | 33 | CANHeader was designed solely for 29-bit frames but supports 11-bit too by just setting the ArbID |
foxdie | 3:09fdfec053cd | 34 | |
foxdie | 3:09fdfec053cd | 35 | Example 29-bit header packet from Steering Wheel Switches: |
foxdie | 3:09fdfec053cd | 36 | |
foxdie | 3:09fdfec053cd | 37 | Hexadecimal: 0x10 0x0D 0x00 0x60 |
foxdie | 3:09fdfec053cd | 38 | Binary: 00010000 00001101 00000000 01100000 |
foxdie | 3:09fdfec053cd | 39 | Priority: --- |
foxdie | 3:09fdfec053cd | 40 | Arbitration: -- -------- --- |
foxdie | 3:09fdfec053cd | 41 | Sending ECU: ----- -------- |
foxdie | 3:09fdfec053cd | 42 | |
foxdie | 3:09fdfec053cd | 43 | Example 11-bit header packet from Head Unit: |
foxdie | 3:09fdfec053cd | 44 | |
foxdie | 3:09fdfec053cd | 45 | Hexadecimal: 0x02 0x44 |
foxdie | 3:09fdfec053cd | 46 | Binary: 00000010 01000100 |
foxdie | 3:09fdfec053cd | 47 | Identifier: --- -------- |
foxdie | 3:09fdfec053cd | 48 | |
foxdie | 3:09fdfec053cd | 49 | */ |
foxdie | 0:9266fbfbef88 | 50 | |
foxdie | 0:9266fbfbef88 | 51 | private: |
foxdie | 0:9266fbfbef88 | 52 | int priorityID, arbitrationID, senderID; |
foxdie | 0:9266fbfbef88 | 53 | |
foxdie | 0:9266fbfbef88 | 54 | public: |
foxdie | 1:9dfa8ee351a3 | 55 | // Main function |
foxdie | 1:9dfa8ee351a3 | 56 | CANHeader() { } |
foxdie | 3:09fdfec053cd | 57 | |
foxdie | 0:9266fbfbef88 | 58 | // Methods for getting / setting priority, both integers |
foxdie | 0:9266fbfbef88 | 59 | int priority(void) { return priorityID; } |
foxdie | 0:9266fbfbef88 | 60 | void priority(int _priority) { priorityID = _priority; } |
foxdie | 3:09fdfec053cd | 61 | |
foxdie | 0:9266fbfbef88 | 62 | // Method for getting / setting arbitration id aka arbid, both integers |
foxdie | 0:9266fbfbef88 | 63 | int arbitration(void) { return arbitrationID; } |
foxdie | 0:9266fbfbef88 | 64 | void arbitration(int _arbitration) { arbitrationID = _arbitration; } |
foxdie | 3:09fdfec053cd | 65 | |
foxdie | 0:9266fbfbef88 | 66 | // Method for getting / setting sender id, both integers |
foxdie | 0:9266fbfbef88 | 67 | int sender(void) { return senderID; } |
foxdie | 0:9266fbfbef88 | 68 | void sender(int _sender) { senderID = _sender; } |
foxdie | 0:9266fbfbef88 | 69 | |
foxdie | 3:09fdfec053cd | 70 | // Function to decode either an 11-bit or 29-bit header packet and store values in respective variables |
foxdie | 0:9266fbfbef88 | 71 | void decode(int _header); |
foxdie | 3:09fdfec053cd | 72 | |
foxdie | 3:09fdfec053cd | 73 | // Function to encode stored values as 29-bit header and return header packet as int |
foxdie | 3:09fdfec053cd | 74 | int encode29bit(void); |
foxdie | 0:9266fbfbef88 | 75 | }; |
foxdie | 0:9266fbfbef88 | 76 | |
foxdie | 0:9266fbfbef88 | 77 | #endif |