Handle slave status frames
This commit is contained in:
@ -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;
|
||||
}
|
||||
if (slaves[i].min_voltage < min_voltage_new) {
|
||||
min_voltage_new = slaves[i].min_voltage;
|
||||
}
|
||||
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].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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user