76 lines
2.2 KiB
C
76 lines
2.2 KiB
C
//
|
|
// Created by cfif on 05.04.2024.
|
|
//
|
|
#include <SystemDelayInterface.h>
|
|
#include "CanSpamDebugReceiver.h"
|
|
#include "CmsisRtosThreadUtils.h"
|
|
#include "CanPorts.h"
|
|
#include "string.h"
|
|
#include "HVAC_model.h"
|
|
|
|
#define LOG_SIGN "CAN_DEBUG_RECEIVED"
|
|
#define LOGGER env->logger
|
|
|
|
void CanSpamDebugReceiver_Init(tCanSpamDebugReceiver *env,
|
|
tSerialPortFrameIO *ioCanFrame,
|
|
tLoggerInterface *logger) {
|
|
|
|
env->ioCanFrame = ioCanFrame;
|
|
env->logger = logger;
|
|
env->access = osMutexNew(NULL);
|
|
|
|
InitThreadAtrStatic(&env->thread.attr, "CanSpamDebugRec", env->thread.controlBlock, env->thread.stack,
|
|
osPriorityNormal);
|
|
}
|
|
|
|
static void ListenCanSpamDebugReceiver(tCanSpamDebugReceiver *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;
|
|
}
|
|
|
|
uint32_t result = ccu_candb_dbg_Receive(&ccu_candb_dbg_rx, env->canFrame.data, id, env->canFrame.dlc);
|
|
|
|
osMutexRelease(env->access);
|
|
} else {
|
|
LoggerErrorStatic(LOGGER, LOG_SIGN, "Access error ListenCanSpamDebugReceiver");
|
|
}
|
|
|
|
}
|
|
|
|
uint8_t get_CanSpamDebugReceiverMultiIndex(tCanSpamDebugReceiver *env) {
|
|
uint8_t index = 0;
|
|
|
|
if (osMutexAcquire(env->access, 5000) == osOK) {
|
|
|
|
index = ccu_candb_dbg_rx.dbg_Cmd_Act_Information.Cmd_Target_Act_Index;
|
|
|
|
osMutexRelease(env->access);
|
|
} else {
|
|
LoggerErrorStatic(LOGGER, LOG_SIGN, "Access error get_CanSpamDebugReceiver");
|
|
}
|
|
|
|
return index;
|
|
}
|
|
|
|
static _Noreturn void CanSpamDebugReceiver_Thread(tCanSpamDebugReceiver *env) {
|
|
for (;;) {
|
|
ListenCanSpamDebugReceiver(env);
|
|
}
|
|
}
|
|
|
|
void CanSpamDebugReceiver_StartThread(tCanSpamDebugReceiver *env) {
|
|
if (!env->thread.id) {
|
|
env->thread.id = osThreadNew((osThreadFunc_t) (CanSpamDebugReceiver_Thread), (void *) (env), &env->thread.attr);
|
|
}
|
|
} |