Fix parser tail pointer semantics and add further TODO
This commit is contained in:
@@ -3,16 +3,16 @@
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
#define CMD_MAX_LEN 128
|
||||
|
||||
// TODO: Write documentation.
|
||||
// TODO: Implement start and stop commands.
|
||||
// TODO: Reset command buffer on timeout.
|
||||
// TODO: Test with different RXBUF sizes.
|
||||
// TODO: Add commands update, start and stop.
|
||||
|
||||
static char cmdbuf[CMD_MAX_LEN + 1];
|
||||
static char *tail = cmdbuf + CMD_MAX_LEN - 1;
|
||||
static char *tail = cmdbuf + CMD_MAX_LEN;
|
||||
static char *head = cmdbuf;
|
||||
|
||||
static bool ParseLine(cmd_t *out);
|
||||
@@ -29,13 +29,13 @@ bool CMD_Parse(char ch, cmd_t *out)
|
||||
|
||||
if (ch == '\n' || ch == '\r') {
|
||||
is_valid = ParseLine(out);
|
||||
tail = cmdbuf + CMD_MAX_LEN - 1;
|
||||
tail = cmdbuf + CMD_MAX_LEN;
|
||||
head = cmdbuf;
|
||||
|
||||
return is_valid;
|
||||
}
|
||||
|
||||
if (head < tail) {
|
||||
if (head < tail - 1) {
|
||||
*head++ = ch;
|
||||
*head = '\0';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user