Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --topic-config to specify QoS by topic via a .js file #2

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bin/rosbridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

const rosbridge = require('../index.js');
const app = require('commander');
const path = require('path');
const pkg = require('../package.json');

app
Expand All @@ -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>', '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);
50 changes: 50 additions & 0 deletions data/example.topic-config.js
Original file line number Diff line number Diff line change
@@ -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
}
}
};
7 changes: 6 additions & 1 deletion lib/subscription_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down