-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bluetooth: shell: Port to the new shell #10239
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10239 +/- ##
==========================================
- Coverage 53.05% 53.04% -0.01%
==========================================
Files 214 214
Lines 26201 26229 +28
Branches 5645 5653 +8
==========================================
+ Hits 13901 13914 +13
- Misses 10028 10042 +14
- Partials 2272 2273 +1
Continue to review full report at Codecov.
|
{ | ||
int err; | ||
|
||
if (!default_conn) { | ||
printk("Not connected\n"); | ||
return 0; | ||
print(shell, "Not connected\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New shell expects \r\n
} | ||
|
||
exchange_params.func = exchange_func; | ||
|
||
err = bt_gatt_exchange_mtu(default_conn, &exchange_params); | ||
if (err) { | ||
printk("Exchange failed (err %d)\n", err); | ||
print(shell, "Exchange failed (err %d)\n", err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\r\n
} | ||
|
||
printk("\n"); | ||
print(shell, "\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\r\n
@@ -109,7 +108,7 @@ static u8_t discover_func(struct bt_conn *conn, | |||
char str[37]; | |||
|
|||
if (!attr) { | |||
printk("Discover complete\n"); | |||
print(NULL, "Discover complete\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\r\n
SHELL_CREATE_STATIC_SUBCMD_SET(l2cap_cmds) { | ||
SHELL_CMD(connect, NULL, "<psm>", cmd_connect), | ||
SHELL_CMD(disconnect, NULL, HELP_NONE, cmd_disconnect), | ||
SHELL_CMD(metrics, NULL, "<value on, off>", cmd_metrics), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can consider implementing subcommands: off
and on
without a handler. In such case body of function cmd_metrics
remain unchanged but off
and on
can be prompted and autocompleated.
You can also implement handlers to on
and off
. Code will look like:
static void cmd_metrics_on(const struct shell *shell, size_t argc, char *argv[])
{
if (!shell_cmd_precheck(shell, argc == 1, NULL, 0)) {
return;
}
l2cap_ops.recv = l2cap_recv_metrics;
}
static void cmd_metrics_off(const struct shell *shell, size_t argc, char *argv[])
{
if (!shell_cmd_precheck(shell, argc == 1, NULL, 0)) {
return;
}
l2cap_ops.recv = l2cap_recv;
}
static void cmd_metrics(const struct shell *shell, size_t argc, char *argv[])
{
if (!shell_cmd_precheck(shell, argc == 1, NULL, 0)) {
return;
}
print(shell, "Please specify valid argument.\r\n");
}
SHELL_CREATE_STATIC_SUBCMD_SET(sub_cmd_connect)
{
SHELL_CMD(off, NULL, "switch off", cmd_metrics_off),
SHELL_CMD(on, NULL, "switch on", cmd_metrics_on),
SHELL_SUBCMD_SET_END
};
and modify this line:
SHELL_CMD(metrics, NULL, "<value on, off>", cmd_metrics),
to
SHELL_CMD(metrics, &sub_cmd_connect, "switch value", cmd_metrics),
This approach will limit strcmp calls and simplify commands usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't like the idea of going more than 2 subcommand, specially when all it would do is to show on/off to auto complete. Btw, I wish we didn't have to do the precheck ourselves so how about we define a format define parameters in the command description so the shell parse that to know how many parameters the command takes and do the precheck before calling the command handler. While at that we could also make it auto complete using the parameters not only commands (so we don't have to add command representing parameters).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough.
Regarding auto precheck I have some doubts. You will always have the same behavior for all commands when wrong argument count is passed.
What if in this case some people want to print error message while others command help.
Another problem I see is with command options defined with macro SHELL_OPT
in command handler - see below example:
static void cmd_typical_handler(const struct shell *shell, size_t argc,
char **argv)
{
/* Dummy option showing options usage */
static const struct shell_getopt_option opt[] = {
SHELL_OPT(
"--test",
"-t",
"test option help string"
),
SHELL_OPT(
"--dummy",
"-d",
"dummy option help string"
)
};
/* Function shell_cmd_precheck will do one of below actions:
* 1. print help if user will call it -h or --help parameter
* 2. print error message if called with too many arguments (argc > 2)
*
* Each of these actions can be deactivated in Kconfig.
*/
if (!shell_cmd_precheck(shell, (argc <= 2), opt,
sizeof(opt)/sizeof(opt[1]))) {
return;
}
}
It will be hard to access these options from the shell context to print them in help message.
General remak:
|
Will fix the \r\n, though that is very window-ish and Im pretty sure it worked with just \n for me so I would expect more people to make such mistake. I guess this is the problem of having shell_fprintf only function, perhaps having some like shell_print that adds whatever line termination the shell expects so the handlers don't have to use shell_fprintf directly. |
4d57b94
to
6fa3747
Compare
recheck |
5ad805f
to
47438bc
Compare
@aescolar Looks like Im still not able to use the native board with shell or Im missing something? |
This is the problem. Those 2 project files[1] need to set CONFIG_SERIAL=y so the serial driver is compiled in. |
Fixes zephyrproject-rtos#8873 Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This splits BR/EDR command under 'bt' to 'br' to reduce the command list and at same time cleaning the mix between different bearers. In addition to that also remove "br-" prefix for the commands: br - Bluetooth BR/EDR shell commands Options: -h, --help :Show command help. Subcommands: auth-pincode :<pincode> connect :<address> discovery :<value: on, off> [length: 1-48] [mode: limited] iscan :<value: on, off> l2cap-register :<psm> oob : pscan :value: on, off sdp-find :<HFPAG> rfcomm-register :<channel> rfcomm-connect :<channel> rfcomm-send :<number of packets> rfcomm-disconnect :[none] Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This splits RFCOMM command under 'br' to 'rfcomm' removing 'rfcomm-' prefix from commands: rfcomm - Bluetooth RFCOMM shell commands Options: -h, --help :Show command help. Subcommands: register :<channel> connect :<channel> disconnect :[none] send :<number of packets> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This splits GATT command under 'bt' to 'gatt' removing 'gatt-' prefix from commands: gatt - Bluetooth GATT shell commands Options: -h, --help :Show command help. Subcommands: discover-characteristic :[UUID] [start handle] [end handle] discover-descriptor :[UUID] [start handle] [end handle] discover-include :[UUID] [start handle] [end handle] discover-primary :[UUID] [start handle] [end handle] discover-secondary :[UUID] [start handle] [end handle] exchange-mtu :[none] read :<handle> [offset] read-multiple :<handle 1> <handle 2> ... subscribe :<CCC handle> <value handle> [ind] write :<handle> <offset> <data> [length] write-without-response :<handle> <data> [length] [repeat] write-signed :<handle> <data> [length] [repeat] unsubscribe :[none] metrics :register vendr char and measure rx [value on, off] register :register pre-predefined test service show-db :[none] unregister :unregister pre-predefined test service Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This splits L2CAP commands under 'bt' to 'l2cap' removing 'l2cap-' prefix from the commands: l2cap - Bluetooth L2CAP shell commands Options: -h, --help :Show command help. Subcommands: connect :<psm> disconnect :[none] metrics :<value on, off> recv :[delay (in miliseconds) register :<psm> [sec_level] send :<number of packets> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Shell expects each printed lined to be terminated with \r\n. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
recheck |
@jarz-nordic any feedback on these? We can rework some of the commands later if we find it is worth adding more depth for the getting autocomplete. |
Did you change \n to \r\n? I will verify it in 2h, it is hard on a phone :) |
@jarz-nordic It should be part of the last patch: |
LGTM |
This port the existing Bluetooth commands for the legacy shell to the new shell and modify the commands so protocols such as GATT, L2CAP, RFCOMM have their how subcommands instead of everything being under 'bt'.
The new hierarchy is as follow:
uart:~$ bt
bt - Bluetooth shell commands
Options:
-h, --help :Show command help.
Subcommands:
init :<address: XX:XX:XX:XX:XX:XX> <type: (public|random)>
hci-cmd : [data]
id-create :[addr]
id-reset : [addr]
id-delete :
id-show :[none]
id-select :
name :[name]
scan :<value: on, passive, off> <dup filter: dups, nodups>
advertise :<type: off, on, scan, nconn> <mode: discov, non_discov>
connect :<address: XX:XX:XX:XX:XX:XX> <type: (public|random)>
disconnect :[none]
auto-conn :<address: XX:XX:XX:XX:XX:XX> <type: (public|random)>
directed-adv :<address: XX:XX:XX:XX:XX:XX> <type: (public|random)>
[mode: low]
select :<address: XX:XX:XX:XX:XX:XX> <type: (public|random)>
conn-update :
oob :
clear :
channel-map :<channel-map: XX:XX:XX:XX:XX> (36-0)
security :<security level: 0, 1, 2, 3>
bondable :<bondable: on, off>
auth :<auth method: all, input, display, yesno, confirm,
none>
auth-cancel :[none]
auth-passkey :
auth-passkey-confirm :[none]
auth-pairing-confirm :[none]
uart:~$ br
br - Bluetooth BR/EDR shell commands
Options:
-h, --help :Show command help.
Subcommands:
auth-pincode :
connect :
discovery :<value: on, off> [length: 1-48] [mode: limited]
iscan :<value: on, off>
l2cap-register :
oob :
pscan :value: on, off
sdp-find :
uart:~$ gatt
gatt - Bluetooth GATT shell commands
Options:
-h, --help :Show command help.
Subcommands:
discover-characteristic :[UUID] [start handle] [end handle]
discover-descriptor :[UUID] [start handle] [end handle]
discover-include :[UUID] [start handle] [end handle]
discover-primary :[UUID] [start handle] [end handle]
discover-secondary :[UUID] [start handle] [end handle]
exchange-mtu :[none]
read : [offset]
read-multiple :<handle 1> <handle 2> ...
subscribe : [ind]
write : [length]
write-without-response : [length] [repeat]
write-signed : [length] [repeat]
unsubscribe :[none]
metrics :register vendr char and measure rx [value on, off]
register :register pre-predefined test service
show-db :[none]
unregister :unregister pre-predefined test service
uart:~$ l2cap
l2cap - Bluetooth L2CAP shell commands
Options:
-h, --help :Show command help.
Subcommands:
connect :
disconnect :[none]
metrics :<value on, off>
recv :[delay (in miliseconds)
register : [sec_level]
send :
uart:~$ rfcomm
rfcomm - Bluetooth RFCOMM shell commands
Options:
-h, --help :Show command help.
Subcommands:
register :
connect :
disconnect :[none]
send :