Hi
I am looking for a description on how to implement my own shell commands:
I have added my command to the SHELL_COMMAND_STRUCT. But now:
My MQX version is 3.8
Any advice?
Cheers NeraPhil
OK - that's what I found out so far:
int_32 my_command(int_32 argc, char_ptr argv[])
{
boolean print_usage = FALSE;
boolean shorthelp = FALSE;
int_32 return_code = MQX_OK;
print_usage = Shell_check_help_request(argc, argv, &shorthelp);
if (!print_usage) {
int_32 idx = 0;
for (idx = 0; idx < argc; idx++) {
printf("argv[%d] = %s\n", idx, argv[idx]);
}
// add here implementation of this command
printf("G3_debug has been called!\n");
} else if (print_usage) {
if (shorthelp) {
printf("%s <arg1> [<arg2>]\n", argv[0]);
} else {
printf("Usage: %s <arg1> [<arg2>]\n", argv[0]);
}
}
return return_code;
}
So I guess I found out myself how to use this function - nonetheless: If somebody could point me to some documentation, that could be of value for me.
Cheers
NeraPhil
hi NeraPhil,
Just as a recap, the structure with new command my_command and function to be invoked if this command is typed on the shell.
const SHELL_COMMAND_STRUCT Shell_commands[] = {
{"my_command", my_command_function},
{"exit", Shell_exit},
{"help", Shell_help},
{NULL, NULL}
}
Explanation how the shell is used in application:
print_usage purpose is to represent boolean value to print the help or to execute the command. If it's FALSE, then command was typed, otherwise (TRUE) help was requested.
If help is typed without any following argument , number of arguments argc = 1 and argv[0] is help command. Value TRUE is stored in shorthelp.
Help with more arguments (help my_command), shorthelp holds FALSE.
Check an example which is using shell like HVAC.
Regards,
MartinK