/*
Forum: https://forum.arduino.cc/t/esp32-serial-kommunikation-mit-arduino-uno-grbl/1239346
Wokwi: https://wokwi.com/projects/393623376239161345
ec2021
*/
struct tokenStruct {
char name[8];
byte num;
};
const tokenStruct tokens[] = {
{"M2",0},
{"M7",0},
{"M8",0},
{"G0",2},
{"G1",2},
{"G21",0},
{"G90",0},
{"F1000",0},
};
const int noOfTokens = sizeof(tokens)/sizeof(tokens[0]);
void setup(){
Serial.begin(115200);
check("M1");
check("M2");
check("M21");
check("G0");
check("G012345");
check("F1000");
}
void loop(){
}
void check(char * line){
Serial.print(line);
if (isValid(line)) {
Serial.println(" is valid");
} else {
Serial.println(" is not valid");
}
}
boolean isValid(char * token){
for (int i = 0; i<noOfTokens;i++){
if (tokens[i].num == 0){
if (strcmp(token,tokens[i].name) == 0) {
return true;
}
} else {
if (strncmp(token,tokens[i].name, tokens[i].num) == 0) {
return true;
}
}
}
return false;
}