2021-10-03 13:36:05 +03:00
|
|
|
/**
|
|
|
|
|
* @file cli.h
|
|
|
|
|
* Cli API
|
|
|
|
|
*/
|
|
|
|
|
|
2020-11-16 13:16:34 +03:00
|
|
|
#pragma once
|
2022-10-06 01:15:23 +10:00
|
|
|
#include <furi.h>
|
2021-10-03 13:36:05 +03:00
|
|
|
|
2021-01-14 07:23:34 +10:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-07-18 21:09:00 +03:00
|
|
|
typedef enum {
|
2021-10-03 13:36:05 +03:00
|
|
|
CliCommandFlagDefault = 0, /**< Default, loader lock is used */
|
2021-07-18 21:09:00 +03:00
|
|
|
CliCommandFlagParallelSafe =
|
2021-10-03 13:36:05 +03:00
|
|
|
(1 << 0), /**< Safe to run in parallel with other apps, loader lock is not used */
|
|
|
|
|
CliCommandFlagInsomniaSafe = (1 << 1), /**< Safe to run with insomnia mode on */
|
2024-10-14 17:50:18 +03:00
|
|
|
CliCommandFlagHidden = (1 << 2), /**< Not shown in `help` */
|
2021-07-18 21:09:00 +03:00
|
|
|
} CliCommandFlag;
|
|
|
|
|
|
2022-07-26 15:21:51 +03:00
|
|
|
#define RECORD_CLI "cli"
|
|
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Cli type anonymous structure */
|
2020-11-16 13:16:34 +03:00
|
|
|
typedef struct Cli Cli;
|
|
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** 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
|
2020-11-16 13:16:34 +03:00
|
|
|
*/
|
2022-10-06 01:15:23 +10:00
|
|
|
typedef void (*CliCallback)(Cli* cli, FuriString* args, void* context);
|
2020-11-16 13:16:34 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Add cli command Registers you command callback
|
|
|
|
|
*
|
|
|
|
|
* @param cli pointer to cli instance
|
|
|
|
|
* @param name command name
|
|
|
|
|
* @param flags CliCommandFlag
|
|
|
|
|
* @param callback callback function
|
|
|
|
|
* @param context pointer to whatever we need to pass to callback
|
2020-11-16 13:16:34 +03:00
|
|
|
*/
|
2021-07-18 21:09:00 +03:00
|
|
|
void cli_add_command(
|
|
|
|
|
Cli* cli,
|
|
|
|
|
const char* name,
|
|
|
|
|
CliCommandFlag flags,
|
|
|
|
|
CliCallback callback,
|
|
|
|
|
void* context);
|
2020-11-16 13:16:34 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Print unified cmd usage tip
|
|
|
|
|
*
|
|
|
|
|
* @param cmd cmd name
|
|
|
|
|
* @param usage usage tip
|
|
|
|
|
* @param arg arg passed by user
|
2021-05-24 17:50:28 +03:00
|
|
|
*/
|
|
|
|
|
void cli_print_usage(const char* cmd, const char* usage, const char* arg);
|
|
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Delete cli command
|
|
|
|
|
*
|
|
|
|
|
* @param cli pointer to cli instance
|
|
|
|
|
* @param name command name
|
2021-04-14 17:24:33 +03:00
|
|
|
*/
|
|
|
|
|
void cli_delete_command(Cli* cli, const char* name);
|
|
|
|
|
|
2022-04-29 15:02:17 +03:00
|
|
|
/** Read from terminal
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
|
|
|
|
* @param cli Cli instance
|
|
|
|
|
* @param buffer pointer to buffer
|
|
|
|
|
* @param size size of buffer in bytes
|
|
|
|
|
*
|
2022-04-29 15:02:17 +03:00
|
|
|
* @return bytes read
|
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);
|
|
|
|
|
|
2022-04-29 15:02:17 +03:00
|
|
|
/** Non-blocking read from terminal
|
|
|
|
|
*
|
|
|
|
|
* @param cli Cli instance
|
|
|
|
|
* @param buffer pointer to buffer
|
|
|
|
|
* @param size size of buffer in bytes
|
|
|
|
|
* @param timeout timeout value in ms
|
|
|
|
|
*
|
|
|
|
|
* @return bytes read
|
|
|
|
|
*/
|
|
|
|
|
size_t cli_read_timeout(Cli* cli, uint8_t* buffer, size_t size, uint32_t timeout);
|
|
|
|
|
|
|
|
|
|
/** Non-blocking check for interrupt command received
|
2021-10-03 13:36:05 +03:00
|
|
|
*
|
|
|
|
|
* @param cli Cli instance
|
|
|
|
|
*
|
|
|
|
|
* @return true if received
|
2021-04-19 19:36:45 +03:00
|
|
|
*/
|
|
|
|
|
bool cli_cmd_interrupt_received(Cli* cli);
|
|
|
|
|
|
2021-10-03 13:36:05 +03: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
|
2021-02-13 14:40:20 +03:00
|
|
|
*/
|
2021-08-31 11:22:52 +03:00
|
|
|
void cli_write(Cli* cli, const uint8_t* buffer, size_t size);
|
2021-02-13 14:40:20 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** Read character
|
|
|
|
|
*
|
|
|
|
|
* @param cli Cli instance
|
|
|
|
|
*
|
|
|
|
|
* @return char
|
2021-02-13 14:40:20 +03:00
|
|
|
*/
|
|
|
|
|
char cli_getc(Cli* cli);
|
2020-11-16 13:16:34 +03:00
|
|
|
|
2021-10-03 13:36:05 +03:00
|
|
|
/** New line Send new ine sequence
|
2020-11-16 13:16:34 +03:00
|
|
|
*/
|
2024-03-19 23:43:52 +09:00
|
|
|
void cli_nl(Cli* cli);
|
2021-01-14 07:23:34 +10:00
|
|
|
|
2022-04-29 15:02:17 +03:00
|
|
|
void cli_session_open(Cli* cli, void* session);
|
|
|
|
|
|
|
|
|
|
void cli_session_close(Cli* cli);
|
|
|
|
|
|
|
|
|
|
bool cli_is_connected(Cli* cli);
|
|
|
|
|
|
2021-01-14 07:23:34 +10:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|