Skip to content

Commit

Permalink
examples/twr_aloha: default print rng result only on initiator
Browse files Browse the repository at this point in the history
  • Loading branch information
fjmolinas committed Apr 27, 2022
1 parent f5a4a48 commit a5f54b5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 10 additions & 0 deletions examples/twr_aloha/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ static bool _complete_cb(struct uwb_dev *inst, struct uwb_mac_interface *cbs)
event_post(uwb_core_get_eventq(), &_rng_listen_event.super);
return false;
}

/* get received frame */
struct uwb_rng_instance *rng = (struct uwb_rng_instance *)cbs->inst_ptr;

Expand All @@ -157,6 +158,15 @@ static bool _complete_cb(struct uwb_dev *inst, struct uwb_mac_interface *cbs)
/* parse data*/
uwb_core_rng_data_t data;

/* with ss twr, the last frame will hold the initiator as the src address,
with ds twr, it will hold the responder address */
if (IS_ACTIVE(CONFIG_TWR_PRINTF_INITIATOR_ONLY) &&
((frame->code < UWB_DATA_CODE_DS_TWR && frame->src_address != _udev->uid) ||
(frame->code >= UWB_DATA_CODE_DS_TWR && frame->dst_address != _udev->uid))) {
event_post(uwb_core_get_eventq(), &_rng_listen_event.super);
return true;
}

data.src = frame->src_address;
data.dest = frame->dst_address;
data.time = ztimer_now(ZTIMER_MSEC);
Expand Down
11 changes: 9 additions & 2 deletions examples/twr_aloha/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@ extern "C" {
* @brief Block after a request is sent
*/
#ifndef CONFIG_TWR_SHELL_BLOCKING
#define CONFIG_TWR_SHELL_BLOCKING 1
#define CONFIG_TWR_SHELL_BLOCKING 1
#endif

/**
* @brief Minimum idle time to enable putting the radio to sleep
*/
#ifndef CONFIG_TWR_MIN_IDLE_SLEEP_MS
#define CONFIG_TWR_MIN_IDLE_SLEEP_MS 20
#define CONFIG_TWR_MIN_IDLE_SLEEP_MS 20
#endif

/*
* @brief Block after a request is sent
*/
#ifndef CONFIG_TWR_PRINTF_INITIATOR_ONLY
#define CONFIG_TWR_PRINTF_INITIATOR_ONLY 1
#endif

/**
Expand Down

0 comments on commit a5f54b5

Please sign in to comment.