diff --git a/examples/twr_aloha/control.c b/examples/twr_aloha/control.c index 2553cb613c..42d1332d04 100644 --- a/examples/twr_aloha/control.c +++ b/examples/twr_aloha/control.c @@ -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; @@ -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); diff --git a/examples/twr_aloha/control.h b/examples/twr_aloha/control.h index f533b23f15..195a41c24b 100644 --- a/examples/twr_aloha/control.h +++ b/examples/twr_aloha/control.h @@ -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 /**