Start implementing proper parser state machine
This commit is contained in:
59
src/parser.c
59
src/parser.c
@@ -2,18 +2,51 @@
|
|||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
// # Supported Commands
|
/*
|
||||||
// (Optional decimal point for numbers)
|
* # Supported Commands
|
||||||
// - START
|
* (Optional decimal point for numbers)
|
||||||
// - RESET
|
*
|
||||||
// - STOP
|
* - RUN
|
||||||
// - SET TEMP 20
|
* - STOP
|
||||||
// - SET DEWP 60.0
|
* - TEMP 20
|
||||||
|
* - DEWP 60.0
|
||||||
|
*/
|
||||||
|
|
||||||
static int state;
|
static int state;
|
||||||
|
|
||||||
|
#define PARSE_IDLE 0
|
||||||
|
#define PARSE_CMD_RUN 1
|
||||||
|
#define PARSE_CMD_STOP 2
|
||||||
|
#define PARSE_CMD_SET_TEMP 3
|
||||||
|
#define PARSE_CMD_SET_DEWP 4
|
||||||
|
|
||||||
void CMD_Parse(char ch)
|
void CMD_Parse(char ch)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
|
switch (state) {
|
||||||
|
case PARSE_IDLE:
|
||||||
|
if (ch == 'R')
|
||||||
|
state = PARSE_CMD_RUN;
|
||||||
|
else if (ch == 'S')
|
||||||
|
state = PARSE_CMD_STOP;
|
||||||
|
else if (ch == 'T')
|
||||||
|
state = PARSE_CMD_SET_TEMP;
|
||||||
|
else if (ch == 'D')
|
||||||
|
state = PARSE_CMD_SET_DEWP;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PARSE_CMD_RUN:
|
||||||
|
break;
|
||||||
|
case PARSE_CMD_STOP:
|
||||||
|
break;
|
||||||
|
case PARSE_CMD_SET_TEMP:
|
||||||
|
break;
|
||||||
|
case PARSE_CMD_SET_DEWP:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Placeholder
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case 0:
|
case 0:
|
||||||
if (ch == 't')
|
if (ch == 't')
|
||||||
@@ -24,21 +57,25 @@ void CMD_Parse(char ch)
|
|||||||
state = 2;
|
state = 2;
|
||||||
else
|
else
|
||||||
state = 0;
|
state = 0;
|
||||||
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (ch == 's')
|
if (ch == 's')
|
||||||
state = 3;
|
state = 3;
|
||||||
else
|
else
|
||||||
state = 0;
|
state = 0;
|
||||||
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
if (ch == 't')
|
if (ch == 't')
|
||||||
state = 4;
|
state = 4;
|
||||||
else
|
else
|
||||||
state = 0;
|
state = 0;
|
||||||
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
if (ch == '\n') {
|
if (ch == '\n') {
|
||||||
USART_Printf("[CORE] Parsed 'test'!\r\n");
|
// XXX: Just so the web server can show something...
|
||||||
state = 0;
|
USART_Printf("[CORE] Parsed 'CMD_SET_TEMP' token.\r\n");
|
||||||
} else
|
USART_Printf("[CORE] Parsed 'CMD_SET_DEWP' token.\r\n");
|
||||||
state = 0;
|
}
|
||||||
|
state = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user