test/ieee802154_hal: use l2util where possible
This commit is contained in:
parent
57ee43a048
commit
3b4240dd22
@ -21,6 +21,7 @@ DISABLE_MODULE += auto_init_at86rf2xx auto_init_nrf802154
|
|||||||
|
|
||||||
USEMODULE += od
|
USEMODULE += od
|
||||||
USEMODULE += luid
|
USEMODULE += luid
|
||||||
|
USEMODULE += l2util
|
||||||
USEMODULE += ieee802154
|
USEMODULE += ieee802154
|
||||||
USEMODULE += shell
|
USEMODULE += shell
|
||||||
USEMODULE += shell_commands
|
USEMODULE += shell_commands
|
||||||
|
|||||||
@ -5,6 +5,7 @@ CONFIG_MODULE_LUID=y
|
|||||||
CONFIG_MODULE_IEEE802154=y
|
CONFIG_MODULE_IEEE802154=y
|
||||||
CONFIG_MODULE_SHELL=y
|
CONFIG_MODULE_SHELL=y
|
||||||
CONFIG_MODULE_SHELL_COMMANDS=y
|
CONFIG_MODULE_SHELL_COMMANDS=y
|
||||||
|
CONFIG_MODULE_L2UTIL=y
|
||||||
CONFIG_MODULE_PS=y
|
CONFIG_MODULE_PS=y
|
||||||
|
|
||||||
CONFIG_MODULE_EVENT=y
|
CONFIG_MODULE_EVENT=y
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
#include "event/thread.h"
|
#include "event/thread.h"
|
||||||
#include "luid.h"
|
#include "luid.h"
|
||||||
|
|
||||||
|
#include "net/l2util.h"
|
||||||
#include "net/ieee802154.h"
|
#include "net/ieee802154.h"
|
||||||
#include "net/ieee802154/radio.h"
|
#include "net/ieee802154/radio.h"
|
||||||
|
|
||||||
@ -37,6 +38,8 @@
|
|||||||
|
|
||||||
#define SYMBOL_TIME (16U) /**< 16 us */
|
#define SYMBOL_TIME (16U) /**< 16 us */
|
||||||
#define ACK_TIMEOUT_TIME (40 * SYMBOL_TIME)
|
#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);
|
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)
|
static int print_addr(int argc, char **argv)
|
||||||
{
|
{
|
||||||
(void) argc;
|
(void)argc;
|
||||||
(void) argv;
|
(void)argv;
|
||||||
uint8_t *_p = (uint8_t*) &ext_addr;
|
char addr_str[IEEE802154_LONG_ADDRESS_LEN_STR_MAX];
|
||||||
for(int i=0;i<8;i++) {
|
printf("%s\n", l2util_addr_to_str(
|
||||||
printf("%02x", *_p++);
|
ext_addr.uint8, IEEE802154_LONG_ADDRESS_LEN, addr_str));
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,72 +357,6 @@ static int send(uint8_t *dst, size_t dst_len,
|
|||||||
return 0;
|
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)
|
int _cca(int argc, char **argv)
|
||||||
{
|
{
|
||||||
(void) argc;
|
(void) argc;
|
||||||
@ -508,7 +443,7 @@ int txtsnd(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = _parse_addr(addr, sizeof(addr), argv[1]);
|
res = l2util_addr_from_str(argv[ 1], addr);
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
puts("Usage: txtsnd <long_addr> <len>");
|
puts("Usage: txtsnd <long_addr> <len>");
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user