SMART_COMPONENTS_CrashDetec.../CrashDetection.c

57 lines
1.7 KiB
C

//
// Created by ilya on 05.04.24.
//
#include "CrashDetection.h"
#include "CmsisRtosThreadUtils.h"
#include "SystemDelayInterface.h"
#define LOG_SIGN "Опр.Авар."
#define LOGGER env->logger
void CrashDetection_Init(
tCrashDetection *env,
tAccelDataFlowInterface *accelData,
float *asi15threshold,
tCarFlipDetectionSettings *settings,
tLoggerInterface *logger
) {
env->logger = logger;
CarCrashDetection_Init(&env->carCrashDetection, accelData, asi15threshold, settings);
env->emergencyEvents = CarCrashDetection_GetInterface(&env->carCrashDetection);
env->simulationInterface = CarCrashDetection_GetSimInterface(&env->carCrashDetection);
InitThreadAtrStatic(
&env->thread.attr,
"CrashDetection",
env->thread.controlBlock,
env->thread.stack,
osPriorityNormal
);
env->thread.id = 0;
}
static _Noreturn void CrashDetection_Thread(tCrashDetection *env) {
for (;;) {
CarCrashDetection_Processing(&env->carCrashDetection, SystemWaitForever);
}
}
void CrashDetection_StopThread(tCrashDetection *env) {
if(env->thread.id != NULL) {
if (osThreadTerminate(env->thread.id) == osOK) {
SystemDelayMs(100);
env->thread.id = NULL;
LoggerInfoStatic(LOGGER, LOG_SIGN, "Поток обработки данных акселерометра остановлен")
SystemDelayMs(500);
}
}
}
void CrashDetection_StartThread(tCrashDetection *env) {
if (env->thread.id == NULL) {
env->thread.id = osThreadNew((osThreadFunc_t) (CrashDetection_Thread), (void *) (env), &env->thread.attr);
}
}