System Management code

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

serviceCAN/serviceCAN.cpp

Committer:
pspatel321
Date:
2014-11-13
Revision:
30:91af74a299e1
Child:
31:7eaa5e881b56

File content as of revision 30:91af74a299e1:

#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;
}