-
Notifications
You must be signed in to change notification settings - Fork 16
/
Shell.ino
102 lines (86 loc) · 2.41 KB
/
Shell.ino
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
/*
* sakura.io shell example
*
* For detailed command information please see the datasheet.
* https://sakura.io/developer/pdf/sakura_module_datasheet_latest.pdf
*/
#include <SakuraIO.h>
#include "ntshell.h"
#include "commands.h"
static int func_read(char *buf, int cnt, void *extobj);
static int func_write(const char *buf, int cnt, void *extobj);
static int func_callback(const char *text, void *extobj);
static int ntopt_callback(int argc, char **argv, void *extobj);
static void ntshell_poll(ntshell_t *p);
ntshell_t ntshell;
cmd_list_t cmd_list[] = {
{(char*)"version", cmd_version},
{(char*)"serial", cmd_serial},
{(char*)"status", cmd_status},
{(char*)"sqi", cmd_sqi},
{(char*)"unixtime", cmd_unixtime},
{(char*)"update", cmd_update},
{(char*)"reset", cmd_reset},
{(char*)"enqueue", cmd_enqueue},
{(char*)"sendnow", cmd_sendnow},
{(char*)"send", cmd_send},
{(char*)"size", cmd_size},
{(char*)"cleartx", cmd_cleartx},
{(char*)"dequeue", cmd_dequeue},
{(char*)"peek", cmd_peek},
{(char*)"clearrx", cmd_clearrx},
{(char*)"file", cmd_file},
{NULL, NULL}
};
//SakuraIO_SPI sakuraio(10);
SakuraIO_I2C sakuraio;
void setup() {
Serial.begin(9600);
Serial.println("Hello");
Serial.print(">");
ntshell_init(&ntshell, func_read, func_write, func_callback, (void *)&ntshell);
ntshell_set_prompt(&ntshell, ">");
}
void loop() {
ntshell_poll(&ntshell);
}
/* NT-Shell */
static int func_read(char *buf, int cnt, void *extobj) {
if (Serial.available())
return Serial.readBytes(buf, cnt);
else
return 0;
}
static int func_write(const char *buf, int cnt, void *extobj) {
return Serial.write(buf, cnt);
}
static int func_callback(const char *text, void *extobj) {
return ntopt_parse((const char *)text, ntopt_callback, extobj);
}
static int ntopt_callback(int argc, char **argv, void *extobj){
if (argc == 0) {
return 0;
}
int execnt = 0;
const cmd_list_t *p = cmd_list;
while (p->command != NULL) {
if (ntlibc_strcmp((const char *)argv[0], p->command) == 0) {
p->func(argc, argv);
execnt++;
}
p++;
}
if (execnt == 0) {
Serial.println("unknown command");
}
return 0;
}
static void ntshell_poll(ntshell_t *p)
{
if (p->initcode != INITCODE) {
return;
}
unsigned char ch;
if(SERIAL_READ(p, (char *)&ch, sizeof(ch)) > 0)
vtrecv_execute(&(p->vtrecv), &ch, sizeof(ch));
}