rclnodejs 0.30.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.
package/README.md CHANGED
@@ -45,7 +45,7 @@ npm i rclnodejs@x.y.z
45
45
 
46
46
  | RCLNODEJS Version | Compatible ROS 2 LTS |
47
47
  | :------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------: |
48
- | latest version (currently [v0.30.0](https://github.com/RobotWebTools/rclnodejs/tree/0.30.0)) | [Humble](https://github.com/RobotWebTools/rclnodejs/tree/humble-hawksbill)<br>[Jazzy](https://github.com/RobotWebTools/rclnodejs/tree/jazzy) |
48
+ | latest version (currently [v0.31.0](https://github.com/RobotWebTools/rclnodejs/tree/0.31.0)) | [Humble](https://github.com/RobotWebTools/rclnodejs/tree/humble-hawksbill)<br>[Jazzy](https://github.com/RobotWebTools/rclnodejs/tree/jazzy) |
49
49
 
50
50
  ## Documentation
51
51
 
@@ -266,10 +266,12 @@ class ActionServer extends Entity {
266
266
  let goalHandle;
267
267
  if (accepted) {
268
268
  // Stamp time of acceptance
269
- const secondsAndNanos = this._node.getClock().now().secondsAndNanoseconds;
269
+ const { seconds, nanoseconds } = this._node
270
+ .getClock()
271
+ .now().secondsAndNanoseconds;
270
272
  goalInfo.stamp = {
271
- sec: secondsAndNanos.seconds,
272
- nanosec: secondsAndNanos.nanoseconds,
273
+ sec: Number(seconds),
274
+ nanosec: Number(nanoseconds),
273
275
  };
274
276
 
275
277
  try {
package/lib/clock.js CHANGED
@@ -52,8 +52,8 @@ class Clock {
52
52
  * @return {Time} Return the current time.
53
53
  */
54
54
  now() {
55
- let time = rclnodejs.clockGetNow(this._handle);
56
- return new Time(time.sec, time.nanosec, this._clockType);
55
+ const nowInNanosec = rclnodejs.clockGetNow(this._handle);
56
+ return new Time(0n, nowInNanosec, this._clockType);
57
57
  }
58
58
  }
59
59
 
package/lib/duration.js CHANGED
@@ -15,7 +15,7 @@
15
15
  'use strict';
16
16
 
17
17
  const rclnodejs = require('bindings')('rclnodejs');
18
- const int64 = require('int64-napi');
18
+ const S_TO_NS = 10n ** 9n;
19
19
 
20
20
  /**
21
21
  * @class - Class representing a Duration in ROS
@@ -24,51 +24,38 @@ const int64 = require('int64-napi');
24
24
  class Duration {
25
25
  /**
26
26
  * Create a Duration.
27
- * @param {number|string} [seconds=0] - The second part of the duration.
28
- * @param {number|string} [nanoseconds=0] - The nanosecond part of the duration.
27
+ * @param {bigint} [seconds=0] - The second part of the duration.
28
+ * @param {bigint} [nanoseconds=0] - The nanosecond part of the duration.
29
29
  */
30
- constructor(seconds = 0, nanoseconds = 0) {
31
- if (typeof seconds !== 'number' && typeof seconds !== 'string') {
30
+ constructor(seconds = 0n, nanoseconds = 0n) {
31
+ if (typeof seconds !== 'bigint') {
32
32
  throw new TypeError('Invalid argument of seconds');
33
33
  }
34
34
 
35
- if (typeof nanoseconds !== 'number' && typeof nanoseconds !== 'string') {
35
+ if (typeof nanoseconds !== 'bigint') {
36
36
  throw new TypeError('Invalid argument of nanoseconds');
37
37
  }
38
38
 
39
- let secondInt64 = int64.from(seconds);
40
- let nanoInt64 = int64.from(nanoseconds);
41
-
42
- if (typeof seconds === 'string' && seconds.startsWith('-')) {
43
- secondInt64 = int64.negative(secondInt64);
44
- }
45
- if (typeof nanoseconds === 'string' && nanoseconds.startsWith('-')) {
46
- nanoInt64 = int64.negative(nanoInt64);
39
+ const total = seconds * S_TO_NS + nanoseconds;
40
+ if (total >= 2n ** 63n) {
41
+ throw new RangeError(
42
+ 'Total nanoseconds value is too large to store in C time point.'
43
+ );
47
44
  }
48
- this._nanoseconds = secondInt64.multiply(1e9).add(nanoInt64);
49
- this._handle = rclnodejs.createDuration(this._nanoseconds.toString());
45
+
46
+ this._nanoseconds = total;
47
+ this._handle = rclnodejs.createDuration(this._nanoseconds);
50
48
  }
51
49
 
52
50
  /**
53
51
  * Get the nanosecond part of the Duration.
54
52
  * @name Duration#get:nanoseconds
55
53
  * @function
56
- * @return {number|string} - value in nanosecond, if the value is greater than Number.MAX_SAFE_INTEGER (2^53-1), will be presented in string of decimal format.
54
+ * @return {bigint} - value in nanosecond.
57
55
  */
58
56
 
59
57
  get nanoseconds() {
60
- let nanoStr = rclnodejs.getDurationNanoseconds(this._handle);
61
- let nano;
62
-
63
- if (nanoStr.startsWith('-')) {
64
- nano = int64.negative(int64.from(nanoStr));
65
- } else {
66
- nano = int64.from(nanoStr);
67
- }
68
- if (Number.isFinite(nano.toNumber())) {
69
- return nano.toNumber();
70
- }
71
- return nano.toString();
58
+ return rclnodejs.getDurationNanoseconds(this._handle);
72
59
  }
73
60
 
74
61
  /**
@@ -78,7 +65,7 @@ class Duration {
78
65
  */
79
66
  eq(other) {
80
67
  if (other instanceof Duration) {
81
- return this._nanoseconds.eq(other.nanoseconds);
68
+ return this._nanoseconds === other.nanoseconds;
82
69
  }
83
70
  throw new TypeError(
84
71
  `Can't compare duration with object of type: ${other.constructor.name}`
@@ -92,7 +79,7 @@ class Duration {
92
79
  */
93
80
  ne(other) {
94
81
  if (other instanceof Duration) {
95
- return this._nanoseconds.ne(other.nanoseconds);
82
+ return this._nanoseconds !== other.nanoseconds;
96
83
  }
97
84
  throw new TypeError('Invalid argument');
98
85
  }
@@ -104,7 +91,7 @@ class Duration {
104
91
  */
105
92
  lt(other) {
106
93
  if (other instanceof Duration) {
107
- return this._nanoseconds.lt(other.nanoseconds);
94
+ return this._nanoseconds < other.nanoseconds;
108
95
  }
109
96
  throw new TypeError('Invalid argument');
110
97
  }
@@ -116,7 +103,7 @@ class Duration {
116
103
  */
117
104
  lte(other) {
118
105
  if (other instanceof Duration) {
119
- return this._nanoseconds.lte(other.nanoseconds);
106
+ return this._nanoseconds <= other.nanoseconds;
120
107
  }
121
108
  throw new TypeError('Invalid argument');
122
109
  }
@@ -128,7 +115,7 @@ class Duration {
128
115
  */
129
116
  gt(other) {
130
117
  if (other instanceof Duration) {
131
- return this._nanoseconds.gt(other.nanoseconds);
118
+ return this._nanoseconds > other.nanoseconds;
132
119
  }
133
120
  throw new TypeError('Invalid argument');
134
121
  }
@@ -140,7 +127,7 @@ class Duration {
140
127
  */
141
128
  gte(other) {
142
129
  if (other instanceof Duration) {
143
- return this._nanoseconds.gte(other.nanoseconds);
130
+ return this._nanoseconds >= other.nanoseconds;
144
131
  }
145
132
  throw new TypeError('Invalid argument');
146
133
  }
package/lib/node.js CHANGED
@@ -507,7 +507,7 @@ class Node extends rclnodejs.ShadowNode {
507
507
 
508
508
  /**
509
509
  * Create a Timer.
510
- * @param {number} period - The number representing period in millisecond.
510
+ * @param {bigint} period - The number representing period in nanoseconds.
511
511
  * @param {function} callback - The callback to be called when timeout.
512
512
  * @param {Clock} [clock] - The clock which the timer gets time from.
513
513
  * @return {Timer} - An instance of Timer.
@@ -519,22 +519,11 @@ class Node extends rclnodejs.ShadowNode {
519
519
  clock = arguments[3];
520
520
  }
521
521
 
522
- if (typeof period !== 'number' || typeof callback !== 'function') {
522
+ if (typeof period !== 'bigint' || typeof callback !== 'function') {
523
523
  throw new TypeError('Invalid argument');
524
524
  }
525
525
 
526
- // The period unit is millisecond in JavaScript side. When being passed to the
527
- // C++ side, the value will be converted to nanosecond, which goes into a uint64_t
528
- // with maxmium value of 2^64-1. So the maxmium is UINT64_MAX in ns, that's 0x10c6f7a0b5ed in ms.
529
- const MAX_TIMER_PERIOD_IN_MILLISECOND = 0x10c6f7a0b5ed;
530
- if (period > 0x10c6f7a0b5ed || period < 0) {
531
- throw new RangeError(
532
- `Parameter must be between 0.0 and ${MAX_TIMER_PERIOD_IN_MILLISECOND}`
533
- );
534
- }
535
-
536
526
  const timerClock = clock || this._clock;
537
-
538
527
  let timerHandle = rclnodejs.createTimer(
539
528
  timerClock.handle,
540
529
  this.context.handle,
@@ -573,7 +562,7 @@ class Node extends rclnodejs.ShadowNode {
573
562
  }
574
563
 
575
564
  const period = Math.round(1000 / hz);
576
- const timer = this._rateTimerServer.createTimer(period);
565
+ const timer = this._rateTimerServer.createTimer(BigInt(period) * 1000000n);
577
566
  const rate = new Rates.Rate(hz, timer);
578
567
 
579
568
  return rate;
@@ -1480,10 +1469,10 @@ class Node extends rclnodejs.ShadowNode {
1480
1469
  PARAMETER_EVENT_MSG_TYPE
1481
1470
  ))();
1482
1471
 
1483
- const secondsAndNanos = this._clock.now().secondsAndNanoseconds;
1472
+ const { seconds, nanoseconds } = this._clock.now().secondsAndNanoseconds;
1484
1473
  parameterEvent.stamp = {
1485
- sec: secondsAndNanos.seconds,
1486
- nanosec: secondsAndNanos.nanoseconds,
1474
+ sec: Number(seconds),
1475
+ nanosec: Number(nanoseconds),
1487
1476
  };
1488
1477
 
1489
1478
  parameterEvent.node =
package/lib/rate.js CHANGED
@@ -166,7 +166,7 @@ class RateTimerServer {
166
166
  /**
167
167
  * Create a new timer instance with callback set to NOP.
168
168
  *
169
- * @param {number} period - The period in milliseconds
169
+ * @param {bigint} period - The period in nanoseconds.
170
170
  * @returns {Timer} - The new timer instance.
171
171
  */
172
172
  createTimer(period) {
package/lib/time.js CHANGED
@@ -17,7 +17,7 @@
17
17
  const rclnodejs = require('bindings')('rclnodejs');
18
18
  const Duration = require('./duration.js');
19
19
  const ClockType = require('./clock_type.js');
20
- const int64 = require('int64-napi');
20
+ const S_TO_NS = 10n ** 9n;
21
21
 
22
22
  /**
23
23
  * @class - Class representing a Time in ROS
@@ -26,16 +26,20 @@ const int64 = require('int64-napi');
26
26
  class Time {
27
27
  /**
28
28
  * Create a Time.
29
- * @param {number|string} [seconds=0] - The second part of the time.
30
- * @param {number|string} [nanoseconds=0] - The nanosecond part of the time.
29
+ * @param {bigint} [seconds=0] - The second part of the time.
30
+ * @param {bigint} [nanoseconds=0] - The nanosecond part of the time.
31
31
  * @param {ClockType} [clockType=Clock.ClockType.SYSTEM_TIME] - The clock type.
32
32
  */
33
- constructor(seconds = 0, nanoseconds = 0, clockType = ClockType.SYSTEM_TIME) {
34
- if (typeof seconds !== 'number' && typeof seconds !== 'string') {
33
+ constructor(
34
+ seconds = 0n,
35
+ nanoseconds = 0n,
36
+ clockType = ClockType.SYSTEM_TIME
37
+ ) {
38
+ if (typeof seconds !== 'bigint') {
35
39
  throw new TypeError('Invalid argument of seconds');
36
40
  }
37
41
 
38
- if (typeof nanoseconds !== 'number' && typeof nanoseconds !== 'string') {
42
+ if (typeof nanoseconds !== 'bigint') {
39
43
  throw new TypeError('Invalid argument of nanoseconds');
40
44
  }
41
45
 
@@ -43,25 +47,22 @@ class Time {
43
47
  throw new TypeError('Invalid argument of clockType');
44
48
  }
45
49
 
46
- if (
47
- int64.lt(seconds, 0) ||
48
- (typeof seconds === 'string' && seconds.startsWith('-'))
49
- ) {
50
+ if (seconds < 0n) {
50
51
  throw new RangeError('seconds value must not be negative');
51
52
  }
52
53
 
53
- if (
54
- int64.lt(nanoseconds, 0) ||
55
- (typeof nanoseconds === 'string' && nanoseconds.startsWith('-'))
56
- ) {
54
+ if (nanoseconds < 0n) {
57
55
  throw new RangeError('nanoseconds value must not be negative');
58
56
  }
59
57
 
60
- this._nanoseconds = int64.from(seconds).multiply(1e9).add(nanoseconds);
61
- this._handle = rclnodejs.createTimePoint(
62
- this._nanoseconds.toString(),
63
- clockType
64
- );
58
+ const total = seconds * S_TO_NS + nanoseconds;
59
+ if (total >= 2n ** 63n) {
60
+ throw new RangeError(
61
+ 'Total nanoseconds value is too large to store in C time point.'
62
+ );
63
+ }
64
+ this._nanoseconds = total;
65
+ this._handle = rclnodejs.createTimePoint(this._nanoseconds, clockType);
65
66
  this._clockType = clockType;
66
67
  }
67
68
 
@@ -80,22 +81,11 @@ class Time {
80
81
  * Get the nanosecond part of the time.
81
82
  * @name Time#get:nanoseconds
82
83
  * @function
83
- * @return {number|string} - value in nanosecond, if the value is greater than Number.MAX_SAFE_INTEGER (2^53-1), will be presented in string of decimal format.
84
+ * @return {bigint} - value in nanosecond.
84
85
  */
85
86
 
86
87
  get nanoseconds() {
87
- let str = rclnodejs.getNanoseconds(this._handle);
88
- let nano;
89
-
90
- if (str.startsWith('-')) {
91
- nano = int64.negative(int64.from(str));
92
- } else {
93
- nano = int64.from(str);
94
- }
95
- if (Number.isFinite(nano.toNumber())) {
96
- return nano.toNumber();
97
- }
98
- return nano.toString();
88
+ return rclnodejs.getNanoseconds(this._handle);
99
89
  }
100
90
 
101
91
  /**
@@ -106,9 +96,11 @@ class Time {
106
96
  */
107
97
 
108
98
  get secondsAndNanoseconds() {
109
- const seconds = int64.from(this._nanoseconds).divide(1e9).toNumber();
110
- const nanoseconds = int64.from(this._nanoseconds).mod(1e9).toNumber();
111
- return { seconds, nanoseconds };
99
+ const nanoseconds = this._nanoseconds;
100
+ return {
101
+ seconds: nanoseconds / S_TO_NS,
102
+ nanoseconds: nanoseconds % S_TO_NS,
103
+ };
112
104
  }
113
105
 
114
106
  /**
@@ -119,8 +111,8 @@ class Time {
119
111
  add(other) {
120
112
  if (other instanceof Duration) {
121
113
  return new Time(
122
- 0,
123
- int64.add(this._nanoseconds, other.nanoseconds).toString(),
114
+ 0n,
115
+ this._nanoseconds + other.nanoseconds,
124
116
  this._clockType
125
117
  );
126
118
  }
@@ -137,14 +129,11 @@ class Time {
137
129
  if (other._clockType !== this._clockType) {
138
130
  throw new TypeError("Can't subtract times with different clock types");
139
131
  }
140
- return new Duration(
141
- 0,
142
- int64.subtract(this._nanoseconds, other._nanoseconds).toString()
143
- );
132
+ return new Duration(0n, this._nanoseconds - other._nanoseconds);
144
133
  } else if (other instanceof Duration) {
145
134
  return new Time(
146
- 0,
147
- int64.subtract(this._nanoseconds, other._nanoseconds).toString(),
135
+ 0n,
136
+ this._nanoseconds - other._nanoseconds,
148
137
  this._clockType
149
138
  );
150
139
  }
@@ -161,7 +150,7 @@ class Time {
161
150
  if (other._clockType !== this._clockType) {
162
151
  throw new TypeError("Can't compare times with different clock types");
163
152
  }
164
- return this._nanoseconds.eq(other.nanoseconds);
153
+ return this._nanoseconds === other.nanoseconds;
165
154
  }
166
155
  throw new TypeError('Invalid argument');
167
156
  }
@@ -176,7 +165,7 @@ class Time {
176
165
  if (other._clockType !== this._clockType) {
177
166
  throw new TypeError("Can't compare times with different clock types");
178
167
  }
179
- return this._nanoseconds.ne(other.nanoseconds);
168
+ return this._nanoseconds !== other.nanoseconds;
180
169
  }
181
170
  }
182
171
 
@@ -190,7 +179,7 @@ class Time {
190
179
  if (other._clockType !== this._clockType) {
191
180
  throw new TypeError("Can't compare times with different clock types");
192
181
  }
193
- return this._nanoseconds.lt(other.nanoseconds);
182
+ return this._nanoseconds < other.nanoseconds;
194
183
  }
195
184
  throw new TypeError('Invalid argument');
196
185
  }
@@ -205,7 +194,7 @@ class Time {
205
194
  if (other._clockType !== this._clockType) {
206
195
  throw new TypeError("Can't compare times with different clock types");
207
196
  }
208
- return this._nanoseconds.lte(other.nanoseconds);
197
+ return this._nanoseconds <= other.nanoseconds;
209
198
  }
210
199
  throw new TypeError('Invalid argument');
211
200
  }
@@ -220,7 +209,7 @@ class Time {
220
209
  if (other._clockType !== this._clockType) {
221
210
  throw new TypeError("Can't compare times with different clock types");
222
211
  }
223
- return this._nanoseconds.gt(other.nanoseconds);
212
+ return this._nanoseconds > other.nanoseconds;
224
213
  }
225
214
  throw new TypeError('Invalid argument');
226
215
  }
@@ -235,7 +224,7 @@ class Time {
235
224
  if (other._clockType !== this._clockType) {
236
225
  throw new TypeError("Can't compare times with different clock types");
237
226
  }
238
- return this._nanoseconds.gte(other.nanoseconds);
227
+ return this._nanoseconds >= other.nanoseconds;
239
228
  }
240
229
  throw new TypeError('Invalid argument');
241
230
  }
@@ -261,7 +250,7 @@ class Time {
261
250
  * @return {Time} Return the created Time object.
262
251
  */
263
252
  static fromMsg(msg, clockType = ClockType.ROS_TIME) {
264
- return new Time(msg.sec, msg.nanosec, clockType);
253
+ return new Time(BigInt(msg.sec), BigInt(msg.nanosec), clockType);
265
254
  }
266
255
  }
267
256
 
@@ -37,7 +37,7 @@ class TimeSource {
37
37
  this._node = node;
38
38
  this._associatedClocks = [];
39
39
  this._clockSubscription = undefined;
40
- this._lastTimeSet = new Time(0, 0, ClockType.ROS_TIME);
40
+ this._lastTimeSet = new Time(0n, 0n, ClockType.ROS_TIME);
41
41
  this._isRosTimeActive = false;
42
42
 
43
43
  if (this._node) {
package/lib/timer.js CHANGED
@@ -29,7 +29,7 @@ class Timer {
29
29
  }
30
30
 
31
31
  /**
32
- * @type {number}
32
+ * @type {bigint} - The period of the timer in nanoseconds.
33
33
  */
34
34
  get period() {
35
35
  return this._period;
@@ -73,18 +73,18 @@ class Timer {
73
73
 
74
74
  /**
75
75
  * Get the interval since the last call of this timer.
76
- * @return {number} - the interval value - ms.
76
+ * @return {bigint} - the interval value in nanoseconds.
77
77
  */
78
78
  timeSinceLastCall() {
79
- return parseInt(rclnodejs.timerGetTimeSinceLastCall(this._handle), 10);
79
+ return rclnodejs.timerGetTimeSinceLastCall(this._handle);
80
80
  }
81
81
 
82
82
  /**
83
83
  * Get the interval until the next call will happen.
84
- * @return {number} - the interval value - ms.
84
+ * @return {bigint} - the interval value in nanoseconds.
85
85
  */
86
86
  timeUntilNextCall() {
87
- return parseInt(rclnodejs.timerGetTimeUntilNextCall(this._handle), 10);
87
+ return rclnodejs.timerGetTimeUntilNextCall(this._handle);
88
88
  }
89
89
  }
90
90
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rclnodejs",
3
- "version": "0.30.0",
3
+ "version": "0.31.0",
4
4
  "description": "ROS2.0 JavaScript client with Node.js",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -63,7 +63,6 @@
63
63
  "tree-kill": "^1.2.2",
64
64
  "typescript": "^5.7.2"
65
65
  },
66
- "//": "Pin int64-napi to ^1.0.2",
67
66
  "dependencies": {
68
67
  "@rclnodejs/ref-array-di": "^1.2.2",
69
68
  "@rclnodejs/ref-napi": "^4.0.0",
@@ -76,7 +75,6 @@
76
75
  "dtslint": "^4.2.1",
77
76
  "fs-extra": "^11.2.0",
78
77
  "json-bigint": "^1.0.0",
79
- "int64-napi": "^1.0.2",
80
78
  "is-close": "^1.3.3",
81
79
  "mkdirp": "^3.0.1",
82
80
  "mz": "^2.7.0",
@@ -45,7 +45,7 @@ npm i rclnodejs@x.y.z
45
45
 
46
46
  | RCLNODEJS Version | Compatible ROS 2 LTS |
47
47
  | :------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------: |
48
- | latest version (currently [v0.30.0](https://github.com/RobotWebTools/rclnodejs/tree/0.30.0)) | [Humble](https://github.com/RobotWebTools/rclnodejs/tree/humble-hawksbill)<br>[Jazzy](https://github.com/RobotWebTools/rclnodejs/tree/jazzy) |
48
+ | latest version (currently [v0.31.0](https://github.com/RobotWebTools/rclnodejs/tree/0.31.0)) | [Humble](https://github.com/RobotWebTools/rclnodejs/tree/humble-hawksbill)<br>[Jazzy](https://github.com/RobotWebTools/rclnodejs/tree/jazzy) |
49
49
 
50
50
  ## Documentation
51
51
 
@@ -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;
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
  }