Skip to content

Commit 06761f1

Browse files
committed
Fix bms can temp type error (Optional A != A)
1 parent 713d293 commit 06761f1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

bms/src/BmsThread.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class BMSThread {
4646
}
4747
void threadWorker() {
4848
uint16_t* allVoltages = new uint16_t[BMS_BANK_COUNT * BMS_BANK_CELL_COUNT];
49-
tl::optional<int8_t>* allTemps = new tl::optional<int8_t>[BMS_BANK_COUNT * BMS_BANK_CELL_COUNT];
49+
auto allTemps = std::array<tl::optional<int8_t>, BMS_BANK_COUNT * BMS_BANK_CELL_COUNT>();
5050
uint16_t averageVoltage = -1;
5151
uint16_t prevMinVoltage = -1;
5252

@@ -201,7 +201,12 @@ class BMSThread {
201201

202202
// Send CAN
203203
for (size_t i = 0; i < BMS_BANK_COUNT; i++) {
204-
canBus->write(BMSTempMessage(i, allTemps + (BMS_BANK_TEMP_COUNT * i)));
204+
auto temps = std::array<int8_t, BMS_BANK_TEMP_COUNT>();
205+
std::transform(allTemps.begin() + (BMS_BANK_TEMP_COUNT * i),
206+
allTemps.begin() + (BMS_BANK_TEMP_COUNT * (i + 1)),
207+
temps.begin(),
208+
[](tl::optional<int8_t> t) { return t.value_or(-127); });
209+
canBus->write(BMSTempMessage(i, (uint8_t*)temps.data()));
205210
}
206211

207212
for (size_t i = 0; i < 7; i++) {

0 commit comments

Comments
 (0)