Code to run on the charger board (used to charge the car from the mains).

Dependencies:   mbed CUER_CAN

Revision:
3:a7626dffb64a
Parent:
1:0c77e20b4d4c
Child:
5:756fae795d37
--- a/CANParserCharger.cpp	Sun Jul 23 21:57:34 2017 +0000
+++ b/CANParserCharger.cpp	Thu Jul 27 21:00:52 2017 +0000
@@ -6,26 +6,22 @@
 
 using namespace CAN_IDs;
 
-
-
-
-
 void get_charger_control_info(CANMessage msg, float &_voltage_error, float &_temp_margin, float &_discharge_error, float &_pack_capacity) {
     CAN_Data data;
     data.importCANData(msg);
     
-    _voltage_error = data.get_u16(0)*1.0;
+    _voltage_error = (float) data.get_u16(0);
     _temp_margin = data.get_u16(1) /10.0;
-    _discharge_error = data.get_u16(2)*1.0;
-    _pack_capacity = data.get_u16(3)*1.0;
+    _discharge_error = (float) data.get_u16(2);
+    _pack_capacity = (float) data.get_u16(3);
 }
 
 void get_max_min_voltage(CANMessage msg, float &_min_cell_voltage, float &_max_cell_voltage) {
     CAN_Data data;
     data.importCANData(msg);
     
-    _min_cell_voltage = data.get_u16(0)*1.0;
-    _max_cell_voltage = data.get_u16(1)*1.0;
+    _min_cell_voltage = (float) data.get_u16(0);
+    _max_cell_voltage = (float) data.get_u16(1);
 }    
 
 void get_battery_status(CANMessage msg, bool &error) { //note using extended battery pack status
@@ -82,4 +78,19 @@
     }
     
     return msg;
+}
+
+CANMessage generate_charging_finished_msg() {
+    CANMessage msg;
+    msg.len = 8;
+    msg.id = BMS_BASE_ID + EEPROM_RESET_ID;
+    
+    CAN_Data data;
+    data.setLowerFloat(42); //42 is the pack capacity in Ah
+    data.setUpperFloat(100); //100% as fully charged
+    
+    for(int i=0; i<8; i++) {
+        msg.data[i] = data.get_u8(i);
+    }
+    return msg;    
 }
\ No newline at end of file