243 lines
10 KiB
C
243 lines
10 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"
|
|
|
|
#define LOG_SIGN "CAN_RECEIVED"
|
|
#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_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);
|
|
|
|
|
|
InitThreadAtrStatic(&env->thread.attr, "CanSpamRec", env->thread.controlBlock, env->thread.stack,
|
|
osPriorityNormal);
|
|
}
|
|
|
|
static void set_CanSpamReceiver(tCanSpamReceiver *env, uint32_t recid) {
|
|
osStatus_t status = osOK;
|
|
|
|
uint32_t 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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
static void ListenCanSpamReceiver(tCanSpamReceiver *env) {
|
|
|
|
uint16_t recv = env->ioCanFrame->receive(env->ioCanFrame->env, PROTOCOL_CAN_RAW, (uint8_t *) &env->canFrame, 1,
|
|
1000);
|
|
|
|
if (recv == 0) {
|
|
return;
|
|
}
|
|
|
|
if (osMutexAcquire(env->access, 5000) == osOK) {
|
|
|
|
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) {
|
|
|
|
osStatus_t status = osOK;
|
|
|
|
uint32_t 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);
|
|
}
|
|
|
|
memset(&rtDW.FIU_CCU1_MODEL, 0, sizeof(rtDW.FIU_CCU1_MODEL));
|
|
memset(&rtDW.FIU_CCU2_MODEL, 0, sizeof(rtDW.FIU_CCU2_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_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);
|
|
}
|
|
|
|
/*
|
|
if (osMutexAcquire(env->access, 5000) == osOK) {
|
|
memcpy(&rtDW.TM_CP_model, &ccu_candb_rx.TM_CP, sizeof(rtDW.TM_CP_model));
|
|
memcpy(&rtDW.FIU_CCU1_MODEL, &ccu_candb_rx.FIU_CCU1, sizeof(rtDW.FIU_CCU1_MODEL));
|
|
memcpy(&rtDW.FIU_CCU2_MODEL, &ccu_candb_rx.FIU_CCU2, sizeof(rtDW.FIU_CCU2_MODEL));
|
|
// memcpy(&rtDW.FIU_CCU3_MODEL, &ccu_candb_rx.FIU_CCU3, sizeof(rtDW.FIU_CCU3_MODEL));
|
|
|
|
memset(&ccu_candb_rx.FIU_CCU1,0,sizeof(ccu_candb_rx.FIU_CCU1));
|
|
memset(&ccu_candb_rx.FIU_CCU2,0,sizeof(ccu_candb_rx.FIU_CCU2));
|
|
|
|
memcpy(&rtDW.CCUCAN_BCM_Powertrain_model, &ccu_candb_rx.BCM_Powertrain,
|
|
sizeof(rtDW.CCUCAN_BCM_Powertrain_model));
|
|
memcpy(&rtDW.CCUCAN_BCM_Climatic_model, &ccu_candb_rx.BCM_CLIMATIC_DATA,
|
|
sizeof(rtDW.CCUCAN_BCM_Climatic_model));
|
|
memcpy(&rtDW.CCUCAN_EMS_Veh_model, &ccu_candb_rx.EMS_Veh, sizeof(rtDW.CCUCAN_EMS_Veh_model));
|
|
memcpy(&rtDW.CCUCAN_ESC_04_model, &ccu_candb_rx.ESC_04, sizeof(rtDW.CCUCAN_ESC_04_model));
|
|
memcpy(&rtDW.CCUCAN_BCM_VEH_STATE_model, &ccu_candb_rx.BCM_VEH_STATE, sizeof(rtDW.CCUCAN_BCM_VEH_STATE_model));
|
|
memcpy(&rtDW.CCUCAN_EMS_HVC_REQ_MSG_MODEL, &ccu_candb_rx.EMS_HVC_Req_Msg,
|
|
sizeof(rtDW.CCUCAN_EMS_HVC_REQ_MSG_MODEL));
|
|
memcpy(&rtDW.HVC_ERR_STATUS_MSG_MODEL, &ccu_candb_rx.HVC_Err_Status_Msg, sizeof(rtDW.HVC_ERR_STATUS_MSG_MODEL));
|
|
|
|
osMutexRelease(env->access);
|
|
|
|
} else {
|
|
LoggerErrorStatic(LOGGER, LOG_SIGN, "Access error get_CanSpamReceiver");
|
|
}
|
|
*/
|
|
|
|
}
|
|
|
|
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);
|
|
}
|
|
} |