From 3c407f52c1ba51cd5fc533b530082978c757ef3d Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 8 May 2024 22:06:19 +0100 Subject: [PATCH] verified working telemetry receive --- car-bsp/DataModules/inc/CustomBMS.hpp | 128 +++++++++++++++++++++ car-bsp/DataModules/inc/DataModuleInfo.hpp | 5 + car-bsp/DataModules/src/CustomBMS.cpp | 117 +++++++++++++++++++ telemetry-collector/src/.ma.swp | Bin 0 -> 1024 bytes telemetry-collector/src/main.cpp | 6 + 5 files changed, 256 insertions(+) create mode 100644 car-bsp/DataModules/inc/CustomBMS.hpp create mode 100644 car-bsp/DataModules/src/CustomBMS.cpp create mode 100644 telemetry-collector/src/.ma.swp diff --git a/car-bsp/DataModules/inc/CustomBMS.hpp b/car-bsp/DataModules/inc/CustomBMS.hpp new file mode 100644 index 0000000..ad9bda4 --- /dev/null +++ b/car-bsp/DataModules/inc/CustomBMS.hpp @@ -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 + +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_ */ diff --git a/car-bsp/DataModules/inc/DataModuleInfo.hpp b/car-bsp/DataModules/inc/DataModuleInfo.hpp index 838b54d..4fa0b62 100644 --- a/car-bsp/DataModules/inc/DataModuleInfo.hpp +++ b/car-bsp/DataModules/inc/DataModuleInfo.hpp @@ -21,6 +21,11 @@ static constexpr uint32_t BMS_RX3_MSG_ID = 0x6B3; 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; +static constexpr uint32_t CBMS_RX3_MSG_ID = 0x6C3; + // Mitsuba //TX Messages static constexpr uint32_t MOTORTX_RL_MSG_ID = 0x08F89540; diff --git a/car-bsp/DataModules/src/CustomBMS.cpp b/car-bsp/DataModules/src/CustomBMS.cpp new file mode 100644 index 0000000..c54b250 --- /dev/null +++ b/car-bsp/DataModules/src/CustomBMS.cpp @@ -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(buff[1]) << 8) | buff[0]; + // Voltage in mV for remaining values + avg_cell_voltage_ = (static_cast(buff[3]) << 8) | buff[2]; + high_cell_voltage_ = (static_cast(buff[5]) << 8) | buff[4]; + low_cell_voltage_ = (static_cast(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(buff[1]) << 8) | buff[0]; + integral_current_ = (static_cast(buff[3]) << 8) | buff[2]; + average_power_ = (static_cast(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 diff --git a/telemetry-collector/src/.ma.swp b/telemetry-collector/src/.ma.swp new file mode 100644 index 0000000000000000000000000000000000000000..f39046fd4112e36501211a2d1365b575bd522159 GIT binary patch literal 1024 zcmYc?$V<%2S1{ExVL$;-*clj#^K%l5(i2Pai;7X?&^bkk#RW;JMMaebndnj|{Nkcy T{oF(pp;69g2#kin0EPen9Vicq literal 0 HcmV?d00001 diff --git a/telemetry-collector/src/main.cpp b/telemetry-collector/src/main.cpp index 72cdbff..d18b57c 100644 --- a/telemetry-collector/src/main.cpp +++ b/telemetry-collector/src/main.cpp @@ -12,6 +12,7 @@ #include "PowerBoard.hpp" #include "DataModuleInfo.hpp" #include "Mppt.hpp" +#include "CustomBMS.hpp" #include "GPS.hpp" #include "crc16.hpp" #include "Logger.hpp" @@ -22,6 +23,9 @@ SolarGators::DataModules::MitsubaRx0 MitsubaRx0(SolarGators::DataModuleInfo::MOT SolarGators::DataModules::MitsubaRx1 MitsubaRx1(SolarGators::DataModuleInfo::MOTORRX1_RL_MSG_ID, 0); SolarGators::DataModules::MitsubaRx2 MitsubaRx2(SolarGators::DataModuleInfo::MOTORRX2_RL_MSG_ID, 0); +SolarGators::DataModules::CustomBMSRx0 CustomBMSRx0(SolarGators::DataModuleInfo::CBMS_RX0_MSG_ID); +SolarGators::DataModules::CustomBMSRx1 CustomBMSRx1(SolarGators::DataModuleInfo::CBMS_RX1_MSG_ID); + SolarGators::DataModules::OrionBMSRx0 OrionBMSRx0(SolarGators::DataModuleInfo::BMS_RX0_MSG_ID, 0); SolarGators::DataModules::OrionBMSRx1 OrionBMSRx1(SolarGators::DataModuleInfo::BMS_RX1_MSG_ID, 0); SolarGators::DataModules::OrionBMSRx2 OrionBMSRx2(SolarGators::DataModuleInfo::BMS_RX2_MSG_ID, 0); @@ -77,6 +81,8 @@ int main(int argc, char *argv[]) { modules.insert(std::make_pair(OrionBMSRx4.can_id_, &OrionBMSRx4)); modules.insert(std::make_pair(OrionBMSRx5.can_id_, &OrionBMSRx5)); + modules.insert(std::make_pair(CustomBMSRx0.can_id_, &CustomBMSRx0)); + modules.insert(std::make_pair(CustomBMSRx0.can_id_, &CustomBMSRx1)); // MPPTs modules.insert(std::make_pair(MPPT0_Rx_0.can_id_, &MPPT0_Rx_0)); modules.insert(std::make_pair(MPPT1_Rx_0.can_id_, &MPPT1_Rx_0));