Cell voltages fork (SoC)

Dependencies:   CUER_CAN CUER_DS1820 LTC2943 LTC6804 mbed PowerControl

Revision:
18:521ffdd724f3
Parent:
17:94dd9a0d3870
Child:
23:a1af4439c1fc
--- a/CANParserBMU.cpp	Sun Jul 02 13:35:18 2017 +0000
+++ b/CANParserBMU.cpp	Sun Jul 02 15:06:51 2017 +0000
@@ -45,7 +45,7 @@
 {
     individual_temperature probe_reading;
     CAN_Data decode;
-    long fullID = 0;
+    unsigned long fullID = 0;
     
     decode.importCANData(msg);
     short shortTemp = decode.get_16(3);
@@ -84,12 +84,14 @@
 * meanings of them as decided in the transmit data function (modified Tritium specs).
 * Function must only be called when the msg has a valid ID for voltage!
 */
-void decodeVoltageTelemetry(CANMessage msg, CMU_voltage readings[NO_CMUS])
+bool decodeVoltageTelemetry(CANMessage msg, CMU_voltage readings[NO_CMUS])
 {
     CAN_Data voltData;
     voltData.importCANData(msg);
     int repeating_length = NO_READINGS_PER_CMU /4 + 1; 
     int offset = msg.id - BMS_BASE_ID;
+    if(offset <= 0 || offset >= 0x100 || offset % 4 == 1)
+        return false;  
     
     int cellsubset = ((offset-1) % repeating_length) - 1; //Which set of 4 voltages within the CMU
     int CMU_number = (offset-1) / repeating_length;
@@ -97,6 +99,7 @@
     {
         readings[CMU_number].voltages[cellsubset*4 + i] = voltData.get_u16(i);
     } 
+    return true;
 } 
 
 CANMessage createPackSOC(float SOC, float percentageCharge)