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 ;)

Committer:
foxdie
Date:
Wed Feb 20 20:10:50 2013 +0000
Revision:
3:09fdfec053cd
Parent:
0:9266fbfbef88
Child:
4:486fec88517e
Added basic support for 11-bit frame headers, changing function names to support

Who changed what in which revision?

UserRevisionLine numberNew contents of line
foxdie 0:9266fbfbef88 1 /*
foxdie 0:9266fbfbef88 2 GMLAN.cpp - Source 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 0:9266fbfbef88 19 #include "GMLAN.h"
foxdie 0:9266fbfbef88 20
foxdie 0:9266fbfbef88 21 void CANHeader::decode(int _header) {
foxdie 3:09fdfec053cd 22 if (_header < 0x800)
foxdie 3:09fdfec053cd 23 {
foxdie 3:09fdfec053cd 24 // 11-bit header
foxdie 3:09fdfec053cd 25 arbitrationID = _header;
foxdie 3:09fdfec053cd 26 } else {
foxdie 3:09fdfec053cd 27 // 29-bit header
foxdie 3:09fdfec053cd 28 priorityID = (_header >> 26) & 0x7;
foxdie 3:09fdfec053cd 29 arbitrationID = (_header >> 13) & 0x1FFF;
foxdie 3:09fdfec053cd 30 senderID = (_header >> 0) & 0x1FFF;
foxdie 3:09fdfec053cd 31 }
foxdie 0:9266fbfbef88 32 }
foxdie 3:09fdfec053cd 33 int CANHeader::encode29bit(void) {
foxdie 0:9266fbfbef88 34 long int buffer = 0;
foxdie 0:9266fbfbef88 35 buffer = (buffer << 3) | 0x0; // 3 bit padding
foxdie 0:9266fbfbef88 36 buffer = (buffer << 3) | priorityID;
foxdie 0:9266fbfbef88 37 buffer = (buffer << 13) | arbitrationID;
foxdie 0:9266fbfbef88 38 buffer = (buffer << 13) | senderID;
foxdie 0:9266fbfbef88 39 return buffer;
foxdie 0:9266fbfbef88 40 }