Cell voltages fork (SoC)

Dependencies:   CUER_CAN CUER_DS1820 LTC2943 LTC6804 mbed PowerControl

Revision:
17:94dd9a0d3870
Parent:
16:b2ef68c9a4fd
Child:
18:521ffdd724f3
--- a/CANParserBMU.cpp	Sun Jul 02 11:39:39 2017 +0000
+++ b/CANParserBMU.cpp	Sun Jul 02 13:35:18 2017 +0000
@@ -2,6 +2,7 @@
 #include "CANParserBMU.h"
 #include "mbed.h"
 #include "Data_Types_BMU.h"
+#include "CAN_IDs.h"
 
 
 using namespace CAN_IDs;
@@ -44,6 +45,7 @@
 {
     individual_temperature probe_reading;
     CAN_Data decode;
+    long fullID = 0;
     
     decode.importCANData(msg);
     short shortTemp = decode.get_16(3);
@@ -51,9 +53,10 @@
     
     for(int i = 1; i <=6; i++)
     {
-        probe_reading.ROMID[i] = decode.get_u8(i-1);    
+        probe_reading.ROMID[i] = decode.get_u8(i-1);
+        fullID += (probe_reading.ROMID[i] << (8 * (i-1))); //Bit order not particularly important    
     }
-    
+    probe_reading.ID = fullID;
     return probe_reading;
 }
 
@@ -75,6 +78,26 @@
 
     return msg;
 }
+/**
+* This function will properly fill the appropriate entry in an array of voltage
+* readings of the form CMU_voltage voltage[NO_CMUS]. Uses the msg ID and the standard
+* 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])
+{
+    CAN_Data voltData;
+    voltData.importCANData(msg);
+    int repeating_length = NO_READINGS_PER_CMU /4 + 1; 
+    int offset = msg.id - BMS_BASE_ID;
+    
+    int cellsubset = ((offset-1) % repeating_length) - 1; //Which set of 4 voltages within the CMU
+    int CMU_number = (offset-1) / repeating_length;
+    for(int i = 0; i < 4; i++)
+    {
+        readings[CMU_number].voltages[cellsubset*4 + i] = voltData.get_u16(i);
+    } 
+} 
 
 CANMessage createPackSOC(float SOC, float percentageCharge)
 {
@@ -229,6 +252,5 @@
             msg.data[7-i] = convH.b[i];
         }
     }
-
 }