From a44d574836f908a788799e8515880d4c4143c4cb Mon Sep 17 00:00:00 2001 From: cfif Date: Tue, 30 Sep 2025 15:52:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9?= =?UTF-8?q?=D1=81=D1=8B=20=D0=B8=20=D0=B4=D1=80=D0=B0=D0=B9=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CommandLines.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ CommandLines.h | 36 ++++++++++++++++++++++++++ modular.json | 22 ++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 CommandLines.c create mode 100644 CommandLines.h create mode 100755 modular.json diff --git a/CommandLines.c b/CommandLines.c new file mode 100644 index 0000000..620e3c1 --- /dev/null +++ b/CommandLines.c @@ -0,0 +1,68 @@ +// +// Created by cfif on 05.04.2024. +// +#include +#include "CommandLines.h" +#include "CmsisRtosThreadUtils.h" +#include "stdio.h" +#include "CliCmd.h" +#include +#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); + } +} \ No newline at end of file diff --git a/CommandLines.h b/CommandLines.h new file mode 100644 index 0000000..3250a80 --- /dev/null +++ b/CommandLines.h @@ -0,0 +1,36 @@ +// +// Created by cfif on 05.04.2024. +// + +#ifndef WATER_BLACKBOX2_G_COMMANDLINES_H +#define WATER_BLACKBOX2_G_COMMANDLINES_H + +#include +#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 diff --git a/modular.json b/modular.json new file mode 100755 index 0000000..d62862e --- /dev/null +++ b/modular.json @@ -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" + ] + } +}