@@ -295,13 +295,19 @@ void send_empty_panda_state(PubMaster *pm) {
295
295
296
296
std::optional<bool > send_panda_states (PubMaster *pm, const std::vector<Panda *> &pandas, bool spoofing_started) {
297
297
bool ignition_local = false ;
298
+ const uint32_t pandas_cnt = pandas.size ();
298
299
299
300
// build msg
300
301
MessageBuilder msg;
301
302
auto evt = msg.initEvent ();
302
- auto pss = evt.initPandaStates (pandas. size () );
303
+ auto pss = evt.initPandaStates (pandas_cnt );
303
304
304
305
std::vector<health_t > pandaStates;
306
+ pandaStates.reserve (pandas_cnt);
307
+
308
+ std::vector<std::array<can_health_t , PANDA_CAN_CNT>> pandaCanStates;
309
+ pandaCanStates.reserve (pandas_cnt);
310
+
305
311
for (const auto & panda : pandas){
306
312
auto health_opt = panda->get_state ();
307
313
if (!health_opt) {
@@ -310,6 +316,16 @@ std::optional<bool> send_panda_states(PubMaster *pm, const std::vector<Panda *>
310
316
311
317
health_t health = *health_opt;
312
318
319
+ std::array<can_health_t , PANDA_CAN_CNT> can_health{};
320
+ for (uint32_t i = 0 ; i < PANDA_CAN_CNT; i++) {
321
+ auto can_health_opt = panda->get_can_state (i);
322
+ if (!can_health_opt) {
323
+ return std::nullopt;
324
+ }
325
+ can_health[i] = *can_health_opt;
326
+ }
327
+ pandaCanStates.push_back (can_health);
328
+
313
329
if (spoofing_started) {
314
330
health.ignition_line_pkt = 1 ;
315
331
}
@@ -319,7 +335,7 @@ std::optional<bool> send_panda_states(PubMaster *pm, const std::vector<Panda *>
319
335
pandaStates.push_back (health);
320
336
}
321
337
322
- for (uint32_t i = 0 ; i < pandas. size () ; i++) {
338
+ for (uint32_t i = 0 ; i < pandas_cnt ; i++) {
323
339
auto panda = pandas[i];
324
340
const auto &health = pandaStates[i];
325
341
@@ -366,6 +382,32 @@ std::optional<bool> send_panda_states(PubMaster *pm, const std::vector<Panda *>
366
382
ps.setInterruptLoad (health.interrupt_load );
367
383
ps.setFanPower (health.fan_power );
368
384
385
+ std::array<cereal::PandaState::PandaCanState::Builder, PANDA_CAN_CNT> cs = {ps.initCanState0 (), ps.initCanState1 (), ps.initCanState2 ()};
386
+
387
+ for (uint32_t j = 0 ; j < PANDA_CAN_CNT; j++) {
388
+ const auto &can_health = pandaCanStates[i][j];
389
+ cs[j].setBusOff ((bool )can_health.bus_off );
390
+ cs[j].setBusOffCnt (can_health.bus_off_cnt );
391
+ cs[j].setErrorWarning ((bool )can_health.error_warning );
392
+ cs[j].setErrorPassive ((bool )can_health.error_passive );
393
+ cs[j].setLastError (cereal::PandaState::PandaCanState::LecErrorCode (can_health.last_error ));
394
+ cs[j].setLastStoredError (cereal::PandaState::PandaCanState::LecErrorCode (can_health.last_stored_error ));
395
+ cs[j].setLastDataError (cereal::PandaState::PandaCanState::LecErrorCode (can_health.last_data_error ));
396
+ cs[j].setLastDataStoredError (cereal::PandaState::PandaCanState::LecErrorCode (can_health.last_data_stored_error ));
397
+ cs[j].setReceiveErrorCnt (can_health.receive_error_cnt );
398
+ cs[j].setTransmitErrorCnt (can_health.transmit_error_cnt );
399
+ cs[j].setTotalErrorCnt (can_health.total_error_cnt );
400
+ cs[j].setTotalTxLostCnt (can_health.total_tx_lost_cnt );
401
+ cs[j].setTotalRxLostCnt (can_health.total_rx_lost_cnt );
402
+ cs[j].setTotalTxCnt (can_health.total_tx_cnt );
403
+ cs[j].setTotalRxCnt (can_health.total_rx_cnt );
404
+ cs[j].setTotalFwdCnt (can_health.total_fwd_cnt );
405
+ cs[j].setCanSpeed (can_health.can_speed );
406
+ cs[j].setCanDataSpeed (can_health.can_data_speed );
407
+ cs[j].setCanfdEnabled (can_health.canfd_enabled );
408
+ cs[j].setBrsEnabled (can_health.canfd_enabled );
409
+ }
410
+
369
411
// Convert faults bitset to capnp list
370
412
std::bitset<sizeof (health.faults_pkt ) * 8 > fault_bits (health.faults_pkt );
371
413
auto faults = ps.initFaults (fault_bits.count ());
0 commit comments