Move parser to separate module and add USART_IsDataAvailable
This commit is contained in:
44
src/parser.c
Normal file
44
src/parser.c
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "common.h"
|
||||
#include "serial.h"
|
||||
#include "parser.h"
|
||||
|
||||
// # Supported Commands
|
||||
// (Optional decimal point for numbers)
|
||||
// - START
|
||||
// - RESET
|
||||
// - STOP
|
||||
// - SET TEMP 20
|
||||
// - SET DEWP 60.0
|
||||
|
||||
static int state;
|
||||
|
||||
void CMD_Parse(char ch)
|
||||
{
|
||||
switch (state) {
|
||||
case 0:
|
||||
if (ch == 't')
|
||||
state = 1;
|
||||
break;
|
||||
case 1:
|
||||
if (ch == 'e')
|
||||
state = 2;
|
||||
else
|
||||
state = 0;
|
||||
case 2:
|
||||
if (ch == 's')
|
||||
state = 3;
|
||||
else
|
||||
state = 0;
|
||||
case 3:
|
||||
if (ch == 't')
|
||||
state = 4;
|
||||
else
|
||||
state = 0;
|
||||
case 4:
|
||||
if (ch == '\n') {
|
||||
USART_Printf("[CORE] Parsed 'test'!\r\n");
|
||||
state = 0;
|
||||
} else
|
||||
state = 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user