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