Начало
This commit is contained in:
commit
6421e0de8b
|
|
@ -0,0 +1,65 @@
|
||||||
|
//
|
||||||
|
// Created by ilya on 04.10.23.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef ERA_ELEMENT_2_COMINT_H
|
||||||
|
#define ERA_ELEMENT_2_COMINT_H
|
||||||
|
|
||||||
|
#include <SerialPortIO.h>
|
||||||
|
#include <XfcProtTable.h>
|
||||||
|
//#include <DeviceTestsTable.h>
|
||||||
|
//#include <DeviceStorageIni.h>
|
||||||
|
#include "XfcProtRespondent.h"
|
||||||
|
#include "ComIntCmd/Mandatory.h"
|
||||||
|
#include "ComIntCmd/SerialBridge.h"
|
||||||
|
#include "VersionsInfoTable.h"
|
||||||
|
#include "VariablesTable.h"
|
||||||
|
#include "cmsis_os2.h"
|
||||||
|
#include "FreeRTOS.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tSerialPortIO *io;
|
||||||
|
struct {
|
||||||
|
tXfcProtProcessor table[16];
|
||||||
|
uint8_t rxArr[256];
|
||||||
|
uint8_t txArr[2048];
|
||||||
|
tSerialBridge serialBridge[8];
|
||||||
|
tVersionPair versions[3];
|
||||||
|
} memAlloc;
|
||||||
|
|
||||||
|
tXfcProtTable table;
|
||||||
|
tXfcProtRespondent service;
|
||||||
|
tSerialBridges serialBridges;
|
||||||
|
tVersionsInfoTable versionsTable;
|
||||||
|
struct {
|
||||||
|
tStringStatic board;
|
||||||
|
tStringStatic serialNumber;
|
||||||
|
tStringStatic firmware;
|
||||||
|
tStringStatic gsm;
|
||||||
|
} versions;
|
||||||
|
|
||||||
|
tComIntPing ping;
|
||||||
|
tString16 sn;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
osThreadId_t id;
|
||||||
|
uint32_t stack[2048];
|
||||||
|
StaticTask_t controlBlock;
|
||||||
|
osThreadAttr_t attr;
|
||||||
|
} thread;
|
||||||
|
} tComInt;
|
||||||
|
|
||||||
|
void ComInt_Init(
|
||||||
|
tComInt *env,
|
||||||
|
tSerialPortIO *io,
|
||||||
|
tVariablesTable *varsTab,
|
||||||
|
tSerialPortIO *gsmIo,
|
||||||
|
tSerialPortIO *gnssIo,
|
||||||
|
tSerialPortIO *cliIo,
|
||||||
|
tStringLink *currentModeName
|
||||||
|
);
|
||||||
|
|
||||||
|
void ComInt_StartThread(tComInt *env);
|
||||||
|
|
||||||
|
|
||||||
|
#endif //ERA_ELEMENT_2_COMINT_H
|
||||||
|
|
@ -0,0 +1,145 @@
|
||||||
|
//
|
||||||
|
// Created by ilya on 04.10.23.
|
||||||
|
//
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <SystemDelayInterface.h>
|
||||||
|
#include <ComInt.h>
|
||||||
|
#include <CmsisRtosThreadUtils.h>
|
||||||
|
#include "SerialPort.h"
|
||||||
|
//#include "ComIntCmd/Vars.h"
|
||||||
|
//#include "ComIntCmd/Tests.h"
|
||||||
|
#include "ComIntCmd/VersionsInfo.h"
|
||||||
|
#include "FirmwareMetadataSection.h"
|
||||||
|
#include "ComIntCmd/Vars.h"
|
||||||
|
#include "stdlib.h"
|
||||||
|
|
||||||
|
|
||||||
|
static void ComInt_LoadMetadata(tComInt *env) {
|
||||||
|
env->versions.firmware = (tStringStatic) {.data = (char *) (META_FW_NAME), .length = META_FW_NAME_SIZE};
|
||||||
|
env->versions.board = (tStringStatic) {.data = (char *) (META_HW_NAME), .length = META_HW_NAME_SIZE};
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ComIntInitRoot(tComInt *env, tSerialPortIO *io) {
|
||||||
|
env->io = io;
|
||||||
|
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 *cliIo, tSerialPortIO *gnssIo) {
|
||||||
|
SerialBridges_InitStatic(&env->serialBridges, env->memAlloc.serialBridge);
|
||||||
|
SerialBridges_AddStatic(&env->serialBridges, "AT_GSM", gsmIo);
|
||||||
|
SerialBridges_AddStatic(&env->serialBridges, "CLI", cliIo);
|
||||||
|
// SerialBridges_AddStatic(&env->serialBridges, "GNSS", gnssIo);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComInt_Init(
|
||||||
|
tComInt *env,
|
||||||
|
tSerialPortIO *io,
|
||||||
|
tVariablesTable *varsTab,
|
||||||
|
tSerialPortIO *gsmIo,
|
||||||
|
tSerialPortIO *gnssIo,
|
||||||
|
tSerialPortIO *cliIo,
|
||||||
|
tStringLink *currentModeName
|
||||||
|
) {
|
||||||
|
|
||||||
|
|
||||||
|
char strTmp[16];
|
||||||
|
utoa(123, strTmp, 10);
|
||||||
|
env->sn.length = strlen(strTmp);
|
||||||
|
memcpy(env->sn.data, strTmp, env->sn.length);
|
||||||
|
|
||||||
|
ComIntInitRoot(env, io);
|
||||||
|
ComIntInitPing(env, &env->sn, currentModeName);
|
||||||
|
ComIntInitVersions(env, &env->sn);
|
||||||
|
|
||||||
|
if (gsmIo != NULL)
|
||||||
|
ComIntInitSerialBridges(env, gsmIo, cliIo, gnssIo);
|
||||||
|
|
||||||
|
//Добавляем обработчики комманд
|
||||||
|
XfcProtMethodsAdd_Mandatory(&env->table, &env->ping, &env->table);
|
||||||
|
// XfcProtMethodsAdd_VersionsInfo(&env->table, &env->versionsTable);
|
||||||
|
// XfcProtMethodsAdd_Vars(&env->table, &store->publicVariablesTable);
|
||||||
|
//XfcProtMethodsAdd_Tests(&env->table, tests);
|
||||||
|
|
||||||
|
if (varsTab) {
|
||||||
|
XfcProtMethodsAdd_Vars(&env->table, varsTab);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((gsmIo != NULL) || (gnssIo != NULL))
|
||||||
|
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) {
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
uint8_t byte;
|
||||||
|
|
||||||
|
if (SerialPortReceive(env->io, &byte, 1, 1000)) {
|
||||||
|
|
||||||
|
XfcProtRespondent_AddBytes(&env->service, &byte, 1);
|
||||||
|
|
||||||
|
while (XfcArrayGetDataSize(env->service.requestDecoder.buffer)) {
|
||||||
|
|
||||||
|
if (XfcProtRespondent_Step(&env->service)) {
|
||||||
|
|
||||||
|
SerialPortTransmit(
|
||||||
|
env->io,
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
{
|
||||||
|
"dep": [
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"provider": "HVAC_DEV",
|
||||||
|
"repo": "BaseTypes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"provider": "HVAC_DEV",
|
||||||
|
"repo": "ComIntCmd_Mandatory"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"provider": "HVAC_DEV",
|
||||||
|
"repo": "ComIntCmd_SerialBridge"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "git",
|
||||||
|
"provider": "HVAC_DEV",
|
||||||
|
"repo": "ComIntCmd_VersionsInfo"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"cmake": {
|
||||||
|
"inc_dirs": [
|
||||||
|
"Inc"
|
||||||
|
],
|
||||||
|
"srcs": [
|
||||||
|
"Src/**.c"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue