Skip to content

Commit d0af34a

Browse files
committed
Disable GetTimerNextCallTime() for ROS2 <= humble
1 parent e19bcff commit d0af34a

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/timer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,14 @@ class Timer {
9090

9191
/**
9292
* Get the absolute time in nanoseconds when the next callback is due.
93+
* Note: Only available on ROS2 distributions after Humble.
9394
* @return {bigint | null} - The next call time in nanoseconds, or null if the timer is canceled.
95+
* Returns undefined if not supported on current ROS2 distribution.
9496
*/
9597
getNextCallTime() {
98+
if (typeof rclnodejs.getTimerNextCallTime !== 'function') {
99+
return undefined;
100+
}
96101
return rclnodejs.getTimerNextCallTime(this._handle);
97102
}
98103

src/rcl_timer_bindings.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ Napi::Value GetTimerPeriod(const Napi::CallbackInfo& info) {
257257
return Napi::BigInt::New(env, period_nsec);
258258
}
259259

260+
#if ROS_VERSION > 2205 // 2205 == Humble
260261
Napi::Value GetTimerNextCallTime(const Napi::CallbackInfo& info) {
261262
Napi::Env env = info.Env();
262263
RclHandle* timer_handle = RclHandle::Unwrap(info[0].As<Napi::Object>());
@@ -274,6 +275,7 @@ Napi::Value GetTimerNextCallTime(const Napi::CallbackInfo& info) {
274275
return env.Undefined();
275276
}
276277
}
278+
#endif
277279

278280
#if ROS_VERSION > 2205 // 2205 == Humble
279281
Napi::Value CallTimerWithInfo(const Napi::CallbackInfo& info) {
@@ -362,9 +364,9 @@ Napi::Object InitTimerBindings(Napi::Env env, Napi::Object exports) {
362364
Napi::Function::New(env, TimerGetTimeUntilNextCall));
363365
exports.Set("changeTimerPeriod", Napi::Function::New(env, ChangeTimerPeriod));
364366
exports.Set("getTimerPeriod", Napi::Function::New(env, GetTimerPeriod));
367+
#if ROS_VERSION > 2205 // 2205 == Humble
365368
exports.Set("getTimerNextCallTime",
366369
Napi::Function::New(env, GetTimerNextCallTime));
367-
#if ROS_VERSION > 2205 // 2205 == Humble
368370
exports.Set("setTimerOnResetCallback",
369371
Napi::Function::New(env, SetTimerOnResetCallback));
370372
exports.Set("clearTimerOnResetCallback",

test/test-timer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ describe('rclnodejs Timer class testing', function () {
140140
});
141141

142142
it('timer.getNextCallTime', function (done) {
143+
// Skip test if ROS2 version is Humble or earlier (not supported)
144+
if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) {
145+
this.skip();
146+
}
143147
var timer = node.createTimer(TIMER_INTERVAL, function () {
144148
var nextCallTime = timer.getNextCallTime();
145149
assert.deepStrictEqual(typeof nextCallTime, 'bigint');

0 commit comments

Comments
 (0)