This commit is contained in:
cfif 2025-06-02 13:26:39 +03:00
commit 2415f2ceb7
3 changed files with 102 additions and 0 deletions

57
CrashDetection.c Normal file
View File

@ -0,0 +1,57 @@
//
// 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);
}
}

33
CrashDetection.h Normal file
View File

@ -0,0 +1,33 @@
//
// Created by ilya on 05.04.24.
//
#ifndef SMART_COMPONENTS_CRASHDETECTION_H
#define SMART_COMPONENTS_CRASHDETECTION_H
#include "CarCrashDetection.h"
#include "LoggerInterface.h"
typedef struct {
tCarCrashDetection carCrashDetection;
tUveosEmergencyEventInterface emergencyEvents;
tUveosEmergencySimulationInterface simulationInterface;
tLoggerInterface *logger;
struct {
osThreadId_t id;
uint32_t stack[512];
StaticTask_t controlBlock;
osThreadAttr_t attr;
} thread;
} tCrashDetection;
void CrashDetection_Init(
tCrashDetection *env,
tAccelDataFlowInterface *accelData,
float *asi15threshold,
tCarFlipDetectionSettings *settings,
tLoggerInterface *logger
);
void CrashDetection_StopThread(tCrashDetection *env);
void CrashDetection_StartThread(tCrashDetection *env);
#endif //SMART_COMPONENTS_CRASHDETECTION_H

12
modular.json Normal file
View File

@ -0,0 +1,12 @@
{
"dep": [
],
"cmake": {
"inc_dirs": [
"./"
],
"srcs": [
"./**.c"
]
}
}