Description
I was asked to add a help mechanism to list all currently supported scpi commands. Hopefully I haven't overlooked another implementation somewhere. I'd love to hear your thoughts on the approach described below. I feel it's a trade-off between conformity and readability.
Here's what the user sees in a PuTTY session:
The implementation is rather straight-forward:
static scpi_result_t My_HelpQ(scpi_t * context) {
int i = 0;
for(;;){
SCPI_ResultCharacters(context, "\r\n", 2);
SCPI_ResultMnemonic(context, scpi_commands[i].pattern);
if(scpi_commands[++i].pattern == NULL){
break;
}
}
return SCPI_RES_OK;
}
const scpi_command_t scpi_commands[] = {
{.pattern = "HELP", .callback = My_HelpQ,},
{.pattern = "HELP?", .callback = My_HelpQ,},
// ...
Now I would expect the pattern strings would need to be returned in quotes, but then again it's most likely a human operator that opened the connection exclusively, so one would in turn even want to do away with the comma separation.
Going one step further even, one might be tempted to add short description strings where commands are not completely clear to the new user, and print them next to the listed commands.
_scpi_command_t
would need to be changed to
struct _scpi_command_t {
const char * pattern;
scpi_command_callback_t callback;
#if USE_COMMAND_TAGS
int32_t tag;
#endif
#if USE_COMMAND_DESCRIPTIONS
const char * description;
#endif
};