Hello all, I'm trying to find an efficient way to take commands from a serial terminal in a project.. Currently, I have an mBed connected via usb using putty to terminal into it... I've been experimenting and have come up with the following code based on some stuff I was able to scrounge up on the web...
char string[128];
void recvCMD(void const *argument) {
while (true) {
if (pc.readable()) {
pc.scanf("%s", &string);
const char *options[]={
"led1",
"led2",
"led3",
"led4",
"led5",
0
};
long option=-1;
for (long a=0; options[a] && option<0; a++)
if (!strcmp(string,options[a])) {
option=a;
switch (option) {
case 0:
pc.printf("%s\n", string);
led1Var = !led1Var;
break;
case 1:
pc.printf("%s\n", string);
led2Var = !led2Var;
break;
case 2:
pc.printf("%s\n", string);
led3Var = !led3Var;
break;
case 3:
pc.printf("%s\n", string);
led4Var = !led4Var;
break;
case 4:
pc.printf("%s\n", string);
break;
default:
pc.printf("No Command: %s\n", string);
osDelay(1000);
break;
}
}
}
}
}
What I'd like to do, is something a little more structured.. Like accept a command such as "LED" and then use whatever follows it as a variable for that root command.... So later I can have something like a hierarchical list of commands...
Any help or word in a direction would be great!! Thanks!
Hello all, I'm trying to find an efficient way to take commands from a serial terminal in a project.. Currently, I have an mBed connected via usb using putty to terminal into it... I've been experimenting and have come up with the following code based on some stuff I was able to scrounge up on the web...
What I'd like to do, is something a little more structured.. Like accept a command such as "LED" and then use whatever follows it as a variable for that root command.... So later I can have something like a hierarchical list of commands...
Any help or word in a direction would be great!! Thanks!