I am attempting to write a command line interface for my embedded application (LM3S1439 based). I would like some advice on how to best approach it.
Some of my specifications would be:
-the CLI should communicate with any terminal emulator.
-the backspace key should work as intended
-other controls like arrow keys etc not necessary and should be ignored
-the enter key delimits the command entry
-command names vary in length
-command arguments vary in number
-multiple argument types (ex: cmr -p=4 -f=true -z=22.5)
-binary transfer mode (ymodem transfer?)
-new commands implemented with ease (subjective, I know, but the point is it should be extensible/flexible)
At the moment I have the UART receive interrupt grabbing chars from the input buffer examining them for a few control characters which I wish to observe (BS,CR,LF), as well as dumping chars I am not concerned about (other ASCII control chars) and stuffing the remaining chars into a command buffer. This all works quite well via several terminal emulators.
The idea was that once a CR or LF was detected the command buffer would be evaluated/compared against an array of structures which contained the name (string) of the command as well as a pointer to the appropriate function to be called. The function would be called and supplied the number of arguments and the pointer to the argument string.
I think that makes sense. Any suggestions on how best to structure this? This could get messy very quickly if not done right.
To further complicate issues I have the requirement to receive binary data. How do I best handle this transfer? I was thinking I could have a global flag that could be set as COMMAND or BINARY. If set as COMMAND then the incoming data would be processed as above. If not, then the data would be passed without interpretation to a buffer called out by the function requesting the binary transfer. Reasonable?
Regarding the deciphering of arguments. The functions atoi,atof, atol would really come in handy here ,but from what I have picked up in the recent months, including stdlib.h is not recommended in embedded apps? Comments?
Thanks!