Skip to content

Commit f70359b

Browse files
ndrs-pstkartben
authored andcommitted
bluetooth: mesh: shell: eliminate ctx_shell usage
This change aims to eliminate the dependency on `ctx_shell` in the Bluetooth `mesh/shell/*`, making the code more maintainable. Replaced `shell_*` functions that depended on `ctx_shell` with the appropriate `bt_shell_*` functions. Signed-off-by: Pisit Sawangvonganan <[email protected]>
1 parent f1516c9 commit f70359b

File tree

8 files changed

+112
-150
lines changed

8 files changed

+112
-150
lines changed

subsys/bluetooth/mesh/shell/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
menuconfig BT_MESH_SHELL
77
bool "Bluetooth Mesh shell"
88
select SHELL
9+
select BT_PRIVATE_SHELL
910
help
1011
Activate shell module that provides Bluetooth Mesh commands to
1112
the console.

subsys/bluetooth/mesh/shell/blob.c

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
#include <zephyr/bluetooth/mesh.h>
1212
#include <zephyr/bluetooth/mesh/shell.h>
1313

14+
#include "common/bt_shell_private.h"
1415
#include "utils.h"
1516

16-
extern const struct shell *bt_mesh_shell_ctx_shell;
17-
1817
/***************************************************************************************************
1918
* Implementation of models' instances
2019
**************************************************************************************************/
@@ -85,8 +84,7 @@ static void blob_cli_lost_target(struct bt_mesh_blob_cli *cli,
8584
struct bt_mesh_blob_target *target,
8685
enum bt_mesh_blob_status reason)
8786
{
88-
shell_print(bt_mesh_shell_ctx_shell, "Mesh Blob: Lost target 0x%04x (reason: %u)",
89-
target->addr, reason);
87+
bt_shell_print("Mesh Blob: Lost target 0x%04x (reason: %u)", target->addr, reason);
9088
}
9189

9290
static void blob_cli_caps(struct bt_mesh_blob_cli *cli,
@@ -100,30 +98,29 @@ static void blob_cli_caps(struct bt_mesh_blob_cli *cli,
10098
};
10199

102100
if (!caps) {
103-
shell_print(bt_mesh_shell_ctx_shell,
104-
"None of the targets can be used for BLOB transfer");
101+
bt_shell_print("None of the targets can be used for BLOB transfer");
105102
return;
106103
}
107104

108-
shell_print(bt_mesh_shell_ctx_shell, "Mesh BLOB: capabilities:");
109-
shell_print(bt_mesh_shell_ctx_shell, "\tMax BLOB size: %u bytes", caps->max_size);
110-
shell_print(bt_mesh_shell_ctx_shell, "\tBlock size: %u-%u (%u-%u bytes)",
111-
caps->min_block_size_log, caps->max_block_size_log,
112-
1 << caps->min_block_size_log,
113-
1 << caps->max_block_size_log);
114-
shell_print(bt_mesh_shell_ctx_shell, "\tMax chunks: %u", caps->max_chunks);
115-
shell_print(bt_mesh_shell_ctx_shell, "\tChunk size: %u", caps->max_chunk_size);
116-
shell_print(bt_mesh_shell_ctx_shell, "\tMTU size: %u", caps->mtu_size);
117-
shell_print(bt_mesh_shell_ctx_shell, "\tModes: %s", modes[caps->modes]);
105+
bt_shell_print("Mesh BLOB: capabilities:");
106+
bt_shell_print("\tMax BLOB size: %u bytes", caps->max_size);
107+
bt_shell_print("\tBlock size: %u-%u (%u-%u bytes)",
108+
caps->min_block_size_log, caps->max_block_size_log,
109+
1 << caps->min_block_size_log,
110+
1 << caps->max_block_size_log);
111+
bt_shell_print("\tMax chunks: %u", caps->max_chunks);
112+
bt_shell_print("\tChunk size: %u", caps->max_chunk_size);
113+
bt_shell_print("\tMTU size: %u", caps->mtu_size);
114+
bt_shell_print("\tModes: %s", modes[caps->modes]);
118115
}
119116

120117
static void blob_cli_end(struct bt_mesh_blob_cli *cli,
121118
const struct bt_mesh_blob_xfer *xfer, bool success)
122119
{
123120
if (success) {
124-
shell_print(bt_mesh_shell_ctx_shell, "Mesh BLOB transfer complete.");
121+
bt_shell_print("Mesh BLOB transfer complete.");
125122
} else {
126-
shell_print(bt_mesh_shell_ctx_shell, "Mesh BLOB transfer failed.");
123+
bt_shell_print("Mesh BLOB transfer failed.");
127124
}
128125
}
129126

@@ -142,7 +139,7 @@ static uint8_t get_progress(const struct bt_mesh_blob_xfer_info *info)
142139
blocks_not_rxed += info->missing_blocks[i % 8] & (1 << (i % 8));
143140
}
144141

145-
return (total_blocks - blocks_not_rxed) / total_blocks;
142+
return (total_blocks - blocks_not_rxed) / total_blocks;
146143
}
147144

148145
static void xfer_progress(struct bt_mesh_blob_cli *cli,
@@ -151,16 +148,15 @@ static void xfer_progress(struct bt_mesh_blob_cli *cli,
151148
{
152149
uint8_t progress = get_progress(info);
153150

154-
shell_print(bt_mesh_shell_ctx_shell,
155-
"BLOB transfer progress received from target 0x%04x:\n"
156-
"\tphase: %d\n"
157-
"\tprogress: %u%%",
158-
target->addr, info->phase, progress);
151+
bt_shell_print("BLOB transfer progress received from target 0x%04x:\n"
152+
"\tphase: %d\n"
153+
"\tprogress: %u%%",
154+
target->addr, info->phase, progress);
159155
}
160156

161157
static void xfer_progress_complete(struct bt_mesh_blob_cli *cli)
162158
{
163-
shell_print(bt_mesh_shell_ctx_shell, "Determine BLOB transfer progress procedure complete");
159+
bt_shell_print("Determine BLOB transfer progress procedure complete");
164160
}
165161

166162
static const struct bt_mesh_blob_cli_cb blob_cli_handlers = {
@@ -185,7 +181,7 @@ static int blob_srv_start(struct bt_mesh_blob_srv *srv,
185181
struct bt_mesh_msg_ctx *ctx,
186182
struct bt_mesh_blob_xfer *xfer)
187183
{
188-
shell_print(bt_mesh_shell_ctx_shell, "BLOB start");
184+
bt_shell_print("BLOB start");
189185
blob_time = k_uptime_get();
190186
return 0;
191187
}
@@ -196,11 +192,11 @@ static void blob_srv_end(struct bt_mesh_blob_srv *srv, uint64_t id,
196192
if (success) {
197193
int64_t duration = k_uptime_delta(&blob_time);
198194

199-
shell_print(bt_mesh_shell_ctx_shell, "BLOB completed in %u.%03u s",
200-
(uint32_t)(duration / MSEC_PER_SEC),
201-
(uint32_t)(duration % MSEC_PER_SEC));
195+
bt_shell_print("BLOB completed in %u.%03u s",
196+
(uint32_t)(duration / MSEC_PER_SEC),
197+
(uint32_t)(duration % MSEC_PER_SEC));
202198
} else {
203-
shell_print(bt_mesh_shell_ctx_shell, "BLOB cancelled");
199+
bt_shell_print("BLOB cancelled");
204200
}
205201
}
206202

subsys/bluetooth/mesh/shell/dfu.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <zephyr/dfu/mcuboot.h>
1717
#include <zephyr/storage/flash_map.h>
1818

19+
#include "common/bt_shell_private.h"
1920
#include "utils.h"
2021
#include "blob.h"
2122
#include "../dfu_slot.h"
@@ -24,30 +25,28 @@
2425
* Implementation of models' instances
2526
**************************************************************************************************/
2627

27-
extern const struct shell *bt_mesh_shell_ctx_shell;
28-
2928
#if defined(CONFIG_BT_MESH_SHELL_DFU_CLI)
3029

3130
static void dfu_cli_ended(struct bt_mesh_dfu_cli *cli,
3231
enum bt_mesh_dfu_status reason)
3332
{
34-
shell_print(bt_mesh_shell_ctx_shell, "DFU ended: %u", reason);
33+
bt_shell_print("DFU ended: %u", reason);
3534
}
3635

3736
static void dfu_cli_applied(struct bt_mesh_dfu_cli *cli)
3837
{
39-
shell_print(bt_mesh_shell_ctx_shell, "DFU applied.");
38+
bt_shell_print("DFU applied.");
4039
}
4140

4241
static void dfu_cli_lost_target(struct bt_mesh_dfu_cli *cli,
4342
struct bt_mesh_dfu_target *target)
4443
{
45-
shell_print(bt_mesh_shell_ctx_shell, "DFU target lost: 0x%04x", target->blob.addr);
44+
bt_shell_print("DFU target lost: 0x%04x", target->blob.addr);
4645
}
4746

4847
static void dfu_cli_confirmed(struct bt_mesh_dfu_cli *cli)
4948
{
50-
shell_print(bt_mesh_shell_ctx_shell, "DFU confirmed");
49+
bt_shell_print("DFU confirmed");
5150
}
5251

5352
const struct bt_mesh_dfu_cli_cb dfu_cli_cb = {
@@ -86,7 +85,7 @@ static int dfu_start(struct bt_mesh_dfu_srv *srv,
8685
struct net_buf_simple *metadata,
8786
const struct bt_mesh_blob_io **io)
8887
{
89-
shell_print(bt_mesh_shell_ctx_shell, "DFU setup");
88+
bt_shell_print("DFU setup");
9089

9190
*io = bt_mesh_shell_blob_io;
9291

@@ -96,7 +95,7 @@ static int dfu_start(struct bt_mesh_dfu_srv *srv,
9695
static void dfu_end(struct bt_mesh_dfu_srv *srv, const struct bt_mesh_dfu_img *img, bool success)
9796
{
9897
if (!success) {
99-
shell_print(bt_mesh_shell_ctx_shell, "DFU failed");
98+
bt_shell_print("DFU failed");
10099
return;
101100
}
102101

@@ -115,7 +114,7 @@ static int dfu_apply(struct bt_mesh_dfu_srv *srv,
115114
return -EINVAL;
116115
}
117116

118-
shell_print(bt_mesh_shell_ctx_shell, "Applying DFU transfer...");
117+
bt_shell_print("Applying DFU transfer...");
119118

120119
return 0;
121120
}
@@ -620,10 +619,10 @@ static enum bt_mesh_dfu_iter dfu_img_cb(struct bt_mesh_dfu_cli *cli,
620619
len = bin2hex(img->fwid, img->fwid_len, fwid, sizeof(fwid));
621620
fwid[len] = '\0';
622621

623-
shell_print(bt_mesh_shell_ctx_shell, "Image %u:", idx);
624-
shell_print(bt_mesh_shell_ctx_shell, "\tFWID: %s", fwid);
622+
bt_shell_print("Image %u:", idx);
623+
bt_shell_print("\tFWID: %s", fwid);
625624
if (img->uri) {
626-
shell_print(bt_mesh_shell_ctx_shell, "\tURI: %s", img->uri);
625+
bt_shell_print("\tURI: %s", img->uri);
627626
}
628627

629628
return BT_MESH_DFU_ITER_CONTINUE;

subsys/bluetooth/mesh/shell/large_comp_data.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,19 @@
99
#include <zephyr/bluetooth/mesh.h>
1010
#include <zephyr/bluetooth/mesh/shell.h>
1111

12+
#include "common/bt_shell_private.h"
1213
#include "utils.h"
1314

14-
extern const struct shell *bt_mesh_shell_ctx_shell;
15-
1615
static void status_print(int err, char *msg, uint16_t addr, struct bt_mesh_large_comp_data_rsp *rsp)
1716
{
1817
if (err) {
19-
shell_error(bt_mesh_shell_ctx_shell,
20-
"Failed to send %s Get message (err %d)", msg, err);
18+
bt_shell_error("Failed to send %s Get message (err %d)", msg, err);
2119
return;
2220
}
2321

24-
shell_print(bt_mesh_shell_ctx_shell,
25-
"%s [0x%04x]: page: %u offset: %u total size: %u", msg, addr, rsp->page,
26-
rsp->offset, rsp->total_size);
27-
shell_hexdump(bt_mesh_shell_ctx_shell, rsp->data->data, rsp->data->len);
22+
bt_shell_print("%s [0x%04x]: page: %u offset: %u total size: %u", msg, addr, rsp->page,
23+
rsp->offset, rsp->total_size);
24+
bt_shell_hexdump(rsp->data->data, rsp->data->len);
2825
}
2926

3027
static int cmd_large_comp_data_get(const struct shell *sh, size_t argc, char *argv[])

subsys/bluetooth/mesh/shell/rpr.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ static const struct bt_mesh_model *mod;
1717
* Implementation of the model's instance
1818
**************************************************************************************************/
1919

20-
extern const struct shell *bt_mesh_shell_ctx_shell;
21-
2220
static void rpr_scan_report(struct bt_mesh_rpr_cli *cli,
2321
const struct bt_mesh_rpr_node *srv,
2422
struct bt_mesh_rpr_unprov *unprov,
@@ -28,11 +26,10 @@ static void rpr_scan_report(struct bt_mesh_rpr_cli *cli,
2826

2927
bin2hex(unprov->uuid, 16, uuid_hex_str, sizeof(uuid_hex_str));
3028

31-
shell_print(bt_mesh_shell_ctx_shell,
32-
"Server 0x%04x:\n"
33-
"\tuuid: %s\n"
34-
"\tOOB: 0x%04x",
35-
srv->addr, uuid_hex_str, unprov->oob);
29+
bt_shell_print("Server 0x%04x:\n"
30+
"\tuuid: %s\n"
31+
"\tOOB: 0x%04x",
32+
srv->addr, uuid_hex_str, unprov->oob);
3633

3734
while (adv_data && adv_data->len > 2) {
3835
uint8_t len, type;
@@ -61,15 +58,14 @@ static void rpr_scan_report(struct bt_mesh_rpr_cli *cli,
6158
data[len] = '\0';
6259

6360
if (type == BT_DATA_URI) {
64-
shell_print(bt_mesh_shell_ctx_shell, "\tURI: \"\\x%02x%s\"",
65-
data[0], &data[1]);
61+
bt_shell_print("\tURI: \"\\x%02x%s\"", data[0], &data[1]);
6662
} else if (type == BT_DATA_NAME_COMPLETE) {
67-
shell_print(bt_mesh_shell_ctx_shell, "\tName: \"%s\"", data);
63+
bt_shell_print("\tName: \"%s\"", data);
6864
} else {
6965
char string[64 + 1];
7066

7167
bin2hex(data, len, string, sizeof(string));
72-
shell_print(bt_mesh_shell_ctx_shell, "\t0x%02x: %s", type, string);
68+
bt_shell_print("\t0x%02x: %s", type, string);
7369
}
7470
}
7571
}

0 commit comments

Comments
 (0)