From 9055b940cee3be6d287d2c0a8aaa1a27de5164bf Mon Sep 17 00:00:00 2001 From: cfif Date: Mon, 2 Jun 2025 13:26:40 +0300 Subject: [PATCH] Init --- ComInt.c | 210 +++++++++++++++++++++++++++++++++++++++++++++++++++ ComInt.h | 93 +++++++++++++++++++++++ modular.json | 52 +++++++++++++ 3 files changed, 355 insertions(+) create mode 100644 ComInt.c create mode 100644 ComInt.h create mode 100644 modular.json diff --git a/ComInt.c b/ComInt.c new file mode 100644 index 0000000..419a553 --- /dev/null +++ b/ComInt.c @@ -0,0 +1,210 @@ +// +// Created by cfif on 04.10.2022. +// + +#include +#include +#include +#include +#include "SerialPort.h" +#include "ComIntCmd/Vars.h" +#include "ComIntCmd/Tests.h" +#include "ComIntCmd/VersionsInfo.h" +#include "ComIntCmd/AccelCalibration.h" +#include "ComIntAmplifier.h" +#include "ComIntCodec.h" +#include "ext_telematica.h" +#include "ComIntThisSubSystem.h" + +static void ComInt_LoadMetadata(tComInt *env) { + env->versions.firmware = StringStaticInit("2.1.7"); + + env->versions.board = (tStringStatic) { + .data = (char *) (HARDWARE_REVISION), + .length = sizeof(HARDWARE_REVISION) - 1 + }; +}; + +static void ComIntInitRoot(tComInt *env) { + XfcProtTable_InitStatic(&env->table, env->memAlloc.table); + tXfcArray rxArr; + tXfcArray txArr; + XfcArrayInitStatic(&rxArr, env->memAlloc.rxArr); + XfcArrayInitStatic(&txArr, env->memAlloc.txArr); + XfcProtRespondent_Init(&env->service, NULL, &env->table, rxArr, txArr, XFC_STD_MAGIC_NUMBERS); + ComInt_LoadMetadata(env); +} + +static void ComIntInitPing(tComInt *env, tString16 *deviceId, tStringLink *currentModeName) { + env->ping.device = String16GetLink(deviceId); + env->ping.board = StringStaticGetLink(&env->versions.board); + env->ping.mode = currentModeName; +} + +static void ComIntInitVersions(tComInt *env, tString16 *deviceId) { + + VersionsInfoTable_InitStatic(&env->versionsTable, env->memAlloc.versions); + + VersionsInfoTable_AddStatic( + &env->versionsTable, "DEVICE_ID", String16GetLink(deviceId) + ); + VersionsInfoTable_AddStatic( + &env->versionsTable, "FIRMWARE", StringStaticGetLink(&env->versions.firmware) + ); + VersionsInfoTable_AddStatic( + &env->versionsTable, "BOARD", StringStaticGetLink(&env->versions.board) + ); +} + +static void ComIntInitSerialBridges( + tComInt *env, + tSerialPortIO *gsmIo, + tSerialPortIO *gnssIo, + tSerialPortIO *cliIo +) { + SerialBridges_InitStatic(&env->serialBridges, env->memAlloc.serialBridge); + if (gnssIo)SerialBridges_AddStatic(&env->serialBridges, "GNSS", gnssIo); + if (gsmIo)SerialBridges_AddStatic(&env->serialBridges, "AT_GSM", gsmIo); + if (cliIo)SerialBridges_AddStatic(&env->serialBridges, "CLI", cliIo); +} + +void ComInt_Init( + tComInt *env, + tSerialPortIO *io, + tSerialPortIO *canIo, + tString16 *deviceId, + tVariablesTable *varsTab, + tDeviceTestsTable *tests, + tSerialPortIO *gsmIo, + tSerialPortIO *cliIo, + tSerialPortIO *gnssIo, + tStringLink *currentModeName, + tCarFlipDetection *carFlipDetection, + tAmplifier *Amplifier, + tAudioCodec *audioCodec, + tDeviceTesting *tDeviceTesting, + tPowerManagement *power, + bool *playMode, + eSubSystems *subSystem, + bool *telematicaIsActive, + bool *telematicaServerIsActive, + bool *factoryMode +) { + env->serialPortIo = io; + env->serialCanPortIo = canIo; + + ComIntInitRoot(env); + ComIntInitPing(env, deviceId, currentModeName); + ComIntInitVersions(env, deviceId); + ComIntInitSerialBridges(env, gsmIo, gnssIo, cliIo); + + XfcProtMethodsInit_AccelCalibration(&env->accelCalibData, carFlipDetection, varsTab); + XfcProtMethodsAdd_AmplifierInit(&env->Amplifier, Amplifier, playMode); + XfcProtMethodsAdd_CodecInit(&env->Codec, audioCodec); + XfcProtMethodsAdd_PowerManagerInit(&env->Power, power, telematicaIsActive, telematicaServerIsActive); + XfcProtMethodsAdd_SybSystemInit(&env->XfcSybSystem, subSystem); + XfcProtMethodsAdd_TestInit( &env->TestButton, tDeviceTesting, factoryMode); + + //Добавляем обработчики комманд + XfcProtMethodsAdd_Mandatory(&env->table, &env->ping, &env->table); + XfcProtMethodsAdd_VersionsInfo(&env->table, &env->versionsTable); + XfcProtMethodsAdd_AccelCalibration(&env->table,&env->accelCalibData); + XfcProtMethodsAdd_Amplifier(&env->table,&env->Amplifier); + XfcProtMethodsAdd_Codec(&env->table, &env->Codec); + XfcProtMethodsAdd_Test(&env->table, &env->TestButton); + XfcProtMethodsAdd_PowerManager(&env->table, &env->Power); + XfcProtMethodsAdd_SybSystem(&env->table, &env->XfcSybSystem); + + if (EXT_ENV_ADR_TELE.META_EXT_ENV_TELE) + EXT_ENV_ADR_TELE.tele_func(&env->table, TELE_MODULE_COM_INT); + + if (varsTab) { + XfcProtMethodsAdd_Vars(&env->table, varsTab); + } + + XfcProtMethodsAdd_Tests(&env->table, tests); + XfcProtMethodsAdd_SerialBridge(&env->table, &env->serialBridges); + + //Инициализируем поток + InitThreadAtrStatic(&env->thread.attr, "ComInt", env->thread.controlBlock, env->thread.stack, osPriorityNormal); + env->thread.id = 0; +} + + +static _Noreturn void ComInt_Thread(tComInt *env) { + uint8_t byte; + tSerialPortIO *io = NULL; +// io = env->serialCanPortIo; + for (;;) { + if (SerialPortReceive(env->serialPortIo, &byte, 1, 100)) { + io = env->serialPortIo; + break; + } + + if (SerialPortReceive(env->serialCanPortIo, &byte, 1, 100)) { + io = env->serialCanPortIo; + break; + } + } + + XfcProtRespondent_AddBytes(&env->service, &byte, 1); + + for (;;) { + + if (SerialPortReceive(io, &byte, 1, SystemWaitForever)) { + + XfcProtRespondent_AddBytes(&env->service, &byte, 1); + + while (XfcArrayGetDataSize(env->service.requestDecoder.buffer)) { + + if (XfcProtRespondent_Step(&env->service)) { + + SerialPortTransmit( + io, + env->service.responseEncoder.buffer->data, + XfcArrayGetDataSize(env->service.responseEncoder.buffer), + 1000 + ); + + + XfcProtRespondent_SkipCurrentRequest(&env->service); + } else { + break; + } + } + } + } + +/* + if (SerialPortReceive(env->serialPortIo, &byte, 1, SystemWaitForever)) { + + XfcProtRespondent_AddBytes(&env->service, &byte, 1); + + while (XfcArrayGetDataSize(env->service.requestDecoder.buffer)) { + + if (XfcProtRespondent_Step(&env->service)) { + + SerialPortTransmit( + env->serialPortIo, + env->service.responseEncoder.buffer->data, + XfcArrayGetDataSize(env->service.responseEncoder.buffer), + 1000 + ); + + XfcProtRespondent_SkipCurrentRequest(&env->service); + } else { + break; + } + } + } + } + */ +} + +void ComInt_StartThread(tComInt *env) { + if (!env->thread.id) { + env->thread.id = osThreadNew((osThreadFunc_t) (ComInt_Thread), (void *) (env), &env->thread.attr); + } else { + osThreadResume(env->thread.id); + } +} diff --git a/ComInt.h b/ComInt.h new file mode 100644 index 0000000..5c7f14e --- /dev/null +++ b/ComInt.h @@ -0,0 +1,93 @@ +// +// Created by cfif on 04.10.2022. +// + +#ifndef XFCTRANSPACKSINGLESERVICERESPONDENTTASK_H +#define XFCTRANSPACKSINGLESERVICERESPONDENTTASK_H + +#include +#include +#include +#include +#include "XfcProtRespondent.h" +#include "ComIntCmd/Mandatory.h" +#include "ComIntCmd/SerialBridge.h" +#include "VersionsInfoTable.h" +#include "ComIntCmd/AccelCalibration.h" +#include "Amplifier.h" +#include "ComIntAmplifier.h" +#include "ComIntCodec.h" +#include "ComIntPowerManager.h" +#include "ComIntThisSubSystem.h" +#include "ComIntTest.h" + +typedef struct { + tSerialPortIO *serialPortIo; + tSerialPortIO *serialCanPortIo; + struct { + tXfcProtProcessor table[34]; +#ifndef COM_INT_BIG_BUFFERS + uint8_t rxArr[256]; + uint8_t txArr[2048]; +#else + uint8_t rxArr[1024 * 10]; + uint8_t txArr[1024 * 10]; +#endif + tSerialBridge serialBridge[8]; + tVersionPair versions[3]; + } memAlloc; + + tXfcProtTable table; + tXfcProtRespondent service; + tSerialBridges serialBridges; + tVersionsInfoTable versionsTable; + tAccelCalibData accelCalibData; + tXfcAmplifier Amplifier; + tXfcCodec Codec; + tXfcTest TestButton; + tXfcPower Power; + tXfcSybSystem XfcSybSystem; + + struct { + tStringStatic board; + tStringStatic serialNumber; + tStringStatic firmware; + tStringStatic gsm; + } versions; + + tComIntPing ping; + + struct { + osThreadId_t id; + uint32_t stack[1536]; + StaticTask_t controlBlock; + osThreadAttr_t attr; + } thread; +} tComInt; + +void ComInt_Init( + tComInt *env, + tSerialPortIO *io, + tSerialPortIO *canIo, + tString16 *deviceId, + tVariablesTable *varsTab, + tDeviceTestsTable *tests, + tSerialPortIO *gsmIo, + tSerialPortIO *cliIo, + tSerialPortIO *gnssIo, + tStringLink *currentModeName, + tCarFlipDetection *carFlipDetection, + tAmplifier *Amplifier, + tAudioCodec *audioCodec, + tDeviceTesting *deviceTesting, + tPowerManagement *power, + bool *playMode, + eSubSystems *subSystem, + bool *telematicaIsActive, + bool *telematicaServerIsActive, + bool *factoryMode +); + +void ComInt_StartThread(tComInt *env); + +#endif //XFCTRANSPACKSINGLESERVICERESPONDENTTASK_H diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..85538d4 --- /dev/null +++ b/modular.json @@ -0,0 +1,52 @@ +{ + "dep": [ + { + "type": "git", + "provider": "Smart_Components_Aurus", + "repo": "XfcTransportProtocol" + }, + { + "type": "git", + "provider": "Smart_Components_Aurus", + "repo": "BaseTypes" + }, + { + "type": "git", + "provider": "Smart_Components_Aurus", + "repo": "ComIntCmd_Mandatory" + }, + { + "type": "git", + "provider": "Smart_Components_Aurus", + "repo": "ComIntCmd_SerialBridge" + }, + { + "type": "git", + "provider": "Smart_Components_Aurus", + "repo": "ComIntCmd_Vars" + }, + { + "type": "git", + "provider": "Smart_Components_Aurus", + "repo": "ComIntCmd_Tests" + }, + { + "type": "git", + "provider": "Smart_Components_Aurus", + "repo": "CliCmd_Vars" + }, + { + "type": "git", + "provider": "Smart_Components_Aurus", + "repo": "ComIntCmd_VersionsInfo" + } + ], + "cmake": { + "inc_dirs": [ + "./" + ], + "srcs": [ + "./**.c" + ] + } +} \ No newline at end of file