diff --git a/function/rbe/locales/en-US/rbe.json b/function/rbe/locales/en-US/rbe.json
index 8adbb62a..9b1a276c 100644
--- a/function/rbe/locales/en-US/rbe.json
+++ b/function/rbe/locales/en-US/rbe.json
@@ -5,7 +5,8 @@
"func": "Mode",
"init": "Send initial value",
"start": "Start value",
- "name": "Name"
+ "name": "Name",
+ "septopics": "Apply mode for each msg.topic
separately"
},
"placeholder":{
"bandgap": "e.g. 10 or 5%",
diff --git a/function/rbe/rbe.html b/function/rbe/rbe.html
index 70cad4c5..58a5a9be 100644
--- a/function/rbe/rbe.html
+++ b/function/rbe/rbe.html
@@ -27,6 +27,11 @@
+
+
+
+
+
@@ -43,6 +48,7 @@
gap: {value:"",validate:RED.validators.regex(/^(\d*[.]*\d*|)(%|)$/)},
start: {value:""},
inout: {value:"out"},
+ septopics: {value:true},
property: {value:"payload",required:true}
},
inputs:1,
@@ -59,6 +65,9 @@
if (this.property === undefined) {
$("#node-input-property").val("payload");
}
+ if (this.septopics === undefined) {
+ $("#node-input-septopics").prop('checked', true);
+ }
$("#node-input-property").typedInput({default:'msg',types:['msg']});
//$( "#node-input-gap" ).spinner({min:0});
if ($("#node-input-inout").val() === null) {
diff --git a/function/rbe/rbe.js b/function/rbe/rbe.js
index dc98496a..c5885101 100644
--- a/function/rbe/rbe.js
+++ b/function/rbe/rbe.js
@@ -14,20 +14,25 @@ module.exports = function(RED) {
}
this.g = this.gap;
this.property = n.property||"payload";
+ this.septopics = true;
+ if (n.septopics !== undefined && n.septopics === false) {
+ this.septopics = false;
+ }
var node = this;
node.previous = {};
this.on("input",function(msg) {
if (msg.hasOwnProperty("reset")) {
- if (msg.hasOwnProperty("topic") && (typeof msg.topic === "string") && (msg.topic !== "")) {
+ if (node.septopics && msg.hasOwnProperty("topic") && (typeof msg.topic === "string") && (msg.topic !== "")) {
delete node.previous[msg.topic];
}
else { node.previous = {}; }
}
var value = RED.util.getMessageProperty(msg,node.property);
if (value !== undefined) {
- var t = msg.topic || "_no_topic";
+ var t = "_no_topic";
+ if (node.septopics) { t = msg.topic || t; }
if ((this.func === "rbe") || (this.func === "rbei")) {
var doSend = (this.func !== "rbei") || (node.previous.hasOwnProperty(t)) || false;
if (typeof(value) === "object") {
diff --git a/test/function/rbe/rbe_spec.js b/test/function/rbe/rbe_spec.js
index 8d220c15..0f8e8747 100644
--- a/test/function/rbe/rbe_spec.js
+++ b/test/function/rbe/rbe_spec.js
@@ -27,7 +27,7 @@ describe('rbe node', function() {
});
});
- it('should only send output if payload changes (rbe)', function(done) {
+ it('should only send output if payload changes - with multiple topics (rbe)', function(done) {
var flow = [{"id":"n1", "type":"rbe", func:"rbe", gap:"0", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(testNode, flow, function() {
@@ -57,8 +57,24 @@ describe('rbe node', function() {
msg.should.have.a.property("payload",false);
c+=1;
}
- else {
+ else if (c == 5) {
msg.should.have.a.property("payload",true);
+ c+=1;
+ }
+ else if (c == 6) {
+ msg.should.have.a.property("topic","a");
+ msg.should.have.a.property("payload",1);
+ c+=1;
+ }
+ else if (c == 7) {
+ msg.should.have.a.property("topic","b");
+ msg.should.have.a.property("payload",1);
+ c+=1;
+ }
+ else {
+ c += 1;
+ msg.should.have.a.property("topic","c");
+ msg.should.have.a.property("payload",1);
done();
}
});
@@ -74,6 +90,80 @@ describe('rbe node', function() {
n1.emit("input", {payload:false});
n1.emit("input", {payload:false});
n1.emit("input", {payload:true});
+
+ n1.emit("input", {topic:"a",payload:1});
+ n1.emit("input", {topic:"b",payload:1});
+ n1.emit("input", {topic:"b",payload:1});
+ n1.emit("input", {topic:"a",payload:1});
+ n1.emit("input", {topic:"c",payload:1});
+
+ });
+ });
+
+ it('should ignore multiple topics if told to (rbe)', function(done) {
+ var flow = [{id:"n1", type:"rbe", func:"rbe", gap:"0", septopics:false, wires:[["n2"]] },
+ {id:"n2", type:"helper"} ];
+ helper.load(testNode, flow, function() {
+ var n1 = helper.getNode("n1");
+ var n2 = helper.getNode("n2");
+ var c = 0;
+ n2.on("input", function(msg) {
+ if (c === 0) {
+ msg.should.have.a.property("payload", "a");
+ c+=1;
+ }
+ else if (c === 1) {
+ msg.should.have.a.property("payload", 2);
+ c+=1;
+ }
+ else if (c == 2) {
+ msg.should.have.a.property("payload");
+ msg.payload.should.have.a.property("b",1);
+ msg.payload.should.have.a.property("c",2);
+ c+=1;
+ }
+ else if (c == 3) {
+ msg.should.have.a.property("payload",true);
+ c+=1;
+ }
+ else if (c == 4) {
+ msg.should.have.a.property("payload",false);
+ c+=1;
+ }
+ else if (c == 5) {
+ msg.should.have.a.property("payload",true);
+ c+=1;
+ }
+ else if (c == 6) {
+ msg.should.have.a.property("topic","a");
+ msg.should.have.a.property("payload",1);
+ c+=1;
+ }
+ else {
+ msg.should.have.a.property("topic","a");
+ msg.should.have.a.property("payload",2);
+ done();
+ }
+ });
+ n1.emit("input", {topic:"a",payload:"a"});
+ n1.emit("input", {topic:"b",payload:"a"});
+ n1.emit("input", {topic:"c",payload:"a"});
+ n1.emit("input", {topic:"a",payload:2});
+ n1.emit("input", {topic:"b",payload:2});
+ n1.emit("input", {payload:{b:1,c:2}});
+ n1.emit("input", {payload:{c:2,b:1}});
+ n1.emit("input", {payload:{c:2,b:1}});
+ n1.emit("input", {topic:"a",payload:true});
+ n1.emit("input", {topic:"b",payload:false});
+ n1.emit("input", {topic:"c",payload:false});
+ n1.emit("input", {topic:"d",payload:true});
+
+ n1.emit("input", {topic:"a",payload:1});
+ n1.emit("input", {topic:"b",payload:1});
+ n1.emit("input", {topic:"c",payload:1});
+ n1.emit("input", {topic:"d",payload:1});
+ n1.emit("input", {topic:"a",payload:2});
+
});
});