System Management code

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Revision:
30:91af74a299e1
Child:
31:7eaa5e881b56
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/serviceCAN/serviceCAN.cpp	Thu Nov 13 10:53:10 2014 +0000
@@ -0,0 +1,25 @@
+#include "serviceCAN.h"
+
+// MACRO to setup handling of timeouts
+#define TIMEOUT(VAR)            Timeout timer_##VAR; void timeout_##VAR(){ flags.VAR = false; }
+#define REFRESH_TIMEOUT(VAR)    timer_##VAR.detach(); timer_##VAR.attach(&timeout_##VAR, DEVICE_CAN_TIMEOUT/100.0);
+#define CHECK_ERRORS(VAR, MSG)  if (hasErrors(MSG)) { flags.VAR = false; } else { flags.VAR = true; }
+
+// Timeouts to handle cases where CAN messages stop coming in
+
+
+// Check every byte of the message for an error bit
+bool hasErrors(CANMessage& msg) {
+    bool errorPresent = false;
+    for (int i = 0; i < msg.len; i++) {
+        if (i >= 8) { errorPresent = true; break; }     // out of bounds, bad CAN message
+        if (msg.data[i]) errorPresent = true;
+    }
+    return errorPresent;
+}
+
+bool canbus::serviceCAN() {
+    CANMessage msg;
+    
+    return false;
+}
\ No newline at end of file