@@ -41,6 +41,20 @@ impl Timer {
4141 } )
4242 }
4343
44+ pub fn timer_period_ns ( & self ) -> Result < i64 , RclrsError > {
45+ let mut timer_period_ns = 0 ;
46+ let get_period_result = unsafe {
47+ let rcl_timer = self . rcl_timer . lock ( ) . unwrap ( ) ;
48+ rcl_timer_get_period (
49+ & * rcl_timer,
50+ & mut timer_period_ns
51+ )
52+ } ;
53+ to_rclrs_result ( get_period_result) . map ( |_| {
54+ timer_period_ns
55+ } )
56+ }
57+
4458 pub fn cancel ( & self ) -> Result < ( ) , RclrsError > {
4559 let mut rcl_timer = self . rcl_timer . lock ( ) . unwrap ( ) ;
4660 let cancel_result = unsafe { rcl_timer_cancel ( & mut * rcl_timer) } ;
@@ -105,8 +119,6 @@ impl Timer {
105119
106120 // clock() -> Clock ?
107121
108- // timer_period_ns -> i64 ?
109-
110122 // is_ready() -> bool
111123
112124 // reset() -> None
@@ -178,6 +190,21 @@ mod tests {
178190 assert ! ( dut. is_ok( ) ) ;
179191 }
180192
193+ #[ test]
194+ fn test_get_period ( ) {
195+ let clock = Clock :: steady ( ) ;
196+ let context = Context :: new ( vec ! [ ] ) . unwrap ( ) ;
197+ let period: i64 = 1e6 as i64 ; // 1 milliseconds.
198+
199+ let dut = Timer :: new ( & clock, & context, period) ;
200+ assert ! ( dut. is_ok( ) ) ;
201+ let dut = dut. unwrap ( ) ;
202+ let period_result = dut. timer_period_ns ( ) ;
203+ assert ! ( period_result. is_ok( ) ) ;
204+ let period_result = period_result. unwrap ( ) ;
205+ assert_eq ! ( period_result, 1e6 as i64 ) ;
206+ }
207+
181208 #[ test]
182209 fn test_cancel ( ) {
183210 let clock = Clock :: steady ( ) ;
0 commit comments