rclnodejs 0.29.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -319,8 +319,12 @@ NAN_METHOD(CreateTimer) {
319
319
  Nan::To<v8::Object>(info[1]).ToLocalChecked());
320
320
  rcl_context_t* context =
321
321
  reinterpret_cast<rcl_context_t*>(context_handle->ptr());
322
- int64_t period_ms = Nan::To<int64_t>(info[2]).FromJust();
323
-
322
+ if (!info[2]->IsBigInt()) {
323
+ Nan::ThrowTypeError("Timer period must be a BigInt");
324
+ return;
325
+ }
326
+ v8::Local<v8::BigInt> bigInt = info[2].As<v8::BigInt>();
327
+ int64_t period_nsec = bigInt->Int64Value();
324
328
  rcl_timer_t* timer =
325
329
  reinterpret_cast<rcl_timer_t*>(malloc(sizeof(rcl_timer_t)));
326
330
  *timer = rcl_get_zero_initialized_timer();
@@ -328,15 +332,14 @@ NAN_METHOD(CreateTimer) {
328
332
  #if ROS_VERSION > 2305 // After Iron.
329
333
  THROW_ERROR_IF_NOT_EQUAL(
330
334
  RCL_RET_OK,
331
- rcl_timer_init2(timer, clock, context, RCL_MS_TO_NS(period_ms), nullptr,
335
+ rcl_timer_init2(timer, clock, context, period_nsec, nullptr,
332
336
  rcl_get_default_allocator(), /*autostart=*/true),
333
337
  rcl_get_error_string().str);
334
338
  #else
335
- THROW_ERROR_IF_NOT_EQUAL(
336
- RCL_RET_OK,
337
- rcl_timer_init(timer, clock, context, RCL_MS_TO_NS(period_ms), nullptr,
338
- rcl_get_default_allocator()),
339
- rcl_get_error_string().str);
339
+ THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK,
340
+ rcl_timer_init(timer, clock, context, period_nsec,
341
+ nullptr, rcl_get_default_allocator()),
342
+ rcl_get_error_string().str);
340
343
  #endif
341
344
 
342
345
  auto js_obj = RclHandle::NewInstance(timer, clock_handle, [](void* ptr) {
@@ -410,9 +413,9 @@ NAN_METHOD(TimerGetTimeUntilNextCall) {
410
413
  RCL_RET_OK, rcl_timer_get_time_until_next_call(timer, &remaining_time),
411
414
  rcl_get_error_string().str);
412
415
 
413
- info.GetReturnValue().Set(
414
- Nan::New<v8::String>(std::to_string(RCL_NS_TO_MS(remaining_time)))
415
- .ToLocalChecked());
416
+ v8::Local<v8::BigInt> bigInt =
417
+ v8::BigInt::New(v8::Isolate::GetCurrent(), remaining_time);
418
+ info.GetReturnValue().Set(bigInt);
416
419
  }
417
420
 
418
421
  NAN_METHOD(TimerGetTimeSinceLastCall) {
@@ -425,18 +428,23 @@ NAN_METHOD(TimerGetTimeSinceLastCall) {
425
428
  RCL_RET_OK, rcl_timer_get_time_since_last_call(timer, &elapsed_time),
426
429
  rcl_get_error_string().str);
427
430
 
428
- info.GetReturnValue().Set(
429
- Nan::New<v8::String>(std::to_string(RCL_NS_TO_MS(elapsed_time)))
430
- .ToLocalChecked());
431
+ v8::Local<v8::BigInt> bigInt =
432
+ v8::BigInt::New(v8::Isolate::GetCurrent(), elapsed_time);
433
+ info.GetReturnValue().Set(bigInt);
431
434
  }
432
435
 
433
436
  NAN_METHOD(CreateTimePoint) {
434
- std::string str(*Nan::Utf8String(info[0]));
437
+ if (!info[0]->IsBigInt()) {
438
+ Nan::ThrowTypeError("Timer period must be a BigInt");
439
+ return;
440
+ }
441
+ v8::Local<v8::BigInt> bigInt = info[0].As<v8::BigInt>();
442
+ const int64_t nanoseconds = bigInt->Int64Value();
435
443
  uint32_t clock_type = Nan::To<uint32_t>(info[1]).FromJust();
436
444
  rcl_time_point_t* time_point =
437
445
  reinterpret_cast<rcl_time_point_t*>(malloc(sizeof(rcl_time_point_t)));
438
446
 
439
- time_point->nanoseconds = std::stoll(str);
447
+ time_point->nanoseconds = nanoseconds;
440
448
  time_point->clock_type = static_cast<rcl_clock_type_t>(clock_type);
441
449
 
442
450
  auto js_obj =
@@ -449,16 +457,21 @@ NAN_METHOD(GetNanoseconds) {
449
457
  Nan::To<v8::Object>(info[0]).ToLocalChecked());
450
458
  rcl_time_point_t* time_point =
451
459
  reinterpret_cast<rcl_time_point_t*>(time_point_handle->ptr());
452
- info.GetReturnValue().Set(
453
- Nan::New<v8::String>(std::to_string(time_point->nanoseconds))
454
- .ToLocalChecked());
460
+ v8::Local<v8::BigInt> bigInt =
461
+ v8::BigInt::New(v8::Isolate::GetCurrent(), time_point->nanoseconds);
462
+ info.GetReturnValue().Set(bigInt);
455
463
  }
456
464
 
457
465
  NAN_METHOD(CreateDuration) {
458
- std::string str(*Nan::Utf8String(info[0]));
466
+ if (!info[0]->IsBigInt()) {
467
+ Nan::ThrowTypeError("Timer period must be a BigInt");
468
+ return;
469
+ }
470
+ v8::Local<v8::BigInt> bigInt = info[0].As<v8::BigInt>();
471
+ const int64_t nanoseconds = bigInt->Int64Value();
459
472
  rcl_duration_t* duration =
460
473
  reinterpret_cast<rcl_duration_t*>(malloc(sizeof(rcl_duration_t)));
461
- duration->nanoseconds = std::stoll(str);
474
+ duration->nanoseconds = nanoseconds;
462
475
 
463
476
  auto js_obj =
464
477
  RclHandle::NewInstance(duration, nullptr, [](void* ptr) { free(ptr); });
@@ -470,10 +483,9 @@ NAN_METHOD(GetDurationNanoseconds) {
470
483
  Nan::To<v8::Object>(info[0]).ToLocalChecked());
471
484
  rcl_duration_t* duration =
472
485
  reinterpret_cast<rcl_duration_t*>(duration_handle->ptr());
473
-
474
- info.GetReturnValue().Set(
475
- Nan::New<v8::String>(std::to_string(duration->nanoseconds))
476
- .ToLocalChecked());
486
+ v8::Local<v8::BigInt> bigInt =
487
+ v8::BigInt::New(v8::Isolate::GetCurrent(), duration->nanoseconds);
488
+ info.GetReturnValue().Set(bigInt);
477
489
  }
478
490
 
479
491
  NAN_METHOD(SetRosTimeOverrideIsEnabled) {
@@ -539,25 +551,6 @@ NAN_METHOD(CreateClock) {
539
551
  }));
540
552
  }
541
553
 
542
- static void ReturnJSTimeObj(
543
- Nan::NAN_METHOD_ARGS_TYPE info, int64_t nanoseconds,
544
- rcl_clock_type_t clock_type = RCL_CLOCK_UNINITIALIZED) {
545
- auto obj = v8::Object::New(v8::Isolate::GetCurrent());
546
-
547
- const auto sec = static_cast<std::int32_t>(RCL_NS_TO_S(nanoseconds));
548
- const auto nanosec =
549
- static_cast<std::int32_t>(nanoseconds % (1000 * 1000 * 1000));
550
- const int32_t type = clock_type;
551
-
552
- Nan::Set(obj, Nan::New("sec").ToLocalChecked(), Nan::New(sec));
553
- Nan::Set(obj, Nan::New("nanosec").ToLocalChecked(), Nan::New(nanosec));
554
- if (clock_type != RCL_CLOCK_UNINITIALIZED) {
555
- Nan::Set(obj, Nan::New("type").ToLocalChecked(), Nan::New(type));
556
- }
557
-
558
- info.GetReturnValue().Set(obj);
559
- }
560
-
561
554
  NAN_METHOD(ClockGetNow) {
562
555
  rcl_clock_t* clock = reinterpret_cast<rcl_clock_t*>(
563
556
  RclHandle::Unwrap<RclHandle>(
@@ -569,64 +562,9 @@ NAN_METHOD(ClockGetNow) {
569
562
  THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK,
570
563
  rcl_clock_get_now(clock, &time_point.nanoseconds),
571
564
  rcl_get_error_string().str);
572
-
573
- ReturnJSTimeObj(info, time_point.nanoseconds, time_point.clock_type);
574
- }
575
-
576
- NAN_METHOD(StaticClockGetNow) {
577
- int32_t type = Nan::To<int32_t>(info[0]).FromJust();
578
-
579
- if (type < RCL_ROS_TIME && type > RCL_STEADY_TIME) {
580
- info.GetReturnValue().Set(Nan::Undefined());
581
- return;
582
- }
583
-
584
- rcl_clock_t ros_clock;
585
- rcl_time_point_t rcl_time;
586
- rcl_allocator_t allocator = rcl_get_default_allocator();
587
-
588
- THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK,
589
- rcl_clock_init(static_cast<rcl_clock_type_t>(type),
590
- &ros_clock, &allocator),
591
- rcl_get_error_string().str);
592
-
593
- THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK,
594
- rcl_clock_get_now(&ros_clock, &rcl_time.nanoseconds),
595
- rcl_get_error_string().str);
596
-
597
- THROW_ERROR_IF_NOT_EQUAL(RCL_RET_OK, rcl_clock_fini(&ros_clock),
598
- rcl_get_error_string().str);
599
-
600
- ReturnJSTimeObj(info, rcl_time.nanoseconds, rcl_time.clock_type);
601
- }
602
-
603
- NAN_METHOD(TimeDiff) {
604
- int64_t s_sec = Nan::To<int32_t>(info[0]).FromJust();
605
- uint32_t s_nano = Nan::To<uint32_t>(info[1]).FromJust();
606
- int32_t s_type = Nan::To<int32_t>(info[2]).FromJust();
607
-
608
- int64_t f_sec = Nan::To<int32_t>(info[3]).FromJust();
609
- uint32_t f_nano = Nan::To<uint32_t>(info[4]).FromJust();
610
- int32_t f_type = Nan::To<int32_t>(info[5]).FromJust();
611
-
612
- rcl_time_point_t start;
613
- rcl_time_point_t finish;
614
- rcl_duration_t delta;
615
-
616
- start.nanoseconds = s_sec * 1000 * 1000 * 1000 + s_nano;
617
- start.clock_type = static_cast<rcl_clock_type_t>(s_type);
618
-
619
- finish.nanoseconds = f_sec * 1000 * 1000 * 1000 + f_nano;
620
- finish.clock_type = static_cast<rcl_clock_type_t>(f_type);
621
-
622
- auto ret = rcl_difference_times(&start, &finish, &delta);
623
-
624
- if (ret == RCL_RET_OK) {
625
- ReturnJSTimeObj(info, delta.nanoseconds);
626
- return;
627
- }
628
-
629
- info.GetReturnValue().Set(Nan::Undefined());
565
+ v8::Local<v8::BigInt> bigInt =
566
+ v8::BigInt::New(v8::Isolate::GetCurrent(), time_point.nanoseconds);
567
+ info.GetReturnValue().Set(bigInt);
630
568
  }
631
569
 
632
570
  NAN_METHOD(RclTake) {
@@ -2051,8 +1989,6 @@ std::vector<BindingMethod> binding_methods = {
2051
1989
  {"timerGetTimeUntilNextCall", TimerGetTimeUntilNextCall},
2052
1990
  {"createClock", CreateClock},
2053
1991
  {"clockGetNow", ClockGetNow},
2054
- {"staticClockGetNow", StaticClockGetNow},
2055
- {"timeDiff", TimeDiff},
2056
1992
  {"createTimePoint", CreateTimePoint},
2057
1993
  {"getNanoseconds", GetNanoseconds},
2058
1994
  {"createDuration", CreateDuration},
@@ -10,15 +10,14 @@ declare module 'rclnodejs' {
10
10
  * @param seconds - The seconds component of the duration, default = 0.
11
11
  * @param nanoseconds - The nanoseconds component of the duration, default = 0.
12
12
  */
13
- constructor(seconds?: number | string, nanoseconds?: number | string);
13
+ constructor(seconds?: bigint, nanoseconds?: bigint);
14
14
 
15
15
  /**
16
16
  * Get the nanosecond component of the Duration.
17
17
  *
18
- * @returns The nanoseconds, if the value is greater than Number.MAX_SAFE_INTEGER (2^53-1),
19
- * will be presented in a string of decimal format.
18
+ * @returns The nanoseconds.
20
19
  */
21
- readonly nanoseconds: number | string;
20
+ readonly nanoseconds: bigint;
22
21
 
23
22
  /**
24
23
  * Test if this Duration is equal to another Duration.
package/types/node.d.ts CHANGED
@@ -267,7 +267,7 @@ declare module 'rclnodejs' {
267
267
  * @returns New instance of Timer.
268
268
  */
269
269
  createTimer(
270
- period: number,
270
+ period: bigint,
271
271
  callback: TimerRequestCallback,
272
272
  clock?: Clock
273
273
  ): Timer;
@@ -45,7 +45,7 @@ declare module 'rclnodejs' {
45
45
  *
46
46
  * @param name - The parameter name, must be a valid name.
47
47
  * @param type - The type identifier.
48
- * @param {value - The parameter value.
48
+ * @param value - The parameter value.
49
49
  */
50
50
  constructor(name: string, type: ParameterType, value?: any);
51
51
 
@@ -261,16 +261,15 @@ declare module 'rclnodejs' {
261
261
  /**
262
262
  *
263
263
  */
264
- class IntegerRange extends FloatingPointRange {
264
+ class IntegerRange extends Range {
265
265
  /**
266
266
  * Create a new instance.
267
267
  * @constructor
268
- * @param {number} fromValue - The lowest inclusive value in range
269
- * @param {number} toValue - The highest inclusive value in range
270
- * @param {number} step - The internal unit size.
271
- * @param {number} tolerance - The plus/minus tolerance for number equivalence.
268
+ * @param {bigint} fromValue - The lowest inclusive value in range
269
+ * @param {bigint} toValue - The highest inclusive value in range
270
+ * @param {bigint} step - The internal unit size.
272
271
  */
273
- constructor(from: number, to: number, step?: number, tolerance?: number);
272
+ constructor(from: bigint, to: bigint, step?: bigint);
274
273
 
275
274
  /**
276
275
  * Determine if a ParameterType is compatible.
package/types/time.d.ts CHANGED
@@ -14,11 +14,7 @@ declare module 'rclnodejs' {
14
14
  * @param nanoseconds - The nanoseconds component of the time, default = 0.
15
15
  * @param clockType - The clock type, default = Clock.ClockType.SYSTEM_TIME
16
16
  */
17
- constructor(
18
- seconds?: number | string,
19
- nanoseconds?: number | string,
20
- clockType?: ClockType
21
- );
17
+ constructor(seconds?: bigint, nanoseconds?: bigint, clockType?: ClockType);
22
18
 
23
19
  /**
24
20
  * Get the the clock type of the Time object.
@@ -27,15 +23,13 @@ declare module 'rclnodejs' {
27
23
 
28
24
  /**
29
25
  * Get the nanosecond part of the time.
30
- * If the value is greater than Number.MAX_SAFE_INTEGER (2^53-1) it
31
- * will be returned in a string of decimal format.
32
26
  */
33
- readonly nanoseconds: number | string;
27
+ readonly nanoseconds: bigint;
34
28
 
35
29
  /**
36
30
  * Get the time as a plain JavaScript object.
37
31
  */
38
- readonly secondsAndNanoseconds: { seconds: number; nanoseconds: number };
32
+ readonly secondsAndNanoseconds: { seconds: bigint; nanoseconds: bigint };
39
33
 
40
34
  /**
41
35
  * Add a duration to this time object.
package/types/timer.d.ts CHANGED
@@ -4,9 +4,9 @@ declare module 'rclnodejs' {
4
4
  */
5
5
  interface Timer {
6
6
  /**
7
- * Time between callbacks in milliseconds.
7
+ * Time between callbacks in nanoseconds.
8
8
  */
9
- readonly period: number;
9
+ readonly period: bigint;
10
10
 
11
11
  /**
12
12
  * Check if the timer is ready.
@@ -35,15 +35,15 @@ declare module 'rclnodejs' {
35
35
  /**
36
36
  * Get the interval since the last call of this timer.
37
37
  *
38
- * @returns The interval value in milliseconds.
38
+ * @returns The interval value in nanoseconds.
39
39
  */
40
- timeSinceLastCall(): number;
40
+ timeSinceLastCall(): bigint;
41
41
 
42
42
  /**
43
43
  * Get the interval until the next call will happen.
44
44
  *
45
- * @returns The interval value in milliseconds
45
+ * @returns The interval value in nanoseconds
46
46
  */
47
- timeUntilNextCall(): number;
47
+ timeUntilNextCall(): bigint;
48
48
  }
49
49
  }