Read speed from CAN bus
This commit is contained in:
		@ -132,6 +132,8 @@ typedef struct {
 | 
			
		||||
  float ts_current;
 | 
			
		||||
  float ts_voltage_bat;
 | 
			
		||||
  float ts_voltage_veh;
 | 
			
		||||
 | 
			
		||||
  float speed;
 | 
			
		||||
} VehicleState;
 | 
			
		||||
 | 
			
		||||
extern VehicleState vehicle_state;
 | 
			
		||||
 | 
			
		||||
@ -14,6 +14,7 @@
 | 
			
		||||
#define CAN_ID_AMS_SLAVE_PANIC 0x9
 | 
			
		||||
#define CAN_ID_AMS_STATUS 0xA
 | 
			
		||||
#define CAN_ID_AMS_ERROR 0xC
 | 
			
		||||
#define CAN_ID_ABX_DRIVER 0x101
 | 
			
		||||
#define CAN_ID_CS_INTERNAL 0x108
 | 
			
		||||
#define CAN_ID_MISSION_SELECTED 0x400
 | 
			
		||||
#define CAN_ID_STW_BUTTONS 0x401
 | 
			
		||||
@ -25,6 +26,7 @@
 | 
			
		||||
#define CAN_ID_SHUNT_VOLTAGE2 0x523
 | 
			
		||||
#define CAN_AMS_STATUS_VOLTAGE_FACTOR 1e-4
 | 
			
		||||
#define CAN_AMS_STATUS_TEMP_FACTOR 0.0625
 | 
			
		||||
#define CAN_ABX_DRIVER_SPEED_FACTOR (0.2 * 3.6)
 | 
			
		||||
#define CAN_CS_INTERNAL_TEMP_FACTOR 0.01
 | 
			
		||||
 | 
			
		||||
VehicleState vehicle_state = {0};
 | 
			
		||||
@ -34,6 +36,7 @@ void vehicle_thread_entry(ULONG 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_ABX_DRIVER, 0x7FF);
 | 
			
		||||
  ftcan_add_filter(CAN_ID_CS_INTERNAL, 0x7FF);
 | 
			
		||||
  ftcan_add_filter(CAN_ID_AS_MISSION_FB, 0x7FF);
 | 
			
		||||
  ftcan_add_filter(CAN_ID_STW_STATUS, 0x7FF);
 | 
			
		||||
@ -87,6 +90,9 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
 | 
			
		||||
    vehicle_state.last_ams_error.kind = data[0];
 | 
			
		||||
    vehicle_state.last_ams_error.arg = data[1];
 | 
			
		||||
    break;
 | 
			
		||||
  case CAN_ID_ABX_DRIVER:
 | 
			
		||||
    vehicle_state.speed = data[5] * CAN_ABX_DRIVER_SPEED_FACTOR;
 | 
			
		||||
    break;
 | 
			
		||||
  case CAN_ID_CS_INTERNAL:
 | 
			
		||||
    vehicle_state.temps.inv_l =
 | 
			
		||||
        (data[0] | (data[1] << 8)) * CAN_CS_INTERNAL_TEMP_FACTOR;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user