52 lines
1.1 KiB
C++
52 lines
1.1 KiB
C++
#include "dagon.h"
|
|
|
|
static struct libscomp_input in;
|
|
static struct libscomp_cmd cmdarr[] = {
|
|
{"CON", dagon_con},
|
|
{"IDN", dagon_idn},
|
|
{"RMP", dagon_rmp},
|
|
{"RST", dagon_rst},
|
|
{"SET", dagon_set},
|
|
{"VLT", dagon_vlt}
|
|
};
|
|
|
|
static struct libscomp_cmd_store store = {
|
|
cmdarr, sizeof cmdarr / sizeof cmdarr[0]
|
|
};
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
while (!Serial);
|
|
spi_init();
|
|
libscomp_reset(&in);
|
|
Serial.setTimeout(10);
|
|
}
|
|
|
|
void loop() {
|
|
static char buf[4096];
|
|
|
|
struct libscomp_line l;
|
|
char *p = buf;
|
|
enum libscomp_input_r r;
|
|
|
|
size_t vl = Serial.readBytes(buf, sizeof buf - 1);
|
|
buf[vl] = 0;
|
|
|
|
do {
|
|
r = libscomp_read(&in, &p, &l);
|
|
switch (r) {
|
|
case LIBSCOMP_OVERFLOW:
|
|
serial_printf("ERROR\toverflow\n");
|
|
break;
|
|
case LIBSCOMP_ARG_OVERFLOW:
|
|
serial_printf("ERROR\targument overflow\n");
|
|
break;
|
|
case LIBSCOMP_COMPLETE:
|
|
if (libscomp_exec(&store, &l, nullptr) == LIBSCOMP_NOT_FOUND)
|
|
print_start(&l, "ERROR\tno known command\n");
|
|
break;
|
|
// LIBSCOMP_MORE left out
|
|
}
|
|
} while (r != LIBSCOMP_MORE);
|
|
}
|