enable streaming for testing, route FC messages to isotp stack
This commit is contained in:
parent
354b6dc453
commit
765f1e5ee1
@ -22,6 +22,9 @@
|
||||
#define CAN_ID_SHUNT_CURRENT_COUNTER 0x527
|
||||
#define CAN_ID_SHUNT_ENERGY_COUNTER 0x528
|
||||
|
||||
//TEMP until final IDs are defined
|
||||
#define CAN_ID_LOG_FC 0x132
|
||||
|
||||
void can_init(FDCAN_HandleTypeDef *handle);
|
||||
HAL_StatusTypeDef can_send_status();
|
||||
HAL_StatusTypeDef can_send_error(TSErrorKind kind, uint8_t arg);
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 4e3bb026f88a7ee5a89ec48dc10281e8e0a3175a
|
||||
Subproject commit 887f92167d58e551abac18f4f899c74bddc13d46
|
@ -3,13 +3,15 @@
|
||||
#include "log.h"
|
||||
|
||||
/* ISO-TP Backend Configuration */
|
||||
#define ISOTP_LOG_BUFFER_MIN_LEVEL LOG_LEVEL_WARNING // log level where messages are buffered before streaming mode is enabled
|
||||
#define ISOTP_LOG_BUFFER_MIN_LEVEL LOG_LEVEL_INFO // log level where messages are buffered before streaming mode is enabled
|
||||
#define ISOTP_LOG_BUFFER_1_BYTES 1024 // Primary buffer, used when streaming is disabled
|
||||
#define ISOTP_LOG_BUFFER_2_BYTES 256 // Secondary buffer, used for double-buffering during streaming, can be smaller
|
||||
|
||||
|
||||
/* ISO-TP CAN ID configuration */
|
||||
#ifndef ISOTP_LOG_CAN_ID
|
||||
#define ISOTP_LOG_CAN_ID 0x123 // CAN ID to use for ISO-TP log messages
|
||||
#endif
|
||||
|
||||
/* ISO-TP backend API */
|
||||
void isotp_log_backend_init(void);
|
||||
|
@ -1,6 +1,9 @@
|
||||
#include "can.h"
|
||||
|
||||
#include "imd_monitoring.h"
|
||||
#include "isotp.h"
|
||||
#include "isotp_log_backend.h"
|
||||
#include "log.h"
|
||||
#include "main.h"
|
||||
#include "shunt_monitoring.h"
|
||||
#include "battery.h"
|
||||
@ -33,7 +36,7 @@ HAL_StatusTypeDef can_send_status() {
|
||||
uint8_t data[8];
|
||||
data[0] = ts_state.current_state | (sdc_closed << 7);
|
||||
data[1] = roundf(current_soc);
|
||||
ftcan_marshal_unsigned(&data[2], min_voltage, 2); //was declared in slave_monitoring.c
|
||||
ftcan_marshal_unsigned(&data[2], min_voltage, 2);
|
||||
ftcan_marshal_signed(&data[4], max_temp, 2);
|
||||
data[6] = imd_data.state | (imd_data.ok << 7);
|
||||
if (imd_data.r_iso < 0xFFF) {
|
||||
@ -58,24 +61,21 @@ HAL_StatusTypeDef can_send_error(TSErrorKind kind, uint8_t arg) {
|
||||
return ftcan_transmit(CAN_ID_AMS_ERROR, data, sizeof(data));
|
||||
}
|
||||
|
||||
void ftcan_msg_received_cb(uint16_t id, size_t, const uint8_t *data) {
|
||||
void ftcan_msg_received_cb(uint16_t id, size_t len, const uint8_t *data) {
|
||||
if ((id & 0xFF0) == CAN_ID_SHUNT_BASE) {
|
||||
shunt_handle_can_msg(id, data);
|
||||
return;
|
||||
}
|
||||
// else if ((id & 0xFF0) == CAN_ID_SLAVE_STATUS_BASE) {
|
||||
// slaves_handle_status(data);
|
||||
// return;
|
||||
// }
|
||||
// switch (id) {
|
||||
// case CAN_ID_SLAVE_PANIC:
|
||||
// slaves_handle_panic(data);
|
||||
// break;
|
||||
// case CAN_ID_SLAVE_LOG:
|
||||
// slaves_handle_log(data);
|
||||
// break;
|
||||
// case CAN_ID_AMS_IN:
|
||||
// ts_sm_handle_ams_in(data);
|
||||
// break;
|
||||
// }
|
||||
|
||||
switch (id) {
|
||||
case CAN_ID_LOG_FC:
|
||||
auto status = isotp_handle_flow_control(ISOTP_LOG_CAN_ID, data, len);
|
||||
if (status != ISOTP_OK) {
|
||||
log_debug("Error when handling flow control: %s", isotp_status_to_string(status));
|
||||
}
|
||||
break;
|
||||
case CAN_ID_AMS_IN:
|
||||
ts_sm_handle_ams_in(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,8 @@
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "battery.h"
|
||||
#include "isotp.h"
|
||||
#include "isotp_log_backend.h"
|
||||
#define SWO_LOG_PREFIX "[MAIN] "
|
||||
#include "swo_log.h"
|
||||
|
||||
@ -93,15 +95,15 @@ void init_logging(void);
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
#define MAIN_LOOP_PERIOD 50
|
||||
#define ISO_TP_UPDATE_PERIOD 1
|
||||
|
||||
static void loop_delay() {
|
||||
static uint32_t last_loop = 0;
|
||||
uint32_t dt = HAL_GetTick() - last_loop;
|
||||
if (dt < MAIN_LOOP_PERIOD) {
|
||||
HAL_Delay(MAIN_LOOP_PERIOD - dt);
|
||||
//HAL_GPIO_WritePin(STATUS2_GPIO_Port, STATUS2_Pin, GPIO_PIN_RESET);
|
||||
} else {
|
||||
//HAL_GPIO_WritePin(STATUS2_GPIO_Port, STATUS2_Pin, GPIO_PIN_SET);
|
||||
while (dt < MAIN_LOOP_PERIOD) {
|
||||
HAL_Delay(ISO_TP_UPDATE_PERIOD);
|
||||
isotp_update(); // make sure isotp messages are processed reasonably quickly
|
||||
dt = HAL_GetTick() - last_loop;
|
||||
}
|
||||
last_loop = HAL_GetTick();
|
||||
}
|
||||
@ -132,6 +134,8 @@ void init_logging(void) {
|
||||
/* Register and initialize SWO backend */
|
||||
swo_log_backend_init();
|
||||
|
||||
isotp_log_backend_init();
|
||||
|
||||
/* Initialize all registered backends */
|
||||
log_init_all_backends();
|
||||
|
||||
@ -194,6 +198,10 @@ int main(void)
|
||||
|
||||
// init for master functions
|
||||
can_init(&hfdcan1);
|
||||
|
||||
// for testing. in the final code can log streaming will be enabled by can message
|
||||
isotp_log_enable_streaming(LOG_LEVEL_INFO);
|
||||
|
||||
shunt_init();
|
||||
ts_sm_init();
|
||||
soc_init();
|
||||
@ -208,6 +216,7 @@ int main(void)
|
||||
int error_count = 0;
|
||||
while (1)
|
||||
{
|
||||
isotp_update();
|
||||
//left over from slave communication test, could be nicer and in an additional function !!
|
||||
if (error_count > 25) {
|
||||
debug_log(LOG_LEVEL_ERROR, "Too many errors, restarting BMS...");
|
||||
@ -221,7 +230,6 @@ int main(void)
|
||||
}
|
||||
error_count = 0;
|
||||
}
|
||||
uint32_t lastTimestamp = HAL_GetTick();
|
||||
|
||||
update_sdc();
|
||||
update_tsal_signals();
|
||||
@ -238,6 +246,7 @@ int main(void)
|
||||
soc_update();
|
||||
imd_update();
|
||||
can_send_status();
|
||||
isotp_update();
|
||||
|
||||
loop_delay();
|
||||
/* USER CODE END WHILE */
|
||||
|
Loading…
x
Reference in New Issue
Block a user