2020-11-16 13:16:34 +03:00
|
|
|
#pragma once
|
|
|
|
|
2021-01-14 00:23:34 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-11-16 13:16:34 +03:00
|
|
|
#include <m-string.h>
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
typedef void (*CliCallback)(string_t args, void* context);
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
void cli_add_command(Cli* cli, const char* name, CliCallback callback, void* context);
|
|
|
|
|
2021-04-14 17:24:33 +03: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 14:40:20 +03:00
|
|
|
/* Read from terminal
|
|
|
|
* Do it only from inside of cli call.
|
|
|
|
* @param cli - Cli instance
|
|
|
|
* @param buffer - pointer to buffer
|
2020-11-16 13:16:34 +03:00
|
|
|
* @param size - size of buffer in bytes
|
2021-02-13 14:40:20 +03:00
|
|
|
* @return bytes written
|
2020-11-16 13:16:34 +03:00
|
|
|
*/
|
2021-02-13 14:40:20 +03:00
|
|
|
size_t cli_read(Cli* cli, uint8_t* buffer, size_t size);
|
|
|
|
|
|
|
|
/* 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 13:16:34 +03:00
|
|
|
|
|
|
|
/* New line
|
|
|
|
* Send new ine sequence
|
|
|
|
*/
|
|
|
|
void cli_nl();
|
2021-01-14 00:23:34 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|