Skip to content

Commit

Permalink
verified working telemetry receive
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed May 8, 2024
1 parent e1a5a7f commit 3c407f5
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 0 deletions.
128 changes: 128 additions & 0 deletions car-bsp/DataModules/inc/CustomBMS.hpp
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_ */
5 changes: 5 additions & 0 deletions car-bsp/DataModules/inc/DataModuleInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
117 changes: 117 additions & 0 deletions car-bsp/DataModules/src/CustomBMS.cpp
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 added telemetry-collector/src/.ma.swp
Binary file not shown.
6 changes: 6 additions & 0 deletions telemetry-collector/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 3c407f5

Please sign in to comment.