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

Files at this revision

API Documentation at this revision

Comitter:
foxdie
Date:
Tue Mar 19 10:03:21 2013 +0000
Parent:
4:486fec88517e
Child:
6:32592425aa57
Commit message:
Fixed a couple of syntax errors

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	Wed Mar 13 14:50:15 2013 +0000
+++ b/GMLAN.cpp	Tue Mar 19 10:03:21 2013 +0000
@@ -16,7 +16,9 @@
 Jason Gaunt, 18th Feb 2013
 */
 
+#include "mbed.h"
 #include "GMLAN.h"
+#include <vector>
 
 void CANHeader::decode(int _header) {
     if (_header < 0x800)
@@ -43,4 +45,34 @@
     buffer = (buffer << 5) | 0x0; // 5 bit padding
     buffer = (buffer << 11) | arbitrationID;
     return buffer;
+}
+
+    
+GMLAN_Message::GMLAN_Message(int _priority, int _arbitration, int _sender,
+int _b0, int _b1, int _b2, int _b3, int _b4, int _b5, int _b6, int _b7) {
+    priority = _priority;
+    arbitration = _arbitration;
+    sender = _sender;
+    if (_b0 != -1) data.push_back(_b0);
+    if (_b1 != -1) data.push_back(_b1);
+    if (_b2 != -1) data.push_back(_b2);
+    if (_b3 != -1) data.push_back(_b3);
+    if (_b4 != -1) data.push_back(_b4);
+    if (_b5 != -1) data.push_back(_b5);
+    if (_b6 != -1) data.push_back(_b6);
+    if (_b7 != -1) data.push_back(_b7);
+}
+CANMessage GMLAN_Message::generate(void) {
+    CANHeader hdr;
+    hdr.priority(priority);
+    hdr.arbitration(arbitration);
+    hdr.sender(sender);
+    
+    char datatochars [data.size()];
+    for (int i = 0; i < data.size(); i++) datatochars[i] = data[i];
+    
+    if (sender > 0x0)
+        return CANMessage(hdr.encode29bit(), datatochars, data.size(), CANData, CANExtended);
+    else
+        return CANMessage(arbitration, datatochars, data.size(), CANData, CANStandard);
 }
\ No newline at end of file
--- a/GMLAN.h	Wed Mar 13 14:50:15 2013 +0000
+++ b/GMLAN.h	Tue Mar 19 10:03:21 2013 +0000
@@ -16,8 +16,10 @@
 Jason Gaunt, 18th Feb 2013
 */
 
+#include "mbed.h"
 #include "GMLAN_29bit.h"
 #include "GMLAN_11bit.h"
+#include <vector>
 
 #ifndef GMLAN_H
 #define GMLAN_H
@@ -77,4 +79,21 @@
         int encode11bit(void);
 };
 
+class GMLAN_Message {
+    /*
+    Wrapper for CANMessage that automatically parses settings
+    */
+    private:
+        vector<char> data;
+        int priority, arbitration, sender;
+    
+    public:
+        // Main function
+        GMLAN_Message(int _priority = -1, int _arbitration = -1, int _sender = -1,
+        int _b0 = -1, int _b1 = -1, int _b2 = -1, int _b3 = -1, int _b4 = -1, int _b5 = -1, int _b6 = -1, int _b7 = -1);
+    
+        // Return result
+        CANMessage generate(void);
+};
+
 #endif
\ No newline at end of file