enabled can support and cleaned up the code for it

This commit is contained in:
hamza
2024-06-06 16:46:10 +03:00
parent 757165c9bf
commit 8983097b87
5 changed files with 55 additions and 11 deletions

View File

@ -19,13 +19,14 @@ once every 1s in states: INACTIVE, PRECHARGE, DISCHARGE, CHARGING, ERROR.
once every 0.5s in states: READY, ACTIVE.
with format of:
CAN Messages:
- MVBMS Status (1B), Powerground Status 0-100% (1 bit)
- Battery: SoC (1B), Pack Voltage (2B), Current (1B),
Min/Max. Cell Temp (ID, Min Temp, ID, Max Temp)(4B),
Min/Max Cell Voltage (ID, Min Voltage, ID, Max Voltage)(4B)
MVBMS Status (1B), Powerground Status 0-100% (1B)
Battery: SoC (1B), Pack Voltage (2B), Current (1B),
Min/Max. Cell Temp (ID, Min Temp, ID, Max Temp)(3B),
Min/Max Cell Voltage (ID, Min Voltage, ID, Max Voltage)(3B)
bit 0-2: status
bit 0-7:
bit 3-7:
bit 8-15: State of Charge from 0-100%
bit 16-31: Battery voltage
bit 32-47: Current measurement
@ -48,8 +49,11 @@ void can_handle_send_status() {
int8_t id = -1;
int16_t temp = INT16_MIN;
sm_check_cell_temps(&id, &temp);
data[6] = (id << 5) | (temp >> 4); // there are only 7 TMP1075
data[6] = (id << 4) | (temp >> 4); // there are only 7 TMP1075
ftcan_transmit(CAN_ID_OUT, data, sizeof(data));
;
}
/*
@ -59,9 +63,9 @@ to the sm_handle_ams_in() which handles the state machine transition.
void can_handle_recieve_command(const uint8_t *data){
if (data[0] == 0x00 && data[1] == 0x00){
sm_handle_ams_in(data);
} else if (data[0] == 0b10000000 && data[1] == 0x00){
} else if (data[0] == 0x01 && data[1] == 0x00){
sm_handle_ams_in(data);
} else if (data[0] == 0b11000000 && data[1] <= 100) {
} else if (data[0] == 0x02 && data[1] <= 100) {
sm_handle_ams_in(data);
}
}
@ -69,9 +73,11 @@ void can_handle_recieve_command(const uint8_t *data){
/*
implements the _weak method ftcan_msg_recieved_cb() which throws an interrupt when a CAN message is recieved.
it only checks if the id is and datalen is correct thans hands data over to can_handle_recieve_command().
in MXCUBE under CAN NVIC settings "USB low priority or CAN_RX0 interrupts" has to be on
*/
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data){
if (id == 0x501 && datalen == 16){
if (id == 0x501 && datalen == 2){
can_handle_recieve_command(data);
}
}