System Management code
Dependencies: mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP
Fork of SystemManagement by
Diff: inCommands/inCommands.cpp
- Revision:
- 39:ddf38df9699e
- Parent:
- 38:8efacce315ae
diff -r 8efacce315ae -r ddf38df9699e inCommands/inCommands.cpp --- a/inCommands/inCommands.cpp Sat Feb 07 08:54:51 2015 +0000 +++ b/inCommands/inCommands.cpp Wed Feb 11 23:09:57 2015 +0000 @@ -177,9 +177,6 @@ CHANGE_VAR("CANrxSize", CANrxSize) CHANGE_VAR("SerialBaud", SerialBaud) CHANGE_VAR("SerialTx", SerialTxSize) - CHANGE_VAR("XbeeBaud", XbeeBaud) - CHANGE_VAR("XbeeTxSize", XbeeTxSize) - CHANGE_VAR("XbeeRxSize", XbeeRxSize) CHANGE_VAR("CANack", CANnoAck) if (!parsed) return -1; @@ -191,9 +188,6 @@ CMP(1, "CANrxSize") return can.rxSize(param->CANrxSize)?1:-1; CMP(1, "SerialBaud") pc.baud(param->SerialBaud); CMP(1, "SerialTx") return (pc.txBufferSetSize(param->SerialTxSize) == 0)?1:-1; - CMP(1, "XbeeBaud") xbeeRelay.baud(param->XbeeBaud); - CMP(1, "XbeeTxSize") return (xbeeRelay.txSize(param->XbeeTxSize))?1:-1; - CMP(1, "XbeeRxSize") return (xbeeRelay.rxSize(param->XbeeRxSize))?1:-1; return 1; } @@ -357,6 +351,8 @@ } else { if (!can.rxRead(msg)) return false; } + xbee.receive(msg); + // Redirect global car reset if (msg.id == GLOBAL_CAR_RESET_RX_ID) msg.id = RESETCLEAR_RX_ID; @@ -369,8 +365,8 @@ } CAN_FAIL - - // Clear non-volatile fault flags, then reset microcontroller + + // Clear non-volatile fault flags, then reset microcontroller case (RESETCLEAR_RX_ID): if (msg.len == 0) { // Length must = 0 FreezeFrame::clearError(); @@ -378,30 +374,13 @@ CAN_SUCCESS } CAN_FAIL - - // Artificially capture a freeze frame - case (CAPTURE_RX_ID): - if (msg.len == 0) { // Length must = 0 - if (!FreezeFrame::getError()) { // Only allow capture if freeze frame from the last error was read - if (FreezeFrame::writeFrame()) { // Capture the RAM contents to flash - CAN_SUCCESS - } - } - } - CAN_FAIL - - // Clear fault conditions + + // Clear fault conditions case (CLEAR_RX_ID): - if (msg.len == 1) { // One data byte - if (msg.data[0] == 0) { // Clear only freeze frame error if = 0 - FreezeFrame::clearError(); // Clear non-volatile freeze frame marker - CAN_SUCCESS - } - if (msg.data[0] == 1) { // Clear everything if = 1 - runTime::clearFaults(); - op->faultCode = 0; - CAN_SUCCESS - } + if (msg.len == 0) { // No data byte + runTime::clearFaults(); + op->faultCode = 0; + CAN_SUCCESS } CAN_FAIL @@ -427,9 +406,15 @@ // RAM and flash profile manipulations case (PROFILE_RX_ID): if (msg.len == 2*sizeof(char)) { // 2 command bytes + int index=-2; + for (int i = 0; i < NUM_STORED_PROFILES+1; i++) { // Get the profile number + if (msg.data[1] == (1<<i)) index=i; + } + if (msg.data[1] == 1<<6) index=-1; // Special case for Freeze + if (index == -2) { // Not matched to anything, fail + CAN_FAIL + } if (msg.data[0] == 0) { // Load profile from a flash location to RAM - int index = msg.data[1]; // Second byte contains profile index - if (msg.data[1] == 0xff) index = -1; // If freeze (special case) if (Profile::loadProfile(index)) { // Attempt to load (copy flash to RAM) op->profileIndex = Profile::usingProfile(); // Change the currently loaded profile marker op->profileModded = false; // Mark it as a fresh, unmodified profile @@ -437,8 +422,6 @@ } } if (msg.data[0] == 1) { // Write profile to flash from RAM - int index = msg.data[1]; // Get which slot to write to from message - if (msg.data[1] == 0xff) index = -1; // If freeze (special case) bool s = Profile::saveProfile(index); // Write profile to flash slot if (s) { op->profileIndex = Profile::usingProfile(); // Change the currently loaded profile marker @@ -449,30 +432,30 @@ } CAN_FAIL - case FAN_CONTROL_ID: + case FAN_CONTROL_RX_ID: if (msg.len != 2*sizeof(float)) return false; REFRESH_TIMEOUT(FANS) op->dcdc.request.fan1 = *((float*)((void*)(&msg.data[0]))); op->dcdc.request.fan2 = *((float*)((void*)(&msg.data[4]))); return true; - case PUMP_CONTROL_ID: + case PUMP_CONTROL_RX_ID: if (msg.len != 2*sizeof(float)) return false; REFRESH_TIMEOUT(PUMPS) op->dcdc.request.pump1 = *((float*)((void*)(&msg.data[0]))); op->dcdc.request.pump2 = *((float*)((void*)(&msg.data[4]))); return true; - case AMS_MODE_ID: + case AMS_MODE_RX_ID: if (msg.len != sizeof(char)) return false; REFRESH_TIMEOUT(AIRS_CLOSED) - if (msg.data[0] & 1<<2) { // AIRs closed? + if (msg.data[0] & 1<<3) { // AIRs closed? op->signals |= AIRS_CLOSED; } else { op->signals &= ~AIRS_CLOSED; } return true; - case CHARGER_ERR_ID: + case CHARGER_ERR_RX_ID: REFRESH_TIMEOUT(CHARGER_DET) op->signals |= CHARGER_DET; return true; @@ -491,6 +474,7 @@ CAN_CHANGE(dcdcStopDelay, PROFILE_DCDCSTOPDELAY_RX_ID ) CAN_CHANGE(dcdc_taps, PROFILE_DCDC_TAPS_RX_ID ) CAN_CHANGE(imdStartDelay, PROFILE_IMDSTARTDELAY_RX_ID ) + CAN_CHANGE(amsStartDelay, PROFILE_AMSSTARTDELAY_RX_ID ) CAN_CHANGE(internalOverTemp, PROFILE_INTERNALOVERTEMP_RX_ID ) CAN_CHANGE(CANnoAck, PROFILE_CANNOACK_RX_ID ) CAN_CHANGE(extendedSerial, PROFILE_EXTENDSERIAL_RX_ID ) @@ -498,9 +482,6 @@ CAN_CHANGE(CANrxSize, PROFILE_CANRXSIZE_RX_ID ) CAN_CHANGE(SerialBaud, PROFILE_SERIALBAUD_RX_ID ) CAN_CHANGE(SerialTxSize, PROFILE_SERIALTXSIZE_RX_ID ) - CAN_CHANGE(XbeeBaud, PROFILE_XBEEBAUD_RX_ID ) - CAN_CHANGE(XbeeTxSize, PROFILE_XBEETXSIZE_RX_ID ) - CAN_CHANGE(XbeeRxSize, PROFILE_XBEERXSIZE_RX_ID ) if (!parsed) return false; @@ -511,13 +492,11 @@ if (msg.id == PROFILE_CANRXSIZE_RX_ID ) return can.rxSize(param->CANrxSize)?1:-1; if (msg.id == PROFILE_SERIALBAUD_RX_ID ) pc.baud(param->SerialBaud); if (msg.id == PROFILE_SERIALTXSIZE_RX_ID ) return (pc.txBufferSetSize(param->SerialTxSize) == 0)?1:-1; - if (msg.id == PROFILE_XBEEBAUD_RX_ID ) xbeeRelay.baud(param->XbeeBaud); - if (msg.id == PROFILE_XBEETXSIZE_RX_ID ) return (xbeeRelay.txSize(param->XbeeTxSize))?1:-1; - if (msg.id == PROFILE_XBEERXSIZE_RX_ID ) return (xbeeRelay.rxSize(param->XbeeRxSize))?1:-1; return true; } // Check for incoming messages from the xbees, relay them to the CAN function and send them out on the bus +/* bool receiveMsgXbee() { CANMessage msg; @@ -526,14 +505,13 @@ serviceCAN(&msg); // Send it into the local serviceCAN routine return true; } else return false; -} - +}*/ void inCommands::thread_getInputs(void const* args) { while(1) { serviceCAN(0); - receiveMsgXbee(); + //receiveMsgXbee(); int ret = serviceSerial(); if (ret == -1) tempData.parseGoodChar = 'x';