-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dylan Donahue
committed
Jan 2, 2024
1 parent
caaad96
commit d4e0bba
Showing
4 changed files
with
77 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,62 @@ | ||
#include "can_handler.h" | ||
#include "ringbuffer.h" | ||
#include "analyzer.h" | ||
#include "ringbuffer.h" | ||
|
||
ringbuffer_t can_receive_queue; | ||
|
||
void can_receive_callback(CAN_HandleTypeDef *hcan) | ||
void can_receive_callback(CAN_HandleTypeDef* hcan) | ||
{ | ||
CAN_RxHeaderTypeDef rx_header; | ||
can_msg_t new_msg; | ||
/* Read in CAN message */ | ||
CAN_RxHeaderTypeDef rx_header; | ||
can_msg_t new_msg; | ||
/* Read in CAN message */ | ||
if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &rx_header, new_msg.data) != HAL_OK) { | ||
|
||
// TODO add non crtical fault capability - could create one for failed can receieve | ||
return; | ||
} | ||
|
||
new_msg.len = rx_header.DLC; | ||
new_msg.id = rx_header.StdId; | ||
// TODO add non crtical fault capability - could create one for failed can receieve | ||
return; | ||
} | ||
|
||
new_msg.len = rx_header.DLC; | ||
new_msg.id = rx_header.StdId; | ||
if (hcan == &hcan1) { | ||
ringbuffer_enqueue(can1_rx_queue, new_msg); | ||
} else { | ||
ringbuffer_enqueue(can2_rx_queue, new_msg); | ||
} | ||
} | ||
|
||
ringbuffer_enqueue(can_receive_queue, new_msg); | ||
int8_t get_can1_msg(can_msg_t* msg) | ||
{ | ||
/* no messages to read */ | ||
if (ringbuffer_is_empty(&can1_rx_queue)) | ||
return -1; | ||
|
||
ringbuffer_dequeue(&can1_rx_queue, msg); | ||
|
||
// TODO list : | ||
// 1. | ||
switch (msg->id) { | ||
case NULL: | ||
break; | ||
} | ||
return 0; | ||
} | ||
|
||
uint8_t get_can_msg(can_msg_t* msg) | ||
int8_t get_can2_msg(can_msg_t* msg) | ||
{ | ||
/* no messages to read */ | ||
if (ringbuffer_is_empty(&can_receive_queue)) return -1; | ||
|
||
ringbuffer_dequeue(&can_receive_queue, msg); | ||
|
||
// TODO list : | ||
// 1. Charger connection flag - have Charger set up with following logic, add correct CAN ID | ||
switch (msg->id) { | ||
case NULL: | ||
if (msg->data[0] == 0x01) { | ||
bmsdata->is_charger_connected = true; | ||
} else { | ||
bmsdata->is_charger_connected = false; | ||
} | ||
break; | ||
} | ||
return 0; | ||
/* no messages to read */ | ||
if (ringbuffer_is_empty(&can2_rx_queue)) | ||
return -1; | ||
|
||
ringbuffer_dequeue(&can2_rx_queue, msg); | ||
|
||
// TODO list : | ||
// 1. Charger connection flag - have Charger set up with following logic, add correct CAN ID | ||
switch (msg->id) { | ||
case NULL: | ||
if (msg->data[0] == 0x01) { | ||
bmsdata->is_charger_connected = true; | ||
} else { | ||
bmsdata->is_charger_connected = false; | ||
} | ||
break; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters