Добавлены интерфейсы и драйверы

This commit is contained in:
cfif 2025-09-30 15:52:33 +03:00
commit a44d574836
3 changed files with 126 additions and 0 deletions

68
CommandLines.c Normal file
View File

@ -0,0 +1,68 @@
//
// Created by cfif on 05.04.2024.
//
#include <SystemDelayInterface.h>
#include "CommandLines.h"
#include "CmsisRtosThreadUtils.h"
#include "stdio.h"
#include "CliCmd.h"
#include <string.h>
#include "math.h"
#include "stdlib.h"
int32_t CliCmd_baseCommandHelp(void *env, tCliCmd *cli) {
CliCmd_PrintLnStatic(cli, "================================================");
CliCmd_PrintLnStatic(cli, "Команды:");
CliCmd_PrintLnStatic(cli, "");
CliCmd_PrintLnStatic(cli, "reboot - Перезагрузка");
CliCmd_PrintLnStatic(cli, "================================================");
return 0;
}
int32_t CliCmd_baseCommandReboot(void *env, tCliCmd *cli) {
NVIC_SystemReset();
return 0;
}
void CommandLine_Init(tCommandLine *env, tSerialPortIO *serial) {
CliCmd_InitStatic(&env->cmd, serial, env->mem.cmdRxLine);
CliRedirectionTable_InitStatic(&env->redirectTable, env->mem.commandPrefixes);
CliRedirectionTable_RecAddStatic(&env->redirectTable, "help", (cliCall) CliCmd_baseCommandHelp, NULL);
CliRedirectionTable_RecAddStatic(&env->redirectTable, "reboot", (cliCall) CliCmd_baseCommandReboot, NULL);
InitThreadAtrStatic(&env->thread.attr, "CommandLine", env->thread.controlBlock, env->thread.stack,
osPriorityNormal);
}
void ListenCLICommand(tCommandLine *env) {
CliCmd_WaitLine(&env->cmd);
if (CliRedirectionTable_ProcessCmd(&env->redirectTable, &env->cmd) != 0) {
CliCmd_PrintStatic(&env->cmd, "Команда ");
CliCmd_Print(&env->cmd, env->cmd.rxLine.begin, env->cmd.rxLine.length - 1);
CliCmd_PrintLnStatic(&env->cmd, " не найдена");
CliCmd_PrintStatic(&env->cmd, "используйте ");
CliRedirectionTable_ListCmd(&env->redirectTable, &env->cmd, ' ');
CliCmd_PrintLnStatic(&env->cmd, "");
CliCmd_PrintLnStatic(&env->cmd, "введите команду [ help ] для большей получений большей информации");
}
}
static _Noreturn void CommandLine_Thread(tCommandLine *env) {
for (;;) {
ListenCLICommand(env);
SystemDelayMs(10);
}
}
void CommandLine_StartThread(tCommandLine *env) {
if (!env->thread.id) {
env->thread.id = osThreadNew((osThreadFunc_t) (CommandLine_Thread), (void *) (env), &env->thread.attr);
}
}

36
CommandLines.h Normal file
View File

@ -0,0 +1,36 @@
//
// Created by cfif on 05.04.2024.
//
#ifndef WATER_BLACKBOX2_G_COMMANDLINES_H
#define WATER_BLACKBOX2_G_COMMANDLINES_H
#include <cmsis_os.h>
#include "SerialPort.h"
#include "CliCmd.h"
#include "CliRedirectTable.h"
typedef struct {
struct {
tCliRedirectItem commandPrefixes[10];
uint8_t cmdRxLine[128];
} mem;
tCliCmd cmd;
tCliRedirectTable redirectTable;
struct {
osThreadId_t id;
uint32_t stack[1024];
StaticTask_t controlBlock;
osThreadAttr_t attr;
} thread;
} tCommandLine;
void CommandLine_Init(tCommandLine *env, tSerialPortIO *serial);
void CommandLine_StartThread(tCommandLine *env);
#endif //WATER_BLACKBOX2_G_COMMANDLINES_H

22
modular.json Executable file
View File

@ -0,0 +1,22 @@
{
"dep": [
{
"type": "git",
"provider": "HVAC_M7",
"repo": "CliCmd"
},
{
"type": "git",
"provider": "HVAC_M7",
"repo": "CliCmd_RedirectTable"
}
],
"cmake": {
"inc_dirs": [
"./"
],
"srcs": [
"./**.c"
]
}
}