refactor(shell): Improve shell command naming and output formatting
- Renamed shell commands in and to be shorter and remove underscores (e.g., to ). - Consolidated get functions into a single show command for both valve and Modbus settings (e.g., , ). - Adjusted output formatting for show commands to be right-aligned and remove horizontal lines for better readability. - Fixed missing getter function implementations in and their declarations in . - Ensured is correctly selected in to make valve shell commands available.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
config SHELL_MODBUS
|
||||
bool "Enable Shell Modbus"
|
||||
default y
|
||||
default n
|
||||
depends on SHELL
|
||||
depends on LIB_MODBUS_SERVER
|
||||
help
|
||||
Enable the modnbus shell commands.
|
||||
Enable the modbus shell commands.
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
#include <zephyr/shell/shell.h>
|
||||
#include <lib/modbus_server.h>
|
||||
#include <lib/valve.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
@@ -21,10 +20,10 @@
|
||||
* @param argv Argument values.
|
||||
* @return 0 on success, -EINVAL on error.
|
||||
*/
|
||||
static int cmd_modbus_set_baud(const struct shell *sh, size_t argc, char **argv)
|
||||
static int cmd_modbus_setb(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
shell_error(sh, "Usage: set_baud <baudrate>");
|
||||
shell_error(sh, "Usage: setb <baudrate>");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -70,10 +69,10 @@ static int cmd_modbus_set_baud(const struct shell *sh, size_t argc, char **argv)
|
||||
* @param argv Argument values.
|
||||
* @return 0 on success, -EINVAL on error.
|
||||
*/
|
||||
static int cmd_modbus_set_id(const struct shell *sh, size_t argc, char **argv)
|
||||
static int cmd_modbus_setid(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
shell_error(sh, "Usage: set_id <slave_id>");
|
||||
shell_error(sh, "Usage: setid <slave_id>");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -94,78 +93,27 @@ static int cmd_modbus_set_id(const struct shell *sh, size_t argc, char **argv)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shell command to set the valve's maximum opening time.
|
||||
*
|
||||
* @param sh The shell instance.
|
||||
* @param argc Argument count.
|
||||
* @param argv Argument values.
|
||||
* @return 0 on success, -EINVAL on error.
|
||||
*/
|
||||
static int cmd_valve_set_open_time(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
shell_error(sh, "Usage: set_open_time <seconds>");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
uint16_t seconds = (uint16_t)strtoul(argv[1], NULL, 10);
|
||||
valve_set_max_open_time(seconds);
|
||||
shell_print(sh, "Max opening time set to: %u seconds (and saved)", seconds);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shell command to set the valve's maximum closing time.
|
||||
*
|
||||
* @param sh The shell instance.
|
||||
* @param argc Argument count.
|
||||
* @param argv Argument values.
|
||||
* @return 0 on success, -EINVAL on error.
|
||||
*/
|
||||
static int cmd_valve_set_close_time(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
shell_error(sh, "Usage: set_close_time <seconds>");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
uint16_t seconds = (uint16_t)strtoul(argv[1], NULL, 10);
|
||||
valve_set_max_close_time(seconds);
|
||||
shell_print(sh, "Max closing time set to: %u seconds (and saved)", seconds);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Shell command to show the current configuration.
|
||||
* @brief Shell command to show the current Modbus configuration.
|
||||
*
|
||||
* @param sh The shell instance.
|
||||
* @param argc Argument count.
|
||||
* @param argv Argument values.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
static int cmd_config_show(const struct shell *sh, size_t argc, char **argv)
|
||||
static int cmd_modbus_show(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
shell_print(sh, "Current Modbus Configuration:");
|
||||
shell_print(sh, " Baudrate: %u", modbus_get_baudrate());
|
||||
shell_print(sh, " Slave ID: %u", modbus_get_unit_id());
|
||||
shell_print(sh, "Current Valve Configuration:");
|
||||
shell_print(sh, " Max Opening Time: %u s", valve_get_max_open_time());
|
||||
shell_print(sh, " Max Closing Time: %u s", valve_get_max_close_time());
|
||||
const int label_width = 15;
|
||||
|
||||
shell_print(sh, "Modbus Settings:");
|
||||
shell_print(sh, "%*s %u", label_width, "Baudrate:", modbus_get_baudrate());
|
||||
shell_print(sh, "%*s %u", label_width, "Slave ID:", modbus_get_unit_id());
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHELL_STATIC_SUBCMD_SET_CREATE(sub_modbus_cmds,
|
||||
SHELL_CMD(set_baud, NULL, "Set Modbus baudrate", cmd_modbus_set_baud),
|
||||
SHELL_CMD(set_id, NULL, "Set Modbus slave ID", cmd_modbus_set_id),
|
||||
SHELL_CMD(setb, NULL, "Set Modbus baudrate", cmd_modbus_setb),
|
||||
SHELL_CMD(setid, NULL, "Set Modbus slave ID", cmd_modbus_setid),
|
||||
SHELL_CMD(show, NULL, "Show Modbus configuration", cmd_modbus_show),
|
||||
SHELL_SUBCMD_SET_END);
|
||||
|
||||
SHELL_STATIC_SUBCMD_SET_CREATE(sub_valve_cmds,
|
||||
SHELL_CMD(set_open_time, NULL, "Set max valve opening time", cmd_valve_set_open_time),
|
||||
SHELL_CMD(set_close_time, NULL, "Set max valve closing time", cmd_valve_set_close_time),
|
||||
SHELL_SUBCMD_SET_END);
|
||||
|
||||
SHELL_CMD_REGISTER(modbus, &sub_modbus_cmds, "Modbus configuration", NULL);
|
||||
SHELL_CMD_REGISTER(valve, &sub_valve_cmds, "Valve configuration", NULL);
|
||||
SHELL_CMD_REGISTER(show_config, NULL, "Show all configurations", cmd_config_show);
|
||||
SHELL_CMD_REGISTER(modbus, &sub_modbus_cmds, "Modbus commands", NULL);
|
||||
Reference in New Issue
Block a user