2828#include <uxr/client/util/ping.h>
2929#include <uxr/client/util/time.h>
3030
31+ int64_t rmw_uros_epoch_millis ()
32+ {
33+ // Check session is initialized
34+ if (NULL == session_memory .allocateditems )
35+ {
36+ RMW_SET_ERROR_MSG ("Uninitialized session." );
37+ return 0 ;
38+ }
39+
40+ rmw_uxrce_mempool_item_t * item = session_memory .allocateditems ;
41+ rmw_context_impl_t * context = (rmw_context_impl_t * )item -> data ;
42+
43+ if (!context -> session .synchronized )
44+ {
45+ RMW_SET_ERROR_MSG ("Session time not synchronized" );
46+ return -1 ;
47+ }
48+
49+ return uxr_epoch_millis (& context -> session );
50+ }
51+
52+ int64_t rmw_uros_epoch_nanos ()
53+ {
54+ // Check session is initialized
55+ if (NULL == session_memory .allocateditems )
56+ {
57+ RMW_SET_ERROR_MSG ("Uninitialized session." );
58+ return 0 ;
59+ }
60+
61+ rmw_uxrce_mempool_item_t * item = session_memory .allocateditems ;
62+ rmw_context_impl_t * context = (rmw_context_impl_t * )item -> data ;
63+
64+ if (!context -> session .synchronized )
65+ {
66+ RMW_SET_ERROR_MSG ("Session time not synchronized" );
67+ return -1 ;
68+ }
69+
70+ return uxr_epoch_nanos (& context -> session );
71+ }
72+
3173rmw_ret_t rmw_uros_sync_session (
32- int64_t * result ,
3374 const int timeout_ms )
3475{
3576 rmw_ret_t ret = RMW_RET_OK ;
@@ -43,12 +84,9 @@ rmw_ret_t rmw_uros_sync_session(
4384
4485 rmw_uxrce_mempool_item_t * item = session_memory .allocateditems ;
4586 rmw_context_impl_t * context = (rmw_context_impl_t * )item -> data ;
87+ context -> session .synchronized = false;
4688
47- if (uxr_sync_session (& context -> session , timeout_ms ))
48- {
49- * result = uxr_nanos () - context -> session .time_offset ;
50- }
51- else
89+ if (!uxr_sync_session (& context -> session , timeout_ms ))
5290 {
5391 RMW_SET_ERROR_MSG ("Time synchronization failed." );
5492 return RMW_RET_ERROR ;
0 commit comments