@@ -159,6 +159,60 @@ Napi::Value TimerGetTimeSinceLastCall(const Napi::CallbackInfo& info) {
159159 return Napi::BigInt::New (env, elapsed_time);
160160}
161161
162+ Napi::Value ChangeTimerPeriod (const Napi::CallbackInfo& info) {
163+ Napi::Env env = info.Env ();
164+
165+ RclHandle* timer_handle = RclHandle::Unwrap (info[0 ].As <Napi::Object>());
166+ rcl_timer_t * timer = reinterpret_cast <rcl_timer_t *>(timer_handle->ptr ());
167+
168+ if (!info[1 ].IsBigInt ()) {
169+ Napi::TypeError::New (env, " Timer period must be a BigInt" )
170+ .ThrowAsJavaScriptException ();
171+ return env.Undefined ();
172+ }
173+
174+ bool lossless;
175+ int64_t period_nsec = info[1 ].As <Napi::BigInt>().Int64Value (&lossless);
176+ int64_t old_period;
177+ THROW_ERROR_IF_NOT_EQUAL (
178+ RCL_RET_OK, rcl_timer_exchange_period (timer, period_nsec, &old_period),
179+ rcl_get_error_string ().str );
180+
181+ return env.Undefined ();
182+ }
183+
184+ Napi::Value GetTimerPeriod (const Napi::CallbackInfo& info) {
185+ Napi::Env env = info.Env ();
186+
187+ RclHandle* timer_handle = RclHandle::Unwrap (info[0 ].As <Napi::Object>());
188+ rcl_timer_t * timer = reinterpret_cast <rcl_timer_t *>(timer_handle->ptr ());
189+ int64_t period_nsec = 0 ;
190+
191+ THROW_ERROR_IF_NOT_EQUAL (RCL_RET_OK,
192+ rcl_timer_get_period (timer, &period_nsec),
193+ rcl_get_error_string ().str );
194+
195+ return Napi::BigInt::New (env, period_nsec);
196+ }
197+
198+ Napi::Value CallTimerWithInfo (const Napi::CallbackInfo& info) {
199+ Napi::Env env = info.Env ();
200+ RclHandle* timer_handle = RclHandle::Unwrap (info[0 ].As <Napi::Object>());
201+ rcl_timer_t * timer = reinterpret_cast <rcl_timer_t *>(timer_handle->ptr ());
202+ rcl_timer_call_info_t call_info;
203+
204+ THROW_ERROR_IF_NOT_EQUAL (RCL_RET_OK,
205+ rcl_timer_call_with_info (timer, &call_info),
206+ rcl_get_error_string ().str );
207+
208+ Napi::Object timer_info = Napi::Object::New (env);
209+ timer_info.Set (" expectedCallTime" ,
210+ Napi::BigInt::New (env, call_info.expected_call_time ));
211+ timer_info.Set (" actualCallTime" ,
212+ Napi::BigInt::New (env, call_info.actual_call_time ));
213+ return timer_info;
214+ }
215+
162216Napi::Object InitTimerBindings (Napi::Env env, Napi::Object exports) {
163217 exports.Set (" createTimer" , Napi::Function::New (env, CreateTimer));
164218 exports.Set (" isTimerReady" , Napi::Function::New (env, IsTimerReady));
@@ -170,6 +224,9 @@ Napi::Object InitTimerBindings(Napi::Env env, Napi::Object exports) {
170224 Napi::Function::New (env, TimerGetTimeSinceLastCall));
171225 exports.Set (" timerGetTimeUntilNextCall" ,
172226 Napi::Function::New (env, TimerGetTimeUntilNextCall));
227+ exports.Set (" changeTimerPeriod" , Napi::Function::New (env, ChangeTimerPeriod));
228+ exports.Set (" getTimerPeriod" , Napi::Function::New (env, GetTimerPeriod));
229+ exports.Set (" callTimerWithInfo" , Napi::Function::New (env, CallTimerWithInfo));
173230 return exports;
174231}
175232
0 commit comments