Skip to content

Commit

Permalink
changes made to bms logging
Browse files Browse the repository at this point in the history
  • Loading branch information
yashtheboss committed Jul 14, 2024
1 parent 378558a commit 6b44c60
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions car-bsp/DataModules/inc/CustomBMS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class CustomBMSRx0 final: public DataModule {

static constexpr uint8_t Size = 8;
protected:
uint16_t pack_voltage_;
uint16_t avg_cell_voltage_;
uint16_t high_cell_voltage_;
uint16_t low_cell_voltage_;
float pack_voltage_;
float avg_cell_voltage_;
float high_cell_voltage_;
float low_cell_voltage_;
};

class CustomBMSRx1 final: public DataModule {
Expand Down
5 changes: 3 additions & 2 deletions car-bsp/DataModules/inc/DataModuleInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ static constexpr uint32_t BMS_RX4_MSG_ID = 0x6B4;
static constexpr uint32_t BMS_RX5_MSG_ID = 0x6B5;

static constexpr uint32_t CBMS_RX0_MSG_ID = 0x6C0;
static constexpr uint32_t CBMS_RX1_MSG_ID = 0x6C1;
static constexpr uint32_t CBMS_RX2_MSG_ID = 0x6C2;
// swapping the below can id's because current and voltage are switched
static constexpr uint32_t CBMS_RX1_MSG_ID = 0x6C2;
static constexpr uint32_t CBMS_RX2_MSG_ID = 0x6C1;
static constexpr uint32_t CBMS_RX3_MSG_ID = 0x6C3;

// Mitsuba
Expand Down
12 changes: 6 additions & 6 deletions car-bsp/DataModules/src/CustomBMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace SolarGators::DataModules {

// BMSFrame0 Implementation
CustomBMSRx0::CustomBMSRx0(uint32_t can_id) : DataModule(can_id, 0, this->Size, 0, false) {}

/*
void CustomBMSRx0::ToByteArray(uint8_t* buff) const {
buff[0] = pack_voltage_ >> 8;
buff[1] = pack_voltage_ & 0xFF;
Expand All @@ -23,14 +23,14 @@ void CustomBMSRx0::ToByteArray(uint8_t* buff) const {
buff[6] = low_cell_voltage_ >> 8;
buff[7] = low_cell_voltage_ & 0xFF;
}

*/
void CustomBMSRx0::FromByteArray(uint8_t* buff) {
// Voltage is in V * 1e-1
pack_voltage_ = (static_cast<uint16_t>(buff[1]) << 8) | buff[0];
pack_voltage_ = (float) ((buff[1]) << 8 | buff[0]) / 10;
// Voltage in mV for remaining values
avg_cell_voltage_ = (static_cast<uint16_t>(buff[3]) << 8) | buff[2];
high_cell_voltage_ = (static_cast<uint16_t>(buff[5]) << 8) | buff[4];
low_cell_voltage_ = (static_cast<uint16_t>(buff[7]) << 8) | buff[6];
avg_cell_voltage_ = (float) ((buff[3]) << 8 | buff[2]) / 1000;
high_cell_voltage_ = (float) ((buff[5]) << 8 | buff[4]) / 1000;
low_cell_voltage_ = (float) ((buff[7]) << 8 | buff[6]) / 1000;
}

uint16_t CustomBMSRx0::GetPackVoltage() const {
Expand Down

0 comments on commit 6b44c60

Please sign in to comment.