CUER / Mbed 2 deprecated BMS_BMUCore_Max

Dependencies:   CUER_CAN CUER_DS1820 LTC2943 LTC6804 mbed PowerControl

Revision:
37:fae62a2773a1
Parent:
36:1b23c0692f54
Child:
38:b1f5bfe38d70
diff -r 1b23c0692f54 -r fae62a2773a1 main.cpp
--- a/main.cpp	Wed Jul 19 20:39:36 2017 +0000
+++ b/main.cpp	Sat Jul 22 10:45:41 2017 +0000
@@ -158,7 +158,6 @@
     can.write(msg);
     wait(0.1); //WAITS ABSOLUTELY NECESSARY! values may be changed. Limit to how fast msg can be sent
     // Battery voltage and current
-    // @TODO add the voltage
     msg = createBatteryVI(measurements.battery_voltage,measurements.battery_current);
     can.write(msg);
     if (DEBUG) printf("Sent Battery voltage %d and current %f with id %d \r\n",decodeBatteryVoltage(msg),decodeBatteryCurrent(msg),msg.id);
@@ -479,27 +478,34 @@
     
     LTC6804_acquireVoltage(cellvoltages);
     pack_voltage_extremes min_voltage;
-    pack_voltage_extremes max_voltage; //TODO do minmax voltage stuff
+    pack_voltage_extremes max_voltage;
     min_voltage.voltage = 65535; //largest 16 bit unsigned int
     max_voltage.voltage = 0;
     
+    bool last_CMU = false;
     //Sets voltage readings as well as max/min voltage values.
     for(int i=0; i<NO_CMUS; i++){
+       if (i == (NO_CMUS - 1)) last_CMU = true;
        for(int j=0; j < NO_READINGS_PER_CMU; j++){
              measurements.cell_voltages[i].voltages[j] =  cellvoltages[i][j]/ 10; //To get units of mV
              measurements.cell_voltages[i].CMU_number = i;
-             if(measurements.cell_voltages[i].voltages[j] < min_voltage.voltage)
+             
+             if(!(last_CMU && j >(NO_READINGS_PER_CMU - (NUM_MISSING_CELLS + 1)))) 
+             //the condition above is to account for the missing cells (not a complete set of 12) on the top CMU 
              {
-                min_voltage.voltage = measurements.cell_voltages[i].voltages[j];
-                min_voltage.CMU_number = i;
-                min_voltage.cell_number = j;   
-             }
-             else if(measurements.cell_voltages[i].voltages[j] > max_voltage.voltage)
-             {
-                max_voltage.voltage = measurements.cell_voltages[i].voltages[j];
-                max_voltage.CMU_number = i;
-                max_voltage.cell_number = j;   
-             }
+                 if(measurements.cell_voltages[i].voltages[j] < min_voltage.voltage)
+                 {
+                    min_voltage.voltage = measurements.cell_voltages[i].voltages[j];
+                    min_voltage.CMU_number = i;
+                    min_voltage.cell_number = j;   
+                 }
+                 else if(measurements.cell_voltages[i].voltages[j] > max_voltage.voltage)
+                 {
+                    max_voltage.voltage = measurements.cell_voltages[i].voltages[j];
+                    max_voltage.CMU_number = i;
+                    max_voltage.cell_number = j;   
+                 }
+             }    
        }   
     }
     measurements.max_cell_voltage = max_voltage;