Skip to content

Commit

Permalink
CAN health packet: add speed and canfd info (commaai#1071)
Browse files Browse the repository at this point in the history
in
  • Loading branch information
briskspirit committed Sep 17, 2022
1 parent 046fd58 commit 59ede3f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion board/can_health.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// When changing this struct, python/__init__.py needs to be kept up to date!
#define CAN_HEALTH_PACKET_VERSION 1
#define CAN_HEALTH_PACKET_VERSION 2
typedef struct __attribute__((packed)) {
uint8_t bus_off;
uint32_t bus_off_cnt;
Expand All @@ -17,4 +17,8 @@ typedef struct __attribute__((packed)) {
uint32_t total_tx_cnt;
uint32_t total_rx_cnt;
uint32_t total_fwd_cnt; // Messages forwarded from one bus to another
uint16_t can_speed;
uint16_t can_data_speed;
uint8_t canfd_enabled;
uint8_t brs_enabled;
} can_health_t;
4 changes: 4 additions & 0 deletions board/main_comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) {
case 0xc2:
COMPILE_TIME_ASSERT(sizeof(can_health_t) <= USBPACKET_MAX_SIZE);
if (req->param1 < 3U) {
can_health[req->param1].can_speed = (bus_config[req->param1].can_speed / 10U);
can_health[req->param1].can_data_speed = (bus_config[req->param1].can_data_speed / 10U);
can_health[req->param1].canfd_enabled = bus_config[req->param1].canfd_enabled;
can_health[req->param1].brs_enabled = bus_config[req->param1].brs_enabled;
resp_len = sizeof(can_health[req->param1]);
(void)memcpy(resp, &can_health[req->param1], resp_len);
}
Expand Down
8 changes: 6 additions & 2 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ class Panda:

CAN_PACKET_VERSION = 2
HEALTH_PACKET_VERSION = 10
CAN_HEALTH_PACKET_VERSION = 1
CAN_HEALTH_PACKET_VERSION = 2
HEALTH_STRUCT = struct.Struct("<IIIIIIIIIBBBBBBHBBBHfB")
CAN_HEALTH_STRUCT = struct.Struct("<BIBBBBBBBBIIIIII")
CAN_HEALTH_STRUCT = struct.Struct("<BIBBBBBBBBIIIIIIHHBB")

F2_DEVICES = (HW_TYPE_PEDAL, )
F4_DEVICES = (HW_TYPE_WHITE_PANDA, HW_TYPE_GREY_PANDA, HW_TYPE_BLACK_PANDA, HW_TYPE_UNO, HW_TYPE_DOS)
Expand Down Expand Up @@ -503,6 +503,10 @@ def can_health(self, can_number):
"total_tx_cnt": a[13],
"total_rx_cnt": a[14],
"total_fwd_cnt": a[15],
"can_speed": a[16],
"can_data_speed": a[17],
"canfd_enabled": a[18],
"brs_enabled": a[19],
}

# ******************* control *******************
Expand Down

0 comments on commit 59ede3f

Please sign in to comment.