chipKIT® Development Platform

Inspired by Arduino™

Parser Arduino

Created Fri, 19 Aug 2011 13:46:29 +0000 by andreibadilacg


andreibadilacg

Fri, 19 Aug 2011 13:46:29 +0000

I want to execute a comand from a String Exemple: String s="digitalRead(c);" I want to execute s It help me to read a comand from UART, to have full control.

Any ideea?

Thanks


KM6VV

Fri, 19 Aug 2011 17:42:56 +0000

Well, you don't need the entire command, just the "digitalRead" part. I'd make a table of strings in your program, then use string compare and go through the array and find your string. Use the index to call via an array of function pointers. Could just make a struct of the string and a function pointer, then an array of the struct type.

Alan KM6VV

I want to execute a comand from a String Exemple: String s="digitalRead(c);" I want to execute s It help me to read a comand from UART, to have full control. Any ideea? Thanks


andreibadilacg

Sat, 20 Aug 2011 09:29:47 +0000

Tank you very much


Mark

Mon, 22 Aug 2011 18:00:56 +0000

I want to execute a comand from a String Exemple: String s="digitalRead(c);" I want to execute s It help me to read a comand from UART, to have full control. Thanks

You cannot "execute" "s". That would imply that for any valid command that "s" could contain, execute it. That would mean writing a C interrupter. You can have a list of things you can do and have commands to do them. For example, "1" = digitalRead(c); "2" = digitialRead(d), etc, but you have to have them pre-defined.

Mark


rasmadrak

Mon, 22 Aug 2011 18:38:24 +0000

You could also do a similar thing that I'm doing in my pinball machine. I'm using serial commands between two MCU's. The master sends three bytes to the slave, for instance - 2,13,1. This would get interpreted as "digitalWrite ( 13, 1)". something like this:

buffer = get_from_command_or_serial;
for (a = 0; a < all bytes in buffer; )
{
   switch (a++)
{
   case 2:
       digitalWrite(a++,a++);
  break;
}

}

Of course, this is pseudo code and a very sloppy such. You really should do error checking if you allow any user to supply commands.

If you send "digitalWrite(13,HIGH)" to the Chipkit, simply scan for the command (this would be a rather slow process, depending on the number of commands to support) and grab the information to the left of the comma, and to right of the comma. Then call the original function with the gathered values.

This is a rather easy thing to do, but it will only be as supported as you make it. If it's for a interactive test-environment, I guess this would be fine. But to do a full sketch parser, that would probably be a waste of time. :)