PDA

View Full Version : Parsing commands and parameters



Ioannis
- 21st May 2022, 22:49
The project involves an arithmetic keyboard (0-9,*,#) on a device that has a module that can be programmed with parameters.

In fact it is a portable transmitter with a module programmable with power level, frequency etc.

My PIC is the good ol' F886 and since it has 8K of flash I d'rather not spend it with if-then tests.

I would like to have an efficient way for the user to enter commands and parameters for example like this:

*10
responds with a beep
434925
responds with a beep

I know this can be done with lots of if-then or select case but maybe there is a better way.

Ioannis

richard
- 21st May 2022, 23:17
ask yourself

what is the biggest command sequence that will be input ?
how does the pic know when the input seq is complete ?

when you know those answers then the answer will be obvious

Ioannis
- 22nd May 2022, 12:16
The commands following the * will not be more than 99 so * and two digits for the commands.

The parameters are max 6.

Once Melanie had posted a similar example for rs232 communication but has its limits.

Ioannis

richard
- 22nd May 2022, 12:53
so a command is *99 or *9 or *09 [where 9 == a numeric digit]
and a parameter is 9 up to 999999

how do you signal that the command has been input and the parameter begins

i would be tempted to use the # as enter

so cmd 33 p2010 would be
*33#2100#
you will need to establish a method to cope with numbers bigger than a word

you need a method first then code it

Ioannis
- 22nd May 2022, 14:02
For a more compact and maybe easier to code the command and data be at defined length.

So command 9 would be 09 and data 9 (this is extreme but for the sake of discussion) would be 00009.

So there is no need for extra termination character.

Also I think word or long variable may not be helpful here. Better an array, since the data are distinct in meaning so a 433925 would mean 433,925MHz in reality as an absolute value.

The beeps would help user to step with confidence entering the commands and data.

I think stuffing an array and then select case is the way to do it.

Ioannis