test/ieee802154_hal: use l2util where possible

This commit is contained in:
Jose Alamos 2021-09-29 11:21:38 +02:00 committed by Francisco Molina
parent 57ee43a048
commit 3b4240dd22
3 changed files with 11 additions and 74 deletions

View File

@ -21,6 +21,7 @@ DISABLE_MODULE += auto_init_at86rf2xx auto_init_nrf802154
USEMODULE += od
USEMODULE += luid
USEMODULE += l2util
USEMODULE += ieee802154
USEMODULE += shell
USEMODULE += shell_commands

View File

@ -5,6 +5,7 @@ CONFIG_MODULE_LUID=y
CONFIG_MODULE_IEEE802154=y
CONFIG_MODULE_SHELL=y
CONFIG_MODULE_SHELL_COMMANDS=y
CONFIG_MODULE_L2UTIL=y
CONFIG_MODULE_PS=y
CONFIG_MODULE_EVENT=y

View File

@ -27,6 +27,7 @@
#include "event/thread.h"
#include "luid.h"
#include "net/l2util.h"
#include "net/ieee802154.h"
#include "net/ieee802154/radio.h"
@ -37,6 +38,8 @@
#define SYMBOL_TIME (16U) /**< 16 us */
#define ACK_TIMEOUT_TIME (40 * SYMBOL_TIME)
#define IEEE802154_LONG_ADDRESS_LEN_STR_MAX \
(sizeof("00:00:00:00:00:00:00:00"))
static inline void _set_trx_state(int state, bool verbose);
@ -69,13 +72,11 @@ static void _print_packet(size_t size, uint8_t lqi, int16_t rssi)
static int print_addr(int argc, char **argv)
{
(void) argc;
(void) argv;
uint8_t *_p = (uint8_t*) &ext_addr;
for(int i=0;i<8;i++) {
printf("%02x", *_p++);
}
printf("\n");
(void)argc;
(void)argv;
char addr_str[IEEE802154_LONG_ADDRESS_LEN_STR_MAX];
printf("%s\n", l2util_addr_to_str(
ext_addr.uint8, IEEE802154_LONG_ADDRESS_LEN, addr_str));
return 0;
}
@ -356,72 +357,6 @@ static int send(uint8_t *dst, size_t dst_len,
return 0;
}
static inline int _dehex(char c, int default_)
{
if ('0' <= c && c <= '9') {
return c - '0';
}
else if ('A' <= c && c <= 'F') {
return c - 'A' + 10;
}
else if ('a' <= c && c <= 'f') {
return c - 'a' + 10;
}
else {
return default_;
}
}
static size_t _parse_addr(uint8_t *out, size_t out_len, const char *in)
{
const char *end_str = in;
uint8_t *out_end = out;
size_t count = 0;
int assert_cell = 1;
if (!in || !*in) {
return 0;
}
while (end_str[1]) {
++end_str;
}
while (end_str >= in) {
int a = 0, b = _dehex(*end_str--, -1);
if (b < 0) {
if (assert_cell) {
return 0;
}
else {
assert_cell = 1;
continue;
}
}
assert_cell = 0;
if (end_str >= in) {
a = _dehex(*end_str--, 0);
}
if (++count > out_len) {
return 0;
}
*out_end++ = (a << 4) | b;
}
if (assert_cell) {
return 0;
}
/* out is reversed */
while (out < --out_end) {
uint8_t tmp = *out_end;
*out_end = *out;
*out++ = tmp;
}
return count;
}
int _cca(int argc, char **argv)
{
(void) argc;
@ -508,7 +443,7 @@ int txtsnd(int argc, char **argv)
return 1;
}
res = _parse_addr(addr, sizeof(addr), argv[1]);
res = l2util_addr_from_str(argv[ 1], addr);
if (res == 0) {
puts("Usage: txtsnd <long_addr> <len>");
return 1;