Compare commits
11 Commits
d0b533daf9
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| a6b356d397 | |||
| a2401f45cc | |||
| 841e30913e | |||
| b1f7e448ab | |||
| 44e4ff3d24 | |||
| 179778d4ac | |||
| e67c12358f | |||
| 363c9568a7 | |||
| c8dc4e7962 | |||
| 47f14990d5 | |||
| 1b83af44e9 |
6
.vscode/c_cpp_properties.json
vendored
6
.vscode/c_cpp_properties.json
vendored
@@ -5,9 +5,11 @@
|
|||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/utility/unity/core",
|
"${workspaceFolder}/utility/unity/core",
|
||||||
"${workspaceFolder}/utility/unity/fixture",
|
"${workspaceFolder}/utility/unity/fixture",
|
||||||
|
"${workspaceFolder}/utility/fff",
|
||||||
|
"${workspaceFolder}/test/cmd_parser/helpers/inc",
|
||||||
|
"${workspaceFolder}/cmd_parser",
|
||||||
"${workspaceFolder}/test/oled/helpers/inc",
|
"${workspaceFolder}/test/oled/helpers/inc",
|
||||||
"${workspaceFolder}/test/oled/",
|
"${workspaceFolder}/oled"
|
||||||
"${workspaceFolder}/**"
|
|
||||||
],
|
],
|
||||||
"defines": [
|
"defines": [
|
||||||
"_DEBUG",
|
"_DEBUG",
|
||||||
|
|||||||
28
.vscode/launch.json
vendored
Normal file
28
.vscode/launch.json
vendored
Normal 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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
17
.vscode/settings.json
vendored
Normal file
17
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"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",
|
||||||
|
"files.associations": {
|
||||||
|
"main.h": "c"
|
||||||
|
},
|
||||||
|
|
||||||
|
}
|
||||||
17
.vscode/tasks.json
vendored
Normal file
17
.vscode/tasks.json
vendored
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -15,4 +15,5 @@ add_definitions(${GLOBAL_DEFINITION})
|
|||||||
add_subdirectory(utility/unity unity)
|
add_subdirectory(utility/unity unity)
|
||||||
link_libraries(unity)
|
link_libraries(unity)
|
||||||
|
|
||||||
add_subdirectory(test/oled oled)
|
add_subdirectory(test/oled oled)
|
||||||
|
add_subdirectory(test/cmd_parser cmd_parser)
|
||||||
62
cbuffer/circular_buffer.c
Normal file
62
cbuffer/circular_buffer.c
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include "stdint.h"
|
||||||
|
#include "circular_buffer.h"
|
||||||
|
|
||||||
|
CB_StatusTypeDef cb_init(CB_TypeDef *cb, void *buffer, uint16_t capacity, uint8_t item_size)
|
||||||
|
{
|
||||||
|
if (buffer == NULL || cb == NULL)
|
||||||
|
{
|
||||||
|
return CB_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
cb->buffer = buffer;
|
||||||
|
cb->buffer_end = (uint8_t *)cb->buffer + capacity * item_size;
|
||||||
|
cb->capacity = capacity;
|
||||||
|
cb->count = 0;
|
||||||
|
cb->item_size = item_size;
|
||||||
|
cb->head = cb->buffer;
|
||||||
|
cb->tail = cb->buffer;
|
||||||
|
|
||||||
|
return CB_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
CB_StatusTypeDef cb_push_back(CB_TypeDef *cb, const void *item)
|
||||||
|
{
|
||||||
|
if (cb == NULL)
|
||||||
|
{
|
||||||
|
return CB_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cb->count == cb->capacity)
|
||||||
|
{
|
||||||
|
return CB_FULL;
|
||||||
|
}
|
||||||
|
memcpy(cb->head, item, cb->item_size);
|
||||||
|
cb->head = (uint8_t *)cb->head + cb->item_size;
|
||||||
|
if (cb->head == cb->buffer_end)
|
||||||
|
cb->head = cb->buffer;
|
||||||
|
cb->count++;
|
||||||
|
|
||||||
|
return CB_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
CB_StatusTypeDef cb_pop_front(CB_TypeDef *cb, void *item)
|
||||||
|
{
|
||||||
|
if (cb == NULL)
|
||||||
|
{
|
||||||
|
return CB_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cb->count == 0)
|
||||||
|
{
|
||||||
|
return CB_EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(item, cb->tail, cb->item_size);
|
||||||
|
cb->tail = (uint8_t *)cb->tail + cb->item_size;
|
||||||
|
if (cb->tail == cb->buffer_end)
|
||||||
|
cb->tail = cb->buffer;
|
||||||
|
cb->count--;
|
||||||
|
|
||||||
|
return CB_OK;
|
||||||
|
}
|
||||||
37
cbuffer/circular_buffer.h
Normal file
37
cbuffer/circular_buffer.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#ifndef __CIRCULAT_BUFFER__
|
||||||
|
#define __CIRCULAT_BUFFER__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
CB_OK = 0x00,
|
||||||
|
CB_ERROR = -0x01,
|
||||||
|
CB_EMPTY = -0x02,
|
||||||
|
CB_FULL = -0x03
|
||||||
|
} CB_StatusTypeDef;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
void *buffer; // data buffer
|
||||||
|
void *buffer_end; // end of data buffer
|
||||||
|
uint16_t capacity; // maximum number of items in the buffer
|
||||||
|
uint16_t count; // number of items in the buffer
|
||||||
|
uint8_t item_size; // size of each item in the buffer
|
||||||
|
void *head; // pointer to head
|
||||||
|
void *tail; // pointer to tail
|
||||||
|
} CB_TypeDef;
|
||||||
|
|
||||||
|
CB_StatusTypeDef cb_init(CB_TypeDef *cb, void *buffer, uint16_t capacity, uint8_t item_size);
|
||||||
|
CB_StatusTypeDef cb_push_back(CB_TypeDef *cb, const void *item);
|
||||||
|
CB_StatusTypeDef cb_pop_front(CB_TypeDef *cb, void *item);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __CIRCULAT_BUFFER__ */
|
||||||
89
cmd_parser/cmd_parser.c
Normal file
89
cmd_parser/cmd_parser.c
Normal 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
24
cmd_parser/cmd_parser.h
Normal 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
59
cmd_parser/cmd_parser2.h
Normal 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);
|
||||||
11
oled/oled.c
11
oled/oled.c
@@ -1,15 +1,18 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
// #include <assert.h>
|
||||||
#include "oled.h"
|
#include "oled.h"
|
||||||
#include "ssd1306.h"
|
#include "ssd1306.h"
|
||||||
#include "sh1106.h"
|
#include "sh1106.h"
|
||||||
|
|
||||||
HAL_StatusTypeDef oled_Config(OLED_HandleTypeDef *hOled, uint8_t DevAddress, uint8_t Width, uint8_t Height, OLED_DisplayType_t OledType)
|
HAL_StatusTypeDef oled_Config(OLED_HandleTypeDef *hOled, uint8_t DevAddress, uint8_t Width, uint8_t Height, OLED_DisplayType_t OledType)
|
||||||
{
|
{
|
||||||
|
// static_assert(hOled != NULL, "brak pointera");
|
||||||
if (hOled == NULL || Width == 0 || Height == 0 || OledType == UNKNOWN)
|
if (hOled == NULL || Width == 0 || Height == 0 || OledType == UNKNOWN)
|
||||||
{
|
{
|
||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hOled->hi2c = NULL;
|
||||||
hOled->DevAddress = DevAddress;
|
hOled->DevAddress = DevAddress;
|
||||||
hOled->Width = Width;
|
hOled->Width = Width;
|
||||||
hOled->Height = Height;
|
hOled->Height = Height;
|
||||||
@@ -78,7 +81,7 @@ OLED_SendStatus_t oled_display_page(OLED_HandleTypeDef *hOled)
|
|||||||
{
|
{
|
||||||
if (hOled == NULL)
|
if (hOled == NULL)
|
||||||
{
|
{
|
||||||
return;
|
return ERROR;
|
||||||
}
|
}
|
||||||
OLED_SendStatus_t sendStatus;
|
OLED_SendStatus_t sendStatus;
|
||||||
switch (hOled->OledType)
|
switch (hOled->OledType)
|
||||||
@@ -97,9 +100,3 @@ OLED_SendStatus_t oled_display_page(OLED_HandleTypeDef *hOled)
|
|||||||
return sendStatus;
|
return sendStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
OLED_HandleTypeDef display;
|
|
||||||
oled_Config(&display, 0x3C, 128, 64, SH1106);
|
|
||||||
}
|
|
||||||
@@ -14,6 +14,7 @@ typedef enum
|
|||||||
} OLED_DisplayType_t;
|
} OLED_DisplayType_t;
|
||||||
|
|
||||||
typedef enum{
|
typedef enum{
|
||||||
|
ERROR,
|
||||||
SENDPAGE,
|
SENDPAGE,
|
||||||
SENDALL
|
SENDALL
|
||||||
} OLED_SendStatus_t;
|
} OLED_SendStatus_t;
|
||||||
@@ -30,4 +31,7 @@ typedef struct
|
|||||||
|
|
||||||
} OLED_HandleTypeDef;
|
} OLED_HandleTypeDef;
|
||||||
|
|
||||||
void oled_init(OLED_HandleTypeDef *hOled, I2C_HandleTypeDef *hi2c);
|
HAL_StatusTypeDef oled_Config(OLED_HandleTypeDef *hOled, uint8_t DevAddress, uint8_t Width, uint8_t Height, OLED_DisplayType_t OledType);
|
||||||
|
void oled_init(OLED_HandleTypeDef *hOled, I2C_HandleTypeDef *hi2c);
|
||||||
|
void oled_display_all(OLED_HandleTypeDef *hOled);
|
||||||
|
OLED_SendStatus_t oled_display_page(OLED_HandleTypeDef *hOled);
|
||||||
1043
printf/printf.c
Normal file
1043
printf/printf.c
Normal file
File diff suppressed because it is too large
Load Diff
109
printf/printf.h
Normal file
109
printf/printf.h
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// \author (c) Marco Paland (info@paland.com)
|
||||||
|
// 2014-2019, PALANDesign Hannover, Germany
|
||||||
|
//
|
||||||
|
// \license The MIT License (MIT)
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
// THE SOFTWARE.
|
||||||
|
//
|
||||||
|
// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on
|
||||||
|
// embedded systems with a very limited resources.
|
||||||
|
// Use this instead of bloated standard/newlib printf.
|
||||||
|
// These routines are thread safe and reentrant.
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef _PRINTF_H_
|
||||||
|
#define _PRINTF_H_
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output a character to a custom device like UART, used by the printf() function
|
||||||
|
* This function is declared here only. You have to write your custom implementation somewhere
|
||||||
|
* \param character Character to output
|
||||||
|
*/
|
||||||
|
void _putchar(char character);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tiny printf implementation
|
||||||
|
* You have to implement _putchar if you use printf()
|
||||||
|
* To avoid conflicts with the regular printf() API it is overridden by macro defines
|
||||||
|
* and internal underscore-appended functions like printf_() are used
|
||||||
|
* \param format A string that specifies the format of the output
|
||||||
|
* \return The number of characters that are written into the array, not counting the terminating null character
|
||||||
|
*/
|
||||||
|
#define printf printf_
|
||||||
|
int printf_(const char *format, ...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tiny sprintf implementation
|
||||||
|
* Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)SNPRINTF INSTEAD!
|
||||||
|
* \param buffer A pointer to the buffer where to store the formatted string. MUST be big enough to store the output!
|
||||||
|
* \param format A string that specifies the format of the output
|
||||||
|
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
|
||||||
|
*/
|
||||||
|
#define sprintf sprintf_
|
||||||
|
int sprintf_(char *buffer, const char *format, ...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tiny snprintf/vsnprintf implementation
|
||||||
|
* \param buffer A pointer to the buffer where to store the formatted string
|
||||||
|
* \param count The maximum number of characters to store in the buffer, including a terminating null character
|
||||||
|
* \param format A string that specifies the format of the output
|
||||||
|
* \param va A value identifying a variable arguments list
|
||||||
|
* \return The number of characters that COULD have been written into the buffer, not counting the terminating
|
||||||
|
* null character. A value equal or larger than count indicates truncation. Only when the returned value
|
||||||
|
* is non-negative and less than count, the string has been completely written.
|
||||||
|
*/
|
||||||
|
#define snprintf snprintf_
|
||||||
|
#define vsnprintf vsnprintf_
|
||||||
|
int snprintf_(char *buffer, size_t count, const char *format, ...);
|
||||||
|
int vsnprintf_(char *buffer, size_t count, const char *format, va_list va);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tiny vprintf implementation
|
||||||
|
* \param format A string that specifies the format of the output
|
||||||
|
* \param va A value identifying a variable arguments list
|
||||||
|
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
|
||||||
|
*/
|
||||||
|
#define vprintf vprintf_
|
||||||
|
int vprintf_(const char *format, va_list va);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* printf with output function
|
||||||
|
* You may use this as dynamic alternative to printf() with its fixed _putchar() output
|
||||||
|
* \param out An output function which takes one character and an argument pointer
|
||||||
|
* \param arg An argument pointer for user data passed to output function
|
||||||
|
* \param format A string that specifies the format of the output
|
||||||
|
* \return The number of characters that are sent to the output function, not counting the terminating null character
|
||||||
|
*/
|
||||||
|
int fctprintf(void (*out)(char character, void *arg), void *arg, const char *format, ...);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // _PRINTF_H_
|
||||||
21
test/cmd_parser/CMakeLists.txt
Normal file
21
test/cmd_parser/CMakeLists.txt
Normal 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_parser.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})
|
||||||
283
test/cmd_parser/cmd_parser_test.c
Normal file
283
test/cmd_parser/cmd_parser_test.c
Normal 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();
|
||||||
|
}
|
||||||
14
test/cmd_parser/helpers/inc/led_cmd.h
Normal file
14
test/cmd_parser/helpers/inc/led_cmd.h
Normal 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);
|
||||||
62
test/cmd_parser/helpers/src/led_cmd.c
Normal file
62
test/cmd_parser/helpers/src/led_cmd.c
Normal 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,
|
||||||
|
};
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
set(TEST_NAME oled)
|
set(TEST_NAME oled_test)
|
||||||
|
|
||||||
set(INCLUDE_DIRS
|
set(INCLUDE_DIRS
|
||||||
../../oled
|
../../oled
|
||||||
@@ -10,12 +10,12 @@ set(INCLUDE_DIRS
|
|||||||
)
|
)
|
||||||
|
|
||||||
set(SRCS
|
set(SRCS
|
||||||
# ../../oled/oled.c
|
../../oled/oled.c
|
||||||
# ../../oled/connection.c
|
../../oled/connection.c
|
||||||
# ../../oled/ssd1306/ssd1306.c
|
../../oled/ssd1306/ssd1306.c
|
||||||
# ../../oled/sh1106/sh1106.c
|
../../oled/sh1106/sh1106.c
|
||||||
|
|
||||||
# helpers/src/mock_i2c.c
|
helpers/src/mock_i2c.c
|
||||||
oled_test.c
|
oled_test.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,41 @@
|
|||||||
|
#include "stdlib.h"
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
|
#include "oled.h"
|
||||||
|
#include "string.h"
|
||||||
|
|
||||||
|
OLED_HandleTypeDef* display;
|
||||||
|
|
||||||
void setUp(void)
|
void setUp(void)
|
||||||
{
|
{
|
||||||
|
// uint32_t size = sizeof(OLED_HandleTypeDef);
|
||||||
|
// printf("size in B: %u\n", size);
|
||||||
|
display = (OLED_HandleTypeDef*)malloc(sizeof(OLED_HandleTypeDef));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tearDown(void)
|
void tearDown(void)
|
||||||
{
|
{
|
||||||
|
free(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_one(void)
|
void test_configWithCorecctArgs(void)
|
||||||
{
|
{
|
||||||
TEST_FAIL();
|
HAL_StatusTypeDef status = oled_Config(display, 0x0F, 128, 64, SH1106);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL(status, HAL_OK);
|
||||||
|
TEST_ASSERT_NULL(display->hi2c);
|
||||||
|
TEST_ASSERT_EQUAL(display->OledType, SH1106);
|
||||||
|
TEST_ASSERT_EQUAL_HEX8(display->DevAddress, 0x0F);
|
||||||
|
TEST_ASSERT_EQUAL(display->Width, 128);
|
||||||
|
TEST_ASSERT_EQUAL(display->Height, 64);
|
||||||
|
TEST_ASSERT_EQUAL(display->BufSize, 128*64/8);
|
||||||
|
TEST_ASSERT_NOT_NULL(display->Buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_configWithoutPointerToDisplay(void)
|
||||||
|
{
|
||||||
|
HAL_StatusTypeDef status = oled_Config(NULL, 0x0F, 128, 64, SH1106);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL(status, HAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -20,7 +43,8 @@ void test_one(void)
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
UNITY_BEGIN();
|
UNITY_BEGIN();
|
||||||
RUN_TEST(test_one);
|
RUN_TEST(test_configWithCorecctArgs);
|
||||||
|
RUN_TEST(test_configWithoutPointerToDisplay);
|
||||||
|
|
||||||
return UNITY_END();
|
return UNITY_END();
|
||||||
}
|
}
|
||||||
6643
utility/fff/fff.h
Normal file
6643
utility/fff/fff.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user