Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/talker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*******************************************************************************/

Expand Down
29 changes: 29 additions & 0 deletions src/picoros.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
17 changes: 17 additions & 0 deletions src/picoros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/** @} */
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/zenoh-pico
Submodule zenoh-pico updated 183 files