Добавлены таймауты CAN
This commit is contained in:
parent
adb3e378fe
commit
4da836da77
|
|
@ -25,7 +25,7 @@ typedef struct
|
||||||
|
|
||||||
// @timeout_cycle keeps maximum timeout for frame, user responsibility
|
// @timeout_cycle keeps maximum timeout for frame, user responsibility
|
||||||
// to init this field and use it in missing frame monitoring function
|
// to init this field and use it in missing frame monitoring function
|
||||||
uint32_t prev_cycle;
|
uint32_t timeout_cycle;
|
||||||
|
|
||||||
// @frame_cnt keeps count of all the received frames
|
// @frame_cnt keeps count of all the received frames
|
||||||
uint32_t frame_cnt;
|
uint32_t frame_cnt;
|
||||||
|
|
|
||||||
|
|
@ -12,52 +12,6 @@
|
||||||
#define LOG_SIGN "CAN_RECEIVED"
|
#define LOG_SIGN "CAN_RECEIVED"
|
||||||
#define LOGGER env->logger
|
#define LOGGER env->logger
|
||||||
|
|
||||||
void CanSpamReceiver_Init(tCanSpamReceiver *env,
|
|
||||||
tSerialPortFrameIO *ioCanFrame,
|
|
||||||
tLoggerInterface *logger) {
|
|
||||||
|
|
||||||
env->ioCanFrame = ioCanFrame;
|
|
||||||
env->logger = logger;
|
|
||||||
env->access = osMutexNew(NULL);
|
|
||||||
|
|
||||||
/*
|
|
||||||
env->ccu_candb_rx_LOCAL_HVAC_VIN = osMessageQueueNew(1, 17, NULL);
|
|
||||||
env->ccu_candb_rx_LOCAL_HVAC_UDS_VIN = osMessageQueueNew(1, 17, NULL);
|
|
||||||
env->ccu_candb_rx_TM_CP = osMessageQueueNew(1, sizeof(ccu_candb_rx.TM_CP), NULL);
|
|
||||||
env->ccu_candb_rx_FIU_CCU1 = osMessageQueueNew(1, sizeof(ccu_candb_rx.FIU_CCU1), NULL);
|
|
||||||
env->ccu_candb_rx_FIU_CCU2 = osMessageQueueNew(1, sizeof(ccu_candb_rx.FIU_CCU2), NULL);
|
|
||||||
env->ccu_candb_rx_BCM_Powertrain = osMessageQueueNew(1, sizeof(ccu_candb_rx.BCM_Powertrain), NULL);
|
|
||||||
env->ccu_candb_rx_BCM_CLIMATIC_DATA = osMessageQueueNew(1, sizeof(ccu_candb_rx.BCM_CLIMATIC_DATA), NULL);
|
|
||||||
env->ccu_candb_rx_EMS_Veh = osMessageQueueNew(1, sizeof(ccu_candb_rx.EMS_Veh), NULL);
|
|
||||||
env->ccu_candb_rx_ESC_04 = osMessageQueueNew(1, sizeof(ccu_candb_rx.ESC_04), NULL);
|
|
||||||
env->ccu_candb_rx_BCM_VEH_STATE = osMessageQueueNew(1, sizeof(ccu_candb_rx.BCM_VEH_STATE), NULL);
|
|
||||||
env->ccu_candb_rx_EMS_HVC_Req_Msg = osMessageQueueNew(1, sizeof(ccu_candb_rx.EMS_HVC_Req_Msg), NULL);
|
|
||||||
env->ccu_candb_rx_HVC_Err_Status_Msg = osMessageQueueNew(1, sizeof(ccu_candb_rx.HVC_Err_Status_Msg), NULL);
|
|
||||||
*/
|
|
||||||
env->ccu_candb_rx_LOCAL_HVAC_VIN = osMessageQueueNew(1, 17, NULL);
|
|
||||||
env->ccu_candb_rx_LOCAL_HVAC_UDS_VIN = osMessageQueueNew(1, 17, NULL);
|
|
||||||
env->ccu_candb_rx_TM_CP = osMessageQueueNew(1, sizeof(rtDW.TM_CP_model), NULL);
|
|
||||||
env->ccu_candb_rx_FIU_CCU1 = osMessageQueueNew(1, sizeof(rtDW.FIU_CCU1_MODEL), NULL);
|
|
||||||
env->ccu_candb_rx_FIU_CCU2 = osMessageQueueNew(1, sizeof(rtDW.FIU_CCU2_MODEL), NULL);
|
|
||||||
env->ccu_candb_rx_BCM_Powertrain = osMessageQueueNew(1, sizeof(rtDW.CCUCAN_BCM_Powertrain_model), NULL);
|
|
||||||
env->ccu_candb_rx_BCM_CLIMATIC_DATA = osMessageQueueNew(1, sizeof(rtDW.CCUCAN_BCM_Climatic_model), NULL);
|
|
||||||
env->ccu_candb_rx_EMS_Veh = osMessageQueueNew(1, sizeof(rtDW.CCUCAN_EMS_Veh_model), NULL);
|
|
||||||
env->ccu_candb_rx_ESC_04 = osMessageQueueNew(1, sizeof(rtDW.CCUCAN_ESC_04_model), NULL);
|
|
||||||
env->ccu_candb_rx_BCM_VEH_STATE = osMessageQueueNew(1, sizeof(rtDW.CCUCAN_BCM_VEH_STATE_model), NULL);
|
|
||||||
env->ccu_candb_rx_EMS_HVC_Req_Msg = osMessageQueueNew(1, sizeof(rtDW.CCUCAN_EMS_HVC_REQ_MSG_MODEL), NULL);
|
|
||||||
env->ccu_candb_rx_HVC_Err_Status_Msg = osMessageQueueNew(1, sizeof(rtDW.HVC_ERR_STATUS_MSG_MODEL), NULL);
|
|
||||||
|
|
||||||
env->thread.stack = tCanSpamReceiver_stack;
|
|
||||||
InitThreadAtr(&env->thread.attr, "CanSpamRec", &env->thread.controlBlock, sizeof(env->thread.controlBlock),
|
|
||||||
env->thread.stack, tCanSpamReceiver_stack_size, osPriorityNormal);
|
|
||||||
env->thread.id = 0;
|
|
||||||
|
|
||||||
// InitThreadAtrStatic(&env->thread.attr, "CanSpamRec", env->thread.controlBlock, env->thread.stack,
|
|
||||||
// osPriorityNormal);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define timeout_CAN_Threshold_Error 3000
|
|
||||||
|
|
||||||
// Структура для таблицы мониторов
|
// Структура для таблицы мониторов
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t can_id;
|
uint32_t can_id;
|
||||||
|
|
@ -101,6 +55,72 @@ static const CAN_MonitorEntry_t g_can_monitors[] = {
|
||||||
|
|
||||||
#define CAN_MONITOR_COUNT (sizeof(g_can_monitors) / sizeof(g_can_monitors[0]))
|
#define CAN_MONITOR_COUNT (sizeof(g_can_monitors) / sizeof(g_can_monitors[0]))
|
||||||
|
|
||||||
|
// Функция поиска монитора по CAN ID
|
||||||
|
static FrameMonitor_t* FindMonitorByCanId(uint32_t can_id) {
|
||||||
|
for (uint32_t i = 0; i < CAN_MONITOR_COUNT; i++) {
|
||||||
|
if (g_can_monitors[i].can_id == can_id) {
|
||||||
|
return g_can_monitors[i].monitor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL; // Не найден
|
||||||
|
}
|
||||||
|
|
||||||
|
void CanSpamReceiver_Init(tCanSpamReceiver *env,
|
||||||
|
tSerialPortFrameIO *ioCanFrame,
|
||||||
|
tLoggerInterface *logger) {
|
||||||
|
|
||||||
|
env->ioCanFrame = ioCanFrame;
|
||||||
|
env->logger = logger;
|
||||||
|
env->access = osMutexNew(NULL);
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < CAN_MONITOR_COUNT; i++) {
|
||||||
|
FrameMonitor_t *mon = g_can_monitors[i].monitor;
|
||||||
|
mon->timeout_cycle = 3000;
|
||||||
|
}
|
||||||
|
|
||||||
|
// VIN
|
||||||
|
FrameMonitor_t *vin_mon = FindMonitorByCanId(VEH_VIN_CANID);
|
||||||
|
if (vin_mon != NULL) {
|
||||||
|
vin_mon->timeout_cycle = 45000; // 45 секунд
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
env->ccu_candb_rx_LOCAL_HVAC_VIN = osMessageQueueNew(1, 17, NULL);
|
||||||
|
env->ccu_candb_rx_LOCAL_HVAC_UDS_VIN = osMessageQueueNew(1, 17, NULL);
|
||||||
|
env->ccu_candb_rx_TM_CP = osMessageQueueNew(1, sizeof(ccu_candb_rx.TM_CP), NULL);
|
||||||
|
env->ccu_candb_rx_FIU_CCU1 = osMessageQueueNew(1, sizeof(ccu_candb_rx.FIU_CCU1), NULL);
|
||||||
|
env->ccu_candb_rx_FIU_CCU2 = osMessageQueueNew(1, sizeof(ccu_candb_rx.FIU_CCU2), NULL);
|
||||||
|
env->ccu_candb_rx_BCM_Powertrain = osMessageQueueNew(1, sizeof(ccu_candb_rx.BCM_Powertrain), NULL);
|
||||||
|
env->ccu_candb_rx_BCM_CLIMATIC_DATA = osMessageQueueNew(1, sizeof(ccu_candb_rx.BCM_CLIMATIC_DATA), NULL);
|
||||||
|
env->ccu_candb_rx_EMS_Veh = osMessageQueueNew(1, sizeof(ccu_candb_rx.EMS_Veh), NULL);
|
||||||
|
env->ccu_candb_rx_ESC_04 = osMessageQueueNew(1, sizeof(ccu_candb_rx.ESC_04), NULL);
|
||||||
|
env->ccu_candb_rx_BCM_VEH_STATE = osMessageQueueNew(1, sizeof(ccu_candb_rx.BCM_VEH_STATE), NULL);
|
||||||
|
env->ccu_candb_rx_EMS_HVC_Req_Msg = osMessageQueueNew(1, sizeof(ccu_candb_rx.EMS_HVC_Req_Msg), NULL);
|
||||||
|
env->ccu_candb_rx_HVC_Err_Status_Msg = osMessageQueueNew(1, sizeof(ccu_candb_rx.HVC_Err_Status_Msg), NULL);
|
||||||
|
*/
|
||||||
|
env->ccu_candb_rx_LOCAL_HVAC_VIN = osMessageQueueNew(1, 17, NULL);
|
||||||
|
env->ccu_candb_rx_LOCAL_HVAC_UDS_VIN = osMessageQueueNew(1, 17, NULL);
|
||||||
|
env->ccu_candb_rx_TM_CP = osMessageQueueNew(1, sizeof(rtDW.TM_CP_model), NULL);
|
||||||
|
env->ccu_candb_rx_FIU_CCU1 = osMessageQueueNew(1, sizeof(rtDW.FIU_CCU1_MODEL), NULL);
|
||||||
|
env->ccu_candb_rx_FIU_CCU2 = osMessageQueueNew(1, sizeof(rtDW.FIU_CCU2_MODEL), NULL);
|
||||||
|
env->ccu_candb_rx_BCM_Powertrain = osMessageQueueNew(1, sizeof(rtDW.CCUCAN_BCM_Powertrain_model), NULL);
|
||||||
|
env->ccu_candb_rx_BCM_CLIMATIC_DATA = osMessageQueueNew(1, sizeof(rtDW.CCUCAN_BCM_Climatic_model), NULL);
|
||||||
|
env->ccu_candb_rx_EMS_Veh = osMessageQueueNew(1, sizeof(rtDW.CCUCAN_EMS_Veh_model), NULL);
|
||||||
|
env->ccu_candb_rx_ESC_04 = osMessageQueueNew(1, sizeof(rtDW.CCUCAN_ESC_04_model), NULL);
|
||||||
|
env->ccu_candb_rx_BCM_VEH_STATE = osMessageQueueNew(1, sizeof(rtDW.CCUCAN_BCM_VEH_STATE_model), NULL);
|
||||||
|
env->ccu_candb_rx_EMS_HVC_Req_Msg = osMessageQueueNew(1, sizeof(rtDW.CCUCAN_EMS_HVC_REQ_MSG_MODEL), NULL);
|
||||||
|
env->ccu_candb_rx_HVC_Err_Status_Msg = osMessageQueueNew(1, sizeof(rtDW.HVC_ERR_STATUS_MSG_MODEL), NULL);
|
||||||
|
|
||||||
|
env->thread.stack = tCanSpamReceiver_stack;
|
||||||
|
InitThreadAtr(&env->thread.attr, "CanSpamRec", &env->thread.controlBlock, sizeof(env->thread.controlBlock),
|
||||||
|
env->thread.stack, tCanSpamReceiver_stack_size, osPriorityNormal);
|
||||||
|
env->thread.id = 0;
|
||||||
|
|
||||||
|
// InitThreadAtrStatic(&env->thread.attr, "CanSpamRec", env->thread.controlBlock, env->thread.stack,
|
||||||
|
// osPriorityNormal);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void CheckAllCANMonitors(void) {
|
static void CheckAllCANMonitors(void) {
|
||||||
uint32_t current_time = SystemGetMs();
|
uint32_t current_time = SystemGetMs();
|
||||||
|
|
||||||
|
|
@ -109,7 +129,7 @@ static void CheckAllCANMonitors(void) {
|
||||||
|
|
||||||
// Проверяем таймаут
|
// Проверяем таймаут
|
||||||
uint32_t diff = current_time - mon->last_cycle;
|
uint32_t diff = current_time - mon->last_cycle;
|
||||||
uint8_t error = (diff > timeout_CAN_Threshold_Error) ? 1 : 0;
|
uint8_t error = (diff > mon->timeout_cycle) ? 1 : 0;
|
||||||
|
|
||||||
// Сохраняем ошибку
|
// Сохраняем ошибку
|
||||||
*(g_can_monitors[i].error_flag) = error;
|
*(g_can_monitors[i].error_flag) = error;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue