rclnodejs
Version:
ROS2.0 JavaScript client with Node.js
85 lines (73 loc) • 2.77 kB
JavaScript
// Copyright (c) 2022 Wayne Parrott. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
;
/**
* enum style distribution identifiers
*/
const DistroId = {
UNKNOWN: 0,
ELOQUENT: 1911,
FOXY: 2006,
GALACTIC: 2105,
HUMBLE: 2205,
IRON: 2305,
JAZZY: 2405,
KILTED: 2505,
LYRICAL: 2605,
ROLLING: 5000,
FUTURE: 9999, // unrecognized ROS_DISTRO assumed newer than Rolling
};
const DistroNameIdMap = new Map();
DistroNameIdMap.set('eloquent', DistroId.ELOQUENT);
DistroNameIdMap.set('foxy', DistroId.FOXY);
DistroNameIdMap.set('galactic', DistroId.GALACTIC);
DistroNameIdMap.set('humble', DistroId.HUMBLE);
DistroNameIdMap.set('iron', DistroId.IRON);
DistroNameIdMap.set('jazzy', DistroId.JAZZY);
DistroNameIdMap.set('kilted', DistroId.KILTED);
DistroNameIdMap.set('lyrical', DistroId.LYRICAL);
DistroNameIdMap.set('rolling', DistroId.ROLLING);
const DistroUtils = {
DistroId: DistroId,
/**
* Get the rclnodejs distro ID for a ROS 2 distro name.
* @param {string|undefined} [distroName] - The ROS 2 short distro name, e.g., foxy, Defaults to the value of the ROS_DISTRO envar.
* @return {number} Return the rclnodejs distro identifier
*/
getDistroId: function (distroName) {
const dname =
(distroName || this.getDistroName() || '').toLowerCase() || undefined;
if (dname && DistroNameIdMap.has(dname)) {
return DistroNameIdMap.get(dname);
}
// Unrecognized but provided/resolved distro name → assume future; unset → unknown
return dname ? DistroId.FUTURE : DistroId.UNKNOWN;
},
/**
* Get the short ROS 2 distro name associated with a rclnodejs distro ID.
* @param {number|undefined} [distroId] - The rclnodejs distro identifier. Defaults to the value of the ROS_DISTRO envar.
* @return {string|undefined} Return the name of the ROS distribution or undefined if unable to identify the distro.
*/
getDistroName: function (distroId) {
if (!distroId) {
return process.env.ROS_DISTRO;
}
const result = [...DistroNameIdMap].find(([, val]) => val == distroId);
return result ? result[0] : undefined;
},
getKnownDistroNames: function () {
return [...DistroNameIdMap.keys()];
},
};
module.exports = DistroUtils;