From bc29328f0ea1bf3300b465d09070090ad2cd82cf Mon Sep 17 00:00:00 2001 From: cfif Date: Wed, 4 Dec 2024 13:10:47 +0300 Subject: [PATCH] Init --- Inc/CrashDetection.h | 35 +++++++++++++++++++++ Src/CrashDetection.c | 75 ++++++++++++++++++++++++++++++++++++++++++++ modular.json | 18 +++++++++++ 3 files changed, 128 insertions(+) create mode 100644 Inc/CrashDetection.h create mode 100644 Src/CrashDetection.c create mode 100644 modular.json diff --git a/Inc/CrashDetection.h b/Inc/CrashDetection.h new file mode 100644 index 0000000..855cefc --- /dev/null +++ b/Inc/CrashDetection.h @@ -0,0 +1,35 @@ +// +// Created by xemon on 23.11.22. +// + +#ifndef UVEOS_ON_NATION_CRASHDETECTION_H +#define UVEOS_ON_NATION_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[2048]; + StaticTask_t controlBlock; + osThreadAttr_t attr; + } thread; +} tCrashDetection; + +void CrashDetection_Init( + tCrashDetection *env, + tAccelDataFlowInterface *accelData, + float *asi15threshold, + tCarFlipDetectionSettings *settings, + tLoggerInterface *logger +); + +void CrashDetection_StartThread(tCrashDetection *env); + +#endif //UVEOS_ON_NATION_CRASHDETECTION_H diff --git a/Src/CrashDetection.c b/Src/CrashDetection.c new file mode 100644 index 0000000..b9a50a7 --- /dev/null +++ b/Src/CrashDetection.c @@ -0,0 +1,75 @@ +// +// Created by xemon on 23.11.22. +// + +#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) { + uint32_t time = SystemGetMs(); + float asi, maxAsi = 0; + uint32_t count = 0; + + for (;;) { + CarCrashDetection_Processing(&env->carCrashDetection, SystemWaitForever); +#if false + asi = EraGlonassAsi15_GetCurrentValue(&env->carCrashDetection.asi15); + if (maxAsi < asi) { + maxAsi = asi; + } + ++count; + + if (time < SystemGetMs()) { + LoggerCnInfoStatic(LOGGER, LOG_SIGN, "CCD >") + + LoggerPrintf(LOGGER, " asi<%f> count %u", maxAsi, count); + maxAsi = 0; + count = 0; + +// LoggerPrintf(LOGGER, "grav[%f %f %f] cos<%f>", +// env->carCrashDetection.flip.current.value.x, +// env->carCrashDetection.flip.current.value.y, +// env->carCrashDetection.flip.current.value.z, +// env->carCrashDetection.flip.current.angleCos +// ); + LoggerInfoStatic(LOGGER, LOG_SIGN, "<") + time = SystemGetMs() + 1000; + } +#endif + } +} + +void CrashDetection_StartThread(tCrashDetection *env) { + if (!env->thread.id) { + env->thread.id = osThreadNew((osThreadFunc_t) (CrashDetection_Thread), (void *) (env), &env->thread.attr); + } +} \ No newline at end of file diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..b713fee --- /dev/null +++ b/modular.json @@ -0,0 +1,18 @@ +{ + "dep": [ + { + "type": "git", + "provider": "NAVIGATOR_UVEOS_NATION_TELIT", + "repo": "CarCrashDetection" + } + ], + "cmake": { + "inc_dirs": [ + "Inc/" + ], + "srcs": [ + "Src/**.c", + "Src_InitDefaults/**.c" + ] + } +} \ No newline at end of file