I was very pleased recently to discover the Command Interpreter in Demo/Common/Utils. One often has to add some sort of command interface to products and having a standard framework to build from is a big time saver. I like the architecture of this one; it seems well thought-out.
Having used it I have a couple of suggestions and comments:
First, the semantics of the return value of xCmdIntProcessCommand surprised me. I was expecting the value to indicate “I did something” or “I did nothing”, so one would use it thus:
while (xCmdIntProcessCommand(line, buf, size)) {
printf(pcCmdIntGetOutputBuffer());
}
Instead, the return value indicates whether there is anything further to do, hence:
do {
more = xCmdIntProcessCommand(line, buf, size);
printf(pcCmdIntGetOutputBuffer());
} while (more);
which seems less elegant.
Second, the pcCmdIntGetParameter() function is handy but I was surprised to see that when requesting parameter N I actually get a string that extends from the beginning of the Nth parameter all the way to the end of the line. I see that the pxParameterStringLength will tell me how many characters actually constitute the parameter. Interpreters I have used previously have had the tokeniser replace the delimiting characters in the command string with nulls, cutting the string in to chunks, so that when later fetching a particular parameter one gets a sub-string containing just that particular parameter. That seems a little more convenient.
Lastly, and somewhat trivially, the long, mixed-case filename CommandInterpreter.c does not really match the style of the other FreeRTOS filenames. Can I suggest cmdint.c (since CmdInt seems to be used as the “module prefix” for functions)?
Anyway, overall I’m very happy. Thanks for making this available.