-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.h
50 lines (41 loc) · 1.8 KB
/
console.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Console is the generic interface to the command line.
// These functions should not need signficant modification, only
// to be called from the normal loop. Note that adding commands should
// be done in console commands.
#ifndef CONSOLE_H
#define CONSOLE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
// User configuration
//#define CONSOLE_PROMPT ("> ")
#define CONSOLE_PROMPT ("")
#define PARAMETER_SEPARATER (' ')
#define STR_ENDLINE "\r\n"
typedef enum {
COMMAND_SUCCESS = 0u,
COMMAND_PARAMETER_ERROR = 0x10u,
COMMAND_PARAMETER_END = 0x11u,
COMMAND_ERROR =0xFFu
} eCommandResult_T;
typedef void(*ConsoleHookFncPtr)(void);
// called from higher up areas of the code (main)
void ConsoleInit(bool echoEn, ConsoleHookFncPtr startHook, ConsoleHookFncPtr exitHook);
eCommandResult_T ConsoleExit(const char buffer[]);
void ConsoleProcess(void); // call this in a loop
// called from lower down areas of the code (consoleCommands)
// The in and output of the int16 parameter use C standard library functions
// atoi and itoa. These are nice functions, usually a lot smaller than scanf and printf
// but they can be memory hogs in their flexibility.
// The HexUint16 functions implement the parsing themselves, eschewing atoi and itoa.
eCommandResult_T ConsoleReceiveParamInt16(const char * buffer, const uint8_t parameterNumber, int16_t* parameterInt16);
eCommandResult_T ConsoleSendParamInt16(int16_t parameterInt);
eCommandResult_T ConsoleSendParamInt32(int32_t parameterInt);
eCommandResult_T ConsoleReceiveParamHexUint16(const char * buffer, const uint8_t parameterNumber, uint16_t* parameterUint16);
eCommandResult_T ConsoleSendParamHexUint16(uint16_t parameterUint16);
eCommandResult_T ConsoleSendParamHexUint8(uint8_t parameterUint8);
#ifdef __cplusplus
}
#endif
#endif // CONSOLE_H