-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBms_Handler.cpp
66 lines (57 loc) · 1.92 KB
/
Bms_Handler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "Bms_Handler.h"
#include "Store_Controller.h"
#include "Logger.h"
void Bms_Handler::begin() {
// No initialization needed
}
void Bms_Handler::handleMessage(Frame& message) {
switch(message.id) {
case BMS_FAULT_ID:
handleFaultMessage(message);
break;
case BMS_VOLTAGE_ID:
handleVoltageMessage(message);
break;
case BMS_TEMP_ID:
handleTempMessage(message);
break;
case BMS_SOC_ID:
handleSocMessage(message);
break;
case BMS_RESISTANCE_ID:
break;
}
}
int16_t Bms_Handler::mergeBytes(uint8_t low, uint8_t high) {
uint16_t low_ext = low & 0x00FF;
uint16_t high_ext = (high << 8);
return high_ext | low_ext;
}
void Bms_Handler::handleVoltageMessage(Frame& message) {
// If voltage ever goes above 32767 volts, use a different method
uint16_t total_volts = mergeBytes(message.body[1], message.body[0]);
Store().logBmsVoltage(total_volts);
uint8_t min_cell_id = message.body[3];
String cell_id_string = "id_" + String(min_cell_id);
// uint8_t min_cell_voltage = message.body[2];
// Xbee().logFour("min_cell_voltage", cell_id_string, min_cell_voltage, "100_millivolts");
// Onboard().logFour("min_cell_voltage", cell_id_string, min_cell_voltage, "100_millivolts");
return;
}
void Bms_Handler::handleTempMessage(Frame& message) {
uint8_t temp = message.body[0];
Store().logBmsTemp(temp);
uint8_t max_cell_id = message.body[5];
String cell_id_string = "id_" + String(max_cell_id);
// uint8_t max_cell_temp = message.body[4];
// Xbee().logFour("max_cell_temp", cell_id_string, max_cell_temp, "degrees");
// Onboard().logFour("max_cell_temp", cell_id_string, max_cell_temp, "degrees");
}
void Bms_Handler::handleSocMessage(Frame& message) {
uint8_t soc = message.body[0];
Store().logBmsSoc(soc);
}
void Bms_Handler::handleFaultMessage(Frame& message) {
Store().logBmsFaults(message.body[5]);
Store().logBmsWarnings(message.body[6]);
}