Skip to content

Commit

Permalink
examples/twr_aloha: error on invalid short address
Browse files Browse the repository at this point in the history
  • Loading branch information
fjmolinas committed Apr 27, 2022
1 parent 410d87f commit 5e7bb6c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions examples/twr_aloha/twr_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ int _twr_handler(int argc, char **argv)
uint32_t count = 1;
uint32_t interval_ms = 1000;
int proto = UWB_DATA_CODE_SS_TWR;
uint8_t addr[IEEE802154_SHORT_ADDRESS_LEN_STR_MAX];
uint8_t addr[IEEE802154_SHORT_ADDRESS_LEN];
uint16_t short_addr = 0x0000;
int res = 0;
if (argc < 3) {
_print_usage();
Expand All @@ -225,6 +226,11 @@ int _twr_handler(int argc, char **argv)
"(hex pairs delimited by colons)");
res = 1;
}
short_addr = addr[1] + (addr[0] << 8);
if (short_addr == 0x0000) {
printf("[ERROR]: invalid addr %s\n", arg);
res = 1;
}
}
else {
switch (arg[1]) {
Expand Down Expand Up @@ -281,11 +287,10 @@ int _twr_handler(int argc, char **argv)
}
}
}
if (res != 0) {
if (res != 0 || (short_addr == 0x0000)) {
_print_usage();
return 1;
}
uint16_t short_addr = addr[1] + (addr[0] << 8);
puts("[twr]: start ranging");
uwb_core_rng_start(short_addr, proto, interval_ms, count);
if (IS_ACTIVE(CONFIG_TWR_SHELL_BLOCKING)) {
Expand Down

0 comments on commit 5e7bb6c

Please sign in to comment.