rclnodejs 0.20.1 → 0.21.2

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.
@@ -0,0 +1,44 @@
1
+ name: Identify ROS Distro from GITHUB_REF_NAME
2
+
3
+ on:
4
+ workflow_call:
5
+ outputs:
6
+ distro:
7
+ description: "The ROS distribution short name"
8
+ value: ${{ jobs.identify-ros-distro.outputs.distro }}
9
+ linuxos:
10
+ description: "The ROS compatible Linux version"
11
+ value: ${{ jobs.identify-ros-distro.outputs.linuxos }}
12
+ env:
13
+ ROLLING_VAR: ${{ contains(github.ref, 'develop') }}
14
+ HUMBLE_VAR: ${{ contains(github.ref, 'humble') }}
15
+ GALACTIC_VAR: ${{ contains(github.ref, 'galactic') }}
16
+ FOXY_VAR: ${{ contains(github.ref, 'foxy') }}
17
+
18
+ jobs:
19
+ identify-ros-distro:
20
+ runs-on: ubuntu-latest
21
+ outputs:
22
+ distro: ${{ steps.identify.outputs.distro }}
23
+ linuxos: ${{ steps.identify.outputs.linuxos }}
24
+ steps:
25
+ - name: Identify distro
26
+ id: identify
27
+ run: |
28
+ if ${ROLLING_VAR} == true; then
29
+ echo "::set-output name=distro::rolling"
30
+ echo "::set-output name=linuxos::ubuntu-22.04"
31
+ elif ${HUMBLE_VAR} == true; then
32
+ echo "::set-output name=distro::humble"
33
+ echo "::set-output name=linuxos::ubuntu-22.04"
34
+ elif ${GALACTIC_VAR} == true; then
35
+ echo "::set-output name=distro::galactic"
36
+ echo "::set-output name=linuxos::ubuntu-20.04"
37
+ elif ${FOXY_VAR} == true; then
38
+ echo "::set-output name=distro::foxy"
39
+ echo "::set-output name=linuxos::ubuntu-20.04"
40
+ else
41
+ echo "Unable to map branch name to ROS distro, using ROLLING as default"
42
+ echo "::set-output name=distro::rolling"
43
+ echo "::set-output name=linuxos::ubuntu-22.04"
44
+ fi
@@ -0,0 +1,67 @@
1
+ on:
2
+ workflow_dispatch:
3
+
4
+ jobs:
5
+ build-humble-and-rolling: # humble and rolling distros
6
+ runs-on: ubuntu-22.04
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ node-version: [10.X, 12.x, 14.X, 16.X, 17.X]
11
+ ros_distribution:
12
+ - humble
13
+ - rolling
14
+
15
+ steps:
16
+ - name: Setup ROS2
17
+ uses: ros-tooling/setup-ros@v0.3
18
+ with:
19
+ required-ros-distributions: ${{ matrix.ros_distribution }}
20
+
21
+ - name: Install test-msgs on Linux
22
+ run: |
23
+ sudo apt install ros-${{ matrix.ros_distribution }}-test-msgs
24
+ - uses: actions/checkout@v3
25
+
26
+ - name: Setup Node.js ${{ matrix.node-version }}
27
+ uses: actions/setup-node@v2
28
+ with:
29
+ node-version: ${{ matrix.node-version }}
30
+
31
+ - name: Build and test rclnodejs
32
+ run: |
33
+ source /opt/ros/${{ matrix.ros_distribution }}/setup.bash
34
+ npm i
35
+ npm test
36
+
37
+ build-foxy-and-galactic: # foxy and galactic distros
38
+ runs-on: ubuntu-20.04
39
+ strategy:
40
+ fail-fast: false
41
+ matrix:
42
+ node-version: [10.X, 12.x, 14.X, 16.X, 17.X]
43
+ ros_distribution:
44
+ - foxy
45
+ - galactic
46
+
47
+ steps:
48
+ - name: Setup ROS2
49
+ uses: ros-tooling/setup-ros@v0.3
50
+ with:
51
+ required-ros-distributions: ${{ matrix.ros_distribution }}
52
+
53
+ - name: Install test-msgs on Linux
54
+ run: |
55
+ sudo apt install ros-${{ matrix.ros_distribution }}-test-msgs
56
+ - uses: actions/checkout@v3
57
+
58
+ - name: Setup Node.js ${{ matrix.node-version }}
59
+ uses: actions/setup-node@v2
60
+ with:
61
+ node-version: ${{ matrix.node-version }}
62
+
63
+ - name: Build and test rclnodejs
64
+ run: |
65
+ source /opt/ros/${{ matrix.ros_distribution }}/setup.bash
66
+ npm i
67
+ npm test
@@ -0,0 +1,51 @@
1
+
2
+ name: rclnodejs - Linux Build and Test
3
+
4
+ on:
5
+ push:
6
+ branches:
7
+ - develop
8
+ - humble-hawksbill
9
+ - galactic-geochelone
10
+ - foxy-fitzroy
11
+ pull_request:
12
+ branches:
13
+ - develop
14
+ - humble-hawksbill
15
+ - galactic-geochelone
16
+ - foxy-fitzroy
17
+ workflow_dispatch:
18
+
19
+ jobs:
20
+ identify-ros-distro:
21
+ uses: ./.github/workflows/identify-ros-distro.yml
22
+
23
+ build:
24
+ needs: identify-ros-distro
25
+ runs-on: ${{ needs.identify-ros-distro.outputs.linuxos }}
26
+ strategy:
27
+ fail-fast: false
28
+ matrix:
29
+ node-version: [10.X, 12.X, 14.X, 16.11.X, 17.X]
30
+ steps:
31
+ - name: Setup Node.js ${{ matrix.node-version }}
32
+ uses: actions/setup-node@v2
33
+ with:
34
+ node-version: ${{ matrix.node-version }}
35
+
36
+ - name: Setup ROS2
37
+ uses: ros-tooling/setup-ros@v0.3
38
+ with:
39
+ required-ros-distributions: ${{ needs.identify-ros-distro.outputs.distro }}
40
+
41
+ - name: Install test-msgs on Linux
42
+ run: |
43
+ sudo apt install ros-${{ needs.identify-ros-distro.outputs.distro }}-test-msgs
44
+
45
+ - uses: actions/checkout@v3
46
+
47
+ - name: Build and test rclnodejs
48
+ run: |
49
+ source /opt/ros/${{ needs.identify-ros-distro.outputs.distro }}/setup.bash
50
+ npm i
51
+ npm test
@@ -0,0 +1,52 @@
1
+
2
+ name: rclnodejs - Windows Build & Test Compatibility
3
+
4
+ on:
5
+ workflow_dispatch:
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: windows-2019
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ node-version: [10.X, 12.X, 14.X, 16.11.X, 17.X]
14
+ ros_distribution:
15
+ - foxy
16
+ - galactic
17
+ - humble
18
+ - rolling
19
+ steps:
20
+ - name: Setup Node.js ${{ matrix.node-version }}
21
+ uses: actions/setup-node@v2
22
+ with:
23
+ node-version: ${{ matrix.node-version }}
24
+
25
+ - name: Setup ROS2
26
+ uses: ros-tooling/setup-ros@v0.3
27
+ with:
28
+ required-ros-distributions: ${{ matrix.ros_distribution }}
29
+
30
+ - name: Install ROS2 Rolling (Conditional)
31
+ if: ${{ matrix.ros_distribution == 'rolling' }}
32
+ shell: bash
33
+ run: |
34
+ wget --quiet https://ci.ros2.org/view/packaging/job/packaging_windows/lastSuccessfulBuild/artifact/ws/ros2-package-windows-AMD64.zip -O rolling.zip
35
+ 7z x rolling.zip -y -o/c/dev/rolling
36
+
37
+ - name: Prebuild - Setup VS Dev Environment
38
+ uses: seanmiddleditch/gha-setup-vsdevenv@v4
39
+
40
+ - uses: actions/checkout@v3
41
+
42
+ - name: Build rclnodejs
43
+ shell: cmd
44
+ run: |
45
+ call "c:\dev\${{ matrix.ros_distribution }}\ros2-windows\setup.bat"
46
+ npm i
47
+
48
+ - name: Test rclnodejs
49
+ shell: cmd
50
+ run: |
51
+ call "c:\dev\${{ needs.identify-ros-distro.outputs.distro }}\ros2-windows\setup.bat"
52
+ npm test
@@ -0,0 +1,63 @@
1
+
2
+ name: rclnodejs - Windows Build & Test
3
+
4
+ on:
5
+ push:
6
+ branches:
7
+ - develop
8
+ - humble-hawksbill
9
+ - galactic-geochelone
10
+ - foxy-fitzroy
11
+ pull_request:
12
+ branches:
13
+ - develop
14
+ - humble-hawksbill
15
+ - galactic-geochelone
16
+ - foxy-fitzroy
17
+ workflow_dispatch:
18
+
19
+ jobs:
20
+ identify-ros-distro:
21
+ uses: ./.github/workflows/identify-ros-distro.yml
22
+
23
+ build:
24
+ needs: identify-ros-distro
25
+ runs-on: windows-2019
26
+ strategy:
27
+ fail-fast: false
28
+ matrix:
29
+ node-version: [10.X, 12.X, 14.X, 16.11.X, 17.X]
30
+ steps:
31
+ - name: Setup Node.js ${{ matrix.node-version }}
32
+ uses: actions/setup-node@v2
33
+ with:
34
+ node-version: ${{ matrix.node-version }}
35
+
36
+ - name: Setup ROS2
37
+ uses: ros-tooling/setup-ros@v0.3
38
+ with:
39
+ required-ros-distributions: ${{ needs.identify-ros-distro.outputs.distro }}
40
+
41
+ - name: Install ROS2 Rolling (Conditional)
42
+ if: ${{ needs.identify-ros-distro.outputs.distro == 'rolling' }}
43
+ shell: bash
44
+ run: |
45
+ wget --quiet https://ci.ros2.org/view/packaging/job/packaging_windows/lastSuccessfulBuild/artifact/ws/ros2-package-windows-AMD64.zip -O rolling.zip
46
+ 7z x rolling.zip -y -o/c/dev/rolling
47
+
48
+ - name: Prebuild - Setup VS Dev Environment
49
+ uses: seanmiddleditch/gha-setup-vsdevenv@v4
50
+
51
+ - uses: actions/checkout@v3
52
+
53
+ - name: Build rclnodejs
54
+ shell: cmd
55
+ run: |
56
+ call "c:\dev\${{ needs.identify-ros-distro.outputs.distro }}\ros2-windows\setup.bat"
57
+ npm i
58
+
59
+ - name: Test rclnodejs
60
+ shell: cmd
61
+ run: |
62
+ call "c:\dev\${{ needs.identify-ros-distro.outputs.distro }}\ros2-windows\setup.bat"
63
+ npm test
package/README.md CHANGED
@@ -18,7 +18,7 @@ rclnodejs.init().then(() => {
18
18
 
19
19
  **Node.js**
20
20
 
21
- - [Node.js](https://nodejs.org/en/) version between 8.12 - 12.x.
21
+ - [Node.js](https://nodejs.org/en/) version between 10.23 - 17.x.
22
22
 
23
23
  **ROS 2 SDK**
24
24
 
@@ -43,10 +43,10 @@ npm i rclnodejs@x.y.z
43
43
 
44
44
  #### RCLNODEJS - ROS 2 Version Compatibility
45
45
 
46
- | RCLNODEJS Version | Compatible ROS 2 Release |
47
- | :-------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
48
- | [0.20.1 (current)](https://www.npmjs.com/package/rclnodejs/v/0.20.1) ([API](http://robotwebtools.org/rclnodejs/docs/0.20.0/index.html)) | [Galactic Geochelone](https://github.com/ros2/ros2/releases/tag/release-galactic-20210716) / [Foxy Fitzroy](https://github.com/ros2/ros2/releases/tag/release-foxy-20201211) / [Eloquent Elusor](https://github.com/ros2/ros2/releases/tag/release-eloquent-20200124) |
49
- | [0.10.3](https://github.com/RobotWebTools/rclnodejs/releases/tag/0.10.3) | [Dashing Diademata - Patch 4](https://github.com/ros2/ros2/releases/tag/release-dashing-20191018) |
46
+ | RCLNODEJS Version | Compatible ROS 2 Release |
47
+ | :-------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
48
+ | [0.21.2 (current)](https://www.npmjs.com/package/rclnodejs/v/0.21.2) ([API](http://robotwebtools.org/rclnodejs/docs/0.21.0/index.html)) | [Humble Hawksbill](https://github.com/ros2/ros2/releases/tag/release-humble-20220523)<br>[Galactic Geochelone](https://github.com/ros2/ros2/releases/tag/release-galactic-20210716)<br>[Foxy Fitzroy](https://github.com/ros2/ros2/releases/tag/release-foxy-20201211)<br>[Eloquent Elusor](https://github.com/ros2/ros2/releases/tag/release-eloquent-20200124) |
49
+ | [0.10.3](https://github.com/RobotWebTools/rclnodejs/releases/tag/0.10.3) | [Dashing Diademata - Patch 4](https://github.com/ros2/ros2/releases/tag/release-dashing-20191018) |
50
50
 
51
51
  ## Documentation
52
52
 
package/binding.gyp CHANGED
@@ -8,7 +8,7 @@
8
8
  }
9
9
  },
10
10
  'variables': {
11
- 'ros_version': '<!(node scripts/ros_distro.js)'
11
+ 'ros_version': '<!(node scripts/ros_distro.js)',
12
12
  },
13
13
  'targets': [
14
14
  {
@@ -61,12 +61,36 @@
61
61
  'cflags_cc': [
62
62
  '-std=c++14'
63
63
  ],
64
- 'include_dirs': [
64
+ 'include_dirs':
65
+ [
65
66
  "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/ ') + '/include/')\")",
66
67
  ],
67
68
  'library_dirs': [
68
69
  "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/lib/ ') + '/lib/')\")",
69
70
  ],
71
+ 'conditions': [
72
+ [
73
+ 'ros_version > 2105', # Humble, Rolling, ...
74
+ {
75
+ 'include_dirs':
76
+ [
77
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/ ') + '/include/')\")",
78
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/rcl/ ') + '/include/rcl')\")",
79
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/rcutils/ ') + '/include/rcutils/')\")",
80
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/rmw/ ') + '/include/rmw/')\")",
81
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/rcl_yaml_param_parser/ ') + '/include/rcl_yaml_param_parser/')\")",
82
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/rosidl_typesupport_interface/ ') + '/include/rosidl_typesupport_interface/')\")",
83
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/rcl_action/ ') + '/include/rcl_action/')\")",
84
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/action_msgs/ ') + '/include/action_msgs/')\")",
85
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/unique_identifier_msgs/ ') + '/include/unique_identifier_msgs/')\")",
86
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/builtin_interfaces/ ') + '/include/builtin_interfaces/')\")",
87
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/rcl_lifecycle/ ') + '/include/rcl_lifecycle/')\")",
88
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/lifecycle_msgs/ ') + '/include/lifecycle_msgs/')\")",
89
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/:/g, '/include/rosidl_runtime_c/ ') + '/include/rosidl_runtime_c/')\")",
90
+ ],
91
+ }
92
+ ],
93
+ ],
70
94
  }
71
95
  ],
72
96
  [
@@ -80,7 +104,7 @@
80
104
  ],
81
105
  'include_dirs': [
82
106
  './src/third_party/dlfcn-win32/',
83
- "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '\\\include ').replace(/\\\/g, '/') + '/include')\")",
107
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include ').replace(/\\\/g, '/') + '/include')\")",
84
108
  ],
85
109
  'msvs_settings': {
86
110
  'VCCLCompilerTool': {
@@ -90,11 +114,34 @@
90
114
  'AdditionalDependencies': ['psapi.lib'],
91
115
  'AdditionalLibraryDirectories': ["<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '\\\lib ').replace(/\\\/g, '/') + '/lib')\")",],
92
116
  }
93
- }
117
+ },
118
+ 'conditions': [
119
+ [
120
+ 'ros_version > 2105', # Humble, Rolling, ... TODO - not tested due to broken setup_ros v3.3 action on windows
121
+ {
122
+ 'include_dirs':
123
+ [
124
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/rcl ').replace(/\\\/g, '/') + '/include/rcl')\")",
125
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/rcutils ').replace(/\\\/g, '/') + '/include/rcutils')\")",
126
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/rmw ').replace(/\\\/g, '/') + '/include/rmw')\")",
127
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/rcl_yaml_param_parser ').replace(/\\\/g, '/') + '/include/rcl_yaml_param_parser')\")",
128
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/rosidl_runtime_c ').replace(/\\\/g, '/') + '/include/rosidl_runtime_c')\")",
129
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/rosidl_typesupport_interface ').replace(/\\\/g, '/') + '/include/rosidl_typesupport_interface')\")",
130
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/rcl_action ').replace(/\\\/g, '/') + '/include/rcl_action')\")",
131
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/action_msgs ').replace(/\\\/g, '/') + '/include/action_msgs')\")",
132
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/unique_identifier_msgs ').replace(/\\\/g, '/') + '/include/unique_identifier_msgs')\")",
133
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/builtin_interfaces ').replace(/\\\/g, '/') + '/include/builtin_interfaces')\")",
134
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/rcl_lifecycle ').replace(/\\\/g, '/') + '/include/rcl_lifecycle')\")",
135
+ "<!@(node -e \"console.log(process.env.AMENT_PREFIX_PATH.replace(/;/g, '/include/lifecycle_msgs ').replace(/\\\/g, '/') + '/include/lifecycle_msgs')\")",
136
+ ],
137
+ }
138
+ ]
139
+ ]
94
140
  }
95
141
  ],
96
142
  [
97
143
  'OS=="mac"',
144
+ # TODO - macos is no longer a tier-1 ROS platform and we have no binary ROS builds to test for Humble & Rolling
98
145
  {
99
146
  'defines': [
100
147
  'OS_MACOS'
package/index.js CHANGED
@@ -14,6 +14,7 @@
14
14
 
15
15
  'use strict';
16
16
 
17
+ const DistroUtils = require('./lib/distro.js');
17
18
  const { Clock, ROSClock } = require('./lib/clock.js');
18
19
  const ClockType = require('./lib/clock_type.js');
19
20
  const compareVersions = require('compare-versions');
@@ -104,6 +105,9 @@ let rcl = {
104
105
  */
105
106
  DEFAULT_NUMERIC_RANGE_TOLERANCE: DEFAULT_NUMERIC_RANGE_TOLERANCE,
106
107
 
108
+ /** {@link DistroUtils} */
109
+ DistroUtils: DistroUtils,
110
+
107
111
  /** {@link Duration} class */
108
112
  Duration: Duration,
109
113
 
package/lib/client.js CHANGED
@@ -28,7 +28,7 @@ class Client extends Entity {
28
28
  super(handle, typeClass, options);
29
29
  this._nodeHandle = nodeHandle;
30
30
  this._serviceName = serviceName;
31
- this._sequenceNumber = 0;
31
+ this._sequenceNumberToCallbackMap = new Map();
32
32
  }
33
33
 
34
34
  /**
@@ -58,18 +58,21 @@ class Client extends Entity {
58
58
  }
59
59
 
60
60
  let rawRequest = requestToSend.serialize();
61
- this._sequenceNumber = rclnodejs.sendRequest(this._handle, rawRequest);
61
+ let sequenceNumber = rclnodejs.sendRequest(this._handle, rawRequest);
62
62
  debug(`Client has sent a ${this._serviceName} request.`);
63
- this._callback = callback;
63
+ this._sequenceNumberToCallbackMap.set(sequenceNumber, callback);
64
64
  }
65
65
 
66
- get sequenceNumber() {
67
- return this._sequenceNumber;
68
- }
69
-
70
- processResponse(response) {
71
- debug(`Client has received ${this._serviceName} response from service.`);
72
- this._callback(response.toPlainObject(this.typedArrayEnabled));
66
+ processResponse(sequenceNumber, response) {
67
+ if (this._sequenceNumberToCallbackMap.has(sequenceNumber)) {
68
+ debug(`Client has received ${this._serviceName} response from service.`);
69
+ let callback = this._sequenceNumberToCallbackMap.get(sequenceNumber);
70
+ this._sequenceNumberToCallbackMap.delete(sequenceNumber);
71
+ callback(response.toPlainObject(this.typedArrayEnabled));
72
+ } else {
73
+ error(`Client has received an unexpected ${this._serviceName}
74
+ response with sequence number ${sequenceNumber}.`);
75
+ }
73
76
  }
74
77
 
75
78
  /**
package/lib/distro.js ADDED
@@ -0,0 +1,70 @@
1
+ // Copyright (c) 2022 Wayne Parrott. All rights reserved.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ 'use strict';
16
+
17
+ /**
18
+ * enum style distribution identifiers
19
+ */
20
+ const DistroId = {
21
+ UNKNOWN: 0,
22
+ ELOQUENT: 1911,
23
+ FOXY: 2006,
24
+ GALACTIC: 2105,
25
+ HUMBLE: 2205,
26
+ ROLLING: 5000,
27
+ };
28
+
29
+ const DistroNameIdMap = new Map();
30
+ DistroNameIdMap.set('eloquent', DistroId.ELOQUENT);
31
+ DistroNameIdMap.set('foxy', DistroId.FOXY);
32
+ DistroNameIdMap.set('galactic', DistroId.GALACTIC);
33
+ DistroNameIdMap.set('humble', DistroId.HUMBLE);
34
+ DistroNameIdMap.set('rolling', DistroId.ROLLING);
35
+
36
+ const DistroUtils = {
37
+ DistroId: DistroId,
38
+
39
+ /**
40
+ * Get the rclnodejs distro ID for a ROS 2 distro name.
41
+ * @param {string|undefined} [distroName] - The ROS 2 short distro name, e.g., foxy, Defaults to the value of the ROS_DISTRO envar.
42
+ * @return {number} Return the rclnodejs distro identifier
43
+ */
44
+ getDistroId: function (distroName) {
45
+ const dname = distroName ? distroName : this.getDistroName();
46
+
47
+ return DistroNameIdMap.has(dname)
48
+ ? DistroNameIdMap.get(dname)
49
+ : DistroId.UNKNOWN;
50
+ },
51
+
52
+ /**
53
+ * Get the short ROS 2 distro name associated with a rclnodejs distro ID.
54
+ * @param {number|undefined} [distroId] - The rclnodejs distro identifier. Defaults to the value of the ROS_DISTRO envar.
55
+ * @return {string|undefined} Return the name of the ROS distribution or undefined if unable to identify the distro.
56
+ */
57
+ getDistroName: function (distroId) {
58
+ if (!distroId) {
59
+ return process.env.ROS_DISTRO;
60
+ }
61
+
62
+ return [...DistroNameIdMap].find(([key, val]) => val == distroId)[0];
63
+ },
64
+
65
+ getKnownDistroNames: function () {
66
+ return [...DistroNameIdMap.keys()];
67
+ },
68
+ };
69
+
70
+ module.exports = DistroUtils;
package/lib/node.js CHANGED
@@ -102,7 +102,7 @@ class Node extends rclnodejs.ShadowNode {
102
102
  this._parameterEventPublisher = null;
103
103
  this._setParametersCallbacks = [];
104
104
  this._logger = new Logging(rclnodejs.getNodeLoggerName(this.handle));
105
- this.spinning = false;
105
+ this._spinning = false;
106
106
 
107
107
  this._parameterEventPublisher = this.createPublisher(
108
108
  PARAMETER_EVENT_MSG_TYPE,
@@ -204,13 +204,12 @@ class Node extends rclnodejs.ShadowNode {
204
204
  this._runWithMessageType(
205
205
  client.typeClass.Response,
206
206
  (message, deserialize) => {
207
- let success = rclnodejs.rclTakeResponse(
207
+ let sequenceNumber = rclnodejs.rclTakeResponse(
208
208
  client.handle,
209
- client.sequenceNumber,
210
209
  message
211
210
  );
212
- if (success) {
213
- client.processResponse(deserialize());
211
+ if (sequenceNumber !== undefined) {
212
+ client.processResponse(sequenceNumber, deserialize());
214
213
  }
215
214
  }
216
215
  );
@@ -375,6 +374,14 @@ class Node extends rclnodejs.ShadowNode {
375
374
  });
376
375
  }
377
376
 
377
+ /**
378
+ * Determine if this node is spinning.
379
+ * @returns {boolean} - true when spinning; otherwise returns false.
380
+ */
381
+ get spinning() {
382
+ return this._spinning;
383
+ }
384
+
378
385
  /**
379
386
  * Trigger the event loop to continuously check for and route.
380
387
  * incoming events.
@@ -388,7 +395,7 @@ class Node extends rclnodejs.ShadowNode {
388
395
  throw new Error('The node is already spinning.');
389
396
  }
390
397
  this.start(this.context.handle, timeout);
391
- this.spinning = true;
398
+ this._spinning = true;
392
399
  }
393
400
 
394
401
  /**
@@ -401,21 +408,21 @@ class Node extends rclnodejs.ShadowNode {
401
408
 
402
409
  /**
403
410
  * Terminate spinning - no further events will be received.
404
- * @returns {undfined}
411
+ * @returns {undefined}
405
412
  */
406
413
  stop() {
407
414
  super.stop();
408
- this.spinning = false;
415
+ this._spinning = false;
409
416
  }
410
417
 
411
418
  /**
412
419
  * Terminate spinning - no further events will be received.
413
- * @returns {undfined}
420
+ * @returns {undefined}
414
421
  * @deprecated since 0.18.0, Use stop().
415
422
  */
416
423
  stopSpinning() {
417
424
  super.stop();
418
- this.spinning = false;
425
+ this._spinning = false;
419
426
  }
420
427
 
421
428
  /**
package/lib/parameter.js CHANGED
@@ -71,7 +71,7 @@ class Parameter {
71
71
  /**
72
72
  * Create a Parameter instance from an rlc_interfaces/msg/Parameter message.
73
73
  * @constructs
74
- * @param {rlc_interfaces/msg/Parameter} parameterMsg - The message to convert to a parameter.
74
+ * @param {rcl_interfaces/msg/Parameter} parameterMsg - The message to convert to a parameter.
75
75
  * @return {Parameter} - The new instance.
76
76
  */
77
77
  static fromParameterMessage(parameterMsg) {
@@ -89,25 +89,25 @@ class Parameter {
89
89
  value = parameterMsg.value.bool_array_value;
90
90
  break;
91
91
  case ParameterType.PARAMETER_BYTE_ARRAY:
92
- value = parameterMsg.value.byte_array_value;
92
+ value = Array.from(parameterMsg.value.byte_array_value);
93
93
  break;
94
94
  case ParameterType.PARAMETER_DOUBLE:
95
95
  value = parameterMsg.value.double_value;
96
96
  break;
97
97
  case ParameterType.PARAMETER_DOUBLE_ARRAY:
98
- value = parameterMsg.value.double_array_value;
98
+ value = Array.from(parameterMsg.value.double_array_value);
99
99
  break;
100
100
  case ParameterType.PARAMETER_INTEGER:
101
101
  value = parameterMsg.value.integer_value;
102
102
  break;
103
103
  case ParameterType.PARAMETER_INTEGER_ARRAY:
104
- value = parameterMsg.value.integer_array_value;
104
+ value = Array.from(parameterMsg.value.integer_array_value);
105
105
  break;
106
106
  case ParameterType.PARAMETER_STRING:
107
107
  value = parameterMsg.value.string_value;
108
108
  break;
109
109
  case ParameterType.PARAMETER_STRING_ARRAY:
110
- value = parameterMsg.value.string_array_value;
110
+ value = Array.from(parameterMsg.value.string_array_value);
111
111
  break;
112
112
  }
113
113
 
@@ -225,12 +225,10 @@ class Parameter {
225
225
  case ParameterType.PARAMETER_NOT_SET:
226
226
  break;
227
227
  case ParameterType.PARAMETER_BOOL:
228
- msg.bool_value = this.value ? 'true' : 'false';
228
+ msg.bool_value = this.value;
229
229
  break;
230
230
  case ParameterType.PARAMETER_BOOL_ARRAY:
231
- msg.bool_array_value = this.value.map((val) =>
232
- val ? 'true' : 'false'
233
- );
231
+ msg.bool_array_value = this.value;
234
232
  break;
235
233
  case ParameterType.PARAMETER_BYTE_ARRAY:
236
234
  msg.byte_array_value = this.value.map((val) => Math.trunc(val));
@@ -773,6 +771,7 @@ function validValue(value, type) {
773
771
  case ParameterType.PARAMETER_BYTE_ARRAY:
774
772
  case ParameterType.PARAMETER_INTEGER_ARRAY:
775
773
  case ParameterType.PARAMETER_DOUBLE_ARRAY:
774
+ case ParameterType.PARAMETER_STRING_ARRAY:
776
775
  const values = value;
777
776
  result = _validArray(values, type);
778
777
  break;
@@ -790,7 +789,7 @@ function _validArray(values, type) {
790
789
  if (type === ParameterType.PARAMETER_BOOL_ARRAY) {
791
790
  arrayElementType = ParameterType.PARAMETER_BOOL;
792
791
  } else if (type === ParameterType.PARAMETER_BYTE_ARRAY) {
793
- arrayElementType = ParameterType.PARAMETER_BYTE;
792
+ arrayElementType = ParameterType.PARAMETER_INTEGER;
794
793
  }
795
794
  if (type === ParameterType.PARAMETER_INTEGER_ARRAY) {
796
795
  arrayElementType = ParameterType.PARAMETER_INTEGER;
@@ -798,6 +797,9 @@ function _validArray(values, type) {
798
797
  if (type === ParameterType.PARAMETER_DOUBLE_ARRAY) {
799
798
  arrayElementType = ParameterType.PARAMETER_DOUBLE;
800
799
  }
800
+ if (type === ParameterType.PARAMETER_STRING_ARRAY) {
801
+ arrayElementType = ParameterType.PARAMETER_STRING;
802
+ }
801
803
 
802
804
  return values.reduce(
803
805
  (compatible, val) =>
@@ -813,7 +815,8 @@ function _isArrayParameterType(type) {
813
815
  type === ParameterType.PARAMETER_BOOL_ARRAY ||
814
816
  type === ParameterType.PARAMETER_BYTE_ARRAY ||
815
817
  type === ParameterType.PARAMETER_INTEGER_ARRAY ||
816
- type === ParameterType.PARAMETER_DOUBLE_ARRAY
818
+ type === ParameterType.PARAMETER_DOUBLE_ARRAY ||
819
+ type === ParameterType.PARAMETER_STRING_ARRAY
817
820
  );
818
821
  }
819
822
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rclnodejs",
3
- "version": "0.20.1",
3
+ "version": "0.21.2",
4
4
  "description": "ROS2.0 JavaScript client with Node.js",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -15,8 +15,8 @@
15
15
  "scripts": {
16
16
  "install": "node-gyp rebuild",
17
17
  "docs": "cd docs && make",
18
- "test": "node ./scripts/compile_tests.js && node --expose-gc ./scripts/run_test.js && npm run dtslint",
19
- "dtslint": "node ./scripts/generate_tsd.js && dtslint test/types",
18
+ "test": "node --expose-gc ./scripts/run_test.js && npm run dtslint",
19
+ "dtslint": "node scripts/generate_tsd.js && dtslint test/types",
20
20
  "lint": "eslint --max-warnings=0 --ext js,ts index.js types scripts lib example rosidl_gen rosidl_parser test benchmark/rclnodejs && node ./scripts/cpplint.js",
21
21
  "postinstall": "node scripts/generate_messages.js",
22
22
  "format": "clang-format -i -style=file ./src/*.cpp ./src/*.hpp && prettier --write \"{lib,rosidl_gen,rostsd_gen,rosidl_parser,types,example,test,scripts,benchmark}/**/*.{js,md,ts}\" ./*.{js,md,ts}"
@@ -43,35 +43,37 @@
43
43
  "clang-format": "^1.4.0",
44
44
  "commander": "^6.0.0",
45
45
  "deep-equal": "^1.1.1",
46
- "dtslint": "^4.1.0",
47
46
  "eslint": "^7.5.0",
48
47
  "eslint-config-prettier": "^6.11.0",
49
48
  "eslint-plugin-prettier": "^3.1.4",
50
49
  "husky": "^4.2.5",
50
+ "jsdoc": "^3.6.7",
51
51
  "lint-staged": "^10.2.11",
52
52
  "mocha": "^8.0.1",
53
53
  "prettier": "^2.0.5",
54
+ "rimraf": "^3.0.2",
54
55
  "sinon": "^9.0.2",
55
56
  "tree-kill": "^1.2.2",
56
57
  "typescript": "^4.0.3"
57
58
  },
58
59
  "dependencies": {
60
+ "@rclnodejs/ref-array-di": "^1.2.2",
61
+ "@rclnodejs/ref-napi": "^4.0.0",
62
+ "@rclnodejs/ref-struct-di": "^1.1.1",
63
+ "array.prototype.flat": "^1.2.4",
59
64
  "bindings": "^1.5.0",
60
65
  "compare-versions": "^3.6.0",
61
66
  "debug": "^4.1.1",
62
67
  "dot": "^1.1.3",
68
+ "dtslint": "^4.2.1",
63
69
  "fs-extra": "^10.0.0",
70
+ "int64-napi": "^1.0.2",
64
71
  "is-close": "^1.3.3",
65
72
  "mkdirp": "^1.0.4",
66
73
  "mz": "^2.7.0",
67
74
  "nan": "^2.14.2",
68
- "ref-napi": "^3.0.0",
69
- "ref-array-di": "^1.2.2",
70
- "ref-struct-di": "^1.1.1",
71
- "walk": "^2.3.14",
72
75
  "uuid": "^8.2.0",
73
- "int64-napi": "^1.0.1",
74
- "array.prototype.flat": "^1.2.4"
76
+ "walk": "^2.3.14"
75
77
  },
76
78
  "husky": {
77
79
  "hooks": {
@@ -87,6 +89,6 @@
87
89
  ]
88
90
  },
89
91
  "engines": {
90
- "node": ">= 10.23.1 <13.0.0"
92
+ "node": ">= 10.23.1 <18.0.0"
91
93
  }
92
94
  }
@@ -24,7 +24,12 @@ let deallocator = {
24
24
  );
25
25
  },
26
26
  freeStructMember(refObj, type, name) {
27
- rclnodejs.freeMemeoryAtOffset(refObj.ref(), type.fields[name].offset);
27
+ if (refObj.ref().length !== 0) {
28
+ rclnodejs.freeMemeoryAtOffset(
29
+ refObj.ref().hexAddress(),
30
+ type.fields[name].offset
31
+ );
32
+ }
28
33
  },
29
34
  };
30
35
 
@@ -14,8 +14,8 @@
14
14
 
15
15
  'use strict';
16
16
 
17
- const ref = require('ref-napi');
18
- const StructType = require('ref-struct-di')(ref);
17
+ const ref = require('@rclnodejs/ref-napi');
18
+ const StructType = require('@rclnodejs/ref-struct-di')(ref);
19
19
  const rclnodejs = require('bindings')('rclnodejs');
20
20
 
21
21
  /* eslint-disable camelcase */
@@ -219,9 +219,9 @@ function extractMemberNames(fields) {
219
219
  {{? usePlainTypedArray}}
220
220
  const rclnodejs = require('bindings')('rclnodejs');
221
221
  {{?}}
222
- const ref = require('ref-napi');
223
- const StructType = require('ref-struct-di')(ref);
224
- const ArrayType = require('ref-array-di')(ref);
222
+ const ref = require('@rclnodejs/ref-napi');
223
+ const StructType = require('@rclnodejs/ref-struct-di')(ref);
224
+ const ArrayType = require('@rclnodejs/ref-array-di')(ref);
225
225
  const primitiveTypes = require('../../rosidl_gen/primitive_types.js');
226
226
  const deallocator = require('../../rosidl_gen/deallocator.js');
227
227
  const translator = require('../../rosidl_gen/message_translator.js');
@@ -750,7 +750,9 @@ class {{=arrayWrapper}} {
750
750
  {{? usePlainTypedArray}}
751
751
  const byteLen = refObject.size * ref.types.{{=currentTypedArrayElementType}}.size;
752
752
  // An ArrayBuffer object that doesn't hold the ownership of the address
753
- const arrayBuffer = rclnodejs.createArrayBufferFromAddress(refObject.data, byteLen);
753
+ const arrayBuffer = refObject.data.length !== 0 ?
754
+ rclnodejs.createArrayBufferFromAddress(refObject.data.hexAddress(), byteLen) :
755
+ Buffer.alloc(0);
754
756
  this._wrappers = new {{=currentTypedArray}}(arrayBuffer);
755
757
  {{?? true}}
756
758
  let refObjectArray = this._refObject.data;
package/scripts/build.sh CHANGED
@@ -19,5 +19,5 @@ set -e
19
19
  pushd $(dirname $0) > /dev/null
20
20
 
21
21
  git submodule update --init --recursive
22
- npm install --unsafe-perm
22
+ npm install
23
23
  npm run lint
@@ -20,7 +20,7 @@ const cmd = 'wget -nc ';
20
20
  const cpplintUrl =
21
21
  'https://raw.githubusercontent.com/google/styleguide' +
22
22
  '/gh-pages/cpplint/cpplint.py';
23
- const root = `${__dirname}/../src/`;
23
+ const root = `${__dirname}/../src`;
24
24
  const args = `--extensions=cpp,h,hpp,cc ${root}/*`;
25
25
 
26
26
  console.log('Downloading the cpplint...');
@@ -18,7 +18,7 @@ rclnodejs.init().then(() => {
18
18
 
19
19
  **Node.js**
20
20
 
21
- - [Node.js](https://nodejs.org/en/) version between 8.12 - 12.x.
21
+ - [Node.js](https://nodejs.org/en/) version between 10.23 - 17.x.
22
22
 
23
23
  **ROS 2 SDK**
24
24
 
@@ -43,10 +43,10 @@ npm i rclnodejs@x.y.z
43
43
 
44
44
  #### RCLNODEJS - ROS 2 Version Compatibility
45
45
 
46
- | RCLNODEJS Version | Compatible ROS 2 Release |
47
- | :-------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
48
- | [0.20.1 (current)](https://www.npmjs.com/package/rclnodejs/v/0.20.1) ([API](http://robotwebtools.org/rclnodejs/docs/0.20.0/index.html)) | [Galactic Geochelone](https://github.com/ros2/ros2/releases/tag/release-galactic-20210716) / [Foxy Fitzroy](https://github.com/ros2/ros2/releases/tag/release-foxy-20201211) / [Eloquent Elusor](https://github.com/ros2/ros2/releases/tag/release-eloquent-20200124) |
49
- | [0.10.3](https://github.com/RobotWebTools/rclnodejs/releases/tag/0.10.3) | [Dashing Diademata - Patch 4](https://github.com/ros2/ros2/releases/tag/release-dashing-20191018) |
46
+ | RCLNODEJS Version | Compatible ROS 2 Release |
47
+ | :-------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
48
+ | [0.21.2 (current)](https://www.npmjs.com/package/rclnodejs/v/0.21.2) ([API](http://robotwebtools.org/rclnodejs/docs/0.21.0/index.html)) | [Humble Hawksbill](https://github.com/ros2/ros2/releases/tag/release-humble-20220523)<br>[Galactic Geochelone](https://github.com/ros2/ros2/releases/tag/release-galactic-20210716)<br>[Foxy Fitzroy](https://github.com/ros2/ros2/releases/tag/release-foxy-20201211)<br>[Eloquent Elusor](https://github.com/ros2/ros2/releases/tag/release-eloquent-20200124) |
49
+ | [0.10.3](https://github.com/RobotWebTools/rclnodejs/releases/tag/0.10.3) | [Dashing Diademata - Patch 4](https://github.com/ros2/ros2/releases/tag/release-dashing-20191018) |
50
50
 
51
51
  ## Documentation
52
52
 
@@ -1,24 +1,22 @@
1
1
  'use strict';
2
2
 
3
- switch (process.env.ROS_DISTRO) {
4
- case 'eloquent':
5
- console.log('1911');
6
- process.exit(0);
7
- case 'foxy':
8
- console.log('2006');
9
- process.exit(0);
10
- case 'galactic':
11
- case 'rolling':
12
- console.log('2105');
13
- process.exit(0);
14
- case undefined:
15
- console.error(
16
- 'Unable to detect ROS, please make sure a supported version of ROS is sourced'
17
- );
18
- process.exit(1);
19
- default:
20
- console.error(
21
- `Unknown or unsupported ROS version "${process.env.ROS_DISTRO}"`
22
- );
23
- process.exit(1);
3
+ const DistroUtils = require('../lib/distro');
4
+
5
+ const distroName = DistroUtils.getDistroName();
6
+ const distroId = DistroUtils.getDistroId(distroName);
7
+
8
+ if (!distroName) {
9
+ console.error(
10
+ `Unable to detect ROS, please make sure a supported version of ROS is sourced.`
11
+ );
12
+ process.exit(1);
24
13
  }
14
+
15
+ if (distroId === DistroUtils.UNKNOWN_ID) {
16
+ console.error(`Unknown or unsupported ROS version "${distroName}"`);
17
+ process.exit(1);
18
+ }
19
+
20
+ // otherwise
21
+ console.log(distroId);
22
+ process.exit(0);
package/src/executor.hpp CHANGED
@@ -24,8 +24,6 @@
24
24
 
25
25
  #include "rcl_handle.hpp"
26
26
 
27
- struct rcl_context_t;
28
-
29
27
  namespace rclnodejs {
30
28
 
31
29
  class HandleManager;
@@ -39,6 +39,9 @@
39
39
  #include <memory>
40
40
  #include <string>
41
41
  #include <vector>
42
+ #if NODE_MAJOR_VERSION > 12
43
+ #include <utility>
44
+ #endif
42
45
 
43
46
  #include "handle_manager.hpp"
44
47
  #include "macros.hpp"
@@ -828,24 +831,21 @@ NAN_METHOD(RclTakeResponse) {
828
831
  RclHandle::Unwrap<RclHandle>(
829
832
  Nan::To<v8::Object>(info[0]).ToLocalChecked())
830
833
  ->ptr());
831
- int64_t sequence_number = Nan::To<int64_t>(info[1]).FromJust();
832
834
 
833
- rmw_request_id_t* header =
834
- reinterpret_cast<rmw_request_id_t*>(malloc(sizeof(rmw_request_id_t)));
835
- header->sequence_number = sequence_number;
835
+ rmw_service_info_t header;
836
836
 
837
837
  void* taken_response =
838
- node::Buffer::Data(Nan::To<v8::Object>(info[2]).ToLocalChecked());
839
- rcl_ret_t ret = rcl_take_response(client, header, taken_response);
840
- free(header);
838
+ node::Buffer::Data(Nan::To<v8::Object>(info[1]).ToLocalChecked());
839
+ rcl_ret_t ret = rcl_take_response_with_info(client, &header, taken_response);
840
+ int64_t sequence_number = header.request_id.sequence_number;
841
841
 
842
842
  if (ret == RCL_RET_OK) {
843
- info.GetReturnValue().Set(Nan::True());
843
+ info.GetReturnValue().Set(Nan::New((uint32_t)sequence_number));
844
844
  return;
845
845
  }
846
846
 
847
847
  rcl_reset_error();
848
- info.GetReturnValue().Set(Nan::False());
848
+ info.GetReturnValue().Set(Nan::Undefined());
849
849
  }
850
850
 
851
851
  NAN_METHOD(CreateService) {
@@ -1292,18 +1292,14 @@ inline char* GetBufAddr(v8::Local<v8::Value> buf) {
1292
1292
  }
1293
1293
 
1294
1294
  NAN_METHOD(FreeMemeoryAtOffset) {
1295
- v8::Local<v8::Value> buf = info[0];
1296
- if (!node::Buffer::HasInstance(buf)) {
1297
- return Nan::ThrowTypeError("Buffer instance expected as first argument");
1298
- }
1299
-
1295
+ v8::Local<v8::Context> currentContent = Nan::GetCurrentContext();
1296
+ std::string addr_str(
1297
+ *Nan::Utf8String(info[0]->ToString(currentContent).ToLocalChecked()));
1298
+ int64_t result = std::stoull(addr_str, 0, 16);
1299
+ char* addr = reinterpret_cast<char*>(result);
1300
1300
  int64_t offset =
1301
1301
  info[1]->IsNumber() ? Nan::To<int64_t>(info[1]).FromJust() : 0;
1302
- auto ptr = GetBufAddr(buf) + offset;
1303
-
1304
- if (ptr == nullptr) {
1305
- return Nan::ThrowError("Cannot read from NULL pointer");
1306
- }
1302
+ auto ptr = addr + offset;
1307
1303
 
1308
1304
  char* val = *reinterpret_cast<char**>(ptr);
1309
1305
  free(val);
@@ -1311,15 +1307,28 @@ NAN_METHOD(FreeMemeoryAtOffset) {
1311
1307
  }
1312
1308
 
1313
1309
  NAN_METHOD(CreateArrayBufferFromAddress) {
1314
- char* addr = GetBufAddr(info[0]);
1310
+ v8::Local<v8::Context> currentContent = Nan::GetCurrentContext();
1311
+ std::string addr_str(
1312
+ *Nan::Utf8String(info[0]->ToString(currentContent).ToLocalChecked()));
1313
+ int64_t result = std::stoull(addr_str, 0, 16);
1314
+ char* addr = reinterpret_cast<char*>(result);
1315
1315
  int32_t length = Nan::To<int32_t>(info[1]).FromJust();
1316
1316
 
1317
1317
  // We will create an ArrayBuffer with mode of
1318
1318
  // ArrayBufferCreationMode::kInternalized and copy data starting from |addr|,
1319
1319
  // thus the memory block will be collected by the garbage collector.
1320
+ #if NODE_MAJOR_VERSION <= 12
1320
1321
  v8::Local<v8::ArrayBuffer> array_buffer =
1321
1322
  v8::ArrayBuffer::New(v8::Isolate::GetCurrent(), addr, length,
1322
1323
  v8::ArrayBufferCreationMode::kInternalized);
1324
+ #else
1325
+ std::unique_ptr<v8::BackingStore> backing =
1326
+ v8::ArrayBuffer::NewBackingStore(v8::Isolate::GetCurrent(), length);
1327
+ memcpy(backing->Data(), addr, length);
1328
+ auto array_buffer =
1329
+ v8::ArrayBuffer::New(v8::Isolate::GetCurrent(), std::move(backing));
1330
+ free(addr);
1331
+ #endif
1323
1332
 
1324
1333
  info.GetReturnValue().Set(array_buffer);
1325
1334
  }
@@ -77,12 +77,14 @@ declare module 'rclnodejs' {
77
77
 
78
78
  type ExecuteCallback<T extends TypeClass<ActionTypeClassName>> = (
79
79
  goalHandle: ServerGoalHandle<T>
80
- ) => ActionResult<T>;
81
- type GoalCallback = () => GoalResponse;
80
+ ) => Promise<ActionResult<T>> | ActionResult<T>;
81
+ type GoalCallback<T extends TypeClass<ActionTypeClassName>> = (
82
+ goalHandle: ServerGoalHandle<T>
83
+ ) => GoalResponse;
82
84
  type HandleAcceptedCallback<T extends TypeClass<ActionTypeClassName>> = (
83
85
  goalHandle: ServerGoalHandle<T>
84
86
  ) => void;
85
- type CancelCallback = () => CancelResponse;
87
+ type CancelCallback = () => Promise<CancelResponse> | CancelResponse;
86
88
 
87
89
  interface ActionServerOptions extends Options<ActionQoS> {
88
90
  /**
@@ -112,7 +114,7 @@ declare module 'rclnodejs' {
112
114
  typeClass: T,
113
115
  actionName: string,
114
116
  executeCallback: ExecuteCallback<T>,
115
- goalCallback?: GoalCallback,
117
+ goalCallback?: GoalCallback<T>,
116
118
  handleAcceptedCallback?: HandleAcceptedCallback<T>,
117
119
  cancelCallback?: CancelCallback,
118
120
  options?: ActionServerOptions
@@ -144,7 +146,7 @@ declare module 'rclnodejs' {
144
146
  *
145
147
  * @param goalCallback - Callback function, if not provided, then unregisters any previously registered callback.
146
148
  */
147
- registerGoalCallback(goalCallback?: GoalCallback): void;
149
+ registerGoalCallback(goalCallback?: GoalCallback<T>): void;
148
150
 
149
151
  /**
150
152
  * Register a callback for handling cancel requests.
package/types/base.d.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  /// <reference path="clock_type.d.ts" />
6
6
  /// <reference path="clock.d.ts" />
7
7
  /// <reference path="context.d.ts" />
8
+ /// <reference path="distro.d.ts" />
8
9
  /// <reference path="duration.d.ts" />
9
10
  /// <reference path="entity.d.ts" />
10
11
  /// <reference path="guard_condition.d.ts" />
@@ -0,0 +1,34 @@
1
+ declare module 'rclnodejs' {
2
+ namespace DistroUtils {
3
+ /**
4
+ * Valid ROS 2 distro short names
5
+ */
6
+ type DistroName = 'eloquent' | 'foxy' | 'galactic' | 'humble' | 'rolling';
7
+
8
+ /**
9
+ * rclnodejs distro ID numbers
10
+ */
11
+ enum DistroId {
12
+ UNKNOWN = 0,
13
+ ELOQUENT = 1911,
14
+ FOXY = 2006,
15
+ GALACTIC = 2105,
16
+ HUMBLE = 2205,
17
+ ROLLING = 5000,
18
+ }
19
+
20
+ /**
21
+ * Get the rclnodejs distro ID for a ROS 2 distro name.
22
+ * @param distroName - The ROS 2 short distro name, e.g., foxy, Defaults to the value of the ROS_DISTRO envar.
23
+ * @return The rclnodejs distro identifier
24
+ */
25
+ function getDistroId(distroName?: DistroName): DistroId;
26
+
27
+ /**
28
+ * Get the short ROS 2 distro name associated with a rclnodejs distro ID.
29
+ * @param distroId - The rclnodejs distro identifier. Defaults to the value of the ROS_DISTRO envar.
30
+ * @returns The name of the ROS distribution or undefined if unable to identify the distro.
31
+ */
32
+ function getDistroName(distroId?: DistroId): string | undefined;
33
+ }
34
+ }
package/types/node.d.ts CHANGED
@@ -182,6 +182,13 @@ declare module 'rclnodejs' {
182
182
  */
183
183
  options(): NodeOptions;
184
184
 
185
+ /**
186
+ * Determine if this node is spinning.
187
+ *
188
+ * @returns true when spinning; otherwise returns false.
189
+ */
190
+ get spinning(): boolean;
191
+
185
192
  /**
186
193
  * Trigger the event loop to continuously check for and route.
187
194
  * incoming events.
@@ -1,15 +0,0 @@
1
- {
2
- "configurations": [
3
- {
4
- "name": "Linux",
5
- "includePath": [
6
- "${default}"
7
- ],
8
- "compilerPath": "/usr/bin/clang-10",
9
- "cStandard": "c11",
10
- "cppStandard": "c++14",
11
- "intelliSenseMode": "linux-clang-x64"
12
- }
13
- ],
14
- "version": 4
15
- }
@@ -1,124 +0,0 @@
1
- // Copyright (c) 2017 Intel Corporation. All rights reserved.
2
-
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
-
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- 'use strict';
16
-
17
- /* eslint-disable */
18
- const fs = require('fs-extra');
19
- const os = require('os');
20
- const path = require('path');
21
- const child = require('child_process');
22
-
23
- var rootDir = path.dirname(__dirname);
24
- var testCppDir = path.join(rootDir, 'test', 'cpp');
25
-
26
- function getExecutable(input) {
27
- if (os.platform() === 'win32') return input + '.exe';
28
-
29
- return input;
30
- }
31
-
32
- var publisher = getExecutable('publisher_msg');
33
- var subscription = getExecutable('subscription_msg');
34
- var listener = getExecutable('listener');
35
- var client = getExecutable('add_two_ints_client');
36
-
37
- function getExecutablePath(input) {
38
- var releaseDir = '';
39
- if (os.platform() === 'win32') releaseDir = 'Release';
40
-
41
- return path.join(rootDir, 'build', 'cpp_nodes', releaseDir, input);
42
- }
43
-
44
- var publisherPath = getExecutablePath(publisher);
45
- var subscriptionPath = getExecutablePath(subscription);
46
- var listenerPath = getExecutablePath(listener);
47
- var clientPath = getExecutablePath(client);
48
-
49
- function copyFile(platform, srcFile, destFile) {
50
- if (!fs.existsSync(destFile)) {
51
- if (os.platform() === 'win32') {
52
- child.spawn('cmd.exe', ['/c', `copy ${srcFile} ${destFile}`]);
53
- } else {
54
- child.spawn('sh', ['-c', `cp ${srcFile} ${destFile}`]);
55
- }
56
- }
57
- }
58
-
59
- function copyAll(fileList, dest) {
60
- fileList.forEach((file) => {
61
- copyFile(os.platform(), file, path.join(dest, path.basename(file)));
62
- console.log(`cpp executables ${file} is copied to test/cpp.`);
63
- });
64
- }
65
-
66
- function copyPkgToRos2(pkgName) {
67
- let srcDir = path.join(rootDir, 'install', pkgName);
68
- let destDir = process.env.COLCON_PREFIX_PATH;
69
- if (os.platform() === 'win32') {
70
- child.spawn('cmd.exe', ['/c', `xcopy ${srcDir} ${destDir} /O /X /E /K`]);
71
- } else {
72
- child.spawn('sh', ['-c ', '"' + `cp -fr ${srcDir}/. ${destDir}` + '"'], {
73
- shell: true,
74
- });
75
- }
76
- }
77
-
78
- var subProcess = child.spawn('colcon', [
79
- 'build',
80
- '--event-handlers',
81
- 'console_cohesion+',
82
- '--base-paths',
83
- path.join(rootDir, 'test', 'rclnodejs_test_msgs'),
84
- ]);
85
- subProcess.on('close', (code) => {
86
- copyPkgToRos2('rclnodejs_test_msgs');
87
- });
88
- subProcess.stdout.on('data', (data) => {
89
- console.log(`${data}`);
90
- });
91
- subProcess.stderr.on('data', (data) => {
92
- console.log(`${data}`);
93
- });
94
-
95
- if (
96
- !fs.existsSync(publisherPath) &&
97
- !fs.existsSync(subscriptionPath) &&
98
- !fs.existsSync(listenerPath) &&
99
- !fs.existsSync(clientPath)
100
- ) {
101
- var compileProcess = child.spawn('colcon', [
102
- 'build',
103
- '--base-paths',
104
- testCppDir,
105
- ]);
106
- compileProcess.on('close', (code) => {
107
- copyAll(
108
- [publisherPath, subscriptionPath, listenerPath, clientPath],
109
- testCppDir
110
- );
111
- });
112
- compileProcess.stdout.on('data', (data) => {
113
- console.log(`${data}`);
114
- });
115
- compileProcess.stderr.on('data', (data) => {
116
- console.log(`${data}`);
117
- });
118
- } else {
119
- copyAll(
120
- [publisherPath, subscriptionPath, , listenerPath, clientPath],
121
- testCppDir
122
- );
123
- }
124
- /* eslint-enable */