1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2026-01-01 01:41:18 +01:00

tests/drivers/nrf802154: test if Beacons can be received

This commit is contained in:
lulu254b 2024-11-13 11:12:03 +01:00 committed by Lukas-Luger
parent b9ba3ee0b2
commit bef67c8a51
2 changed files with 77 additions and 1 deletions

View File

@ -1,6 +1,11 @@
# About
This is a manual test application for the NRF802154 radio driver.
Supported boards must have an nRF52-series chip that has an IEEE 802.15.4 radio (e.g. nrf52840dk).
# Usage
For testing the radio driver you can use the ifconfig and txtsnd shell commands
that are included in this application.
For testing beacon frame acceptance you can flash this test onto two nRF52 devices
and use the beaconsend command to send an IEEE 802.15.4 beacon frame.
The opponent should print the received frame details.

View File

@ -52,6 +52,77 @@ int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) {
return 0;
}
void send_beacon_usage(char *cmd_name)
{
printf("usage: %s [<16 bit hex source PAN ID>] (uses device PAN ID by default)\n", cmd_name);
}
int cmd_send_beacon(int argc, char **argv)
{
uint16_t pan_id;
/* evaluating if argument is present */
switch (argc) {
case 1:
pan_id = nrf802154.dev.pan;
puts("using device PAN ID as source");
break;
case 2:
if (strlen(argv[1]) != 4) {
puts("send: Error parsing PAN ID");
send_beacon_usage(argv[0]);
return 1;
}
pan_id = strtoul(argv[1], NULL, 16);
break;
default:
send_beacon_usage(argv[0]);
return 1;
}
printf("PAN ID: %x\n", pan_id);
/* preparing the mac header */
uint8_t mhr[IEEE802154_MAX_HDR_LEN];
memset(mhr, 0, IEEE802154_MAX_HDR_LEN*sizeof(uint8_t));
le_uint16_t src_pan = byteorder_btols(byteorder_htons(pan_id));
le_uint16_t dst_pan = byteorder_htols(0);
size_t src_len = 2, dst_len = 0;
uint8_t *src = nrf802154.dev.short_addr, *dst = NULL;
uint8_t flags = IEEE802154_FCF_TYPE_BEACON;
int res = ieee802154_set_frame_hdr(mhr, src, src_len,
dst, dst_len,
src_pan, dst_pan,
flags, nrf802154.dev.seq++);
if (res < 0) {
puts("send: Error preparing frame");
send_beacon_usage(argv[0]);
return 1;
}
/* preparing packet to send */
iolist_t iol = {
.iol_base = mhr,
.iol_len = (size_t)res,
.iol_next = NULL,
};
puts("Sending Beacon Frame");
res = netdev_ieee802154_minimal_send(&nrf802154.dev.netdev, &iol);
if (res < 0) {
puts("send: Error on sending");
send_beacon_usage(argv[0]);
return 1;
}
return 0;
}
static const shell_command_t shell_commands[] = {
{ "beaconsend", "Send an IEEE 802.15.4 beacon frame", cmd_send_beacon},
{NULL, NULL, NULL}
};
int main(void)
{
puts("Test application for NRF802154 IEEE 802.15.4 device driver");
@ -66,7 +137,7 @@ int main(void)
puts("Initialization successful - starting the shell now");
char line_buf[SHELL_DEFAULT_BUFSIZE];
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
return 0;
}