commit 3d8f3d27adcc90063e936292d04524544e9fa020 Author: cfif Date: Wed Dec 4 13:10:50 2024 +0300 Init diff --git a/Inc/CliCmd/Vars.h b/Inc/CliCmd/Vars.h new file mode 100644 index 0000000..c4b195b --- /dev/null +++ b/Inc/CliCmd/Vars.h @@ -0,0 +1,19 @@ +// +// Created by zemon on 17.11.22. +// + +#ifndef UVEOS_ON_NATION_CLIVARS_H +#define UVEOS_ON_NATION_CLIVARS_H + +#include "CliCmd.h" +#include "VariablesTable.h" + +int32_t vGetVarsTableSetting(tVariablesTable *extTable, tCliCmd *cli); + +int32_t vSetVarTableSetting(tVariablesTable *extTable, tCliCmd *cli); + +int32_t CliCmd_VarsHelp(tCliCmd *cli); + +int32_t CliCmd_ChangeListVar(tVariablesTable *varTable, tCliCmd *cli); + +#endif //UVEOS_ON_NATION_CLIVARS_H diff --git a/Src/CliCmd/GetVars.c b/Src/CliCmd/GetVars.c new file mode 100644 index 0000000..608014f --- /dev/null +++ b/Src/CliCmd/GetVars.c @@ -0,0 +1,43 @@ +// +// Created by zemon on 15.11.22. +// +#include "CliCmd/Vars.h" +#include "stream.h" + +int32_t vGetVarsTableSetting(tVariablesTable *extTable, tCliCmd *cli) { + + for (uint16_t id = 0; id < extTable->count; ++id) { + CliCmd_Print(cli, extTable->items[id].name.str, extTable->items[id].name.length); + CliCmd_PrintStatic(cli, " "); + tVariableDescriptor *descriptor = extTable->items + id; + + if (descriptor->typeId == VARIABLE_TYPE_STRING) { + CliCmd_Print(cli, descriptor->addr, *(uint8_t *) descriptor->len); + } else { + if (extTable->items[id].typeId == VARIABLE_TYPE_UINT8) { + debug_printf(cli->serialCommandPort, "%u", *(uint8_t *) extTable->items[id].addr); + } + if (extTable->items[id].typeId == VARIABLE_TYPE_UINT16) { + debug_printf(cli->serialCommandPort, "%u", *(uint16_t *) extTable->items[id].addr); + } + if (extTable->items[id].typeId == VARIABLE_TYPE_UINT32) { + debug_printf(cli->serialCommandPort, "%u", *(uint8_t *) extTable->items[id].addr); + } + if (extTable->items[id].typeId == VARIABLE_TYPE_BOOL) { + debug_printf(cli->serialCommandPort, "%u", *(uint8_t *) extTable->items[id].addr); + } + if (extTable->items[id].typeId == VARIABLE_TYPE_FLOAT32) { + debug_printf(cli->serialCommandPort, "%f", *(float *) extTable->items[id].addr); + } + if (!VariablesTable_IsVariableChangeAllowed(descriptor)) { + CliCmd_PrintStatic(cli, " === CHANGE NOT ACCESS ==="); + } + } + CliCmd_PrintLnStatic(cli, ""); + } + + CliCmd_PrintLnStatic(cli, "================================================"); + CliCmd_PrintLnStatic(cli, ""); + + return 0; +} \ No newline at end of file diff --git a/Src/CliCmd/SetVar.c b/Src/CliCmd/SetVar.c new file mode 100644 index 0000000..6eabfef --- /dev/null +++ b/Src/CliCmd/SetVar.c @@ -0,0 +1,151 @@ +// +// Created by zemon on 16.11.22. +// +#include "CliCmd/Vars.h" +#include "freertos_os2.h" +#include + + +uint8_t charToInt16(uint16_t *val, const char *source, uint8_t len) { + unsigned long R = 0; + uint16_t readed; + uint8_t ret = 0, bad = 0, i = 0; + while (i < len) { + + if (source[i] < '0' || source[i] > '9') break; + ret = 1; + R = R * 10L + source[i] - '0'; + if (R > 0xffff) { + R = 0; + bad = 1; + } + i++; + } + if (bad || !ret) return 0; + readed = (uint16_t) R; + *val = readed; + return 1; +} + +uint8_t testIsWriteData(tVariableDescriptor *descriptor, tVariablesTable *extTable) { + //проверяем можно ли ее писать (если есть счетчик разрешения записи то не пустой ли он) + if (VariablesTable_IsVariableChangeAllowed(descriptor)) { + //запрашиваем доступ на изменение настроек + if (VariablesTable_RequireChange(extTable, 10)) { + return 0; + } else { + return 2; + } + } else { + return 1; + } +} + +void saveChenge(tCliCmd *cli, tVariableDescriptor *descriptor, tVariablesTable *extTable) { + VariablesTable_VariableChanged(extTable, descriptor); + VariablesTable_ReleaseChange(extTable); +} + +int32_t vSetVarTableSetting(tVariablesTable *extTable, tCliCmd *cli) { + char *paramVale = ""; + + for (uint16_t id = 0; id < extTable->count; ++id) { + + if (CliCmd_RxStartsWith( + cli, + extTable->items[id].name.str, + extTable->items[id].name.length + ) + ) { + + CliCmd_RxSkip(cli, extTable->items[id].name.length); + CliCmd_RxSkipSpace(cli); + + paramVale = cli->rxLine.begin; + tVariableDescriptor *descriptor = extTable->items + id; + + switch (testIsWriteData(descriptor, extTable)) { + case 0: { + switch (descriptor->typeId) { + case VARIABLE_TYPE_STRING: { + uint8_t len = (CliCmd_RxLineLength(cli)) - 2; + memcpy(descriptor->addr, CliCmd_RxLineBegin(cli), len); + *((uint8_t *) descriptor->len) = len; + } + break; + + case VARIABLE_TYPE_UINT8: { + uint8_t data = (uint8_t) atoi(paramVale); + memcpy(descriptor->addr, &data, sizeof(data)); + } + break; + + case VARIABLE_TYPE_UINT16: { + uint16_t data; + if (charToInt16(&data, paramVale, strlen(paramVale))) { + memcpy(descriptor->addr, &data, sizeof(data)); + } else { + CliCmd_PrintLnStatic(cli, "CONVERSATION FAILED, FORMAT DATA ERROR"); + } + } + break; + + case VARIABLE_TYPE_INT32: { + uint32_t data = (uint8_t) atoi(paramVale); + memcpy(descriptor->addr, &data, sizeof(data)); + } + break; + + case VARIABLE_TYPE_BOOL: { + uint8_t data; + if ((strstr(paramVale, "TRUE")) || (strstr(paramVale, "1"))) { + data = 1; + } + if ((strstr(paramVale, "FALSE")) || (strstr(paramVale, "0"))) { + data = 0; + } + memcpy(descriptor->addr, &data, sizeof(data)); + } + break; + + case VARIABLE_TYPE_FLOAT32: { + float data = atof(paramVale); + memcpy(descriptor->addr, &data, sizeof(data)); + } + break; + + default: + CliCmd_PrintStatic(cli, "Unidentified error!"); + } + + CliCmd_PrintLnStatic(cli, "Save setting? (Yes/No)"); + CliCmd_WaitLine(cli); + if (CliCmd_RxStartsWithStatic(cli, "Yes")) { + saveChenge(cli, descriptor, extTable); + CliCmd_PrintLnStatic(cli, "Setting is success full"); + } + break; + } + + case 1: { + CliCmd_PrintLnStatic(cli, "Access deniedted"); + break; + } + + case 2: { + CliCmd_PrintLnStatic(cli, "Temporarily unavailable "); + //осовбождаем доступ к измененению настроек + VariablesTable_ReleaseChange(extTable); + break; + } + + default: + CliCmd_PrintStatic(cli, "Unidentified error!"); + } + + } + + } + + return 0; +} \ No newline at end of file diff --git a/Src/CliCmd/VarsHelp.c b/Src/CliCmd/VarsHelp.c new file mode 100644 index 0000000..7279fa6 --- /dev/null +++ b/Src/CliCmd/VarsHelp.c @@ -0,0 +1,15 @@ +// +// Created by xemon on 22.12.22. +// +#include "CliCmd/Vars.h" + +int32_t CliCmd_VarsHelp(tCliCmd *cli) { + CliCmd_PrintLnStatic(cli, " access sub commands:"); + CliCmd_PrintLnStatic(cli, " command [ ls ]- listing all access variable and values"); + CliCmd_PrintLnStatic(cli, " command [ set ] - set variable values"); + CliCmd_PrintLnStatic(cli, " syntaxis: [command] [VARIABLE_NAME] [VARIABLE_VALUE]"); + CliCmd_PrintLnStatic(cli, " command [ help ] - help this as sub mode"); + CliCmd_PrintLnStatic(cli, " command [ exit ] - exit as this sub mode"); + CliCmd_PrintLnStatic(cli, ""); + return 0; +} \ No newline at end of file diff --git a/Src/CliCmd/VarsMode.c b/Src/CliCmd/VarsMode.c new file mode 100644 index 0000000..6ee05a1 --- /dev/null +++ b/Src/CliCmd/VarsMode.c @@ -0,0 +1,33 @@ +// +// Created by xemon on 22.12.22. +// +#include "CliCmd/Vars.h" + + +int32_t CliCmd_ChangeListVar(tVariablesTable *varTable, tCliCmd *cli) { + CliCmd_PrintLnStatic(cli, "THIS MODE CHANG BASE VARIABLE"); + CliCmd_VarsHelp(cli); + while (1) { + + CliCmd_WaitLine(cli); + + if (CliCmd_RxStartsWithStatic(cli, "ls")) { + vGetVarsTableSetting(varTable, cli); + } + + if (CliCmd_RxStartsWithStatic(cli, "set")) { + CliCmd_PrintLnStatic(cli, "set"); + CliCmd_RxSkip(cli, sizeof("set")); + vSetVarTableSetting(varTable, cli); + } + + if (CliCmd_RxStartsWithStatic(cli, "exit")) { + CliCmd_PrintLnStatic(cli, "EXIT IN BASE MODE..."); + return 0; + } + + if (CliCmd_RxStartsWithStatic(cli, "help")) { + CliCmd_VarsHelp(cli); + } + } +} diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..e7d865b --- /dev/null +++ b/modular.json @@ -0,0 +1,22 @@ +{ + "dep": [ + { + "type": "git", + "provider": "NAVIGATOR_UVEOS_NATION_TELIT", + "repo": "CmsisCore5" + }, + { + "type": "git", + "provider": "NAVIGATOR_UVEOS_NATION_TELIT", + "repo": "CliCmd" + } + ], + "cmake": { + "inc_dirs": [ + "Inc" + ], + "srcs": [ + "Src/**.c" + ] + } +} \ No newline at end of file