Skip to content

Commit c9733a6

Browse files
authored
move synchronized state to new api (#121)
remove synchronized check from rmw_uros_epoch Signed-off-by: Ilya Guterman <amfernusus@gmail.com>
1 parent 8e41732 commit c9733a6

2 files changed

Lines changed: 20 additions & 15 deletions

File tree

rmw_microxrcedds_c/include/rmw_uros/options.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,23 @@ typedef struct rmw_uxrce_transport_params_t
5858
} rmw_uxrce_transport_params_t;
5959

6060

61+
/**
62+
* \brief Returns the time synchronization state of the epoch time.
63+
* \return true if last time synchronization succeded and false otherwise
64+
*/
65+
bool rmw_uros_epoch_synchronized();
66+
6167
/**
6268
* \brief Returns the epoch time in milliseconds taking into account the offset computed during the time synchronization.
6369
* \return epoch time in milliseconds.
6470
* \return 0 if session is not initialized.
65-
* \return -1 if session time is not synchronized.
6671
*/
6772
int64_t rmw_uros_epoch_millis();
6873

6974
/**
7075
* \brief Returns the epoch time in nanoseconds taking into account the offset computed during the time synchronization.
7176
* \return epoch time in nanoseconds.
7277
* \return 0 if session is not initialized.
73-
* \return -1 if session time is not synchronized.
7478
*/
7579
int64_t rmw_uros_epoch_nanos();
7680

rmw_microxrcedds_c/src/rmw_uros_options.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,32 @@
2828
#include <uxr/client/util/ping.h>
2929
#include <uxr/client/util/time.h>
3030

31-
int64_t rmw_uros_epoch_millis()
31+
bool rmw_uros_epoch_synchronized()
3232
{
3333
// Check session is initialized
3434
if (NULL == session_memory.allocateditems)
3535
{
3636
RMW_SET_ERROR_MSG("Uninitialized session.");
37-
return 0;
37+
return false;
3838
}
39-
4039
rmw_uxrce_mempool_item_t* item = session_memory.allocateditems;
4140
rmw_context_impl_t* context = (rmw_context_impl_t*)item->data;
4241

43-
if (!context->session.synchronized)
42+
return context->session.synchronized;
43+
}
44+
45+
int64_t rmw_uros_epoch_millis()
46+
{
47+
// Check session is initialized
48+
if (NULL == session_memory.allocateditems)
4449
{
45-
RMW_SET_ERROR_MSG("Session time not synchronized");
46-
return -1;
50+
RMW_SET_ERROR_MSG("Uninitialized session.");
51+
return 0;
4752
}
4853

54+
rmw_uxrce_mempool_item_t* item = session_memory.allocateditems;
55+
rmw_context_impl_t* context = (rmw_context_impl_t*)item->data;
56+
4957
return uxr_epoch_millis(&context->session);
5058
}
5159

@@ -61,12 +69,6 @@ int64_t rmw_uros_epoch_nanos()
6169
rmw_uxrce_mempool_item_t* item = session_memory.allocateditems;
6270
rmw_context_impl_t* context = (rmw_context_impl_t*)item->data;
6371

64-
if (!context->session.synchronized)
65-
{
66-
RMW_SET_ERROR_MSG("Session time not synchronized");
67-
return -1;
68-
}
69-
7072
return uxr_epoch_nanos(&context->session);
7173
}
7274

@@ -84,7 +86,6 @@ rmw_ret_t rmw_uros_sync_session(
8486

8587
rmw_uxrce_mempool_item_t* item = session_memory.allocateditems;
8688
rmw_context_impl_t* context = (rmw_context_impl_t*)item->data;
87-
context->session.synchronized = false;
8889

8990
if (!uxr_sync_session(&context->session, timeout_ms))
9091
{

0 commit comments

Comments
 (0)