System Management code
Dependencies: mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP
Fork of SystemManagement by
Diff: inCommands/inCommands.cpp
- Revision:
- 36:0afc0fc8f86b
- Parent:
- 34:18bcf276d3bf
- Child:
- 38:8efacce315ae
--- a/inCommands/inCommands.cpp Wed Jan 07 03:36:43 2015 +0000 +++ b/inCommands/inCommands.cpp Thu Jan 22 07:58:51 2015 +0000 @@ -32,9 +32,9 @@ else dcdc.set(0); break; - case AMS_RELAYS_ID: + case AMS_MODE_ID: if (msg.len != sizeof(char)) break; - if ((msg.data[0] & (1<<3|1<<4|1<<5)) == (1<<3|1<<4|1<<5)) { // AIRs closed? 1<<3=posAIR, 1<<4=negAIR, 1<<5=tractiveEnable signal + if (msg.data[0] & 1<<2) { // AIRs closed? CANdata.airsClosed = true; dcdc.set(1); } else { @@ -43,12 +43,12 @@ } break; - case GLVBAT_CLEARSOC_ID: + case GLVBAT_SETSOC_ID: if (msg.len != sizeof(float)) break; glvBat.resetToSOC(*((float*)(&msg.data[0]))); break; - case GLVBAT_CLEARAH_ID: + case GLVBAT_SETAH_ID: if (msg.len != sizeof(float)) break; glvBat.resetToAh(*((float*)(&msg.data[0]))); break; @@ -80,14 +80,16 @@ // Compare string to a word in the serial input, shorter to type #define CMP(w, string) if (!strcasecmp(word[w-1], string)) -static char word[3][RX_SIZE+1]; + // Serial input int inCommands::serviceSerial() { + static int end = 0; // End of string position - static int end = 0; // End of string position - int c = pc.getcNb(); // Get char from RX buffer (returns an int) + int c=0; + if (pc.readable()) c = pc.getc(); if (c == -1) return -2; // Invalid char, no char available + char b = c; // Casted to char type bool process = false; // Is string complete (ready to parse)? @@ -101,22 +103,20 @@ tempData.inputStr[end] = 0; // Erase char } else if (b > 31 && b < 127) { // New valid displayable char - tempData.inputStr[end] = b; // Add to buffer - end++; // Increment end + tempData.inputStr[end++] = b; // Add to buffer tempData.inputStr[end] = 0; // Add null terminator if (end >= RX_SIZE) { end = 0; // Reset end location process = true; // Flag for processing } } - // Continue to parsing section only if flagged as complete and string not empty - if (!process || strlen(tempData.inputStr) == 0) return 0; - + if (!process || strlen((char*)tempData.inputStr) == 0) return 0; + + static char word[3][RX_SIZE+1]; // Hold 3 words int pieces = sscanf(tempData.inputStr, "%s %s %s", word[0], word[1], word[2]); // Populate words tempData.inputStr[0] = 0; // Empty the string displayed on screen - - char *next; // Used by strtod and strtoul + char *next; // Used by strtof and strtoul // One word commands if (pieces == 1) { @@ -125,8 +125,8 @@ NVIC_SystemReset(); return 1; } - // Two word commands } + // Two word commands if (pieces == 2) { // Manual DC-DC on/off control CMP(1, "dcdc") { @@ -170,9 +170,10 @@ if (*next == 0) { if (glvBat.changeCapacity(cap)) return 1; } - return -1; + return -1; } } + // Three word commands if (pieces == 3) { // Fan Duty CMP(1, "Fan") { @@ -203,4 +204,17 @@ } } return -1; +} + +void inCommands::thread_getInputs(void const* args) +{ + while(1) { + inCommands::serviceCAN(); + inCommands::receiveMsgXbee(); + + int ret = inCommands::serviceSerial(); + if (ret == -1) tempData.parseGoodChar = 'x'; + if (ret == 1) tempData.parseGoodChar = 251; + osSignalSet((osThreadId)(tempData.wdtThreadId), 1<<2); // Signal watchdog thread + } } \ No newline at end of file