mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 02:09:30 +02:00
Merge pull request #1444 from freddanastrom/imporvement/BYD-Atto3-send-voltage
BYD Atto 3: Send correct data in 441 message
This commit is contained in:
commit
94cd2a3309
2 changed files with 23 additions and 4 deletions
|
@ -136,6 +136,16 @@ uint16_t estimateSOCstandard(uint16_t packVoltage) { // Linear interpolation fu
|
|||
return 0; // Default return for safety, should never reach here
|
||||
}
|
||||
|
||||
uint8_t compute441Checksum(const uint8_t* u8) // Computes the 441 checksum byte
|
||||
{
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 7; ++i) {
|
||||
sum += u8[i];
|
||||
}
|
||||
uint8_t lsb = static_cast<uint8_t>(sum & 0xFF);
|
||||
return static_cast<uint8_t>(~lsb & 0xFF);
|
||||
}
|
||||
|
||||
void BydAttoBattery::
|
||||
update_values() { //This function maps all the values fetched via CAN to the correct parameters used for modbus
|
||||
|
||||
|
@ -383,6 +393,7 @@ void BydAttoBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
|
|||
datalayer_battery->status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
battery_voltage = ((rx_frame.data.u8[1] & 0x0F) << 8) | rx_frame.data.u8[0];
|
||||
//battery_temperature_something = rx_frame.data.u8[7] - 40; resides in frame 7
|
||||
BMS_voltage_available = true;
|
||||
break;
|
||||
case 0x445:
|
||||
datalayer_battery->status.CAN_battery_still_alive = CAN_STILL_ALIVE;
|
||||
|
@ -532,10 +543,17 @@ void BydAttoBattery::transmit_can(unsigned long currentMillis) {
|
|||
}
|
||||
|
||||
if (counter_100ms > 3) {
|
||||
ATTO_3_441.data.u8[4] = 0x9D;
|
||||
ATTO_3_441.data.u8[5] = 0x01;
|
||||
ATTO_3_441.data.u8[6] = 0xFF;
|
||||
ATTO_3_441.data.u8[7] = 0xF5;
|
||||
if (BMS_voltage_available) { // Transmit battery voltage back to BMS when confirmed it's available, this closes the contactors
|
||||
ATTO_3_441.data.u8[4] = (uint8_t)(battery_voltage - 1);
|
||||
ATTO_3_441.data.u8[5] = ((battery_voltage - 1) >> 8);
|
||||
ATTO_3_441.data.u8[6] = 0xFF;
|
||||
ATTO_3_441.data.u8[7] = compute441Checksum(ATTO_3_441.data.u8);
|
||||
} else {
|
||||
ATTO_3_441.data.u8[4] = 0x0C;
|
||||
ATTO_3_441.data.u8[5] = 0x00;
|
||||
ATTO_3_441.data.u8[6] = 0xFF;
|
||||
ATTO_3_441.data.u8[7] = 0x87;
|
||||
}
|
||||
}
|
||||
|
||||
transmit_can_frame(&ATTO_3_441);
|
||||
|
|
|
@ -98,6 +98,7 @@ class BydAttoBattery : public CanBattery {
|
|||
unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was send
|
||||
unsigned long previousMillis200 = 0; // will store last time a 200ms CAN Message was send
|
||||
bool SOC_method = false;
|
||||
bool BMS_voltage_available = false;
|
||||
uint8_t counter_50ms = 0;
|
||||
uint8_t counter_100ms = 0;
|
||||
uint8_t frame6_counter = 0xB;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue