-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.h
88 lines (76 loc) · 2.72 KB
/
cli.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
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
/*****************************************************************************
* cli.h
*
* Serial CLI remote/sub-human interface
*
* NOTE: If you have compilation errors related to the absence of '.tokens.h',
* '.clierrs.h' or '.banner_wide.h' includes, run the 'gen_code.sh'
* script.
*
* ---------------------------------------------------------------------------
* ardccino - Arduino dual PWM/DCC controller
* (C) 2013-2015 Gerardo García Peña <killabytenow@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef __CLI_H__
#define __CLI_H__
#include "config.h"
#ifdef CLI_ENABLED
class Cli {
private:
char input[255];
int input_len;
int input_pos;
bool input_reading;
int curr_booster;
// command actions
void _print_text(char **text, int l);
void about(void);
void help(void);
void booster_list(void);
void booster_status(Booster *b);
// output
void _msg(const char *prefix, const char *frmt, va_list args);
// read input
void input_add(char c);
void input_del(void);
void input_reset(void);
// parsing and execution
bool parse_unsigned(char *token, uint16_t *ui);
bool parse_signed(char *token, int16_t *si);
int parse_token(char *token);
int parse_token(char *token, uint16_t *ui);
int parse_token(char *token, int16_t *si);
int execute_booster(char **token, char ntokens);
int execute_dcc(char **token, char ntokens);
int execute_dcc_cmd(char **token, char ntokens);
int execute_dcc_cmd_speed(char **token, char ntokens, bool service_track, uint16_t address);
int execute_dcc_cmd_light(char **token, char ntokens, bool service_track, uint16_t address);
int execute(char **token, char ntokens);
void parse(char *buffer);
public:
Cli(void);
void init(void);
void input_read(void);
void fatal(const char *frmt, ...);
void debug(const char *frmt, ...);
void info(const char *frmt, ...);
void notice(const char *frmt, ...);
void error(const char *frmt, ...);
};
#endif
#endif