Add AMS Error popup
This commit is contained in:
		@ -11,7 +11,9 @@
 | 
			
		||||
#include "stm32h7xx_hal_gpio.h"
 | 
			
		||||
#include "tx_api.h"
 | 
			
		||||
 | 
			
		||||
#define CAN_ID_AMS_SLAVE_PANIC 0x9
 | 
			
		||||
#define CAN_ID_AMS_STATUS 0xA
 | 
			
		||||
#define CAN_ID_AMS_ERROR 0xC
 | 
			
		||||
#define CAN_ID_MISSION_SELECTED 0x400
 | 
			
		||||
#define CAN_ID_STW_BUTTONS 0x401
 | 
			
		||||
#define CAN_ID_STW_PARAM_SET 0x402
 | 
			
		||||
@ -27,7 +29,9 @@ VehicleState vehicle_state = {0};
 | 
			
		||||
 | 
			
		||||
void vehicle_thread_entry(ULONG hfdcan_addr) {
 | 
			
		||||
  ftcan_init((void *)hfdcan_addr);
 | 
			
		||||
  ftcan_add_filter(CAN_ID_AMS_SLAVE_PANIC, 0x7FF);
 | 
			
		||||
  ftcan_add_filter(CAN_ID_AMS_STATUS, 0x7FF);
 | 
			
		||||
  ftcan_add_filter(CAN_ID_AMS_ERROR, 0x7FF);
 | 
			
		||||
  ftcan_add_filter(CAN_ID_AS_MISSION_FB, 0x7FF);
 | 
			
		||||
  ftcan_add_filter(CAN_ID_STW_STATUS, 0x7FF);
 | 
			
		||||
  ftcan_add_filter(CAN_ID_SHUNT_CURRENT, 0x7FF);
 | 
			
		||||
@ -59,16 +63,27 @@ void vehicle_broadcast_buttons(GPIO_PinState *button_states) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
 | 
			
		||||
  const uint8_t *ptr;
 | 
			
		||||
  switch (id) {
 | 
			
		||||
  case CAN_ID_AMS_SLAVE_PANIC:
 | 
			
		||||
    vehicle_state.last_ams_slave_panic.id = data[0];
 | 
			
		||||
    vehicle_state.last_ams_slave_panic.kind = data[1];
 | 
			
		||||
    ptr = &data[2];
 | 
			
		||||
    vehicle_state.last_ams_slave_panic.arg = ftcan_unmarshal_unsigned(&ptr, 4);
 | 
			
		||||
    break;
 | 
			
		||||
  case CAN_ID_AMS_STATUS:
 | 
			
		||||
    vehicle_state.ts_state = data[0] & 0x7F;
 | 
			
		||||
    vehicle_state.soc = data[1];
 | 
			
		||||
    const uint8_t *ptr = &data[2];
 | 
			
		||||
    ptr = &data[2];
 | 
			
		||||
    vehicle_state.min_cell_volt =
 | 
			
		||||
        ftcan_unmarshal_unsigned(&ptr, 2) * CAN_AMS_STATUS_VOLTAGE_FACTOR;
 | 
			
		||||
    vehicle_state.max_cell_temp =
 | 
			
		||||
        ftcan_unmarshal_signed(&ptr, 2) * CAN_AMS_STATUS_TEMP_FACTOR;
 | 
			
		||||
    break;
 | 
			
		||||
  case CAN_ID_AMS_ERROR:
 | 
			
		||||
    vehicle_state.last_ams_error.kind = data[0];
 | 
			
		||||
    vehicle_state.last_ams_error.arg = data[1];
 | 
			
		||||
    break;
 | 
			
		||||
  case CAN_ID_AS_MISSION_FB:
 | 
			
		||||
    vehicle_state.active_mission = data[0] & 0b111;
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user