Has base BMU code but sends dummy temperature and voltage readings to test CAN
Dependencies: CUER_CAN DS1820 LTC2943 LTC6804 mbed
Fork of BMS_BMUCore_Max by
Diff: CANParserBMU.cpp
- Revision:
- 1:51477fe4851b
- Parent:
- 0:0a5f554d2a16
- Child:
- 3:527790e4965a
--- a/CANParserBMU.cpp Thu Dec 22 15:11:29 2016 +0000 +++ b/CANParserBMU.cpp Fri Dec 30 16:01:59 2016 +0000 @@ -2,16 +2,17 @@ #include "CANParserBMU.h" #include "mbed.h" + using namespace CAN_IDs; CANMessage createTemperatureTelemetry(uint8_t ID, uint32_t CMUSerialNumber, uint16_t PCBTemperature, uint16_t cellTemperature) { CANMessage msg; msg.len = 8; - msg.id = BMS_BASE_ID + ID; // for voltage 0x601 - 0x6EF + msg.id = BMS_BASE_ID + ID; // for voltage 0x601 - 0x6EF CAN_Data data; - data.setLower_uLong(CMUSerialNumber); + data.setLower_uLong(CMUSerialNumber); data.set_u16(2, PCBTemperature); data.set_u16(3, cellTemperature); @@ -26,7 +27,7 @@ { CANMessage msg; msg.len = 8; - msg.id = BMS_BASE_ID + ID; // for voltage 0x601 - 0x6EF @TODO + msg.id = BMS_BASE_ID + ID; // for voltage 0x601 - 0x6EF @TODO CAN_Data data; data.set_u16(0, voltage[0]); @@ -41,7 +42,6 @@ return msg; } - CANMessage createPackSOC(float SOC, float percentageCharge) { CANMessage msg; @@ -50,10 +50,10 @@ CAN_Data data; data.setLowerFloat(SOC); data.setUpperFloat(percentageCharge); - for(int i=0; i<8; i++){ + for(int i=0; i<8; i++) { msg.data[i] = data.get_u8(i); } - + return msg; } @@ -62,59 +62,59 @@ // @TODO - check is this being used?? section 5.4 trituim BMU CAN data sheet CANMessage msg; msg.len = 8; - msg.id = BMS_BASE_ID + BATTERY_SOC_BASE_ID; - + msg.id = BMS_BASE_ID + BATTERY_SOC_BASE_ID; + CAN_Data data; data.setLowerFloat(SOC); data.setUpperFloat(percentageCharge); - for(int i=0; i<8; i++){ + for(int i=0; i<8; i++) { msg.data[i] = data.get_u8(i); } - + return msg; } -CANMessage createCellVoltageMAXMIN(uint16_t MAXMINVoltage[], uint8_t cellVoltageInformation[]) +CANMessage createCellVoltageMAXMIN(pack_voltage_extremes max_voltage, pack_voltage_extremes min_voltage) { //@TODO create a structure to store this data , so that the data is stored in the correct order CANMessage msg; msg.len = 8; - msg.id = BMS_BASE_ID + MAX_MIN_VOLTAGE; - + msg.id = BMS_BASE_ID + MAX_MIN_VOLTAGE; + CAN_Data data; - data.set_u16(0,MAXMINVoltage[0]); //Min voltage - data.set_u16(1,MAXMINVoltage[1]); //Max voltage - data.set_u8(4,cellVoltageInformation[0]); //CMU number of lowest cell - data.set_u8(5,cellVoltageInformation[1]); //Cell number in CMU with lowest voltage - data.set_u8(6,cellVoltageInformation[2]); //CMU number of maxiumum cell - data.set_u8(7,cellVoltageInformation[3]); //Cell number in CMU with highest voltage - - for(int i=0; i<8; i++){ + data.set_u16(0,min_voltage.voltage); //Min voltage + data.set_u16(1,max_voltage.voltage); //Max voltage + data.set_u8(4,min_voltage.CMU_number); //CMU number of lowest cell + data.set_u8(5,min_voltage.cell_number); //Cell number in CMU with lowest voltage + data.set_u8(6,min_voltage.CMU_number); //CMU number of maxiumum cell + data.set_u8(7,min_voltage.cell_number); //Cell number in CMU with highest voltage + + for(int i=0; i<8; i++) { msg.data[i] = data.get_u8(i); } - + return msg; } -CANMessage createCellTemperatureMAXMIN(uint16_t MAXMINTemperature[], uint8_t cellTemperatureInformation[]) +CANMessage createCellTemperatureMAXMIN(pack_temperature_extremes min_temperature, pack_temperature_extremes max_temperature) { //@TODO create a structure to store this data , so that the data is stored in the correct order CANMessage msg; msg.len = 8; - msg.id = BMS_BASE_ID + MAX_MIN_TEMPERATURE; - + msg.id = BMS_BASE_ID + MAX_MIN_TEMPERATURE; + CAN_Data data; - data.set_u16(0,MAXMINTemperature[0]); //Min temperature - data.set_u16(1,MAXMINTemperature[1]); //Max temperature - data.set_u8(4,cellTemperatureInformation[0]); //CMU number of lowest temperature cell + data.set_u16(0,min_temperature.temperature); //Min temperature + data.set_u16(1,max_temperature.temperature); //Max temperature + data.set_u8(4,min_temperature.CMU_number); //CMU number of lowest temperature cell data.set_u8(5,BLANK_DATA); //Dummy data - data.set_u8(6,cellTemperatureInformation[1]); //CMU number of maxiumum temperature cell - data.set_u8(7,BLANK_DATA); //Dummy data - - for(int i=0; i<8; i++){ + data.set_u8(6,max_temperature.CMU_number); //CMU number of maxiumum temperature cell + data.set_u8(7,BLANK_DATA); //Dummy data + + for(int i=0; i<8; i++) { msg.data[i] = data.get_u8(i); } - + return msg; } @@ -122,14 +122,14 @@ { CANMessage msg; msg.len = 8; - msg.id = BMS_BASE_ID + BATTERY_VI_ID; - + msg.id = BMS_BASE_ID + BATTERY_VI_ID; + CAN_Data data; //TODO check the below lines - // data.set_u32(0,batteryVoltage); + // data.set_u32(0,batteryVoltage); //data.set_u32(1,batteryCurrent); - - for(int i=0; i<8; i++){ + + for(int i=0; i<8; i++) { msg.data[i] = data.get_u8(i); } return msg; @@ -137,39 +137,39 @@ CANMessage createBatteryPackStatus(uint16_t voltageThreshold[], uint8_t statusFlag,uint8_t BMS_CMU_Count,uint16_t BMS_Firmware_Build) { - CANMessage msg; - msg.len = 8; - msg.id = BMS_BASE_ID + BATTERY_PACK_STATUS_ID; - - CAN_Data data; - data.set_u16(0,voltageThreshold[0]); - data.set_u16(1,voltageThreshold[1]); - data.set_16(3,BMS_Firmware_Build); - data.set_u8(4,statusFlag); - data.set_u8(5,BMS_CMU_Count); - - for(int i=0; i<8; i++){ - msg.data[i] = data.get_u8(i); - } - return msg; + CANMessage msg; + msg.len = 8; + msg.id = BMS_BASE_ID + BATTERY_PACK_STATUS_ID; + + CAN_Data data; + data.set_u16(0,voltageThreshold[0]); + data.set_u16(1,voltageThreshold[1]); + data.set_16(3,BMS_Firmware_Build); + data.set_u8(4,statusFlag); + data.set_u8(5,BMS_CMU_Count); + + for(int i=0; i<8; i++) { + msg.data[i] = data.get_u8(i); + } + return msg; } CANMessage createExtendedBatteryPackStatus(uint32_t status) { - CANMessage msg; - msg.len = 8; - msg.id = BMS_BASE_ID + BATTERY_STATUS_ID; - - CAN_Data data; - data.setLower_uLong(status); //@TODO see the data sheet for this - data.set_u8(4,0x00);//Hardware version random data @TODO check this - data.set_u8(5,0x00);//Model ID @TODO check this - data.set_u16(3,0x00); // Unused - - for(int i=0; i<8; i++){ - msg.data[i] = data.get_u8(i); - } - return msg; + CANMessage msg; + msg.len = 8; + msg.id = BMS_BASE_ID + BATTERY_STATUS_ID; + + CAN_Data data; + data.setLower_uLong(status); //@TODO see the data sheet for this + data.set_u8(4,0x00);//Hardware version random data @TODO check this + data.set_u8(5,0x00);//Model ID @TODO check this + data.set_u16(3,0x00); // Unused + + for(int i=0; i<8; i++) { + msg.data[i] = data.get_u8(i); + } + return msg; } void convertFloatFloat(float lower, float upper, CANMessage& msg, bool littleEndian) @@ -193,11 +193,11 @@ * i.e. convL/H is LSB --> MSB * output is MSB --> LSB */ - + msg.data[4-i] = convL.b[i]; msg.data[7-i] = convH.b[i]; } } - + }