2020-11-16 10:16:34 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-01-13 21:23:34 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-11-16 10:16:34 +00:00
|
|
|
#include <m-string.h>
|
|
|
|
|
2021-07-09 02:16:54 +00:00
|
|
|
typedef enum {
|
|
|
|
CliSymbolAsciiSOH = 0x01,
|
|
|
|
CliSymbolAsciiETX = 0x03,
|
|
|
|
CliSymbolAsciiEOT = 0x04,
|
|
|
|
CliSymbolAsciiBell = 0x07,
|
|
|
|
CliSymbolAsciiBackspace = 0x08,
|
|
|
|
CliSymbolAsciiTab = 0x09,
|
|
|
|
CliSymbolAsciiCR = 0x0D,
|
|
|
|
CliSymbolAsciiEsc = 0x1B,
|
|
|
|
CliSymbolAsciiUS = 0x1F,
|
|
|
|
CliSymbolAsciiSpace = 0x20,
|
|
|
|
CliSymbolAsciiDel = 0x7F,
|
|
|
|
} CliSymbols;
|
|
|
|
|
2021-07-18 18:09:00 +00:00
|
|
|
typedef enum {
|
|
|
|
CliCommandFlagDefault = 0, /** Default, loader lock is used */
|
|
|
|
CliCommandFlagParallelSafe =
|
|
|
|
(1 << 0), /** Safe to run in parallel with other apps, loader lock is not used */
|
|
|
|
} CliCommandFlag;
|
|
|
|
|
2020-11-16 10:16:34 +00:00
|
|
|
/* Cli type
|
|
|
|
* Anonymous structure. Use cli_i.h if you need to go deeper.
|
|
|
|
*/
|
|
|
|
typedef struct Cli Cli;
|
|
|
|
|
|
|
|
/* Cli callback function pointer.
|
|
|
|
* Implement this interface and use add_cli_command
|
|
|
|
* @param args - string with what was passed after command
|
|
|
|
* @param context - pointer to whatever you gave us on cli_add_command
|
|
|
|
*/
|
2021-05-18 13:57:39 +00:00
|
|
|
typedef void (*CliCallback)(Cli* cli, string_t args, void* context);
|
2020-11-16 10:16:34 +00:00
|
|
|
|
|
|
|
/* Add cli command
|
|
|
|
* Registers you command callback
|
|
|
|
* @param cli - pointer to cli instance
|
|
|
|
* @param name - command name
|
|
|
|
* @param callback - callback function
|
|
|
|
* @param context - pointer to whatever we need to pass to callback
|
|
|
|
*/
|
2021-07-18 18:09:00 +00:00
|
|
|
void cli_add_command(
|
|
|
|
Cli* cli,
|
|
|
|
const char* name,
|
|
|
|
CliCommandFlag flags,
|
|
|
|
CliCallback callback,
|
|
|
|
void* context);
|
2020-11-16 10:16:34 +00:00
|
|
|
|
2021-05-24 14:50:28 +00:00
|
|
|
/* Print unified cmd usage tip
|
|
|
|
* @param cmd - cmd name
|
|
|
|
* @param usage - usage tip
|
|
|
|
* @param arg - arg passed by user
|
|
|
|
*/
|
|
|
|
|
|
|
|
void cli_print_usage(const char* cmd, const char* usage, const char* arg);
|
|
|
|
|
2021-04-14 14:24:33 +00:00
|
|
|
/* Delete cli command
|
|
|
|
* @param cli - pointer to cli instance
|
|
|
|
* @param name - command name
|
|
|
|
*/
|
|
|
|
void cli_delete_command(Cli* cli, const char* name);
|
|
|
|
|
2021-02-13 11:40:20 +00:00
|
|
|
/* Read from terminal
|
|
|
|
* Do it only from inside of cli call.
|
|
|
|
* @param cli - Cli instance
|
|
|
|
* @param buffer - pointer to buffer
|
2020-11-16 10:16:34 +00:00
|
|
|
* @param size - size of buffer in bytes
|
2021-02-13 11:40:20 +00:00
|
|
|
* @return bytes written
|
2020-11-16 10:16:34 +00:00
|
|
|
*/
|
2021-02-13 11:40:20 +00:00
|
|
|
size_t cli_read(Cli* cli, uint8_t* buffer, size_t size);
|
|
|
|
|
2021-04-19 16:36:45 +00:00
|
|
|
/* Not blocking check for interrupt command received
|
|
|
|
* @param cli - Cli instance
|
|
|
|
*/
|
|
|
|
bool cli_cmd_interrupt_received(Cli* cli);
|
|
|
|
|
2021-02-13 11:40:20 +00:00
|
|
|
/* Write to terminal
|
|
|
|
* Do it only from inside of cli call.
|
|
|
|
* @param cli - Cli instance
|
|
|
|
* @param buffer - pointer to buffer
|
|
|
|
* @param size - size of buffer in bytes
|
|
|
|
* @return bytes written
|
|
|
|
*/
|
|
|
|
void cli_write(Cli* cli, uint8_t* buffer, size_t size);
|
|
|
|
|
|
|
|
/* Read character
|
|
|
|
* @param cli - Cli instance
|
|
|
|
* @return char
|
|
|
|
*/
|
|
|
|
char cli_getc(Cli* cli);
|
2020-11-16 10:16:34 +00:00
|
|
|
|
|
|
|
/* New line
|
|
|
|
* Send new ine sequence
|
|
|
|
*/
|
|
|
|
void cli_nl();
|
2021-01-13 21:23:34 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|