Skip to content

Commit 67a2f3a

Browse files
committed
Add BLE characteristics for BMS MOS states
Introduces BLE characteristics for charge and discharge MOS states in the BMS. Updates telemetry and notification logic to support these new characteristics, allowing external devices to read MOS status via BLE.
1 parent 3543f19 commit 67a2f3a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/sp140/extra-data.ino

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ Preferences preferences;
109109
#define BMS_LOW_TEMP_UUID "26CD6E8A-175D-4C8E-B487-DEFF0B034F2A"
110110
#define BMS_FAILURE_LEVEL_UUID "396C768B-F348-44CC-9D46-92388F25A557"
111111
#define BMS_VOLTAGE_DIFF_UUID "1C45825B-7C81-430B-8D5F-B644FFFC71BB"
112+
#define BMS_CHARGE_MOS_UUID "8BADF137-FFF5-4FBC-9DD7-DFCEAFB0EDF9"
113+
#define BMS_DISCHARGE_MOS_UUID "D044DEDA-BE72-4B84-A61F-49861501BE9B"
112114
#define BMS_CELL_VOLTAGES_UUID "4337e58b-8462-49b2-b061-c3bf379ef4af"
113115

114116
// ESC Characteristic UUIDs
@@ -134,6 +136,8 @@ static BLECharacteristic* pBMSLowTemp = nullptr;
134136
static BLECharacteristic* pBMSFailureLevel = nullptr;
135137
static BLECharacteristic* pBMSVoltageDiff = nullptr;
136138
static BLECharacteristic* pBMSCellVoltages = nullptr;
139+
static BLECharacteristic* pBMSChargeMos = nullptr;
140+
static BLECharacteristic* pBMSDischargeMos = nullptr;
137141

138142
void updateThrottleBLE(int value) {
139143
// Handle disconnecting
@@ -188,6 +192,14 @@ void updateBMSTelemetry(const STR_BMS_TELEMETRY_140& telemetry) {
188192
if (pBMSLowTemp) pBMSLowTemp->setValue(lowTemp);
189193
if (pBMSFailureLevel) pBMSFailureLevel->setValue((uint8_t*)&telemetry.battery_failure_level, sizeof(uint8_t));
190194
if (pBMSVoltageDiff) pBMSVoltageDiff->setValue(voltageDiff);
195+
if (pBMSChargeMos) {
196+
uint8_t chargeMos = telemetry.is_charge_mos ? 1 : 0;
197+
pBMSChargeMos->setValue(&chargeMos, sizeof(chargeMos));
198+
}
199+
if (pBMSDischargeMos) {
200+
uint8_t dischargeMos = telemetry.is_discharge_mos ? 1 : 0;
201+
pBMSDischargeMos->setValue(&dischargeMos, sizeof(dischargeMos));
202+
}
191203

192204
// Update cell voltages characteristic
193205
if (pBMSCellVoltages != nullptr) {
@@ -220,6 +232,8 @@ void updateBMSTelemetry(const STR_BMS_TELEMETRY_140& telemetry) {
220232
if (pBMSLowTemp) pBMSLowTemp->notify();
221233
if (pBMSFailureLevel) pBMSFailureLevel->notify();
222234
if (pBMSVoltageDiff) pBMSVoltageDiff->notify();
235+
if (pBMSChargeMos) pBMSChargeMos->notify();
236+
if (pBMSDischargeMos) pBMSDischargeMos->notify();
223237
}
224238
}
225239

@@ -542,6 +556,16 @@ void setupBLE() {
542556
BLECharacteristic::PROPERTY_READ // Only READ property for debugging
543557
);
544558

559+
pBMSChargeMos = pBMSService->createCharacteristic(
560+
BLEUUID(BMS_CHARGE_MOS_UUID),
561+
BLECharacteristic::PROPERTY_READ
562+
);
563+
564+
pBMSDischargeMos = pBMSService->createCharacteristic(
565+
BLEUUID(BMS_DISCHARGE_MOS_UUID),
566+
BLECharacteristic::PROPERTY_READ
567+
);
568+
545569
// Set initial value for pBMSCellVoltages (array of zeros)
546570
uint16_t initial_cell_values[BMS_CELLS_NUM] = {0};
547571
pBMSCellVoltages->setValue((uint8_t*)initial_cell_values, BMS_CELLS_NUM * sizeof(uint16_t));

0 commit comments

Comments
 (0)