added sm_check_errors
This commit is contained in:
		@ -1,10 +1,16 @@
 | 
			
		||||
#include "state_machine.h"
 | 
			
		||||
#include "AMS_HighLevel.h"
 | 
			
		||||
#include "TMP1075.h"
 | 
			
		||||
#include "errors.h"
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
StateHandle state;
 | 
			
		||||
int16_t RELAY_BAT_SIDE_VOLTAGE;
 | 
			
		||||
int16_t RELAY_ESC_SIDE_VOLTAGE;
 | 
			
		||||
int16_t CURRENT_MEASUREMENT;
 | 
			
		||||
uint8_t powerground_status;
 | 
			
		||||
 | 
			
		||||
uint32_t timestamp;
 | 
			
		||||
 | 
			
		||||
void sm_init(){
 | 
			
		||||
@ -14,6 +20,8 @@ void sm_init(){
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void sm_update(){
 | 
			
		||||
  sm_check_errors();
 | 
			
		||||
 | 
			
		||||
  RELAY_BAT_SIDE_VOLTAGE = module.auxVoltages[0] * 12.42;     // the calculation says the factor is 11.989. 12.42 yields the better result
 | 
			
		||||
  RELAY_ESC_SIDE_VOLTAGE = module.auxVoltages[1] * 12.42;
 | 
			
		||||
  CURRENT_MEASUREMENT = module.auxVoltages[2] / 2.2;
 | 
			
		||||
@ -197,14 +205,24 @@ void sm_check_charging(){
 | 
			
		||||
    state.target_state = STATE_CHARGING_PRECHARGE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void sm_check_cell_temps(int8_t *id, int16_t *temp){
 | 
			
		||||
/* returns the ID and temperature of the hottest cell */
 | 
			
		||||
void sm_check_battery_temperature(int8_t *id, int16_t *temp){
 | 
			
		||||
  for (int i = 0; i < N_TEMP_SENSORS; i++) {
 | 
			
		||||
    if (tmp1075_temps[i] > *temp){
 | 
			
		||||
      *id = i;
 | 
			
		||||
      *temp = tmp1075_temps[i];
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int16_t sm_return_cell_temperature(int id){
 | 
			
		||||
  return tmp1075_temps[id];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int16_t sm_return_cell_voltage(int id){
 | 
			
		||||
  return module.cellVoltages[id];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void sm_handle_ams_in(const uint8_t *data){  
 | 
			
		||||
  switch (data[0]) {
 | 
			
		||||
    case 0x00:
 | 
			
		||||
@ -235,11 +253,38 @@ void sm_set_error(ErrorKind error_kind, bool is_errored){}
 | 
			
		||||
 | 
			
		||||
#warning TODO: add error checking for everything here
 | 
			
		||||
void sm_check_errors(){
 | 
			
		||||
  if (module.status.THSD == 1) {
 | 
			
		||||
    state.error_type.bms_overtemp = 1;
 | 
			
		||||
  switch (error_data.data_kind) {
 | 
			
		||||
    case SEK_OVERTEMP:
 | 
			
		||||
    case SEK_UNDERTEMP:
 | 
			
		||||
    case SEK_TOO_FEW_TEMPS:
 | 
			
		||||
      state.error_type.temperature_error = 1;
 | 
			
		||||
    case SEK_OVERVOLT:
 | 
			
		||||
    case SEK_UNDERVOLT:
 | 
			
		||||
    case SEK_OPENWIRE:
 | 
			
		||||
    case SEK_EEPROM_ERR:
 | 
			
		||||
    case SEK_INTERNAL_BMS_TIMEOUT:
 | 
			
		||||
      state.error_type.bms_timeout = 1;
 | 
			
		||||
    case SEK_INTERNAL_BMS_CHECKSUM_FAIL:
 | 
			
		||||
    case SEK_INTERNAL_BMS_OVERTEMP:
 | 
			
		||||
    case SEK_INTERNAL_BMS_FAULT:
 | 
			
		||||
      state.error_type.bms_fault = 1;
 | 
			
		||||
      break;
 | 
			
		||||
  }
 | 
			
		||||
  if (RELAY_BAT_SIDE_VOLTAGE < 40){
 | 
			
		||||
    state.error_source = (1 << 10);
 | 
			
		||||
 | 
			
		||||
  if (1){
 | 
			
		||||
    state.error_type.current_error = 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (1){
 | 
			
		||||
    state.error_type.current_sensor_missing = 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (RELAY_BAT_SIDE_VOLTAGE < 30000){
 | 
			
		||||
    state.error_type.voltage_error = 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (1){
 | 
			
		||||
    state.error_type.voltage_missing = 1;
 | 
			
		||||
  }
 | 
			
		||||
}  
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user