osmo-sdr/firmware/include/uart_cmd.h @ master
1 | 41f8d833 | Harald Welte | /* (C) 2012 by Harald Welte <laforge@gnumonks.org>
|
---|---|---|---|
2 | *
|
||
3 | * All Rights Reserved
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or modify
|
||
6 | * it under the terms of the GNU General Public License as published by
|
||
7 | * the Free Software Foundation; either version 3 of the License, or
|
||
8 | * (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
17 | */
|
||
18 | |||
19 | #ifndef _UART_CMD_H
|
||
20 | #define _UART_CMD_H
|
||
21 | |||
22 | #include <stdint.h>
|
||
23 | #include <stdarg.h>
|
||
24 | #include <linuxlist.h>
|
||
25 | |||
26 | enum cmd_op { |
||
27 | CMD_OP_GET = (1 << 0), |
||
28 | CMD_OP_SET = (1 << 1), |
||
29 | CMD_OP_EXEC = (1 << 2), |
||
30 | };
|
||
31 | |||
32 | enum pstate { |
||
33 | ST_IN_CMD, |
||
34 | ST_IN_ARG, |
||
35 | };
|
||
36 | |||
37 | struct strbuf { |
||
38 | uint8_t idx; |
||
39 | c8ac8486 | Harald Welte | char buf[32]; |
40 | 41f8d833 | Harald Welte | };
|
41 | |||
42 | struct cmd_state { |
||
43 | struct strbuf cmd; |
||
44 | struct strbuf arg; |
||
45 | enum pstate state; |
||
46 | void (*out)(const char *format, va_list ap); |
||
47 | };
|
||
48 | |||
49 | int uart_cmd_out(struct cmd_state *cs, char *format, ...); |
||
50 | int uart_cmd_char(struct cmd_state *cs, uint8_t ch); |
||
51 | int uart_cmd_reset(struct cmd_state *cs); |
||
52 | |||
53 | struct cmd { |
||
54 | const char *cmd; |
||
55 | uint32_t ops; |
||
56 | 5a389db1 | Harald Welte | int (*cb)(struct cmd_state *cs, enum cmd_op op, const char *cmd, |
57 | int argc, char **argv); |
||
58 | 41f8d833 | Harald Welte | const char *help; |
59 | /* put list at the end for simpler initialization */
|
||
60 | struct llist_head list; |
||
61 | };
|
||
62 | |||
63 | void uart_cmd_register(struct cmd *c); |
||
64 | void uart_cmd_unregister(struct cmd *c); |
||
65 | void uart_cmds_register(struct cmd *c, unsigned int num); |
||
66 | |||
67 | |||
68 | #endif
|