Skip to content

Commit b66246b

Browse files
committed
Using mynewt extended shell api with streamer
1 parent 3e81b61 commit b66246b

File tree

13 files changed

+235
-222
lines changed

13 files changed

+235
-222
lines changed

Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ uwbcore-y += porting/dpl/kernel/src/stats.o
5252
uwbcore-y += porting/dpl/kernel/src/stats_sysfs.o
5353
uwbcore-y += porting/dpl_lib/src/dpl_mbuf.o
5454
uwbcore-y += porting/dpl_lib/src/dpl_mempool.o
55+
uwbcore-y += porting/dpl_lib/src/streamer.o
5556
uwbcore-y += hw/drivers/uwb/src/uwb.o
5657
uwbcore-y += lib/cir/src/cir.o
5758
uwbcore-y += lib/cir/src/cir_json.o

apps/uwb_desense/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ uwb_desense-y += ../../lib/uwb_rf_tests/desense/src/desense.o
2020
uwb_desense-y += ../../lib/uwb_rf_tests/desense/src/desense_cli.o
2121
uwb_desense-y += ../../lib/uwb_rf_tests/desense/src/desense_sysfs.o
2222
uwb_desense-y += ../../lib/uwb_rf_tests/desense/src/desense_debugfs.o
23+
uwb_desense-y += ../../porting/dpl_lib/src/streamer.o

lib/panmaster/src/panmaster_cli.c

Lines changed: 42 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@
3131

3232
#include <shell/shell.h>
3333
#include <console/console.h>
34+
#include <streamer/streamer.h>
3435

3536
#include "panmaster/panmaster.h"
3637
#include "panmaster_priv.h"
3738
#include "imgmgr/imgmgr.h"
3839
#include <bootutil/image.h>
3940

40-
static int panmaster_cli_cmd(int argc, char **argv);
41+
static int panmaster_cli_cmd(const struct shell_cmd *cmd, int argc, char **argv, struct streamer *streamer);
4142

4243
#if MYNEWT_VAL(SHELL_CMD_HELP)
4344
const struct shell_param cmd_pm_param[] = {
@@ -58,15 +59,7 @@ const struct shell_cmd_help cmd_pm_help = {
5859
};
5960
#endif
6061

61-
62-
static struct shell_cmd shell_panmaster_cmd = {
63-
.sc_cmd = "panm",
64-
.sc_cmd_func = panmaster_cli_cmd,
65-
#if MYNEWT_VAL(SHELL_CMD_HELP)
66-
.help = &cmd_pm_help
67-
#endif
68-
};
69-
62+
static struct shell_cmd shell_panmaster_cmd = SHELL_CMD_EXT("panm", panmaster_cli_cmd, &cmd_pm_help);
7063

7164
static void
7265
list_nodes_load_cb(struct panmaster_node *node, void *cb_arg)
@@ -82,7 +75,7 @@ list_nodes_load_cb(struct panmaster_node *node, void *cb_arg)
8275

8376
#define LIST_NODES_BLK_NNODES (32)
8477
static void
85-
list_nodes_blk()
78+
list_nodes_blk(struct streamer *streamer)
8679
{
8780
int i,j;
8881
struct panmaster_node_idx *node_idx;
@@ -94,7 +87,7 @@ list_nodes_blk()
9487
lne.nodes = (struct panmaster_node*)malloc(lne_nodes_sz);
9588

9689
if (!lne.nodes) {
97-
console_printf("err:mem\n");
90+
streamer_printf(streamer, "err:mem\n");
9891
return;
9992
}
10093

@@ -104,7 +97,7 @@ list_nodes_blk()
10497

10598
panmaster_node_idx(&node_idx, &num_nodes);
10699
os_gettimeofday(&utctime, &timezone);
107-
console_printf("#idx, addr, role, slot, p, lease, euid, flags, date-added, fw-ver\n");
100+
streamer_printf(streamer, "#idx, addr, role, slot, p, lease, euid, flags, date-added, fw-ver\n");
108101
for (i=0;i<num_nodes;i+=LIST_NODES_BLK_NNODES) {
109102
lne.index_off = i;
110103
lne.index_max = i+LIST_NODES_BLK_NNODES;
@@ -117,39 +110,39 @@ list_nodes_blk()
117110
continue;
118111
}
119112

120-
console_printf("%4d, ", i+j);
121-
console_printf("%4x, ", lne.nodes[j].addr);
113+
streamer_printf(streamer, "%4d, ", i+j);
114+
streamer_printf(streamer, "%4x, ", lne.nodes[j].addr);
122115
int slot_id = node_idx[lne.nodes[j].index].slot_id;
123116
if (lne.nodes[j].has_perm_slot) {
124117
slot_id = lne.nodes[j].slot_id;
125118
}
126-
console_printf("%4X, ", lne.nodes[j].role);
119+
streamer_printf(streamer, "%4X, ", lne.nodes[j].role);
127120
if (slot_id != 0xffff) {
128-
console_printf("%4d, ", slot_id);
121+
streamer_printf(streamer, "%4d, ", slot_id);
129122
} else {
130-
console_printf(" , ");
123+
streamer_printf(streamer, " , ");
131124
}
132-
console_printf("%s, ", (lne.nodes[j].has_perm_slot)?"p":" ");
125+
streamer_printf(streamer, "%s, ", (lne.nodes[j].has_perm_slot)?"p":" ");
133126

134127
if (node_idx[lne.nodes[j].index].lease_ends) {
135128
os_get_uptime(&tv);
136129
int32_t le_ms = node_idx[lne.nodes[j].index].lease_ends;
137130
int32_t now_ms = tv.tv_sec*1000 + tv.tv_usec/1000;
138131
le_ms = le_ms - now_ms;
139132
if (le_ms < 0) le_ms = 0;
140-
console_printf("%4ld.%ld, ", le_ms/1000, (le_ms-1000*(le_ms/1000))/100);
133+
streamer_printf(streamer, "%4ld.%ld, ", le_ms/1000, (le_ms-1000*(le_ms/1000))/100);
141134
} else {
142-
console_printf(" , ");
135+
streamer_printf(streamer, " , ");
143136
}
144137

145-
console_printf("%016llX, ", lne.nodes[j].euid);
146-
console_printf("%5X, ", lne.nodes[j].flags);
138+
streamer_printf(streamer, "%016llX, ", lne.nodes[j].euid);
139+
streamer_printf(streamer, "%5X, ", lne.nodes[j].flags);
147140

148141
utctime.tv_sec = lne.nodes[j].first_seen_utc;
149142
utctime.tv_usec = 0;
150143
datetime_format(&utctime, &timezone, buf, sizeof(buf));
151144
buf[19]='\0';
152-
console_printf("%s, ", buf);
145+
streamer_printf(streamer, "%s, ", buf);
153146
struct image_version fw_ver = {
154147
.iv_major = lne.nodes[j].fw_ver.iv_major,
155148
.iv_minor = lne.nodes[j].fw_ver.iv_minor,
@@ -158,8 +151,8 @@ list_nodes_blk()
158151
};
159152
imgr_ver_str(&fw_ver, ver_str);
160153

161-
console_printf("%s", ver_str);
162-
console_printf("\n");
154+
streamer_printf(streamer, "%s", ver_str);
155+
streamer_printf(streamer, "\n");
163156
}
164157
}
165158
free(lne.nodes);
@@ -169,7 +162,8 @@ static void
169162
dump_cb(struct panmaster_node *n, void *cb_arg)
170163
{
171164
char ver_str[32];
172-
console_printf("%3d %04x %016llx %x %x %d %d ", n->index, n->addr, n->euid,
165+
struct streamer *streamer = (struct streamer *)cb_arg;
166+
streamer_printf(streamer, "%3d %04x %016llx %x %x %d %d ", n->index, n->addr, n->euid,
173167
n->flags, n->role, n->has_perm_slot, n->slot_id);
174168

175169
struct image_version fw_ver = {
@@ -179,19 +173,19 @@ dump_cb(struct panmaster_node *n, void *cb_arg)
179173
.iv_build_num = n->fw_ver.iv_build_num,
180174
};
181175
imgr_ver_str(&fw_ver, ver_str);
182-
console_printf("%s\n", ver_str);
176+
streamer_printf(streamer, "%s\n", ver_str);
183177

184178
}
185179

186180
static void
187-
dump(void)
181+
dump(struct streamer *streamer)
188182
{
189-
console_printf("# index addr euid flags role pslot slot_id fw-ver\n");
190-
panmaster_load(dump_cb, 0);
183+
streamer_printf(streamer, "# index addr euid flags role pslot slot_id fw-ver\n");
184+
panmaster_load(dump_cb, streamer);
191185
}
192186

193187
static int
194-
panmaster_cli_cmd(int argc, char **argv)
188+
panmaster_cli_cmd(const struct shell_cmd *cmd, int argc, char **argv, struct streamer *streamer)
195189
{
196190
int rc;
197191
int slot_id, role;
@@ -200,14 +194,14 @@ panmaster_cli_cmd(int argc, char **argv)
200194
struct panmaster_node *node;
201195

202196
if (argc < 2) {
203-
console_printf("Too few args\n");
197+
streamer_printf(streamer, "Too few args\n");
204198
return 0;
205199
}
206200
if (!strcmp(argv[1], "list")) {
207-
list_nodes_blk();
201+
list_nodes_blk(streamer);
208202
} else if (!strcmp(argv[1], "add")) {
209203
if (argc < 3) {
210-
console_printf("euid needed\n");
204+
streamer_printf(streamer, "euid needed\n");
211205
return 0;
212206
}
213207
euid = strtoll(argv[2], NULL, 16);
@@ -223,21 +217,21 @@ panmaster_cli_cmd(int argc, char **argv)
223217
rc = panmaster_idx_find_node(euid, 0, &node);
224218
panmaster_postprocess();
225219
if (!rc) {
226-
console_printf("Added node euid: 0x%llX, addr 0x%X\n",
220+
streamer_printf(streamer, "Added node euid: 0x%llX, addr 0x%X\n",
227221
euid, node->addr);
228222
} else {
229-
console_printf("Add node err\n");
223+
streamer_printf(streamer, "Add node err\n");
230224
}
231225
} else if (!strcmp(argv[1], "del")) {
232226
if (argc < 3) {
233-
console_printf("euid needed\n");
227+
streamer_printf(streamer, "euid needed\n");
234228
return 0;
235229
}
236230
euid = strtoll(argv[2], NULL, 16);
237231
panmaster_delete_node(euid);
238232
} else if (!strcmp(argv[1], "pslot")) {
239233
if (argc < 4) {
240-
console_printf("euid+slot_id needed\n");
234+
streamer_printf(streamer, "euid+slot_id needed\n");
241235
return 0;
242236
}
243237
euid = strtoll(argv[2], NULL, 16);
@@ -248,23 +242,23 @@ panmaster_cli_cmd(int argc, char **argv)
248242

249243
rc = panmaster_idx_find_node(euid, 0, &node);
250244
if (!rc) {
251-
console_printf("0x%llX: pslot -> ", euid);
245+
streamer_printf(streamer, "0x%llX: pslot -> ", euid);
252246
if (slot_id > -1) {
253247
node->slot_id = slot_id;
254248
node->has_perm_slot = 1;
255-
console_printf("%d\n ", slot_id);
249+
streamer_printf(streamer, "%d\n ", slot_id);
256250
} else {
257251
node->slot_id = 0;
258252
node->has_perm_slot = 0;
259-
console_printf("<removed>\n");
253+
streamer_printf(streamer, "<removed>\n");
260254
}
261255
panmaster_save_node(node);
262256
} else {
263-
console_printf("err\n");
257+
streamer_printf(streamer, "err\n");
264258
}
265259
} else if (!strcmp(argv[1], "role")) {
266260
if (argc < 4) {
267-
console_printf("euid+role needed\n");
261+
streamer_printf(streamer, "euid+role needed\n");
268262
return 0;
269263
}
270264
euid = strtoll(argv[2], NULL, 16);
@@ -275,11 +269,11 @@ panmaster_cli_cmd(int argc, char **argv)
275269

276270
rc = panmaster_idx_find_node(euid, 0, &node);
277271
if (!rc) {
278-
console_printf("0x%llX: role -> %d\n ", euid, role);
272+
streamer_printf(streamer, "0x%llX: role -> %d\n ", euid, role);
279273
node->role = role;
280274
panmaster_save_node(node);
281275
} else {
282-
console_printf("err\n");
276+
streamer_printf(streamer, "err\n");
283277
}
284278
} else if (!strcmp(argv[1], "clear")) {
285279
panmaster_clear_list();
@@ -288,9 +282,9 @@ panmaster_cli_cmd(int argc, char **argv)
288282
} else if (!strcmp(argv[1], "sort")) {
289283
panmaster_sort();
290284
} else if (!strcmp(argv[1], "dump")) {
291-
dump();
285+
dump(streamer);
292286
} else {
293-
console_printf("Unknown cmd\n");
287+
streamer_printf(streamer, "Unknown cmd\n");
294288
}
295289
return 0;
296290
}

lib/tofdb/src/tofdb_cli.c

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030

3131
#include <shell/shell.h>
3232
#include <console/console.h>
33+
#include <streamer/streamer.h>
3334

3435
#include "uwb_rng/uwb_rng.h"
3536
#include "tofdb/tofdb.h"
3637

3738
struct tofdb_node* tofdb_get_nodes();
3839

39-
static int tofdb_cli_cmd(int argc, char **argv);
40+
static int tofdb_cli_cmd(const struct shell_cmd *cmd, int argc, char **argv, struct streamer *streamer);
4041

4142
#if MYNEWT_VAL(SHELL_CMD_HELP)
4243
const struct shell_param cmd_tofdb_param[] = {
@@ -49,65 +50,57 @@ const struct shell_cmd_help cmd_tofdb_help = {
4950
};
5051
#endif
5152

52-
53-
static struct shell_cmd shell_tofdb_cmd = {
54-
.sc_cmd = "tdb",
55-
.sc_cmd_func = tofdb_cli_cmd,
56-
#if MYNEWT_VAL(SHELL_CMD_HELP)
57-
.help = &cmd_tofdb_help
58-
#endif
59-
};
60-
53+
static struct shell_cmd shell_tofdb_cmd = SHELL_CMD_EXT("tdb", tofdb_cli_cmd, &cmd_tofdb_help);
6154

6255
static void
63-
list_nodes()
56+
list_nodes(struct streamer *streamer)
6457
{
6558
int i;
6659
struct tofdb_node *nodes;
6760
struct os_timeval tv;
6861

6962
nodes = tofdb_get_nodes();
70-
console_printf("#idx, addr, tof, tof(m), #, stddev, age(s)\n");
63+
streamer_printf(streamer, "#idx, addr, tof, tof(m), #, stddev, age(s)\n");
7164
for (i=0;i<MYNEWT_VAL(TOFDB_MAXNUM_NODES);i++) {
7265
if (!nodes[i].addr) {
7366
continue;
7467
}
75-
console_printf("%4d, ", i);
76-
console_printf("%4x, ", nodes[i].addr);
77-
console_printf("%6ld, ", (uint32_t)nodes[i].tof);
68+
streamer_printf(streamer, "%4d, ", i);
69+
streamer_printf(streamer, "%4x, ", nodes[i].addr);
70+
streamer_printf(streamer, "%6ld, ", (uint32_t)nodes[i].tof);
7871
float ave = nodes[i].tof;
7972
float stddev = uwb_rng_tof_to_meters((uint32_t)sqrtf(nodes[i].sum_sq/nodes[i].num - ave*ave));
8073
ave = uwb_rng_tof_to_meters((uint32_t)(nodes[i].sum/nodes[i].num));
81-
console_printf("%3d.%03d, ", (int)ave, (int)(fabsf(ave-(int)ave)*1000));
82-
console_printf("%4ld, ", nodes[i].num);
74+
streamer_printf(streamer, "%3d.%03d, ", (int)ave, (int)(fabsf(ave-(int)ave)*1000));
75+
streamer_printf(streamer, "%4ld, ", nodes[i].num);
8376
if (nodes[i].num>1) {
84-
console_printf("%3d.%03d, ", (int)stddev, (int)(fabsf(stddev-(int)stddev)*1000));
77+
streamer_printf(streamer, "%3d.%03d, ", (int)stddev, (int)(fabsf(stddev-(int)stddev)*1000));
8578
} else {
86-
console_printf("%7s, ","");
79+
streamer_printf(streamer, "%7s, ","");
8780
}
8881

8982
if (nodes[i].last_updated) {
9083
os_get_uptime(&tv);
9184
uint32_t age = os_cputime_ticks_to_usecs(os_cputime_get32() -
9285
nodes[i].last_updated);
9386
uint32_t age_s = age/1000000;
94-
console_printf("%4ld.%ld", age_s, (age-1000000*(age_s))/100000);
87+
streamer_printf(streamer, "%4ld.%ld", age_s, (age-1000000*(age_s))/100000);
9588
}
96-
console_printf("\n");
89+
streamer_printf(streamer, "\n");
9790
}
9891
}
9992

10093

10194
static int
102-
tofdb_cli_cmd(int argc, char **argv)
95+
tofdb_cli_cmd(const struct shell_cmd *cmd, int argc, char **argv, struct streamer *streamer)
10396
{
10497
if (argc < 2) {
10598
return 0;
10699
}
107100
if (!strcmp(argv[1], "list")) {
108-
list_nodes();
101+
list_nodes(streamer);
109102
} else {
110-
console_printf("Unknown cmd\n");
103+
streamer_printf(streamer, "Unknown cmd\n");
111104
}
112105
return 0;
113106
}

lib/uwb_rf_tests/desense/include/desense/desense.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ extern "C" {
4040

4141
#include <uwb/uwb.h>
4242
#include <uwb/uwb_ftypes.h>
43-
44-
typedef int (*desense_out_cb_t)(const char *fmt, ...);
43+
#include <streamer/streamer.h>
4544

4645
//! Structure of desense test parameters
4746
struct desense_test_parameters {
@@ -118,8 +117,8 @@ int desense_listen(struct uwb_desense_instance * desense);
118117
int desense_txon(struct uwb_desense_instance * desense, uint16_t length, uint32_t delay_ns);
119118
int desense_txoff(struct uwb_desense_instance * desense);
120119

121-
void desense_dump_data(struct uwb_desense_instance * desense, desense_out_cb_t cb);
122-
void desense_dump_stats(struct uwb_desense_instance * desense, desense_out_cb_t cb);
120+
void desense_dump_data(struct uwb_desense_instance * desense, struct streamer *streamer);
121+
void desense_dump_stats(struct uwb_desense_instance * desense, struct streamer *streamer);
123122

124123
int desense_cli_register(void);
125124
int desense_cli_down(int reason);

0 commit comments

Comments
 (0)