Merge commit '179778d4acb8fd12acdd04f3d70f738a4a171fb9'

This commit is contained in:
2022-12-03 20:02:00 +01:00
14 changed files with 7284 additions and 1 deletions

25
.vscode/c_cpp_properties.json vendored Normal file
View File

@@ -0,0 +1,25 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/utility/unity/core",
"${workspaceFolder}/utility/unity/fixture",
// "${workspaceFolder}/test/oled/helpers/inc",
// "${workspaceFolder}/test/oled/",
"${workspaceFolder}/cmd_parser/",
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\Apps\\mingw64\\bin\\gcc.exe",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}

28
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,28 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Unity Test Explorer Debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${command:unityExplorer.debugTestExecutable}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:/Apps/mingw64/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

14
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,14 @@
{
"unityExplorer.testSourceFileRegex": "\\w+_test.c",
"unityExplorer.testCaseRegex": "void\\s+(test_.*)\\s*\\(.*\\)",
"unityExplorer.testExecutableRegex": "build/exe/$1.exe",
"unityExplorer.testSourceFolder": "test",
"unityExplorer.testBuildApplication": "ninja",
"unityExplorer.testBuildCwdPath": "build",
// "unityExplorer.unitUnderTestFolder": "cmd_parser",
"unityExplorer.unitUnderTestFileRegex": "\\w+\\.[ch]",
"unityExplorer.prettyTestCaseRegex": "test_(\\w+)",
"unityExplorer.prettyTestFileRegex": "(\\w+)_test\\.c",
"unityExplorer.debugConfiguration": "Unity Test Explorer Debug",
}

17
.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "build",
"command": "C:/Apps/mingw64/bin/ninja.exe",
"options": {
"cwd": "${workspaceFolder}/build"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

View File

@@ -15,4 +15,5 @@ add_definitions(${GLOBAL_DEFINITION})
add_subdirectory(utility/unity unity)
link_libraries(unity)
add_subdirectory(test/oled oled)
# add_subdirectory(test/oled oled)
add_subdirectory(test/cmd_parser cmd_parser)

89
cmd_parser/cmd_parser.c Normal file
View File

@@ -0,0 +1,89 @@
#include "string.h"
#include "stdint.h"
#include "cmd_parser.h"
static const cmd_t **cmd_array;
static uint8_t cmd_array_size;
void cmd_parser_init(const cmd_t *commands[], uint8_t size)
{
cmd_array = commands;
cmd_array_size = size;
}
void msg_parse(char *msg)
{
char *msgptr, *submsgptr;
parser_t parser = NULL;
result_t result = CMD_OK;
char key = 0;
char *token = strtok_r(msg, " ", &msgptr);
if (token[0] == '?')
{
// help message
}
for (uint8_t i = 0; i < cmd_array_size; i++)
{
if (strcmp(token, cmd_array[i]->name) == 0)
{
parser = cmd_array[i]->parser;
break;
}
}
if (parser == NULL)
{
return;
}
for (token = strtok_r(NULL, " ", &msgptr); token != NULL; token = strtok_r(NULL, " ", &msgptr))
{
if (token[0] == '-')
{
key = token[1];
result = parser(key, NULL);
if (strlen(token) > 2)
{
token = token + 2;
}
}
if (token[0] != '-')
{
switch (result)
{
case CMD_VALUE_REQ:
result = parser(key, token);
break;
case CMD_MULTIVAL_REQ:
for (char *subtoken = strtok_r(token, ", ", &submsgptr); subtoken != NULL; subtoken = strtok_r(NULL, ",", &submsgptr))
{
if (parser(key, subtoken) == CMD_UNKNOWN)
{
result = parser(CMDP_KEY_ARG, subtoken);
}
}
break;
default:
result = parser(CMDP_KEY_ARG, token);
break;
}
}
if (result == CMD_UNKNOWN)
{
break;
}
}
if (result != CMD_UNKNOWN)
{
parser(CMDP_KEY_DONE, NULL);
}
else
{
parser(CMDP_KEY_STOP, NULL);
}
}

24
cmd_parser/cmd_parser.h Normal file
View File

@@ -0,0 +1,24 @@
#pragma once
#define CMDP_KEY_DONE 1
#define CMDP_KEY_ARG 2
#define CMDP_KEY_STOP 3
typedef enum
{
CMD_OK,
CMD_VALUE_REQ,
CMD_MULTIVAL_REQ,
CMD_UNKNOWN,
} result_t;
typedef result_t (*parser_t)(char key, char *arg);
typedef struct
{
char *name;
parser_t parser;
} cmd_t;
void cmd_parser_init(const cmd_t *commands[], uint8_t size);
void msg_parse(char *msg);

59
cmd_parser/cmd_parser2.h Normal file
View File

@@ -0,0 +1,59 @@
#pragma once
#include "main.h"
#define CMDP_KEY_ARG 1
typedef void (*help_filter)(char key, const char *text);
// key = opt_id, arg = value or NULL
// key = CMDP_KEY_ARG, arg = id_arg or token
typedef enum
{
CMD_NULL,
CMD_OK,
CMD_VALUE_REQ,
CMD_MULTIVAL_REQ,
CMD_UNKNOWN,
} result_t;
typedef result_t (*parser)(char key, char *arg);
typedef enum
{
NO_VALUE = 0,
SINGLE_VALE = 1,
MULTI_VALUE = 2,
NOT_OPTIONAL = 4,
} option_flags_t;
typedef const struct
{
uint8_t opt_id;
char *name;
char *description;
option_flags_t flags;
} option_t;
typedef const struct
{
char *name;
uint8_t arg_id;
char *description;
option_t *options;
uint8_t opt_num;
// parser arg_parser;
} argument_t;
typedef const struct
{
char *name;
char *description;
argument_t *arguments;
uint8_t arg_num;
option_t *options;
uint8_t opt_num;
parser cmd_parser;
} cmd_parser_t;
void cmd_parser_init(cmd_parser_t* commands[], uint8_t size);
// void cmd_parse(char *msg, parser parser);
void cmd_parse(char *msg);

View File

@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.10)
set(TEST_NAME cmd_parser_test)
set(INCLUDE_DIRS
../../cmd_parser
helpers/inc
../../utility/fff
)
set(SRCS
../../cmd_parser/cmd_parser2.c
# helpers/src/led_cmd.c
cmd_parser_test.c
)
add_definitions(-DTEST)
add_executable(${TEST_NAME} ${SRCS})
target_include_directories(${TEST_NAME} PUBLIC ${INCLUDE_DIRS})

View File

@@ -0,0 +1,283 @@
#include "unity.h"
#include "fff.h"
#include "cmd_parser.h"
DEFINE_FFF_GLOBALS;
FAKE_VALUE_FUNC(result_t, parse_callback, char, char *);
cmd_t led_cmd = {.name = "led", .parser = parse_callback};
void setUp(void)
{
RESET_FAKE(parse_callback);
FFF_RESET_HISTORY();
}
void tearDown(void)
{
}
void test_splittoken1(void)
{
char msg[] = "led";
parse_callback_fake.return_val = CMD_OK;
msg_parse(msg);
TEST_ASSERT_EQUAL(1, parse_callback_fake.call_count);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
}
void test_splittoken2(void)
{
char msg[] = "led set";
parse_callback_fake.return_val = CMD_OK;
msg_parse(msg);
TEST_ASSERT_EQUAL(2, parse_callback_fake.call_count);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_ARG, parse_callback_fake.arg0_history[0]);
TEST_ASSERT_EQUAL_CHAR_ARRAY("set", parse_callback_fake.arg1_history[0], 3);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
}
void test_splittoken3(void)
{
char msg[] = "led set -p";
parse_callback_fake.return_val = CMD_OK;
msg_parse(msg);
TEST_ASSERT_EQUAL(3, parse_callback_fake.call_count);
TEST_ASSERT_EQUAL_CHAR('p', parse_callback_fake.arg0_history[1]);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[1]);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
}
void test_splittoken4(void)
{
char msg[] = "led set -p 50";
result_t returnValue[] = {CMD_OK, CMD_VALUE_REQ, CMD_OK};
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
msg_parse(msg);
TEST_ASSERT_EQUAL(4, parse_callback_fake.call_count);
TEST_ASSERT_EQUAL_CHAR('p', parse_callback_fake.arg0_history[1]);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[1]);
TEST_ASSERT_EQUAL_CHAR('p', parse_callback_fake.arg0_history[2]);
TEST_ASSERT_EQUAL_CHAR_ARRAY("50", parse_callback_fake.arg1_history[2], 2);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
}
void test_splittoken5(void)
{
char msg[] = "led set -p 50 -l";
result_t returnValue[] = {CMD_OK, CMD_VALUE_REQ, CMD_OK};
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
msg_parse(msg);
TEST_ASSERT_EQUAL(5, parse_callback_fake.call_count);
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[3]);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[3]);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
}
void test_splittoken6(void)
{
char msg[] = "led set -p 50 -l Atop, Btop, Ctop";
result_t returnValue[] = {CMD_OK, CMD_VALUE_REQ, CMD_OK, CMD_MULTIVAL_REQ, CMD_OK};
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
msg_parse(msg);
TEST_ASSERT_EQUAL(8, parse_callback_fake.call_count);
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[3]);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[3]);
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[4]);
TEST_ASSERT_EQUAL_CHAR_ARRAY("Atop", parse_callback_fake.arg1_history[4], 4);
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[5]);
TEST_ASSERT_EQUAL_CHAR_ARRAY("Btop", parse_callback_fake.arg1_history[5], 4);
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[6]);
TEST_ASSERT_EQUAL_CHAR_ARRAY("Ctop", parse_callback_fake.arg1_history[6], 4);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
}
void test_splittoken7(void)
{
char msg[] = "led set -p -l Atop, Btop, Ctop";
result_t returnValue[] = {CMD_OK, CMD_OK, CMD_MULTIVAL_REQ, CMD_OK};
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
msg_parse(msg);
TEST_ASSERT_EQUAL(7, parse_callback_fake.call_count);
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[2]);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[2]);
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[3]);
TEST_ASSERT_EQUAL_CHAR_ARRAY("Atop", parse_callback_fake.arg1_history[3], 4);
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[4]);
TEST_ASSERT_EQUAL_CHAR_ARRAY("Btop", parse_callback_fake.arg1_history[4], 4);
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[5]);
TEST_ASSERT_EQUAL_CHAR_ARRAY("Ctop", parse_callback_fake.arg1_history[5], 4);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
}
void test_splittoken8(void)
{
char msg[] = "led set -p -l Atop, Btop, Ctop test";
result_t returnValue[] = {CMD_OK, CMD_OK, CMD_MULTIVAL_REQ, CMD_OK, CMD_OK, CMD_OK, CMD_UNKNOWN, CMD_OK};
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
msg_parse(msg);
TEST_ASSERT_EQUAL(9, parse_callback_fake.call_count);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_ARG, parse_callback_fake.arg0_history[7]);
TEST_ASSERT_EQUAL_CHAR_ARRAY("test", parse_callback_fake.arg1_history[7], 4);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
}
void test_splittoken9(void)
{
char msg[] = "led set -p -l Atop, Btop, Wrong test";
result_t returnValue[] = {CMD_OK, CMD_OK, CMD_MULTIVAL_REQ, CMD_OK, CMD_OK, CMD_UNKNOWN, CMD_UNKNOWN, CMD_OK};
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
msg_parse(msg);
TEST_ASSERT_EQUAL(8, parse_callback_fake.call_count);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_STOP, parse_callback_fake.arg0_val);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
}
void test_splittoken10(void)
{
char msg[] = "led set -p50";
result_t returnValue[] = {CMD_OK, CMD_VALUE_REQ, CMD_OK};
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
msg_parse(msg);
TEST_ASSERT_EQUAL(4, parse_callback_fake.call_count);
TEST_ASSERT_EQUAL_CHAR('p', parse_callback_fake.arg0_history[1]);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[1]);
TEST_ASSERT_EQUAL_CHAR('p', parse_callback_fake.arg0_history[2]);
TEST_ASSERT_EQUAL_CHAR_ARRAY("50", parse_callback_fake.arg1_history[2], 2);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
}
void test_splittoken11(void)
{
char msg[] = "led set -p50 -l Atop,Btop,Ctop";
result_t returnValue[] = {CMD_OK, CMD_VALUE_REQ, CMD_OK, CMD_MULTIVAL_REQ, CMD_OK};
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
msg_parse(msg);
TEST_ASSERT_EQUAL(8, parse_callback_fake.call_count);
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[3]);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[3]);
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[4]);
TEST_ASSERT_EQUAL_CHAR_ARRAY("Atop", parse_callback_fake.arg1_history[4], 4);
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[5]);
TEST_ASSERT_EQUAL_CHAR_ARRAY("Btop", parse_callback_fake.arg1_history[5], 4);
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[6]);
TEST_ASSERT_EQUAL_CHAR_ARRAY("Ctop", parse_callback_fake.arg1_history[6], 4);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
}
void test_splittoken12(void)
{
char msg[] = "led set -p50 -lAtop,Btop,Ctop";
result_t returnValue[] = {CMD_OK, CMD_VALUE_REQ, CMD_OK, CMD_MULTIVAL_REQ, CMD_OK};
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
msg_parse(msg);
TEST_ASSERT_EQUAL(8, parse_callback_fake.call_count);
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[3]);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[3]);
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[4]);
TEST_ASSERT_EQUAL_CHAR_ARRAY("Atop", parse_callback_fake.arg1_history[4], 4);
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[5]);
TEST_ASSERT_EQUAL_CHAR_ARRAY("Btop", parse_callback_fake.arg1_history[5], 4);
TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[6]);
TEST_ASSERT_EQUAL_CHAR_ARRAY("Ctop", parse_callback_fake.arg1_history[6], 4);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_DONE, parse_callback_fake.arg0_val);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
}
void test_splittoken13(void)
{
char msg[] = "led wrong";
result_t returnValue[] = {CMD_UNKNOWN, CMD_OK};
SET_RETURN_SEQ(parse_callback, returnValue, 5);
msg_parse(msg);
TEST_ASSERT_EQUAL(2, parse_callback_fake.call_count);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_STOP, parse_callback_fake.arg0_val);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
}
void test_splittoken14(void)
{
char msg[] = "led wrong -p 50 -l Atop,Btop,Ctop";
result_t returnValue[] = {CMD_UNKNOWN, CMD_VALUE_REQ, CMD_OK, CMD_MULTIVAL_REQ, CMD_OK};
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
msg_parse(msg);
TEST_ASSERT_EQUAL(2, parse_callback_fake.call_count);
// TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[3]);
// TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[3]);
// TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[4]);
// TEST_ASSERT_EQUAL_CHAR_ARRAY("Atop", parse_callback_fake.arg1_history[4], 4);
// TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[5]);
// TEST_ASSERT_EQUAL_CHAR_ARRAY("Btop", parse_callback_fake.arg1_history[5], 4);
// TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[6]);
// TEST_ASSERT_EQUAL_CHAR_ARRAY("Ctop", parse_callback_fake.arg1_history[6], 4);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_STOP, parse_callback_fake.arg0_val);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
}
void test_splittoken15(void)
{
char msg[] = "led set -X 50 -l Atop,Btop,Ctop";
result_t returnValue[] = {CMD_OK, CMD_UNKNOWN, CMD_OK, CMD_MULTIVAL_REQ, CMD_OK};
SET_RETURN_SEQ(parse_callback, returnValue, sizeof(returnValue) / sizeof(returnValue[0]));
msg_parse(msg);
TEST_ASSERT_EQUAL(3, parse_callback_fake.call_count);
// TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[3]);
// TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_history[3]);
// TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[4]);
// TEST_ASSERT_EQUAL_CHAR_ARRAY("Atop", parse_callback_fake.arg1_history[4], 4);
// TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[5]);
// TEST_ASSERT_EQUAL_CHAR_ARRAY("Btop", parse_callback_fake.arg1_history[5], 4);
// TEST_ASSERT_EQUAL_CHAR('l', parse_callback_fake.arg0_history[6]);
// TEST_ASSERT_EQUAL_CHAR_ARRAY("Ctop", parse_callback_fake.arg1_history[6], 4);
TEST_ASSERT_EQUAL_UINT8(CMDP_KEY_STOP, parse_callback_fake.arg0_val);
TEST_ASSERT_EQUAL_PTR(NULL, parse_callback_fake.arg1_val);
}
int main(void)
{
cmd_t led_cmd = {.name = "led", .parser = parse_callback};
const cmd_t *cmd_list[] = {&led_cmd};
cmd_parser_init(cmd_list, sizeof(cmd_list)/sizeof(cmd_list[0]) );
UNITY_BEGIN();
RUN_TEST(test_splittoken1);
RUN_TEST(test_splittoken2);
RUN_TEST(test_splittoken3);
RUN_TEST(test_splittoken4);
RUN_TEST(test_splittoken5);
RUN_TEST(test_splittoken6);
RUN_TEST(test_splittoken7);
RUN_TEST(test_splittoken8);
RUN_TEST(test_splittoken9);
RUN_TEST(test_splittoken10);
RUN_TEST(test_splittoken11);
RUN_TEST(test_splittoken12);
RUN_TEST(test_splittoken13);
RUN_TEST(test_splittoken14);
RUN_TEST(test_splittoken15);
return UNITY_END();
}

View File

@@ -0,0 +1,14 @@
#pragma once
#include "main.h"
#include "cmd_parser.h"
/*
Usage: led set|get [-p PNUM | --power=PNUM] [-w CHOICES | --which=CHOICES] [-m COICES | --mode=CHOICES]
-p, --power set or get power 0-100
-w, --which set or get specific leds [Atop, Abot, Btop, Bbot, Ctop, Cbot, all]
-m, --mode set or get mode of operation [allways_on, scan]
*/
// cmd_parser_t led_cmd;
result_t parse_callback(char key, char *arg);

View File

@@ -0,0 +1,3 @@
#pragma once
#include <stdint.h>

View File

@@ -0,0 +1,62 @@
#include "led_cmd.h"
enum {set, get};
option_t set_options[] = {
{
.opt_id = 'p',
.name = "power",
.flags = SINGLE_VALE,
.description = "sets the power of the light",
},
{
.opt_id = 'l',
.name = "led",
.flags = MULTI_VALUE,
.description = "diode selection. OPTIONS = [Atop, Abot, Btop, Bbot, Ctop, Cbot, all]",
}
};
option_t get_options[] = {
{
.opt_id = 'p',
.name = "power",
.flags = NO_VALUE,
.description = "gets the power of the light",
},
{
.opt_id = 'l',
.name = "led",
.flags = MULTI_VALUE,
.description = "diode selection. OPTIONS = [Atop, Abot, Btop, Bbot, Ctop, Cbot, all]",
}
};
argument_t arguments[] = {
{
.name = "set",
.arg_id = set,
.options = set_options,
.opt_num = sizeof(set_options) / (sizeof(set_options[0])),
.description = "allows to set operating parameters",
},
{
.name = "get",
.arg_id = get,
.options = get_options,
.opt_num = sizeof(get_options) / (sizeof(get_options[0])),
.description = "allows to get operating parameters",
},
};
cmd_parser_t led_cmd = {
.name = "led",
.arguments = arguments,
.arg_num = sizeof(arguments) / sizeof(arguments[0]),
.description = "allows to controll and check leds",
.cmd_parser = parse_callback,
};

6643
utility/fff/fff.h Normal file

File diff suppressed because it is too large Load Diff