This commit is contained in:
hamza
2024-07-10 01:39:38 +03:00
parent 4375bfce48
commit a86985bfc9
11 changed files with 217 additions and 41 deletions

View File

@ -6,13 +6,19 @@
*/
#include "can.h"
#include <stdint.h>
//#define CAN_ID_IN 0x501
//#define CAN_ID_OUT 0x502
#define CAN_ID_IN 0x501
#define CAN_ID_OUT 0x502
#define CAN_STATUS_FREQ 100
uint8_t last_message[8];
static uint32_t can_delay_manager = 0;
void can_init(CAN_HandleTypeDef* hcan) {
ftcan_init(hcan);
ftcan_add_filter(CAN_ID_IN, 0xFFF);
last_message[0] = -1;
last_message[1] = -1;
}
/*
@ -66,14 +72,15 @@ void can_handle_send_status() {
int16_t lowest_volt = INT16_MIN;
sm_check_battery_temperature(&id_highest_temp, &highest_temp);
data[0] = ((state.current_state << 4) | (powerground_status >> 4)); // 1 bit emptyy | 3 bit state | 4 bit powerground
data[1] = ((powerground_status << 4) | (state.error_source >> 4)); // 4 bit powerground | 4 bit error
data[2] = ((state.error_source << 4) | (0)); // 4 bit error | 4 bit state of charge
data[3] = ((RELAY_BAT_SIDE_VOLTAGE / 1000)); // 8 bit battery voltage
data[4] = ((RELAY_ESC_SIDE_VOLTAGE / 1000));
//data[5] = (() / 1000);
data[6] = ((CURRENT_MEASUREMENT / 1000));
data[7] = ((highest_temp) >> 8);
data[3] = (0); // 8 bit state of charge
data[4] = ((RELAY_BAT_SIDE_VOLTAGE / 1000)); // 8 bit battery voltage
data[5] = ((RELAY_ESC_SIDE_VOLTAGE / 1000)); // 8 bit Inverter voltage
data[6] = ((CURRENT_MEASUREMENT / 1000)); // 8 bit Current
data[7] = ((highest_temp) >> 8); // 8 bit highest cell temperature
//data[6] = (module.cellVoltages[7] >> 8);
//data[7] = (module.cellVoltages[7]);
//data[7] = state.error_source;
@ -165,6 +172,10 @@ in MXCUBE under CAN NVIC settings "USB low priority or CAN_RX0 interrupts" has t
*/
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data){
if (id == 0x501 && datalen == 2){
can_handle_recieve_command(data);
if (last_message[0] != data[0] || last_message[1] != data[1]){
last_message[0] = data[0];
last_message[1] = data[1];
can_handle_recieve_command(data);
}
}
}