-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Your Name
committed
May 8, 2024
1 parent
e1a5a7f
commit 3c407f5
Showing
5 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* CustomBMS.hpp | ||
* | ||
* Created on: April 4, 2024 | ||
* Author: Matthew Shen & Yash Bhat | ||
*/ | ||
|
||
#ifndef SOLARGATORSBSP_DATAMODULES_INC_CUSTOMBMS_HPP_ | ||
#define SOLARGATORSBSP_DATAMODULES_INC_CUSTOMBMS_HPP_ | ||
|
||
#include <DataModule.hpp> | ||
|
||
namespace SolarGators::DataModules { | ||
|
||
class CustomBMSRx0 final: public DataModule { | ||
public: | ||
CustomBMSRx0(uint32_t can_id); | ||
~CustomBMSRx0() {}; | ||
|
||
void ToByteArray(uint8_t* buff) const; | ||
void FromByteArray(uint8_t* buff); | ||
#ifdef IS_TELEMETRY | ||
void PostTelemetry(PythonScripts* scripts); | ||
#endif | ||
|
||
uint16_t GetPackVoltage() const; | ||
uint16_t GetAvgCellVoltage() const; | ||
uint16_t GetHighCellVoltage() const; | ||
uint16_t GetLowCellVoltage() const; | ||
|
||
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_; | ||
}; | ||
|
||
class CustomBMSRx1 final: public DataModule { | ||
public: | ||
CustomBMSRx1(uint32_t can_id); | ||
~CustomBMSRx1() {}; | ||
|
||
void ToByteArray(uint8_t* buff) const; | ||
void FromByteArray(uint8_t* buff); | ||
#ifdef IS_TELEMETRY | ||
void PostTelemetry(PythonScripts* scripts); | ||
#endif | ||
|
||
int16_t GetPackCurrent() const; | ||
int16_t GetIntegralCurrent() const; | ||
int16_t GetAveragePower() const; | ||
uint8_t GetHighCellVoltageID() const; | ||
uint8_t GetLowCellVoltageID() const; | ||
|
||
static constexpr uint8_t Size = 8; | ||
protected: | ||
int16_t pack_current_; | ||
int16_t integral_current_; | ||
int16_t average_power_; | ||
uint8_t high_cell_voltage_id_; | ||
uint8_t low_cell_voltage_id_; | ||
}; | ||
|
||
class CustomBMSRx2 final: public DataModule { | ||
public: | ||
CustomBMSRx2(uint32_t can_id); | ||
~CustomBMSRx2() {}; | ||
|
||
void ToByteArray(uint8_t* buff) const; | ||
void FromByteArray(uint8_t* buff); | ||
#ifdef IS_TELEMETRY | ||
void PostTelemetry(PythonScripts* scripts); | ||
#endif | ||
|
||
uint16_t GetHighTemp() const; | ||
uint16_t GetLowTemp() const; | ||
uint8_t GetHighTempCellID() const; | ||
uint8_t GetLowTempCellID() const; | ||
uint16_t GetInternalTemp() const; | ||
|
||
static constexpr uint8_t Size = 8; | ||
protected: | ||
uint16_t high_temp_; | ||
uint16_t low_temp_; | ||
uint8_t high_temp_cell_id_; | ||
uint8_t low_temp_cell_id_; | ||
uint16_t internal_temp_; | ||
}; | ||
|
||
class CustomBMSRx3 final: public DataModule { | ||
public: | ||
CustomBMSRx3(uint32_t can_id); | ||
~CustomBMSRx3() {}; | ||
|
||
void ToByteArray(uint8_t* buff) const; | ||
void FromByteArray(uint8_t* buff); | ||
#ifdef IS_TELEMETRY | ||
void PostTelemetry(PythonScripts* scripts); | ||
#endif | ||
|
||
uint8_t GetFaultFlags() const; | ||
bool GetLowCellVoltageFault() const; | ||
bool GetHighCellVoltageFault() const; | ||
bool GetHighDischargeCurrentFault() const; | ||
bool GetHighChargeCurrentFault() const; | ||
bool GetHighTempFault() const; | ||
bool GetThermistorDisconnectedFault() const; | ||
bool GetCurrentSensorDisconnectedFault() const; | ||
bool GetKillSwitchPressedFault() const; | ||
uint8_t GetStatusFlags() const; | ||
bool GetContactorStatus(uint8_t contactor) const; | ||
bool GetContactorSource() const; | ||
bool GetBalancingActive() const; | ||
uint16_t GetPackSoC() const; | ||
|
||
static constexpr uint8_t Size = 5; | ||
protected: | ||
uint8_t fault_flags_; | ||
uint8_t status_flags_; | ||
uint16_t pack_soc_; | ||
}; | ||
|
||
// Additional classes for BMSSecondaryFrame0 to BMSSecondaryFrame3 can be defined here following the same pattern. | ||
|
||
} | ||
|
||
#endif /* CUSTOMBMS_HPP_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* CustomBMS.cpp | ||
* | ||
* Created on: April 4, 2024 | ||
* Author: Matthew Shen & Yash Bhat | ||
*/ | ||
|
||
#include "CustomBMS.hpp" | ||
|
||
|
||
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; | ||
buff[2] = avg_cell_voltage_ >> 8; | ||
buff[3] = avg_cell_voltage_ & 0xFF; | ||
buff[4] = high_cell_voltage_ >> 8; | ||
buff[5] = high_cell_voltage_ & 0xFF; | ||
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]; | ||
// 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]; | ||
} | ||
|
||
uint16_t CustomBMSRx0::GetPackVoltage() const { | ||
return pack_voltage_; | ||
} | ||
|
||
uint16_t CustomBMSRx0::GetAvgCellVoltage() const { | ||
return avg_cell_voltage_; | ||
} | ||
|
||
uint16_t CustomBMSRx0::GetHighCellVoltage() const { | ||
return high_cell_voltage_; | ||
} | ||
|
||
uint16_t CustomBMSRx0::GetLowCellVoltage() const { | ||
return low_cell_voltage_; | ||
} | ||
|
||
#ifdef IS_TELEMETRY | ||
void CustomBMSRx0::PostTelemetry(PythonScripts* scripts){ | ||
PythonHttp http; | ||
http.init(); | ||
http.addData("low_cell_volt_", GetLowCellVoltage()); | ||
http.addData("high_cell_volt_", GetHighCellVoltage()); | ||
http.addData("avg_cell_volt_", GetAvgCellVoltage()); | ||
http.addData("pack_sum_volt_", GetPackVoltage()); | ||
scripts->send("bms/rx0", http.getParameters()); | ||
http.flush(); | ||
} | ||
#endif | ||
// BMSFrame1 Implementation | ||
CustomBMSRx1::CustomBMSRx1(uint32_t can_id) : DataModule(can_id, 0, this->Size, 0, false) {} | ||
|
||
void CustomBMSRx1::ToByteArray(uint8_t* buff) const { | ||
buff[0] = pack_current_ >> 8; | ||
buff[1] = pack_current_ & 0xFF; | ||
buff[2] = integral_current_ >> 8; | ||
buff[3] = integral_current_ & 0xFF; | ||
buff[4] = average_power_ >> 8; | ||
buff[5] = average_power_ & 0xFF; | ||
buff[6] = high_cell_voltage_id_; | ||
buff[7] = low_cell_voltage_id_; | ||
} | ||
|
||
void CustomBMSRx1::FromByteArray(uint8_t* buff) { | ||
pack_current_ = (static_cast<int16_t>(buff[1]) << 8) | buff[0]; | ||
integral_current_ = (static_cast<int16_t>(buff[3]) << 8) | buff[2]; | ||
average_power_ = (static_cast<int16_t>(buff[5]) << 8) | buff[4]; | ||
high_cell_voltage_id_ = buff[6]; | ||
low_cell_voltage_id_ = buff[7]; | ||
} | ||
|
||
int16_t CustomBMSRx1::GetPackCurrent() const { | ||
//Current is in A * 1e-2 | ||
return pack_current_; | ||
} | ||
|
||
int16_t CustomBMSRx1::GetIntegralCurrent() const { | ||
//Charge is in uAh | ||
return integral_current_; | ||
} | ||
|
||
int16_t CustomBMSRx1::GetAveragePower() const { | ||
//Power in W | ||
return average_power_; | ||
} | ||
|
||
uint8_t CustomBMSRx1::GetHighCellVoltageID() const { | ||
return high_cell_voltage_id_; | ||
} | ||
|
||
uint8_t CustomBMSRx1::GetLowCellVoltageID() const { | ||
return low_cell_voltage_id_; | ||
} | ||
#ifdef IS_TELEMETRY | ||
void CustomBMSRx1::PostTelemetry(PythonScripts* scripts){ | ||
PythonHttp http; | ||
http.init(); | ||
http.addData("pack_current_", GetPackCurrent()); | ||
scripts->send("bms/rx2", http.getParameters()); | ||
http.flush(); | ||
} | ||
} | ||
#endif |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters