From 3bcac120d4876bc301890a9259231c387f3358c7 Mon Sep 17 00:00:00 2001 From: Gasper Jersin Date: Tue, 23 Dec 2025 19:23:13 +0100 Subject: [PATCH] Add picoros_single_threaded_loop available when using Z_FEATURE_MULTI_THREAD==0 - Update zenoh-pico submodule - Whitespace cleanup --- examples/talker.cpp | 4 ++-- src/picoros.c | 29 +++++++++++++++++++++++++++++ src/picoros.h | 17 +++++++++++++++++ thirdparty/zenoh-pico | 2 +- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/examples/talker.cpp b/examples/talker.cpp index 88e52a9..557ef43 100644 --- a/examples/talker.cpp +++ b/examples/talker.cpp @@ -2,10 +2,10 @@ * @file talker.cpp * @brief Example cpp talker node for picoros * @date 2025-Avg-8 - * + * * @details This example demonstrates a simple ROS publisher node that * publishes string messages on the "picoros/chatter" topic. - * + * * @copyright Copyright (c) 2025 Ubiquity Robotics *******************************************************************************/ diff --git a/src/picoros.c b/src/picoros.c index 94d8327..bc6578a 100644 --- a/src/picoros.c +++ b/src/picoros.c @@ -272,10 +272,39 @@ picoros_res_t picoros_interface_init(picoros_interface_t* ifx) { _PR_LOG("Failed to start read/lease tasks! Error:%d\n", res); return PICOROS_ERROR; } + #if Z_FEATURE_MULTI_THREAD == 0 + ifx->last_keepalive_time = z_clock_now(); + #endif return PICOROS_OK; } +#if Z_FEATURE_MULTI_THREAD == 0 +picoros_res_t picoros_single_threaded_loop(picoros_interface_t* ifx){ + z_result_t res = Z_OK; + res = zp_read(z_session_loan(&s_wrapper), ifx->read_opts); + if (res != Z_OK){ + _PR_LOG("Read task error:%d\n", res); + return PICOROS_ERROR; + } + unsigned long elapsed_ms = z_clock_elapsed_ms(&ifx->last_keepalive_time); + if (elapsed_ms >= (Z_TRANSPORT_LEASE / Z_TRANSPORT_LEASE_EXPIRE_FACTOR)) { + ifx->last_keepalive_time = z_clock_now(); + res = zp_send_keep_alive(z_session_loan(&s_wrapper), ifx->keep_alive_opts); + if (res != Z_OK){ + _PR_LOG("Keep alive task error:%d\n", res); + return PICOROS_ERROR; + } + res = zp_send_join(z_session_loan(&s_wrapper), ifx->join_options); + if (res != Z_OK){ + _PR_LOG("Join task error:%d\n", res); + return PICOROS_ERROR; + } + } + return PICOROS_OK; +} +#endif + picoros_res_t picoros_node_init(picoros_node_t* node) { z_result_t res = Z_OK; char keyexpr[KEYEXPR_SIZE]; diff --git a/src/picoros.h b/src/picoros.h index 85f8a19..3dc8a1a 100644 --- a/src/picoros.h +++ b/src/picoros.h @@ -227,6 +227,12 @@ typedef struct { typedef struct { char* mode; /**< Connection mode (peer/client) */ char* locator; /**< Network locator string */ + #if Z_FEATURE_MULTI_THREAD == 0 + z_clock_t last_keepalive_time; /**< Last time of sent keepalive message */ + zp_read_options_t* read_opts; /**< Read options */ + zp_send_keep_alive_options_t* keep_alive_opts; /**< Keep alive options */ + zp_send_join_options_t* join_options; /**< Join options - multicast only */ + #endif } picoros_interface_t; /** @} */ @@ -250,6 +256,17 @@ typedef enum { */ picoros_res_t picoros_interface_init(picoros_interface_t* ifx); +#if Z_FEATURE_MULTI_THREAD == 0 +/** + * @brief Run single threaded communication tasks. + * @param context Pointer to interface configuration. + * @return PICOROS_OK on success, error code otherwise + * @ingroup interface + */ +picoros_res_t picoros_single_threaded_loop(picoros_interface_t* ifx); + +#endif + /** * @brief Shutdown the network interface * @ingroup interface diff --git a/thirdparty/zenoh-pico b/thirdparty/zenoh-pico index f888c98..84bfb32 160000 --- a/thirdparty/zenoh-pico +++ b/thirdparty/zenoh-pico @@ -1 +1 @@ -Subproject commit f888c98454b7ab0cb9ce715654aec1aaae202ea1 +Subproject commit 84bfb32e1595eab5324b7439862757a615496784