diff --git a/Software/PYLON-CAN.cpp b/Software/PYLON-CAN.cpp index 2c5d0d13..363a7d78 100644 --- a/Software/PYLON-CAN.cpp +++ b/Software/PYLON-CAN.cpp @@ -19,7 +19,45 @@ CAN_frame_t PYLON_4290 = {.FIR = {.B = {.DLC = 8,.FF = CAN_frame_ext,}},.MsgID = void update_values_can_pylon() { //This function maps all the values fetched from battery CAN to the correct CAN messages - //TODO, add mappings + //There are more mappings that could be added, but this should be enough to use as a starting point + + //Charge / Discharge allowed + PYLON_4280.data.u8[0] = 0; + PYLON_4280.data.u8[1] = 0; + PYLON_4280.data.u8[2] = 0; + PYLON_4280.data.u8[3] = 0; + + //Voltage (370.0) + PYLON_4210.data.u8[0] = (battery_voltage >> 8); + PYLON_4210.data.u8[1] = (battery_voltage & 0x00FF); + + //Current (TODO, SIGNED? Or looks like it could be just offset, in that case the below line wont work) + PYLON_4210.data.u8[2] = (battery_current >> 8); + PYLON_4210.data.u8[3] = (battery_current & 0x00FF); + + //SOC (100.00%) + PYLON_4210.data.u8[6] = (SOC*0.01); //Remove decimals + + //StateOfHealth (100.00%) + PYLON_4210.data.u8[7] = (StateOfHealth*0.01); + + //Minvoltage (eg 300.0V = 3000 , 16bits long) Charge Cutoff Voltage + PYLON_4220.data.u8[0] = (min_volt_pylon_can >> 8); + PYLON_4220.data.u8[1] = (min_volt_pylon_can & 0x00FF); + + //Maxvoltage (eg 400.0V = 4000 , 16bits long) Discharge Cutoff Voltage + PYLON_4220.data.u8[2] = (max_volt_pylon_can >> 8); + PYLON_4220.data.u8[3] = (max_volt_pylon_can & 0x00FF); + + //In case we run into any errors/faults, we can set charge / discharge forbidden + if(bms_status == FAULT) + { + PYLON_4280.data.u8[0] = 0xAA; + PYLON_4280.data.u8[1] = 0xAA; + PYLON_4280.data.u8[2] = 0xAA; + PYLON_4280.data.u8[3] = 0xAA; + } + } void receive_can_pylon(CAN_frame_t rx_frame) diff --git a/Software/Software.ino b/Software/Software.ino index 9144c0fc..07fb4bb7 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -52,6 +52,9 @@ uint16_t min_volt_byd_can = min_voltage; uint16_t max_volt_byd_can = max_voltage; uint16_t min_volt_solax_can = min_voltage; uint16_t max_volt_solax_can = max_voltage; +uint16_t min_volt_pylon_can = min_voltage; +uint16_t max_volt_pylon_can = max_voltage; + uint16_t battery_voltage = 3700; uint16_t battery_current = 0; uint16_t SOC = 5000; //SOC 0-100.00% //Updates later on from CAN