2015-09-28 22:49:14 +08:00
|
|
|
/* shell.h - Shell header */
|
2015-04-28 16:37:33 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation
|
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2015-04-28 16:37:33 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-04-28 16:37:33 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2015-04-28 16:37:33 +08:00
|
|
|
*/
|
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-07-06 18:22:48 +08:00
|
|
|
/** @brief Callback called when command is entered.
|
2015-06-17 21:34:18 +08:00
|
|
|
*
|
|
|
|
* @param argc Number of parameters passed.
|
|
|
|
* @param argv Array of option strings. First option is always command name.
|
2016-05-19 18:57:15 +08:00
|
|
|
*
|
|
|
|
* @return 0 in case of success or negative value in case of error.
|
2015-06-17 21:34:18 +08:00
|
|
|
*/
|
2016-05-19 18:57:15 +08:00
|
|
|
typedef int (*shell_cmd_function_t)(int argc, char *argv[]);
|
2015-04-28 16:37:33 +08:00
|
|
|
|
2015-08-28 17:24:13 +08:00
|
|
|
struct shell_cmd {
|
|
|
|
const char *cmd_name;
|
2015-11-05 21:03:24 +08:00
|
|
|
shell_cmd_function_t cb;
|
2016-05-17 19:33:00 +08:00
|
|
|
const char *help;
|
2015-08-28 17:24:13 +08:00
|
|
|
};
|
|
|
|
|
2015-07-06 18:22:48 +08:00
|
|
|
/** @brief Initialize shell with optional prompt, NULL in case no prompt is
|
2015-06-17 21:34:18 +08:00
|
|
|
* needed.
|
2015-04-28 16:37:33 +08:00
|
|
|
*
|
2015-06-17 21:34:18 +08:00
|
|
|
* @param prompt Prompt to be printed on serial console.
|
2015-08-28 17:24:13 +08:00
|
|
|
* @param cmds Commands to register
|
2015-04-28 16:37:33 +08:00
|
|
|
*/
|
2016-04-01 16:22:41 +08:00
|
|
|
void shell_init(const char *prompt, const struct shell_cmd *cmds);
|
2015-09-28 22:49:14 +08:00
|
|
|
|
|
|
|
/** @brief Optionally register an app default cmd handler.
|
|
|
|
*
|
|
|
|
* @param handler To be called if no cmd found in cmds registered with shell_init.
|
|
|
|
*/
|
2015-11-05 21:03:24 +08:00
|
|
|
void shell_register_app_cmd_handler(shell_cmd_function_t handler);
|
2015-09-28 22:49:14 +08:00
|
|
|
|
2015-12-04 19:10:36 +08:00
|
|
|
/** @brief Callback to get the current prompt.
|
|
|
|
*
|
|
|
|
* @returns Current prompt string.
|
|
|
|
*/
|
|
|
|
typedef const char *(*shell_prompt_function_t)(void);
|
|
|
|
|
|
|
|
/** @brief Optionally register a custom prompt callback.
|
|
|
|
*
|
|
|
|
* @param handler To be called to get the current prompt.
|
|
|
|
*/
|
|
|
|
void shell_register_prompt_handler(shell_prompt_function_t handler);
|
2016-01-23 01:38:49 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|