109 lines
5.6 KiB
C
109 lines
5.6 KiB
C
//
|
||
// Created by cfif on 20.01.2026.
|
||
//
|
||
#include "LinActuatorWork.h"
|
||
|
||
|
||
//#define LOG_SIGN "Lin"
|
||
#define LOGGER &env->slog.logger
|
||
|
||
// actuator_Command_Model_local - Выход модели (команды для актуаторов) ЛОКАЛЬНО
|
||
// actuator_Command_Model_trigger_local - Выход модели (команды для актуаторов) ЗАХВАТ
|
||
// actuator_Output_Model_local - Вход модели (состояния актуаторов) ЛОКАЛЬНЫЙ
|
||
// actuator_Output_Model_model - Вход модели (состояния актуаторов) МОДЕЛИ
|
||
|
||
void LinActuatorWork(tMma *env, tLinTaskActuator *linTaskActuator,
|
||
ActuatorCmdBus *actuator_Command_Model_local,
|
||
ActuatorCmdBus *actuator_Command_Model_trigger_local,
|
||
ActuatorCmdBusInput *actuator_Output_Model_local,
|
||
ActuatorCmdBusInput *actuator_Output_Model_model,
|
||
char *LOG_SIGN) {
|
||
|
||
if (osMutexAcquire(linTaskActuator->access, 5000) == osOK) {
|
||
|
||
// Если актуатор не занят
|
||
if (linTaskActuator->busy == false) {
|
||
|
||
for (uint8_t i = 0; i < linTaskActuator->LIN_ISSR_ALL; ++i) {
|
||
|
||
linTaskActuator->linCommandActuator[i].POS = actuator_Command_Model_local->POS[i];
|
||
linTaskActuator->linCommandActuator[i].BUS_ADR = actuator_Command_Model_local->BUS_ADR[i];
|
||
linTaskActuator->linCommandActuator[i].MODE = actuator_Command_Model_local->MODE[i];
|
||
|
||
// Если команда выполнена
|
||
if (linTaskActuator->linCommandActuator[i].COM == LIN_ACT_CFR_SUCCESSFUL) {
|
||
#if (LOG_LIN_ACTUATOR == 1)
|
||
// LoggerInfoStatic(LOGGER, LOG_SIGN, "SUCCESSFUL COMMAND")
|
||
#endif
|
||
// Установка входной команды в LIN_ACT_CFR_NONE
|
||
actuator_Command_Model_local->COM[i] = LIN_ACT_CFR_NONE;
|
||
}
|
||
|
||
linTaskActuator->linCommandActuator[i].COM = actuator_Command_Model_local->COM[i];
|
||
linTaskActuator->linCommandActuator[i].Stall_SET = actuator_Command_Model_local->Stall_SET[i];
|
||
linTaskActuator->linCommandActuator[i].Lnoise_SET = actuator_Command_Model_local->Lnoise_SET[i];
|
||
linTaskActuator->linCommandActuator[i].Autos_SET = actuator_Command_Model_local->Autos_SET[i];
|
||
linTaskActuator->linCommandActuator[i].Speed_SET = actuator_Command_Model_local->Speed_SET[i];
|
||
linTaskActuator->linCommandActuator[i].Coils_Stop_SET = actuator_Command_Model_local->Coils_Stop_SET[i];
|
||
|
||
// Заполнение данных ВХОДЫ МОДЕЛИ
|
||
actuator_Output_Model_local->in_CPOS_ALL_Ch0[i] = (int16_t) linTaskActuator->linStateActuator[i].CPOS_ALL;
|
||
actuator_Output_Model_local->in_Act_Emrf_Slave_Ch0[i] = (int8_t) linTaskActuator->linStateActuator[i].Emrf_Slave;
|
||
actuator_Output_Model_local->in_Mode_Slave_Ch0[i] = (int8_t) linTaskActuator->linStateActuator[i].Mode_Slave;
|
||
actuator_Output_Model_local->in_Act_Err1_Supply_Ch0[i] = (int8_t) linTaskActuator->linStateActuator[i].Error1_Supply_Slave;
|
||
actuator_Output_Model_local->in_Act_Err2_Communication_Ch0[i] = (int8_t) linTaskActuator->linStateActuator[i].Error2_Communication_Slave;
|
||
actuator_Output_Model_local->in_Act_Err3_Temperature_Ch0[i] = (int8_t) linTaskActuator->linStateActuator[i].Error3_Temperature_Slave;
|
||
actuator_Output_Model_local->in_Act_Err4_Permanent_Electrical_Ch0[i] = (int8_t) linTaskActuator->linStateActuator[i].Error4_Permanent_Electrical_Slave;
|
||
actuator_Output_Model_local->in_Act_Stall_Slave_Ch0[i] = linTaskActuator->linStateActuator[i].Stall_Slave;
|
||
actuator_Output_Model_local->in_Act_Reset_Ch0[i] = linTaskActuator->linStateActuator[i].Reset_Slave;
|
||
}
|
||
|
||
env->isActuatorWorkBusy = setBusy(linTaskActuator);
|
||
|
||
// Заполнение данных ВХОДЫ МОДЕЛИ
|
||
actuator_Output_Model_local->Error_Connect_Ch0 = linTaskActuator->error_connect;
|
||
actuator_Output_Model_local->Busy_Ch0 = linTaskActuator->busy;
|
||
}
|
||
|
||
osMutexRelease(linTaskActuator->access);
|
||
}
|
||
|
||
|
||
if (osMutexAcquire(env->ModelTask.access, 5000) == osOK) {
|
||
|
||
// Если принята команда
|
||
if (env->ModelTask.triggerCommand == true) {
|
||
#if (LOG_LIN_ACTUATOR == 1)
|
||
LoggerInfoStatic(LOGGER, LOG_SIGN, "DETECT COMMAND")
|
||
#endif
|
||
//
|
||
actuator_Output_Model_local->Busy_Ch0 = 1;
|
||
}
|
||
|
||
// Если прията команда и актуатор не занят
|
||
if ((env->ModelTask.triggerCommand == true) && (env->isActuatorWorkBusy == false)) {
|
||
|
||
env->ModelTask.triggerCommand = false;
|
||
env->isActuatorWorkBusy = true;
|
||
|
||
// начало --- ВЫХОД МОДЕЛИ ----------
|
||
|
||
// ВЫХОД МОДЕЛИ
|
||
memcpy(actuator_Command_Model_local, actuator_Command_Model_trigger_local, sizeof(ActuatorCmdBus));
|
||
|
||
// Сброс STALL в состоянии актуатор и локальном состоянии
|
||
resetStall(linTaskActuator, (uint8_t *) actuator_Output_Model_local->in_Act_Stall_Slave_Ch0, LOG_SIGN);
|
||
|
||
// конец --- ВЫХОД МОДЕЛИ ----------
|
||
|
||
}
|
||
|
||
// ВХОДЫ МОДЕЛИ
|
||
memcpy(actuator_Output_Model_model, actuator_Output_Model_local, sizeof(ActuatorCmdBusInput));
|
||
|
||
osMutexRelease(env->ModelTask.access);
|
||
}
|
||
|
||
|
||
}
|