88
99// Simple struct to hold TWAI interface state. Unlike other platforms, ESP32's
1010// TWAI driver uses global functions rather than a class instance.
11- struct ESP32TWAIIntf {
12- bool initialized = false ;
13- };
11+ struct ESP32TWAIIntf {};
1412
1513struct CanMsg {
1614 uint32_t id;
@@ -22,14 +20,11 @@ struct CanMsg {
2220void onCanMessage (const CanMsg& msg);
2321
2422static bool sendMsg (ESP32TWAIIntf& intf, uint32_t id, uint8_t length, const uint8_t * data) {
25- if (!intf.initialized ) {
26- return false ;
27- }
28-
23+ (void )intf;
2924 twai_message_t tx_msg = {};
3025 tx_msg.identifier = id;
3126 tx_msg.data_length_code = length;
32- tx_msg.extd = (id > 0x7FF ) ? 1 : 0 ;
27+ tx_msg.extd = (id & 0x80000000 ) ? 1 : 0 ;
3328 tx_msg.rtr = (data == nullptr ) ? 1 : 0 ;
3429
3530 if (data) {
@@ -38,18 +33,15 @@ static bool sendMsg(ESP32TWAIIntf& intf, uint32_t id, uint8_t length, const uint
3833 }
3934 }
4035
41- return twai_transmit (&tx_msg, pdMS_TO_TICKS ( 100 ) ) == ESP_OK;
36+ return twai_transmit (&tx_msg, 0 ) == ESP_OK;
4237}
4338
4439static void onReceive (const CanMsg& msg, ODriveCAN& odrive) {
4540 odrive.onReceive (msg.id , msg.len , msg.buffer );
4641}
4742
4843static void pumpEvents (ESP32TWAIIntf& intf, int max_events = 100 ) {
49- if (!intf.initialized ) {
50- return ;
51- }
52-
44+ (void )intf;
5345 // max_events prevents an infinite loop if messages come at a high rate
5446 twai_message_t rx_msg;
5547 while (twai_receive (&rx_msg, 0 ) == ESP_OK && max_events--) {
0 commit comments