If you have several different prefixes, then you're stuck checking the 1st 3 bytes
pretty much like in your original example.
If you have several different prefixes, then you're stuck checking the 1st 3 bytes
pretty much like in your original example.
Thanks Bruce!
I'll continue to use IF - THENs. This is probably something that could be placed to "PBP Wish List" if it would be benefit also someone else.
BR,
-Gusse-
If you have PBP 2.60, you might do something like this ...Code:LED VAR PortB.0 CmdIdx VAR BYTE Data_Array VAR BYTE[4] CmdString VAR BYTE[3] ;--- Subroutine to parse commands ----------------------------- Parse: FOR CmdIdx = 0 to 3 SELECT CASE CmdIdx CASE 0 : ARRAYWRITE CmdString,["ABC"] CASE 1 : ARRAYWRITE CmdString,["DEF"] CASE 2 : ARRAYWRITE CmdString,["GHI"] CASE 3 : ARRAYWRITE CmdString,["JKL"] END SELECT ARRAYREAD Data_Array,3,NoCmd,[WAITSTR CmdString\3] ON CmdIdx GOTO cmd_ABC, cmd_DEF, cmd_GHI, cmd_JKL ; found cmd NoCmd: NEXT CmdIdx ; if it gets here no commands were found RETURN cmd_ABC: SELECT CASE Data_Array[3] CASE "1" HIGH LED 'If received ABC1 PAUSE 1000 'then turn LED on LOW LED 'for 1s and return CASE "2" HIGH LED 'If received ABC2 PAUSE 2000 'then turn LED on LOW LED 'for 2s and return END SELECT RETURN cmd_DEF: RETURN cmd_GHI: RETURN cmd_JKL: RETURN
DT
Hi Darrel,
At the moment I don't have PBP2.60, still working with 2.50c.
I was wondering what is benefit to upgrade to 2.60, but now I see it clearly![]()
This parse script is something new and ARRAYREAD -function is great.
So in Mainloop, after DEBUGIN, I should call parse? Sounds so easy!
PBP 2.60 will definitely be on my "Wish List".Code:<code><font color="#000000">Mainloop: <b>DEBUGIN </b>1000, Mainloop, [<b>STR </b>Data_Array\4] <b>GOSUB </b>Parse <b>GOTO </b>Mainloop <b>END </b></code>
BR,
-Gusse-
Last edited by Gusse; - 22nd January 2010 at 23:56.
Darrel,
Perfect!
I was just in the process of writing my own routines to do the same thing.
I was comparing element 1 in an array with every element in the second array, then element 2 in the first array against every element in the second. If I found a match, I would increment the pointers to both arrays and compare again.
What a mess that was!
Of course, your routine is better/faster/smaller.
Thanks!
Charles Linquist
You got it! And hopefully it is...Originally Posted by Gusse
I was working on a NMEA sentence parser, and Gusse's problem seemed to fit right in.Originally Posted by Charles Linquist
I may have killed 3 birds with one stone
Hope it works,
Last edited by Darrel Taylor; - 23rd January 2010 at 05:20. Reason: Added original intent.
DT
Bookmarks