567 lines
27 KiB
C
567 lines
27 KiB
C
//
|
|
// Created by cfif on 05.04.2024.
|
|
//
|
|
#include <SystemDelayInterface.h>
|
|
#include "CanSpamReceiver.h"
|
|
#include "CmsisRtosThreadUtils.h"
|
|
#include "CanPorts.h"
|
|
#include "string.h"
|
|
#include "HVAC_model.h"
|
|
#include "MainStack.h"
|
|
|
|
#define LOG_SIGN "CAN_RECEIVED"
|
|
#define LOGGER env->logger
|
|
|
|
// Структура для таблицы мониторов
|
|
typedef struct {
|
|
uint32_t can_id;
|
|
FrameMonitor_t *monitor;
|
|
uint8_t *error_flag_missing;
|
|
uint32_t *time_flag;
|
|
} CAN_MonitorEntry_t;
|
|
|
|
// Таблица всех мониторов
|
|
static const CAN_MonitorEntry_t g_can_monitors[] = {
|
|
{ESC_04_CANID, &ccu_candb_rx.ESC_04.mon1, &ccu_candb_error_missing_rx.ESC_04, &ccu_candb_time_missing_rx.ESC_04},
|
|
{EMS_Veh_CANID, &ccu_candb_rx.EMS_Veh.mon1, &ccu_candb_error_missing_rx.EMS_Veh, &ccu_candb_time_missing_rx.EMS_Veh},
|
|
{BCM_Powertrain_CANID, &ccu_candb_rx.BCM_Powertrain.mon1, &ccu_candb_error_missing_rx.BCM_Powertrain, &ccu_candb_time_missing_rx.BCM_Powertrain},
|
|
{EMS_Veh_02_CANID, &ccu_candb_rx.EMS_Veh_02.mon1, &ccu_candb_error_missing_rx.EMS_Veh_02, &ccu_candb_time_missing_rx.EMS_Veh_02},
|
|
{BCM_EEM_CANID, &ccu_candb_rx.BCM_EEM.mon1, &ccu_candb_error_missing_rx.BCM_EEM, &ccu_candb_time_missing_rx.BCM_EEM},
|
|
{DMFR_Msg1_CANID, &ccu_candb_rx.DMFR_Msg1.mon1, &ccu_candb_error_missing_rx.DMFR_Msg1, &ccu_candb_time_missing_rx.DMFR_Msg1},
|
|
{DMFL_Msg1_CANID, &ccu_candb_rx.DMFL_Msg1.mon1, &ccu_candb_error_missing_rx.DMFL_Msg1, &ccu_candb_time_missing_rx.DMFL_Msg1},
|
|
{TM_Stat_CANID, &ccu_candb_rx.TM_Stat.mon1, &ccu_candb_error_missing_rx.TM_Stat, &ccu_candb_time_missing_rx.TM_Stat},
|
|
{TM_CP_CANID, &ccu_candb_rx.TM_CP.mon1, &ccu_candb_error_missing_rx.TM_CP, &ccu_candb_time_missing_rx.TM_CP},
|
|
{HVC_CCU_Status_Msg_CANID, &ccu_candb_rx.HVC_CCU_Status_Msg.mon1, &ccu_candb_error_missing_rx.HVC_CCU_Status_Msg, &ccu_candb_time_missing_rx.HVC_CCU_Status_Msg},
|
|
{BCM_VEH_STATE_CANID, &ccu_candb_rx.BCM_VEH_STATE.mon1, &ccu_candb_error_missing_rx.BCM_VEH_STATE, &ccu_candb_time_missing_rx.BCM_VEH_STATE},
|
|
{EMS_HVC_Req_Msg_CANID, &ccu_candb_rx.EMS_HVC_Req_Msg.mon1, &ccu_candb_error_missing_rx.EMS_HVC_Req_Msg, &ccu_candb_time_missing_rx.EMS_HVC_Req_Msg},
|
|
{HVC_Err_Status_Msg_CANID, &ccu_candb_rx.HVC_Err_Status_Msg.mon1, &ccu_candb_error_missing_rx.HVC_Err_Status_Msg, &ccu_candb_time_missing_rx.HVC_Err_Status_Msg},
|
|
{BCM_CLIMATIC_DATA_CANID, &ccu_candb_rx.BCM_CLIMATIC_DATA.mon1, &ccu_candb_error_missing_rx.BCM_CLIMATIC_DATA, &ccu_candb_time_missing_rx.BCM_CLIMATIC_DATA},
|
|
{VCU_CCU_Req_CANID, &ccu_candb_rx.VCU_CCU_Req.mon1, &ccu_candb_error_missing_rx.VCU_CCU_Req, &ccu_candb_time_missing_rx.VCU_CCU_Req},
|
|
{ESC_08_CANID, &ccu_candb_rx.ESC_08.mon1, &ccu_candb_error_missing_rx.ESC_08, &ccu_candb_time_missing_rx.ESC_08},
|
|
{SMFL_status_CANID, &ccu_candb_rx.SMFL_status.mon1, &ccu_candb_error_missing_rx.SMFL_status, &ccu_candb_time_missing_rx.SMFL_status},
|
|
{SMFR_status_CANID, &ccu_candb_rx.SMFR_status.mon1, &ccu_candb_error_missing_rx.SMFR_status, &ccu_candb_time_missing_rx.SMFR_status},
|
|
{SMRL_status_CANID, &ccu_candb_rx.SMRL_status.mon1, &ccu_candb_error_missing_rx.SMRL_status, &ccu_candb_time_missing_rx.SMRL_status},
|
|
{SMRR_status_CANID, &ccu_candb_rx.SMRR_status.mon1, &ccu_candb_error_missing_rx.SMRR_status, &ccu_candb_time_missing_rx.SMRR_status},
|
|
{SDM_Cmd_CANID, &ccu_candb_rx.SDM_Cmd.mon1, &ccu_candb_error_missing_rx.SDM_Cmd, &ccu_candb_time_missing_rx.SDM_Cmd},
|
|
{VEH_VIN_CANID, &ccu_candb_rx.VEH_VIN.mon1, &ccu_candb_error_missing_rx.VEH_VIN, &ccu_candb_time_missing_rx.VEH_VIN},
|
|
{OCUFL_MSG_CANID, &ccu_candb_rx.OCUFL_MSG.mon1, &ccu_candb_error_missing_rx.OCUFL_MSG, &ccu_candb_time_missing_rx.OCUFL_MSG},
|
|
{OCUFR_MSG_CANID, &ccu_candb_rx.OCUFR_MSG.mon1, &ccu_candb_error_missing_rx.OCUFR_MSG, &ccu_candb_time_missing_rx.OCUFR_MSG},
|
|
{OCURL_MSG_CANID, &ccu_candb_rx.OCURL_MSG.mon1, &ccu_candb_error_missing_rx.OCURL_MSG, &ccu_candb_time_missing_rx.OCURL_MSG},
|
|
{OCURR_MSG_CANID, &ccu_candb_rx.OCURR_MSG.mon1, &ccu_candb_error_missing_rx.OCURR_MSG, &ccu_candb_time_missing_rx.OCURR_MSG},
|
|
{DW_STATE_CANID, &ccu_candb_rx.DW_STATE.mon1, &ccu_candb_error_missing_rx.DW_STATE, &ccu_candb_time_missing_rx.DW_STATE},
|
|
{FIU_CCU1_CANID, &ccu_candb_rx.FIU_CCU1.mon1, &ccu_candb_error_missing_rx.FIU_CCU1, &ccu_candb_time_missing_rx.FIU_CCU1},
|
|
{FIU_CCU2_CANID, &ccu_candb_rx.FIU_CCU2.mon1, &ccu_candb_error_missing_rx.FIU_CCU2, &ccu_candb_time_missing_rx.FIU_CCU2},
|
|
{FIU_CCU3_CANID, &ccu_candb_rx.FIU_CCU3.mon1, &ccu_candb_error_missing_rx.FIU_CCU3, &ccu_candb_time_missing_rx.FIU_CCU3},
|
|
};
|
|
|
|
#define CAN_MONITOR_COUNT (sizeof(g_can_monitors) / sizeof(g_can_monitors[0]))
|
|
|
|
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;
|
|
// }
|
|
|
|
g_can_monitors[CAN_IDX_ESC_04].monitor->timeout_cycle = ESC_04_CYC * 5; // 0
|
|
g_can_monitors[CAN_IDX_EMS_VEH].monitor->timeout_cycle = EMS_Veh_CYC * 5; // 1
|
|
g_can_monitors[CAN_IDX_BCM_POWERTRAIN].monitor->timeout_cycle = BCM_Powertrain_CYC * 5; // 2
|
|
g_can_monitors[CAN_IDX_EMS_VEH_02].monitor->timeout_cycle = EMS_Veh_02_CYC * 5; // 3
|
|
g_can_monitors[CAN_IDX_BCM_EEM].monitor->timeout_cycle = BCM_EEM_CYC * 5; // 4
|
|
g_can_monitors[CAN_IDX_DMFR_MSG1].monitor->timeout_cycle = DMFR_Msg1_CYC * 5; // 5
|
|
g_can_monitors[CAN_IDX_DMFL_MSG1].monitor->timeout_cycle = DMFL_Msg1_CYC * 5; // 6
|
|
g_can_monitors[CAN_IDX_TM_STAT].monitor->timeout_cycle = TM_Stat_CYC * 5; // 7
|
|
g_can_monitors[CAN_IDX_TM_CP].monitor->timeout_cycle = TM_CP_CYC * 5; // 8
|
|
g_can_monitors[CAN_IDX_HVC_CCU_STATUS_MSG].monitor->timeout_cycle = HVC_CCU_Status_Msg_CYC * 5; // 9
|
|
g_can_monitors[CAN_IDX_BCM_VEH_STATE].monitor->timeout_cycle = BCM_VEH_STATE_CYC * 5; // 10
|
|
g_can_monitors[CAN_IDX_EMS_HVC_REQ_MSG].monitor->timeout_cycle = EMS_HVC_Req_Msg_CYC * 5; // 11
|
|
g_can_monitors[CAN_IDX_HVC_ERR_STATUS_MSG].monitor->timeout_cycle = HVC_Err_Status_Msg_CYC * 5; // 12
|
|
g_can_monitors[CAN_IDX_BCM_CLIMATIC_DATA].monitor->timeout_cycle = BCM_CLIMATIC_DATA_CYC * 5; // 13
|
|
g_can_monitors[CAN_IDX_VCU_CCU_REQ].monitor->timeout_cycle = VCU_CCU_Req_CYC * 5; // 14
|
|
g_can_monitors[CAN_IDX_ESC_08].monitor->timeout_cycle = ESC_08_CYC * 5; // 15
|
|
g_can_monitors[CAN_IDX_SMFL_STATUS].monitor->timeout_cycle = SMFL_status_CYC * 5; // 16
|
|
g_can_monitors[CAN_IDX_SMFR_STATUS].monitor->timeout_cycle = SMFR_status_CYC * 5; // 17
|
|
g_can_monitors[CAN_IDX_SMRL_STATUS].monitor->timeout_cycle = SMRL_status_CYC * 5; // 18
|
|
g_can_monitors[CAN_IDX_SMRR_STATUS].monitor->timeout_cycle = SMRR_status_CYC * 5; // 19
|
|
g_can_monitors[CAN_IDX_SDM_CMD].monitor->timeout_cycle = 0; // 20
|
|
g_can_monitors[CAN_IDX_VEH_VIN].monitor->timeout_cycle = 45000; // 21
|
|
g_can_monitors[CAN_IDX_OCUFL_MSG].monitor->timeout_cycle = OCUFL_MSG_CYC * 5; // 22
|
|
g_can_monitors[CAN_IDX_OCUFR_MSG].monitor->timeout_cycle = OCUFR_MSG_CYC * 5; // 23
|
|
g_can_monitors[CAN_IDX_OCURL_MSG].monitor->timeout_cycle = OCURL_MSG_CYC * 5; // 24
|
|
g_can_monitors[CAN_IDX_OCURR_MSG].monitor->timeout_cycle = OCURR_MSG_CYC * 5; // 25
|
|
g_can_monitors[CAN_IDX_DW_STATE].monitor->timeout_cycle = DW_STATE_CYC * 5; // 26
|
|
g_can_monitors[CAN_IDX_FIU_CCU1].monitor->timeout_cycle = 0; // 27
|
|
g_can_monitors[CAN_IDX_FIU_CCU2].monitor->timeout_cycle = 0; // 28
|
|
g_can_monitors[CAN_IDX_FIU_CCU3].monitor->timeout_cycle = 0; // 29
|
|
|
|
// VIN
|
|
// FrameMonitor_t *vin_mon = g_can_monitors[CAN_IDX_VEH_VIN].monitor;
|
|
// vin_mon->timeout_cycle = 45000; // 45 секунд для VIN
|
|
|
|
/*
|
|
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_error_missing_rx = osMessageQueueNew(1, sizeof(ccu_candb_error_missing_rx_t), NULL);
|
|
env->ccu_candb_time_missing_rx = osMessageQueueNew(1, sizeof(ccu_candb_time_missing_rx_t), 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_FIU_CCU3 = osMessageQueueNew(1, sizeof(rtDW.FIU_CCU3_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);
|
|
|
|
//cfif env->ccu_candb_rx_BCM_EEM = osMessageQueueNew(1, sizeof(rtDW.), NULL);
|
|
//cfif env->ccu_candb_rx_EMS_Veh_02 = osMessageQueueNew(1, sizeof(rtDW.), 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) {
|
|
uint32_t current_time = SystemGetMs();
|
|
|
|
for (uint32_t i = 0; i < CAN_MONITOR_COUNT; ++i) {
|
|
FrameMonitor_t *mon = g_can_monitors[i].monitor;
|
|
|
|
// Проверяем таймаут
|
|
uint32_t diff = current_time - mon->last_cycle;
|
|
uint8_t error_missing = (diff > mon->timeout_cycle) ? 1 : 0;
|
|
|
|
// Сохраняем ошибку
|
|
*(g_can_monitors[i].error_flag_missing) = error_missing;
|
|
|
|
// Сохраняем время
|
|
*(g_can_monitors[i].time_flag) = mon->last_cycle;
|
|
}
|
|
}
|
|
|
|
static void set_CanSpamReceiver(tCanSpamReceiver *env, uint32_t recid) {
|
|
osStatus_t status = osOK;
|
|
|
|
// ВСЕГДА проверяем все мониторы на таймаут
|
|
CheckAllCANMonitors();
|
|
|
|
|
|
uint32_t countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_error_missing_rx);
|
|
if (countQueue_ccu_candb_rx) {
|
|
status = osMessageQueuePut(env->ccu_candb_error_missing_rx, &ccu_candb_error_missing_rx, 0, 0U);
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_time_missing_rx);
|
|
if (countQueue_ccu_candb_rx) {
|
|
status = osMessageQueuePut(env->ccu_candb_time_missing_rx, &ccu_candb_time_missing_rx, 0, 0U);
|
|
}
|
|
|
|
|
|
//cfif countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_BCM_EEM);
|
|
if ((countQueue_ccu_candb_rx) && (recid == BCM_EEM_CANID)) {
|
|
//cfif status = osMessageQueuePut(env->ccu_candb_rx_BCM_EEM, &ccu_candb_rx.BCM_EEM, 0, 0U);
|
|
return;
|
|
}
|
|
|
|
//cfif countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_EMS_Veh_02);
|
|
if ((countQueue_ccu_candb_rx) && (recid == EMS_Veh_02_CANID)) {
|
|
//cfif status = osMessageQueuePut(env->ccu_candb_rx_EMS_Veh_02, &ccu_candb_rx.EMS_Veh_02, 0, 0U);
|
|
return;
|
|
}
|
|
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_TM_CP);
|
|
if ((countQueue_ccu_candb_rx) && (recid == TM_CP_CANID)) {
|
|
status = osMessageQueuePut(env->ccu_candb_rx_TM_CP, &ccu_candb_rx.TM_CP, 0, 0U);
|
|
return;
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_FIU_CCU1);
|
|
if ((countQueue_ccu_candb_rx) && (recid == FIU_CCU1_CANID)) {
|
|
status = osMessageQueuePut(env->ccu_candb_rx_FIU_CCU1, &ccu_candb_rx.FIU_CCU1, 0, 0U);
|
|
return;
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_FIU_CCU2);
|
|
if ((countQueue_ccu_candb_rx) && (recid == FIU_CCU2_CANID)) {
|
|
status = osMessageQueuePut(env->ccu_candb_rx_FIU_CCU2, &ccu_candb_rx.FIU_CCU2, 0, 0U);
|
|
return;
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_FIU_CCU3);
|
|
if ((countQueue_ccu_candb_rx) && (recid == FIU_CCU3_CANID)) {
|
|
status = osMessageQueuePut(env->ccu_candb_rx_FIU_CCU3, &ccu_candb_rx.FIU_CCU3, 0, 0U);
|
|
return;
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_BCM_Powertrain);
|
|
if ((countQueue_ccu_candb_rx) && (recid == BCM_Powertrain_CANID)) {
|
|
status = osMessageQueuePut(env->ccu_candb_rx_BCM_Powertrain, &ccu_candb_rx.BCM_Powertrain, 0, 0U);
|
|
return;
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_BCM_CLIMATIC_DATA);
|
|
if ((countQueue_ccu_candb_rx) && (recid == BCM_CLIMATIC_DATA_CANID)) {
|
|
status = osMessageQueuePut(env->ccu_candb_rx_BCM_CLIMATIC_DATA, &ccu_candb_rx.BCM_CLIMATIC_DATA, 0, 0U);
|
|
return;
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_EMS_Veh);
|
|
if ((countQueue_ccu_candb_rx) && (recid == EMS_Veh_CANID)) {
|
|
status = osMessageQueuePut(env->ccu_candb_rx_EMS_Veh, &ccu_candb_rx.EMS_Veh, 0, 0U);
|
|
return;
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_ESC_04);
|
|
if ((countQueue_ccu_candb_rx) && (recid == ESC_04_CANID)) {
|
|
status = osMessageQueuePut(env->ccu_candb_rx_ESC_04, &ccu_candb_rx.ESC_04, 0, 0U);
|
|
return;
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_BCM_VEH_STATE);
|
|
if ((countQueue_ccu_candb_rx) && (recid == BCM_VEH_STATE_CANID)) {
|
|
status = osMessageQueuePut(env->ccu_candb_rx_BCM_VEH_STATE, &ccu_candb_rx.BCM_VEH_STATE, 0, 0U);
|
|
return;
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_EMS_HVC_Req_Msg);
|
|
if ((countQueue_ccu_candb_rx) && (recid == EMS_HVC_Req_Msg_CANID)) {
|
|
status = osMessageQueuePut(env->ccu_candb_rx_EMS_HVC_Req_Msg, &ccu_candb_rx.EMS_HVC_Req_Msg, 0, 0U);
|
|
return;
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_HVC_Err_Status_Msg);
|
|
if ((countQueue_ccu_candb_rx) && (recid == HVC_Err_Status_Msg_CANID)) {
|
|
status = osMessageQueuePut(env->ccu_candb_rx_HVC_Err_Status_Msg, &ccu_candb_rx.HVC_Err_Status_Msg, 0, 0U);
|
|
return;
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_LOCAL_HVAC_VIN);
|
|
if ((countQueue_ccu_candb_rx) && (recid == VEH_VIN_CANID)) {
|
|
|
|
if (ccu_candb_rx.VEH_VIN.VIN_Addressing == 0) {
|
|
env->SET_HVAC_VIN[0] = ccu_candb_rx.VEH_VIN.VIN_Char1;
|
|
env->SET_HVAC_VIN[1] = ccu_candb_rx.VEH_VIN.VIN_Char2;
|
|
env->SET_HVAC_VIN[2] = ccu_candb_rx.VEH_VIN.VIN_Char3;
|
|
env->SET_HVAC_VIN[3] = ccu_candb_rx.VEH_VIN.VIN_Char4;
|
|
env->SET_HVAC_VIN[4] = ccu_candb_rx.VEH_VIN.VIN_Char5;
|
|
env->SET_HVAC_VIN[5] = ccu_candb_rx.VEH_VIN.VIN_Char6;
|
|
env->SET_HVAC_VIN[6] = ccu_candb_rx.VEH_VIN.VIN_Char7;
|
|
env->getVIN0 = true;
|
|
}
|
|
|
|
if (ccu_candb_rx.VEH_VIN.VIN_Addressing == 1) {
|
|
env->SET_HVAC_VIN[7] = ccu_candb_rx.VEH_VIN.VIN_Char8;
|
|
env->SET_HVAC_VIN[8] = ccu_candb_rx.VEH_VIN.VIN_Char9;
|
|
env->SET_HVAC_VIN[9] = ccu_candb_rx.VEH_VIN.VIN_Char10;
|
|
env->SET_HVAC_VIN[10] = ccu_candb_rx.VEH_VIN.VIN_Char11;
|
|
env->SET_HVAC_VIN[11] = ccu_candb_rx.VEH_VIN.VIN_Char12;
|
|
env->SET_HVAC_VIN[12] = ccu_candb_rx.VEH_VIN.VIN_Char13;
|
|
env->SET_HVAC_VIN[13] = ccu_candb_rx.VEH_VIN.VIN_Char14;
|
|
env->getVIN1 = true;
|
|
}
|
|
|
|
if (ccu_candb_rx.VEH_VIN.VIN_Addressing == 2) {
|
|
env->SET_HVAC_VIN[14] = ccu_candb_rx.VEH_VIN.VIN_Char15;
|
|
env->SET_HVAC_VIN[15] = ccu_candb_rx.VEH_VIN.VIN_Char16;
|
|
env->SET_HVAC_VIN[16] = ccu_candb_rx.VEH_VIN.VIN_Char17;
|
|
env->getVIN2 = true;
|
|
}
|
|
|
|
if ((env->getVIN0) && (env->getVIN1) && (env->getVIN2)) {
|
|
status = osMessageQueuePut(env->ccu_candb_rx_LOCAL_HVAC_VIN, env->SET_HVAC_VIN, 0, 0U);
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_LOCAL_HVAC_UDS_VIN);
|
|
|
|
if (countQueue_ccu_candb_rx) {
|
|
status = osMessageQueuePut(env->ccu_candb_rx_LOCAL_HVAC_UDS_VIN, env->SET_HVAC_VIN, 0, 0U);
|
|
}
|
|
|
|
env->getVIN0 = false;
|
|
env->getVIN1 = false;
|
|
env->getVIN2 = false;
|
|
}
|
|
|
|
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
uint32_t getCanTimeReceived(tCanSpamReceiver *env, bool isCan0BusOff, bool isT15) {
|
|
|
|
uint32_t time = 0;
|
|
|
|
if (osMutexAcquire(env->access, 5000) == osOK) {
|
|
|
|
time = env->canTimeReceived;
|
|
|
|
osMutexRelease(env->access);
|
|
} else {
|
|
LoggerErrorStatic(LOGGER, LOG_SIGN, "Access error getCanTimeReceived");
|
|
}
|
|
|
|
return time;
|
|
}
|
|
|
|
static void ListenCanSpamReceiver(tCanSpamReceiver *env) {
|
|
|
|
uint16_t recv = env->ioCanFrame->receive(env->ioCanFrame->env, PROTOCOL_CAN_RAW, (uint8_t *) &env->canFrame, 1,
|
|
3000);
|
|
// if (recv == 0) {
|
|
// return;
|
|
// }
|
|
|
|
if (osMutexAcquire(env->access, 5000) == osOK) {
|
|
|
|
env->canTimeReceived = SystemGetMs();
|
|
|
|
uint32_t id = env->canFrame.standard_id;
|
|
|
|
if (env->canFrame.id_type == FLEXCAN_ID_EXT) {
|
|
id = env->canFrame.extended_id;
|
|
}
|
|
|
|
env->logger->loggingCan(env->logger->env, 1, 0, env->canFrame.dlc, env->canFrame.standard_id,
|
|
env->canFrame.data, SystemGetMs());
|
|
|
|
uint32_t recid = ccu_candb_Receive(&ccu_candb_rx, env->canFrame.data, id, env->canFrame.dlc);
|
|
|
|
set_CanSpamReceiver(env, recid);
|
|
|
|
osMutexRelease(env->access);
|
|
} else {
|
|
LoggerErrorStatic(LOGGER, LOG_SIGN, "Access error ListenCanSpamReceiver");
|
|
}
|
|
|
|
}
|
|
|
|
bool get_is_NoNull_CanSpam_BCM_PowerTrain_Receiver(tCanSpamReceiver *env) {
|
|
if (osMutexAcquire(env->access, 5000) == osOK) {
|
|
|
|
uint8_t *data = (uint8_t *) &ccu_candb_rx.BCM_Powertrain;
|
|
|
|
for (uint8_t i = 0; i < (uint8_t) sizeof(BCM_Powertrain_t); ++i) {
|
|
if (data[i] != 0) {
|
|
osMutexRelease(env->access);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
osMutexRelease(env->access);
|
|
} else {
|
|
LoggerErrorStatic(LOGGER, LOG_SIGN, "Access error get_CanSpamReceiver");
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void get_CanSpamReceiver(tCanSpamReceiver *env, char *VIN, ccu_candb_error_missing_rx_t *CAN_ERROR_MISSING,
|
|
ccu_candb_time_missing_rx_t *CAN_TIME_MISSING) {
|
|
|
|
osStatus_t status = osOK;
|
|
|
|
|
|
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
uint32_t countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_error_missing_rx);
|
|
if (countQueue_ccu_candb_rx == 0) {
|
|
status = osMessageQueueGet(env->ccu_candb_error_missing_rx, CAN_ERROR_MISSING, 0, 0U);
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_time_missing_rx);
|
|
if (countQueue_ccu_candb_rx == 0) {
|
|
status = osMessageQueueGet(env->ccu_candb_time_missing_rx, CAN_TIME_MISSING, 0, 0U);
|
|
}
|
|
|
|
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
memset(&rtDW.FIU_CCU1_MODEL, 0, sizeof(rtDW.FIU_CCU1_MODEL));
|
|
memset(&rtDW.FIU_CCU2_MODEL, 0, sizeof(rtDW.FIU_CCU2_MODEL));
|
|
memset(&rtDW.FIU_CCU3_MODEL, 0, sizeof(rtDW.FIU_CCU3_MODEL));
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_FIU_CCU1);
|
|
if (countQueue_ccu_candb_rx == 0) {
|
|
status = osMessageQueueGet(env->ccu_candb_rx_FIU_CCU1, &rtDW.FIU_CCU1_MODEL, 0, 0U);
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_FIU_CCU2);
|
|
if (countQueue_ccu_candb_rx == 0) {
|
|
status = osMessageQueueGet(env->ccu_candb_rx_FIU_CCU2, &rtDW.FIU_CCU2_MODEL, 0, 0U);
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_FIU_CCU3);
|
|
if (countQueue_ccu_candb_rx == 0) {
|
|
status = osMessageQueueGet(env->ccu_candb_rx_FIU_CCU3, &rtDW.FIU_CCU3_MODEL, 0, 0U);
|
|
}
|
|
|
|
|
|
if (CAN_ERROR_MISSING->TM_CP) {
|
|
memset(&rtDW.TM_CP_model, 0, sizeof(rtDW.TM_CP_model));
|
|
}
|
|
|
|
if (CAN_ERROR_MISSING->BCM_EEM) {
|
|
//cfif memset(&rtDW.TM_CP_model, 0, sizeof(rtDW.TM_CP_model));
|
|
}
|
|
|
|
if (CAN_ERROR_MISSING->EMS_Veh_02) {
|
|
//cfif memset(&rtDW.TM_CP_model, 0, sizeof(rtDW.TM_CP_model));
|
|
}
|
|
|
|
if (CAN_ERROR_MISSING->BCM_Powertrain) {
|
|
memset(&rtDW.CCUCAN_BCM_Powertrain_model, 0, sizeof(rtDW.CCUCAN_BCM_Powertrain_model));
|
|
}
|
|
|
|
if (CAN_ERROR_MISSING->BCM_CLIMATIC_DATA) {
|
|
memset(&rtDW.CCUCAN_BCM_Climatic_model, 0, sizeof(rtDW.CCUCAN_BCM_Climatic_model));
|
|
}
|
|
|
|
if (CAN_ERROR_MISSING->EMS_Veh) {
|
|
memset(&rtDW.CCUCAN_EMS_Veh_model, 0, sizeof(rtDW.CCUCAN_EMS_Veh_model));
|
|
}
|
|
|
|
if (CAN_ERROR_MISSING->ESC_04) {
|
|
memset(&rtDW.CCUCAN_ESC_04_model, 0, sizeof(rtDW.CCUCAN_ESC_04_model));
|
|
}
|
|
|
|
if (CAN_ERROR_MISSING->BCM_VEH_STATE) {
|
|
memset(&rtDW.CCUCAN_BCM_VEH_STATE_model, 0, sizeof(rtDW.CCUCAN_BCM_VEH_STATE_model));
|
|
}
|
|
|
|
if (CAN_ERROR_MISSING->EMS_HVC_Req_Msg) {
|
|
memset(&rtDW.CCUCAN_EMS_HVC_REQ_MSG_MODEL, 0, sizeof(rtDW.CCUCAN_EMS_HVC_REQ_MSG_MODEL));
|
|
}
|
|
|
|
if (CAN_ERROR_MISSING->HVC_Err_Status_Msg) {
|
|
memset(&rtDW.HVC_ERR_STATUS_MSG_MODEL, 0, sizeof(rtDW.HVC_ERR_STATUS_MSG_MODEL));
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_TM_CP);
|
|
if (countQueue_ccu_candb_rx == 0) {
|
|
status = osMessageQueueGet(env->ccu_candb_rx_TM_CP, &rtDW.TM_CP_model, 0, 0U);
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_BCM_EEM);
|
|
if (countQueue_ccu_candb_rx == 0) {
|
|
//cfif status = osMessageQueueGet(env->ccu_candb_rx_BCM_EEM, &rtDW., 0, 0U);
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_EMS_Veh_02);
|
|
if (countQueue_ccu_candb_rx == 0) {
|
|
//cfif status = osMessageQueueGet(env->ccu_candb_rx_EMS_Veh_02, &rtDW., 0, 0U);
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_BCM_Powertrain);
|
|
if (countQueue_ccu_candb_rx == 0) {
|
|
status = osMessageQueueGet(env->ccu_candb_rx_BCM_Powertrain, &rtDW.CCUCAN_BCM_Powertrain_model, 0, 0U);
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_BCM_CLIMATIC_DATA);
|
|
if (countQueue_ccu_candb_rx == 0) {
|
|
status = osMessageQueueGet(env->ccu_candb_rx_BCM_CLIMATIC_DATA, &rtDW.CCUCAN_BCM_Climatic_model, 0, 0U);
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_EMS_Veh);
|
|
if (countQueue_ccu_candb_rx == 0) {
|
|
status = osMessageQueueGet(env->ccu_candb_rx_EMS_Veh, &rtDW.CCUCAN_EMS_Veh_model, 0, 0U);
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_ESC_04);
|
|
if (countQueue_ccu_candb_rx == 0) {
|
|
status = osMessageQueueGet(env->ccu_candb_rx_ESC_04, &rtDW.CCUCAN_ESC_04_model, 0, 0U);
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_BCM_VEH_STATE);
|
|
if (countQueue_ccu_candb_rx == 0) {
|
|
status = osMessageQueueGet(env->ccu_candb_rx_BCM_VEH_STATE, &rtDW.CCUCAN_BCM_VEH_STATE_model, 0, 0U);
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_EMS_HVC_Req_Msg);
|
|
if (countQueue_ccu_candb_rx == 0) {
|
|
status = osMessageQueueGet(env->ccu_candb_rx_EMS_HVC_Req_Msg, &rtDW.CCUCAN_EMS_HVC_REQ_MSG_MODEL, 0, 0U);
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_HVC_Err_Status_Msg);
|
|
if (countQueue_ccu_candb_rx == 0) {
|
|
status = osMessageQueueGet(env->ccu_candb_rx_HVC_Err_Status_Msg, &rtDW.HVC_ERR_STATUS_MSG_MODEL, 0, 0U);
|
|
}
|
|
|
|
countQueue_ccu_candb_rx = osMessageQueueGetSpace(env->ccu_candb_rx_LOCAL_HVAC_VIN);
|
|
if (countQueue_ccu_candb_rx == 0) {
|
|
status = osMessageQueueGet(env->ccu_candb_rx_LOCAL_HVAC_VIN, VIN, 0, 0U);
|
|
}
|
|
|
|
}
|
|
|
|
bool get_CanSpamReceiverUDS(tCanSpamReceiver *env, char *VIN, func_update_func update_func, void *update_func_env,
|
|
uint32_t timeout, uint32_t count) {
|
|
|
|
|
|
uint32_t u32Time = SystemGetMs() + timeout;
|
|
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
osStatus_t status = osMessageQueueGet(env->ccu_candb_rx_LOCAL_HVAC_UDS_VIN, VIN, 0, timeout);
|
|
|
|
if (update_func != NULL) {
|
|
if (SystemGetMs() > u32Time) {
|
|
update_func(update_func_env);
|
|
u32Time = SystemGetMs() + timeout;
|
|
}
|
|
}
|
|
|
|
if (status == osOK) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
return false;
|
|
}
|
|
|
|
|
|
static _Noreturn void CanSpamReceiver_Thread(tCanSpamReceiver *env) {
|
|
for (;;) {
|
|
ListenCanSpamReceiver(env);
|
|
}
|
|
}
|
|
|
|
void CanSpamReceiver_StartThread(tCanSpamReceiver *env) {
|
|
if (!env->thread.id) {
|
|
env->thread.id = osThreadNew((osThreadFunc_t) (CanSpamReceiver_Thread), (void *) (env), &env->thread.attr);
|
|
}
|
|
} |