Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cli.h « cli « applications - github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1f1b61a2446f7c481de223b5fc088c58ab7fa057 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
 * @file cli.h
 * Cli API
 */

#pragma once

#include <m-string.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
    CliSymbolAsciiSOH = 0x01,
    CliSymbolAsciiETX = 0x03,
    CliSymbolAsciiEOT = 0x04,
    CliSymbolAsciiBell = 0x07,
    CliSymbolAsciiBackspace = 0x08,
    CliSymbolAsciiTab = 0x09,
    CliSymbolAsciiLF = 0x0A,
    CliSymbolAsciiCR = 0x0D,
    CliSymbolAsciiEsc = 0x1B,
    CliSymbolAsciiUS = 0x1F,
    CliSymbolAsciiSpace = 0x20,
    CliSymbolAsciiDel = 0x7F,
} CliSymbols;

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 */
    CliCommandFlagInsomniaSafe = (1 << 1), /**< Safe to run with insomnia mode on */
} CliCommandFlag;

/** Cli type anonymous structure */
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)(Cli* cli, string_t args, void* context);

/** 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
 */
void cli_add_command(
    Cli* cli,
    const char* name,
    CliCommandFlag flags,
    CliCallback callback,
    void* context);

/** 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);

/** Delete cli command
 *
 * @param      cli   pointer to cli instance
 * @param      name  command name
 */
void cli_delete_command(Cli* cli, const char* name);

/** Read from 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
 */
size_t cli_read(Cli* cli, uint8_t* buffer, size_t size);

/** Not blocking check for interrupt command received
 *
 * @param      cli   Cli instance
 *
 * @return     true if received
 */
bool cli_cmd_interrupt_received(Cli* cli);

/** 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
 */
void cli_write(Cli* cli, const uint8_t* buffer, size_t size);

/** Read character
 *
 * @param      cli   Cli instance
 *
 * @return     char
 */
char cli_getc(Cli* cli);

/** New line Send new ine sequence
 */
void cli_nl();

#ifdef __cplusplus
}
#endif