System Management code
Dependencies: mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP
Fork of SystemManagement by
serviceCAN/serviceCAN.cpp@30:91af74a299e1, 2014-11-13 (annotated)
- Committer:
- pspatel321
- Date:
- Thu Nov 13 10:53:10 2014 +0000
- Revision:
- 30:91af74a299e1
- Child:
- 31:7eaa5e881b56
Parth's edits for the week.; DC-DC completed and fixed, IMD updated, LatchMonitor and Temperature added. Serial dashboard updated. File structure changed Everything tested. Compiles and runs.; Still need to write CAN in/out interface.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pspatel321 | 30:91af74a299e1 | 1 | #include "serviceCAN.h" |
pspatel321 | 30:91af74a299e1 | 2 | |
pspatel321 | 30:91af74a299e1 | 3 | // MACRO to setup handling of timeouts |
pspatel321 | 30:91af74a299e1 | 4 | #define TIMEOUT(VAR) Timeout timer_##VAR; void timeout_##VAR(){ flags.VAR = false; } |
pspatel321 | 30:91af74a299e1 | 5 | #define REFRESH_TIMEOUT(VAR) timer_##VAR.detach(); timer_##VAR.attach(&timeout_##VAR, DEVICE_CAN_TIMEOUT/100.0); |
pspatel321 | 30:91af74a299e1 | 6 | #define CHECK_ERRORS(VAR, MSG) if (hasErrors(MSG)) { flags.VAR = false; } else { flags.VAR = true; } |
pspatel321 | 30:91af74a299e1 | 7 | |
pspatel321 | 30:91af74a299e1 | 8 | // Timeouts to handle cases where CAN messages stop coming in |
pspatel321 | 30:91af74a299e1 | 9 | |
pspatel321 | 30:91af74a299e1 | 10 | |
pspatel321 | 30:91af74a299e1 | 11 | // Check every byte of the message for an error bit |
pspatel321 | 30:91af74a299e1 | 12 | bool hasErrors(CANMessage& msg) { |
pspatel321 | 30:91af74a299e1 | 13 | bool errorPresent = false; |
pspatel321 | 30:91af74a299e1 | 14 | for (int i = 0; i < msg.len; i++) { |
pspatel321 | 30:91af74a299e1 | 15 | if (i >= 8) { errorPresent = true; break; } // out of bounds, bad CAN message |
pspatel321 | 30:91af74a299e1 | 16 | if (msg.data[i]) errorPresent = true; |
pspatel321 | 30:91af74a299e1 | 17 | } |
pspatel321 | 30:91af74a299e1 | 18 | return errorPresent; |
pspatel321 | 30:91af74a299e1 | 19 | } |
pspatel321 | 30:91af74a299e1 | 20 | |
pspatel321 | 30:91af74a299e1 | 21 | bool canbus::serviceCAN() { |
pspatel321 | 30:91af74a299e1 | 22 | CANMessage msg; |
pspatel321 | 30:91af74a299e1 | 23 | |
pspatel321 | 30:91af74a299e1 | 24 | return false; |
pspatel321 | 30:91af74a299e1 | 25 | } |