Начало
This commit is contained in:
commit
4e0783a359
|
|
@ -0,0 +1,51 @@
|
|||
//
|
||||
// Created by zemon on 15.11.22.
|
||||
//
|
||||
#include "CliRedirectTable.h"
|
||||
|
||||
|
||||
bool CliRedirectionTable_RecAdd(tCliRedirectTable *baseTable, char *cmdStatic, uint8_t cmdLen, cliCall mtd, void *env) {
|
||||
if (baseTable->count >= baseTable->itemsLimit) {
|
||||
return false;
|
||||
}
|
||||
|
||||
baseTable->items[baseTable->count].cmd.data = cmdStatic;
|
||||
baseTable->items[baseTable->count].cmd.length = cmdLen;
|
||||
baseTable->items[baseTable->count].method = mtd;
|
||||
baseTable->items[baseTable->count].env = env;
|
||||
|
||||
++baseTable->count;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void CliRedirectionTable_Init(tCliRedirectTable *baseTable, tCliRedirectItem *mem, uint16_t itemsLimit) {
|
||||
baseTable->count = 0;
|
||||
baseTable->itemsLimit = itemsLimit;
|
||||
baseTable->items = mem;
|
||||
}
|
||||
|
||||
int32_t CliRedirectionTable_ProcessCmd(tCliRedirectTable *env, tCliCmd *cmd) {
|
||||
for (uint16_t id = 0; id < env->count; ++id) {
|
||||
tCliRedirectItem *item = env->items + id;
|
||||
char *cmdName = CliCmd_RxStartsWith(cmd, item->cmd.data, item->cmd.length);
|
||||
if (cmdName) {
|
||||
CliCmd_RxSkip(cmd, item->cmd.length);
|
||||
CliCmd_RxSkipSpace(cmd);
|
||||
return item->method(item->env, cmd);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t CliRedirectionTable_ListCmd(tCliRedirectTable *env, tCliCmd *cmd, char divider) {
|
||||
for (uint16_t id = 0; id < env->count; ++id) {
|
||||
tCliRedirectItem *item = env->items + id;
|
||||
CliCmd_Print(cmd, item->cmd.data, item->cmd.length);
|
||||
if (divider) {
|
||||
CliCmd_Print(cmd, ÷r, 1);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
//
|
||||
// Created by zemon on 11.11.22.
|
||||
//
|
||||
|
||||
#ifndef UVEOS_ON_NATION_CLIREDIRECTTABLE_H
|
||||
#define UVEOS_ON_NATION_CLIREDIRECTTABLE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "CliCmd.h"
|
||||
#include "BaseTypes.h"
|
||||
|
||||
typedef int32_t (*cliCall)(void *env, tCliCmd *cli);
|
||||
|
||||
typedef struct {
|
||||
tStringStatic cmd;
|
||||
cliCall method;
|
||||
void *env;
|
||||
} tCliRedirectItem;
|
||||
|
||||
typedef struct {
|
||||
tCliRedirectItem *items;
|
||||
uint16_t count;
|
||||
uint16_t itemsLimit;
|
||||
} tCliRedirectTable;
|
||||
|
||||
void CliRedirectionTable_Init(tCliRedirectTable *baseTable, tCliRedirectItem *mem, uint16_t itemsLimit);
|
||||
|
||||
#define CliRedirectionTable_InitStatic(TAB, MEM) CliRedirectionTable_Init(TAB,MEM,sizeof(MEM)/sizeof(tCliRedirectItem))
|
||||
|
||||
bool CliRedirectionTable_RecAdd(tCliRedirectTable *baseTable, char *cmdStatic, uint8_t cmdLen, cliCall mtd, void *env);
|
||||
|
||||
#define CliRedirectionTable_RecAddStatic(TAB, CMD, CALL, ENV) CliRedirectionTable_RecAdd(TAB,CMD,sizeof (CMD)-1,CALL,ENV)
|
||||
|
||||
int32_t CliRedirectionTable_ProcessCmd(tCliRedirectTable *env, tCliCmd *cmd);
|
||||
|
||||
int32_t CliRedirectionTable_ListCmd(tCliRedirectTable *env, tCliCmd *cmd, char divider);
|
||||
|
||||
#endif //UVEOS_ON_NATION_CLIREDIRECTTABLE_H
|
||||
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"dep": [
|
||||
{
|
||||
"type": "git",
|
||||
"provider": "HVAC_DEV",
|
||||
"repo": "BaseTypes"
|
||||
},
|
||||
{
|
||||
"type": "git",
|
||||
"provider": "HVAC_DEV",
|
||||
"repo": "CliCmd"
|
||||
}
|
||||
],
|
||||
"cmake": {
|
||||
"inc_dirs": [
|
||||
"./"
|
||||
],
|
||||
"srcs": [
|
||||
"./**.c"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue