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;
 | 
			
		||||
 | 
			
		||||
@ -268,7 +268,7 @@ NamedFieldDescription dataFieldDescs[] = {
 | 
			
		||||
                         VEH_FIELD(ts_voltage_bat)},
 | 
			
		||||
    [DF_TSVoltageVeh] = {NamedFieldKind::Float, "TSVVEH", 3, 1,
 | 
			
		||||
                         VEH_FIELD(ts_voltage_veh)},
 | 
			
		||||
    [DF_Speed] = {NamedFieldKind::Float, "SPEED", 3, 0, get_zero},
 | 
			
		||||
    [DF_Speed] = {NamedFieldKind::Float, "SPEED", 3, 0, VEH_FIELD(speed)},
 | 
			
		||||
    [DF_BBal] = {NamedFieldKind::Float, "BBAL", 3, 1, get_zero},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -5,7 +5,7 @@
 | 
			
		||||
#include "vehicle.h"
 | 
			
		||||
 | 
			
		||||
DriverViewPresenter::DriverViewPresenter(DriverViewView &v)
 | 
			
		||||
    : view(v), fields{DF_MinCellVolt, DF_TSVoltageVeh, DF_TSCurrent} {}
 | 
			
		||||
    : view(v), fields{DF_MinCellVolt, DF_Speed, DF_MaxCellTemp} {}
 | 
			
		||||
 | 
			
		||||
void DriverViewPresenter::activate() {
 | 
			
		||||
  for (size_t i = 0; i < 3; i++) {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user