diff --git a/bin/rosbridge.js b/bin/rosbridge.js index d71a3c6..9c2866a 100755 --- a/bin/rosbridge.js +++ b/bin/rosbridge.js @@ -18,6 +18,7 @@ const rosbridge = require('../index.js'); const app = require('commander'); +const path = require('path'); const pkg = require('../package.json'); app @@ -33,6 +34,13 @@ app .option('-g, --params_glob [glob_list]', 'A list or None') .option('-b, --bson_only_mode', 'Unsupported in WebSocket server, will be ignored') .option('-l, --status_level [level_string]', 'Status level (one of "error", "warning", "info", "none"; default "error")') + .option('--topic-config ', 'Path to a topic config (js file)') // example.topic-config.js .parse(process.argv); + if (app.topicConfig) { + const SubscriptionManager = require('../lib/subscription_manager.js'); + const {config} = require(path.resolve(app.topicConfig)); + SubscriptionManager._opts = config; + } + rosbridge.createServer(app); diff --git a/data/example.topic-config.js b/data/example.topic-config.js new file mode 100644 index 0000000..ae0d515 --- /dev/null +++ b/data/example.topic-config.js @@ -0,0 +1,50 @@ +/** + * Enum for HistoryPolicy + * @readonly + * @enum {number} + */ +let HistoryPolicy = { + /** @member {number} */ + RMW_QOS_POLICY_HISTORY_SYSTEM_DEFAULT: 0, + /** @member {number} */ + RMW_QOS_POLICY_HISTORY_KEEP_LAST: 1, + /** @member {number} */ + RMW_QOS_POLICY_HISTORY_KEEP_ALL: 2 + }; + + /** + * Enum for ReliabilityPolicy + * @readonly + * @enum {number} + */ + let ReliabilityPolicy = { + /** @member {number} */ + RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT: 0, + /** @member {number} */ + RMW_QOS_POLICY_RELIABILITY_RELIABLE: 1, + /** @member {number} */ + RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT: 2 + }; + + /** + * Enum for DurabilityPolicy + * @readonly + * @enum {number} + */ + let DurabilityPolicy = { + /** @member {number} */ + RMW_QOS_POLICY_DURABILITY_SYSTEM_DEFAULT: 0, + /** @member {number} */ + RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL: 1, + /** @member {number} */ + RMW_QOS_POLICY_DURABILITY_VOLATILE: 2 + }; + + module.exports.config = { + "/heartbeat": { + qos: { + history: HistoryPolicy.RMW_QOS_POLICY_HISTORY_KEEP_ALL, + durability: DurabilityPolicy.RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL + } + } + }; diff --git a/lib/subscription_manager.js b/lib/subscription_manager.js index 0743758..650d626 100644 --- a/lib/subscription_manager.js +++ b/lib/subscription_manager.js @@ -54,7 +54,12 @@ class SubscriptionManager { let handle = this._subscripions.get(topicName); if (!handle) { - let subscription = this._node.createSubscription(messageType, topicName, {enableTypedArray: false}, (message) => { + const defaultOpts = {} + let opts = subscriptionManager._opts[topicName] !== undefined ? subscriptionManager._opts[topicName] : defaultOpts + + console.log(topicName, opts) + + let subscription = this._node.createSubscription(messageType, topicName, {enableTypedArray: false, ...opts}, (message) => { this._subscripions.get(topicName).callbacks.forEach(callback => { callback(topicName, message); });