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:
parent
5fd904de9e
commit
a3e8d5c168
|
|
@ -1,2 +1,7 @@
|
|||
rsource "lib/Kconfig"
|
||||
rsource "lib/shell_valve/Kconfig"
|
||||
|
||||
config SLAVE_NODE_APP
|
||||
bool "Slave Node Application"
|
||||
default y
|
||||
select SHELL_VALVE
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ CONFIG_LOG=y
|
|||
# Enable Shell
|
||||
CONFIG_SHELL=y
|
||||
CONFIG_REBOOT=y
|
||||
CONFIG_SHELL_MODBUS=y
|
||||
CONFIG_SHELL_VALVE=y
|
||||
CONFIG_SHELL_SYSTEM=y
|
||||
|
||||
# Enable Settings Subsystem
|
||||
CONFIG_SETTINGS=y
|
||||
|
|
|
|||
|
|
@ -113,6 +113,20 @@ void valve_set_end_current_threshold_open(uint16_t current_ma);
|
|||
*/
|
||||
void valve_set_end_current_threshold_close(uint16_t current_ma);
|
||||
|
||||
/**
|
||||
* @brief Gets the current threshold for end-position detection during opening.
|
||||
*
|
||||
* @return The current threshold in milliamps.
|
||||
*/
|
||||
uint16_t valve_get_end_current_threshold_open(void);
|
||||
|
||||
/**
|
||||
* @brief Gets the current threshold for end-position detection during closing.
|
||||
*
|
||||
* @return The current threshold in milliamps.
|
||||
*/
|
||||
uint16_t valve_get_end_current_threshold_close(void);
|
||||
|
||||
/**
|
||||
* @brief Gets the configured maximum opening time.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -5,4 +5,5 @@ rsource "modbus_server/Kconfig"
|
|||
rsource "valve/Kconfig"
|
||||
rsource "shell_system/Kconfig"
|
||||
rsource "shell_modbus/Kconfig"
|
||||
rsource "shell_valve/Kconfig"
|
||||
endmenu
|
||||
|
|
@ -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);
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
config SHELL_SYSTEM
|
||||
bool "Enable Shell System"
|
||||
default y
|
||||
default n
|
||||
help
|
||||
Enable the system commands.
|
||||
|
|
@ -1 +1 @@
|
|||
zephyr_library()
|
||||
zephyr_library_sources(shell_valve.c)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
config SHELL_VALVE
|
||||
bool "Shell Valve commands"
|
||||
default y
|
||||
default n
|
||||
depends on SHELL
|
||||
depends on LIB_VALVE
|
||||
help
|
||||
Enable the shell commands for valve control.
|
||||
Enable the valve shell commands.
|
||||
|
|
@ -3,10 +3,10 @@
|
|||
#include <lib/valve.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int cmd_valve_set_max_open_time(const struct shell *sh, size_t argc, char **argv)
|
||||
static int cmd_valve_set_open_t(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
shell_print(sh, "Usage: valve set_max_open_time <seconds>");
|
||||
shell_print(sh, "Usage: valve set_open_t <seconds>");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
@ -16,17 +16,10 @@ static int cmd_valve_set_max_open_time(const struct shell *sh, size_t argc, char
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_valve_get_max_open_time(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
uint16_t seconds = valve_get_max_open_time();
|
||||
shell_print(sh, "Max open time: %u seconds.", seconds);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_valve_set_max_close_time(const struct shell *sh, size_t argc, char **argv)
|
||||
static int cmd_valve_set_close_t(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
shell_print(sh, "Usage: valve set_max_close_time <seconds>");
|
||||
shell_print(sh, "Usage: valve set_close_t <seconds>");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
@ -36,18 +29,10 @@ static int cmd_valve_set_max_close_time(const struct shell *sh, size_t argc, cha
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_valve_get_max_close_time(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
uint16_t seconds = valve_get_max_close_time();
|
||||
shell_print(sh, "Max close time: %u seconds.", seconds);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_valve_set_end_current_threshold_open(
|
||||
const struct shell *sh, size_t argc, char **argv)
|
||||
static int cmd_valve_set_end_curr_open(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
shell_print(sh, "Usage: valve set_end_current_threshold_open <milliamps>");
|
||||
shell_print(sh, "Usage: valve set_end_curr_open <milliamps>");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
@ -57,19 +42,10 @@ static int cmd_valve_set_end_current_threshold_open(
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_valve_get_end_current_threshold_open(
|
||||
const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
uint16_t current_ma = valve_get_end_current_threshold_open();
|
||||
shell_print(sh, "End current threshold (open): %u mA.", current_ma);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_valve_set_end_current_threshold_close(
|
||||
const struct shell *sh, size_t argc, char **argv)
|
||||
static int cmd_valve_set_end_curr_close(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
shell_print(sh, "Usage: valve set_end_current_threshold_close <milliamps>");
|
||||
shell_print(sh, "Usage: valve set_end_curr_close <milliamps>");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
@ -79,37 +55,38 @@ static int cmd_valve_set_end_current_threshold_close(
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_valve_get_end_current_threshold_close(
|
||||
const struct shell *sh, size_t argc, char **argv)
|
||||
static int cmd_valve_show(const struct shell *sh, size_t argc, char **argv)
|
||||
{
|
||||
uint16_t current_ma = valve_get_end_current_threshold_close();
|
||||
shell_print(sh, "End current threshold (close): %u mA.", current_ma);
|
||||
const int label_width = 30;
|
||||
|
||||
shell_print(sh, "Valve Settings:");
|
||||
shell_print(sh, "%*s %u s", label_width, "Max Open Time:", valve_get_max_open_time());
|
||||
shell_print(sh, "%*s %u s", label_width, "Max Close Time:", valve_get_max_close_time());
|
||||
shell_print(sh,
|
||||
"%*s %u mA",
|
||||
label_width,
|
||||
"End Current Threshold (Open):",
|
||||
valve_get_end_current_threshold_open());
|
||||
shell_print(sh,
|
||||
"%*s %u mA",
|
||||
label_width,
|
||||
"End Current Threshold (Close):",
|
||||
valve_get_end_current_threshold_close());
|
||||
return 0;
|
||||
}
|
||||
|
||||
SHELL_STATIC_SUBCMD_SET_CREATE(sub_valve_settings,
|
||||
SHELL_CMD(set_max_open_time, NULL, "Set max open time (seconds)", cmd_valve_set_max_open_time),
|
||||
SHELL_CMD(get_max_open_time, NULL, "Get max open time (seconds)", cmd_valve_get_max_open_time),
|
||||
SHELL_CMD(
|
||||
set_max_close_time, NULL, "Set max close time (seconds)", cmd_valve_set_max_close_time),
|
||||
SHELL_CMD(
|
||||
get_max_close_time, NULL, "Get max close time (seconds)", cmd_valve_get_max_close_time),
|
||||
SHELL_CMD(set_end_current_threshold_open,
|
||||
SHELL_CMD(set_open_t, NULL, "Set max open time (seconds)", cmd_valve_set_open_t),
|
||||
SHELL_CMD(set_close_t, NULL, "Set max close time (seconds)", cmd_valve_set_close_t),
|
||||
SHELL_CMD(set_end_curr_open,
|
||||
NULL,
|
||||
"Set end current threshold for opening (mA)",
|
||||
cmd_valve_set_end_current_threshold_open),
|
||||
SHELL_CMD(get_end_current_threshold_open,
|
||||
NULL,
|
||||
"Get end current threshold for opening (mA)",
|
||||
cmd_valve_get_end_current_threshold_open),
|
||||
SHELL_CMD(set_end_current_threshold_close,
|
||||
cmd_valve_set_end_curr_open),
|
||||
SHELL_CMD(set_end_curr_close,
|
||||
NULL,
|
||||
"Set end current threshold for closing (mA)",
|
||||
cmd_valve_set_end_current_threshold_close),
|
||||
SHELL_CMD(get_end_current_threshold_close,
|
||||
NULL,
|
||||
"Get end current threshold for closing (mA)",
|
||||
cmd_valve_get_end_current_threshold_close),
|
||||
cmd_valve_set_end_curr_close),
|
||||
SHELL_CMD(show, NULL, "Show valve configuration", cmd_valve_show),
|
||||
SHELL_SUBCMD_SET_END);
|
||||
|
||||
SHELL_CMD_REGISTER(valve, &sub_valve_settings, "Valve commands", NULL);
|
||||
|
|
|
|||
|
|
@ -199,6 +199,16 @@ uint16_t valve_get_max_close_time(void)
|
|||
return max_closing_time_s;
|
||||
}
|
||||
|
||||
uint16_t valve_get_end_current_threshold_open(void)
|
||||
{
|
||||
return end_current_threshold_open_ma;
|
||||
}
|
||||
|
||||
uint16_t valve_get_end_current_threshold_close(void)
|
||||
{
|
||||
return end_current_threshold_close_ma;
|
||||
}
|
||||
|
||||
int32_t valve_get_opening_current(void)
|
||||
{
|
||||
int32_t current;
|
||||
|
|
|
|||
Loading…
Reference in New Issue