Handle slave status frames
This commit is contained in:
parent
66d9baba7a
commit
ca6bdec839
@ -8,6 +8,7 @@
|
||||
#define CAN_ID_SLAVE_PANIC 0x009
|
||||
#define CAN_ID_AMS_STATUS 0x00A
|
||||
#define CAN_ID_AMS_IN 0x00B
|
||||
#define CAN_ID_SLAVE_STATUS 0x014
|
||||
#define CAN_ID_SLAVE_LOG 0x4F4
|
||||
#define CAN_ID_SHUNT_BASE 0x520
|
||||
#define CAN_ID_SHUNT_CURRENT 0x521
|
||||
|
@ -20,7 +20,8 @@ typedef enum {
|
||||
SLAVE_ERR_OT,
|
||||
SLAVE_ERR_UT,
|
||||
SLAVE_ERR_OV,
|
||||
SLAVE_ERR_UV
|
||||
SLAVE_ERR_UV,
|
||||
SLAVE_ERR_UNKNOWN,
|
||||
} SlaveErrorKind;
|
||||
|
||||
typedef struct {
|
||||
@ -31,8 +32,10 @@ typedef struct {
|
||||
typedef struct {
|
||||
uint8_t id;
|
||||
SlaveError error;
|
||||
uint16_t voltages[N_CELLS_SERIES];
|
||||
int16_t temperatures[N_TEMP_SENSORS];
|
||||
uint8_t soc;
|
||||
uint16_t min_voltage;
|
||||
uint16_t max_voltage;
|
||||
int16_t max_temp;
|
||||
uint32_t last_message;
|
||||
} SlaveHandle;
|
||||
|
||||
@ -44,6 +47,7 @@ void slaves_init();
|
||||
void slaves_check();
|
||||
|
||||
void slaves_handle_panic(const uint8_t *data);
|
||||
void slaves_handle_status(const uint8_t *data);
|
||||
void slaves_handle_log(const uint8_t *data);
|
||||
|
||||
#endif // INC_SLAVE_MONITORING_H
|
||||
|
@ -15,8 +15,8 @@ void can_init(CAN_HandleTypeDef *handle) {
|
||||
ftcan_add_filter(CAN_ID_SHUNT_BASE, 0xFF0);
|
||||
ftcan_add_filter(CAN_ID_AMS_IN, 0xFFF);
|
||||
ftcan_add_filter(CAN_ID_SLAVE_PANIC, 0xFFF);
|
||||
ftcan_add_filter(CAN_ID_SLAVE_STATUS, 0xFFF);
|
||||
ftcan_add_filter(CAN_ID_SLAVE_LOG, 0xFFF);
|
||||
// TODO: Slave status?
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef can_send_status() {
|
||||
@ -37,6 +37,9 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
|
||||
case CAN_ID_SLAVE_PANIC:
|
||||
slaves_handle_panic(data);
|
||||
break;
|
||||
case CAN_ID_SLAVE_STATUS:
|
||||
slaves_handle_status(data);
|
||||
break;
|
||||
case CAN_ID_SLAVE_LOG:
|
||||
slaves_handle_log(data);
|
||||
break;
|
||||
|
@ -20,8 +20,9 @@ void slaves_init() {
|
||||
slaves[i].id = i;
|
||||
slaves[i].error.kind = SLAVE_ERR_NONE;
|
||||
slaves[i].last_message = 0;
|
||||
memset(&slaves[i].voltages, 0, sizeof(slaves[i].voltages));
|
||||
memset(&slaves[i].temperatures, 0, sizeof(slaves[i].temperatures));
|
||||
slaves[i].min_voltage = 0;
|
||||
slaves[i].max_voltage = 0;
|
||||
slaves[i].max_temp = 0;
|
||||
}
|
||||
|
||||
HAL_GPIO_WritePin(SLAVE_POWER_0_GPIO_Port, SLAVE_POWER_0_Pin, GPIO_PIN_SET);
|
||||
@ -47,17 +48,11 @@ void slaves_check() {
|
||||
} else if (slaves[i].error.kind == SLAVE_ERR_TIMEOUT) {
|
||||
slaves[i].error.kind = SLAVE_ERR_NONE;
|
||||
}
|
||||
for (int j = 0; j < N_CELLS_SERIES; j++) {
|
||||
uint16_t v = slaves[i].voltages[j];
|
||||
if (v < min_voltage_new) {
|
||||
min_voltage_new = v;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < N_TEMP_SENSORS; j++) {
|
||||
int16_t t = slaves[i].temperatures[j];
|
||||
if (t > max_temp_new) {
|
||||
max_temp_new = t;
|
||||
if (slaves[i].min_voltage < min_voltage_new) {
|
||||
min_voltage_new = slaves[i].min_voltage;
|
||||
}
|
||||
if (slaves[i].max_temp > max_temp_new) {
|
||||
max_temp_new = slaves[i].max_temp;
|
||||
}
|
||||
|
||||
if (slaves[i].error.kind != SLAVE_ERR_NONE) {
|
||||
@ -93,6 +88,24 @@ void slaves_handle_panic(const uint8_t *data) {
|
||||
slaves[slave_id].last_message = HAL_GetTick();
|
||||
}
|
||||
|
||||
void slaves_handle_status(const uint8_t *data) {
|
||||
uint8_t slave_id = data[0] & 0x7F;
|
||||
int error = data[0] & 0x80;
|
||||
if (error) {
|
||||
if (slaves[slave_id].error.kind == SLAVE_ERR_NONE) {
|
||||
slaves[slave_id].error.kind = SLAVE_ERR_UNKNOWN;
|
||||
}
|
||||
} else {
|
||||
slaves[slave_id].error.kind = SLAVE_ERR_NONE;
|
||||
}
|
||||
slaves[slave_id].soc = data[1];
|
||||
const uint8_t *ptr = &data[2];
|
||||
slaves[slave_id].min_voltage = ftcan_unmarshal_unsigned(&ptr, 2);
|
||||
slaves[slave_id].max_voltage = ftcan_unmarshal_unsigned(&ptr, 2);
|
||||
slaves[slave_id].max_temp = ftcan_unmarshal_unsigned(&ptr, 2);
|
||||
slaves[slave_id].last_message = HAL_GetTick();
|
||||
}
|
||||
|
||||
void slaves_handle_log(const uint8_t *data) {
|
||||
// TODO
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ target: ams-master-23
|
||||
# Can be C or C++
|
||||
language: C
|
||||
|
||||
optimization: Og
|
||||
optimization: O0 -Og
|
||||
|
||||
# MCU settings
|
||||
targetMCU: stm32f3x
|
||||
@ -46,7 +46,6 @@ assemblyFlags: []
|
||||
linkerFlags:
|
||||
- -specs=nano.specs
|
||||
|
||||
|
||||
# libraries to be included. The -l prefix to the library will be automatically added.
|
||||
libraries:
|
||||
- c
|
||||
@ -67,7 +66,6 @@ excludes:
|
||||
- "**/example/**"
|
||||
- "**_template.*"
|
||||
|
||||
|
||||
# Include directories (directories containing .h or .hpp files)
|
||||
# If a CubeMX makefile is present it will automatically include the include directories from that makefile.
|
||||
includeDirectories:
|
||||
@ -83,7 +81,6 @@ includeDirectories:
|
||||
- Core/Src/**
|
||||
- Core/Lib/**
|
||||
|
||||
|
||||
# Files that should be included in the compilation.
|
||||
# If a CubeMX makefile is present it will automatically include the c and cpp/cxx files from that makefile.
|
||||
# Glob patterns (https://www.wikiwand.com/en/Glob_(programming)) can be used.
|
||||
@ -119,7 +116,6 @@ sourceFiles:
|
||||
- Core/Src/**
|
||||
- Core/Lib/**
|
||||
|
||||
|
||||
# When no makefile is present it will show a warning pop-up.
|
||||
# However when compilation without the CubeMX Makefile is desired, this can be turned of.
|
||||
suppressMakefileWarning: false
|
||||
@ -136,4 +132,3 @@ customMakefileRules:
|
||||
makeFlags:
|
||||
# - -O # use this option when the output of make is mixed up only works for make version 4.0 and upwards
|
||||
# - --silent # use this option to silence the output of the build
|
||||
|
@ -22,7 +22,7 @@ TARGET = ams-master-23
|
||||
# debug build?
|
||||
DEBUG = 1
|
||||
# optimization
|
||||
OPT = -Og
|
||||
OPT = -O0 -Og
|
||||
|
||||
|
||||
#######################################
|
||||
|
Loading…
x
Reference in New Issue
Block a user