Start implementing proper parser state machine

This commit is contained in:
2024-08-27 17:22:34 +02:00
parent df0f33e594
commit ce2af6682f

View File

@@ -2,18 +2,51 @@
#include "serial.h"
#include "parser.h"
// # Supported Commands
// (Optional decimal point for numbers)
// - START
// - RESET
// - STOP
// - SET TEMP 20
// - SET DEWP 60.0
/*
* # Supported Commands
* (Optional decimal point for numbers)
*
* - RUN
* - STOP
* - TEMP 20
* - DEWP 60.0
*/
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)
{
#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) {
case 0:
if (ch == 't')
@@ -24,21 +57,25 @@ void CMD_Parse(char ch)
state = 2;
else
state = 0;
break;
case 2:
if (ch == 's')
state = 3;
else
state = 0;
break;
case 3:
if (ch == 't')
state = 4;
else
state = 0;
break;
case 4:
if (ch == '\n') {
USART_Printf("[CORE] Parsed 'test'!\r\n");
state = 0;
} else
// XXX: Just so the web server can show something...
USART_Printf("[CORE] Parsed 'CMD_SET_TEMP' token.\r\n");
USART_Printf("[CORE] Parsed 'CMD_SET_DEWP' token.\r\n");
}
state = 0;
}
}