node-red-contrib-mobius-flow-base 3.1.0 → 3.1.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.
- package/dist/engine-api-calls.js +12 -5
- package/dist/engine-websocket.js +5 -3
- package/dist/node-red-ui-funcs.js +53 -25
- package/dist/nodes/mobius-change-admin-password.js +1 -1
- package/dist/nodes/mobius-clear-resource.js +29 -6
- package/dist/nodes/mobius-connection.js +167 -62
- package/dist/nodes/mobius-discover-object-list.html +24 -10
- package/dist/nodes/mobius-discover-object-list.js +46 -13
- package/dist/nodes/mobius-get-multi-object.js +14 -10
- package/dist/nodes/mobius-get-multi-resource.js +10 -2
- package/dist/nodes/mobius-get-object.js +19 -4
- package/dist/nodes/mobius-get-resource.js +24 -5
- package/dist/nodes/mobius-send-dcmd.js +43 -19
- package/dist/nodes/mobius-set-multi-resource.js +51 -26
- package/dist/nodes/mobius-set-resource.js +132 -58
- package/package.json +1 -1
|
@@ -72,15 +72,24 @@ module.exports = function (RED) {
|
|
|
72
72
|
this.password
|
|
73
73
|
);
|
|
74
74
|
this.apiClient.EngineWebSocket.clearAllCallbacks();
|
|
75
|
-
this.apiClient.EngineWebSocket.registerCallback(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
this.apiClient.EngineWebSocket.registerCallback(
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
this.apiClient.EngineWebSocket.registerCallback(
|
|
76
|
+
'resource-cov',
|
|
77
|
+
(response) => {
|
|
78
|
+
this.handleCOVEvents(response);
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
this.apiClient.EngineWebSocket.registerCallback(
|
|
82
|
+
'object-cov',
|
|
83
|
+
(response) => {
|
|
84
|
+
this.handleObjectCOVEvents(response);
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
this.apiClient.EngineWebSocket.registerCallback(
|
|
88
|
+
'broadcast-command',
|
|
89
|
+
(response) => {
|
|
90
|
+
this.handleBCMDEvents(response);
|
|
91
|
+
}
|
|
92
|
+
);
|
|
84
93
|
var node = this;
|
|
85
94
|
node.serviceList = [];
|
|
86
95
|
node.hasStarted = false;
|
|
@@ -98,12 +107,20 @@ module.exports = function (RED) {
|
|
|
98
107
|
this.log(`Connected to ${n.host}`);
|
|
99
108
|
this.apiClient.getHubId((err, hubId) => {
|
|
100
109
|
if (err) {
|
|
101
|
-
node.error(
|
|
110
|
+
node.error(
|
|
111
|
+
`Mobius error getting hub ID: ${err.code}, ${
|
|
112
|
+
err.message ? err.message : ''
|
|
113
|
+
}`
|
|
114
|
+
);
|
|
102
115
|
} else {
|
|
103
116
|
node.hubId = hubId;
|
|
104
117
|
this.apiClient.discover(node.hubId, (err, response) => {
|
|
105
118
|
if (err) {
|
|
106
|
-
node.error(
|
|
119
|
+
node.error(
|
|
120
|
+
`Mobius error discovering service list: ${err.code}, ${
|
|
121
|
+
err.message ? err.message : ''
|
|
122
|
+
}`
|
|
123
|
+
);
|
|
107
124
|
} else {
|
|
108
125
|
node.serviceList = response.data;
|
|
109
126
|
node.hasStarted = true;
|
|
@@ -380,8 +397,22 @@ module.exports = function (RED) {
|
|
|
380
397
|
* @param {Function} func - The function used to test the resource values
|
|
381
398
|
* @param {Function} callback - function(err, [object]) {}
|
|
382
399
|
*/
|
|
383
|
-
node.filterObjectsByRIDValue = function (
|
|
384
|
-
|
|
400
|
+
node.filterObjectsByRIDValue = function (
|
|
401
|
+
uri,
|
|
402
|
+
pids,
|
|
403
|
+
rid,
|
|
404
|
+
limit,
|
|
405
|
+
func,
|
|
406
|
+
callback
|
|
407
|
+
) {
|
|
408
|
+
this.apiClient.filterObjectsByRIDValue(
|
|
409
|
+
uri,
|
|
410
|
+
pids,
|
|
411
|
+
rid,
|
|
412
|
+
limit,
|
|
413
|
+
func,
|
|
414
|
+
callback
|
|
415
|
+
);
|
|
385
416
|
};
|
|
386
417
|
|
|
387
418
|
/**
|
|
@@ -389,9 +420,9 @@ module.exports = function (RED) {
|
|
|
389
420
|
* @param {*} password - The new password
|
|
390
421
|
* @param {*} callback - Callback when complete, function(err, [object]) {}
|
|
391
422
|
*/
|
|
392
|
-
node.changeAdminPassword = function(password, callback) {
|
|
423
|
+
node.changeAdminPassword = function (password, callback) {
|
|
393
424
|
this.apiClient.changeAdminPassword(password, callback);
|
|
394
|
-
}
|
|
425
|
+
};
|
|
395
426
|
|
|
396
427
|
/**
|
|
397
428
|
* Subscribe to a resource COV
|
|
@@ -523,8 +554,20 @@ module.exports = function (RED) {
|
|
|
523
554
|
* @param {number} timeout - Optional timeout in ms which overrides the default timeout if > 0
|
|
524
555
|
* @param {Function} callback - Callback when complete
|
|
525
556
|
*/
|
|
526
|
-
node.sendDirectCommand = function (
|
|
527
|
-
|
|
557
|
+
node.sendDirectCommand = function (
|
|
558
|
+
uri,
|
|
559
|
+
cid,
|
|
560
|
+
commandData,
|
|
561
|
+
timeout,
|
|
562
|
+
callback
|
|
563
|
+
) {
|
|
564
|
+
this.apiClient.sendDirectCommand(
|
|
565
|
+
uri,
|
|
566
|
+
cid,
|
|
567
|
+
commandData,
|
|
568
|
+
timeout,
|
|
569
|
+
callback
|
|
570
|
+
);
|
|
528
571
|
};
|
|
529
572
|
|
|
530
573
|
/**
|
|
@@ -546,8 +589,19 @@ module.exports = function (RED) {
|
|
|
546
589
|
* @param {Object} config - The new object configuration, structure given by {ins: string, pid: string, uiname: string, rids: array}
|
|
547
590
|
* @param {Function} callback - Callback when complete
|
|
548
591
|
*/
|
|
549
|
-
node.updateObjectInServiceConfig = function (
|
|
550
|
-
|
|
592
|
+
node.updateObjectInServiceConfig = function (
|
|
593
|
+
hid,
|
|
594
|
+
sid,
|
|
595
|
+
pid,
|
|
596
|
+
ins,
|
|
597
|
+
config,
|
|
598
|
+
callback
|
|
599
|
+
) {
|
|
600
|
+
this.apiClient.updateObject(
|
|
601
|
+
`${hid}/${sid}/${pid}/${ins}`,
|
|
602
|
+
config,
|
|
603
|
+
callback
|
|
604
|
+
);
|
|
551
605
|
};
|
|
552
606
|
|
|
553
607
|
/**
|
|
@@ -557,7 +611,7 @@ module.exports = function (RED) {
|
|
|
557
611
|
*/
|
|
558
612
|
node.getNodeConfig = function (uri, callback) {
|
|
559
613
|
this.apiClient.getNodeConfig(uri, callback);
|
|
560
|
-
}
|
|
614
|
+
};
|
|
561
615
|
|
|
562
616
|
/**
|
|
563
617
|
* Get the list of services on a hub
|
|
@@ -566,7 +620,7 @@ module.exports = function (RED) {
|
|
|
566
620
|
*/
|
|
567
621
|
node.getNodeConfigTree = function (hid, callback) {
|
|
568
622
|
this.apiClient.getNodeConfigTree(hid, callback);
|
|
569
|
-
}
|
|
623
|
+
};
|
|
570
624
|
|
|
571
625
|
/**
|
|
572
626
|
* Get the list of services on a hub
|
|
@@ -575,11 +629,11 @@ module.exports = function (RED) {
|
|
|
575
629
|
*/
|
|
576
630
|
node.getProfileByPid = function (hid, pid, callback) {
|
|
577
631
|
this.apiClient.getProfileByPid(hid, pid, callback);
|
|
578
|
-
}
|
|
632
|
+
};
|
|
579
633
|
|
|
580
634
|
node.getAllObjectProfiles = function (hid, callback) {
|
|
581
635
|
this.apiClient.getAllObjectProfiles(hid, callback);
|
|
582
|
-
}
|
|
636
|
+
};
|
|
583
637
|
}
|
|
584
638
|
|
|
585
639
|
RED.nodes.registerType('mobius connection', MobiusConnectionNode);
|
|
@@ -602,8 +656,12 @@ module.exports = function (RED) {
|
|
|
602
656
|
|
|
603
657
|
let pid = req.query.pid;
|
|
604
658
|
if (conn === null || !conn.connected) {
|
|
605
|
-
RED.log.error(
|
|
606
|
-
|
|
659
|
+
RED.log.error(
|
|
660
|
+
'Discover objects failed - could not to connect to MOBiUS hub.'
|
|
661
|
+
);
|
|
662
|
+
throw new Error(
|
|
663
|
+
'Discover objects failed - could not to connect to MOBiUS hub.'
|
|
664
|
+
);
|
|
607
665
|
} else {
|
|
608
666
|
uiFuncs
|
|
609
667
|
.discoverDevicesByPID(RED, conn, hid, spids, pid)
|
|
@@ -626,8 +684,12 @@ module.exports = function (RED) {
|
|
|
626
684
|
let hid = req.query.hid;
|
|
627
685
|
let spid = req.query.spid;
|
|
628
686
|
if (conn === null || !conn.connected) {
|
|
629
|
-
RED.log.error(
|
|
630
|
-
|
|
687
|
+
RED.log.error(
|
|
688
|
+
'Discover services failed - could not to connect to MOBiUS hub.'
|
|
689
|
+
);
|
|
690
|
+
throw new Error(
|
|
691
|
+
'Discover services failed - could not to connect to MOBiUS hub.'
|
|
692
|
+
);
|
|
631
693
|
} else {
|
|
632
694
|
uiFuncs
|
|
633
695
|
.discoverServicesBySPID(RED, conn, hid, spid)
|
|
@@ -641,13 +703,20 @@ module.exports = function (RED) {
|
|
|
641
703
|
}
|
|
642
704
|
);
|
|
643
705
|
|
|
644
|
-
|
|
645
|
-
|
|
706
|
+
// Register the endpoint for node-red mobius discovery in node-red node config pages
|
|
707
|
+
RED.httpAdmin.get(
|
|
708
|
+
'/mdiscover',
|
|
709
|
+
RED.auth.needsPermission('serial.read'),
|
|
710
|
+
function (req, res) {
|
|
646
711
|
let conn = RED.nodes.getNode(req.query.mobius);
|
|
647
712
|
let uri = req.query.uri;
|
|
648
713
|
if (conn === null || !conn.connected) {
|
|
649
|
-
RED.log.error(
|
|
650
|
-
|
|
714
|
+
RED.log.error(
|
|
715
|
+
'Discover services failed - could not to connect to MOBiUS hub.'
|
|
716
|
+
);
|
|
717
|
+
throw new Error(
|
|
718
|
+
'Discover services failed - could not to connect to MOBiUS hub.'
|
|
719
|
+
);
|
|
651
720
|
} else {
|
|
652
721
|
uiFuncs
|
|
653
722
|
.discover(conn, uri)
|
|
@@ -658,16 +727,24 @@ module.exports = function (RED) {
|
|
|
658
727
|
throw err;
|
|
659
728
|
});
|
|
660
729
|
}
|
|
661
|
-
}
|
|
730
|
+
}
|
|
731
|
+
);
|
|
662
732
|
|
|
663
|
-
|
|
664
|
-
|
|
733
|
+
// Register the endpoint for node-red get resource options for object type
|
|
734
|
+
RED.httpAdmin.get(
|
|
735
|
+
'/mgetresourceoptions',
|
|
736
|
+
RED.auth.needsPermission('serial.read'),
|
|
737
|
+
function (req, res) {
|
|
665
738
|
let conn = RED.nodes.getNode(req.query.mobius);
|
|
666
739
|
let hid = req.query.hid;
|
|
667
740
|
let pid = req.query.pid;
|
|
668
741
|
if (conn === null || !conn.connected) {
|
|
669
|
-
RED.log.error(
|
|
670
|
-
|
|
742
|
+
RED.log.error(
|
|
743
|
+
'Fetching resource options failed - could not to connect to MOBiUS hub.'
|
|
744
|
+
);
|
|
745
|
+
throw new Error(
|
|
746
|
+
'Fetching resource options failed - could not to connect to MOBiUS hub.'
|
|
747
|
+
);
|
|
671
748
|
} else {
|
|
672
749
|
uiFuncs
|
|
673
750
|
.getResourceOptions(conn, hid, pid)
|
|
@@ -678,15 +755,23 @@ module.exports = function (RED) {
|
|
|
678
755
|
throw err;
|
|
679
756
|
});
|
|
680
757
|
}
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
758
|
+
}
|
|
759
|
+
);
|
|
760
|
+
|
|
761
|
+
// Register the endpoint for node-red mobius discovery in node-red node config pages
|
|
762
|
+
RED.httpAdmin.get(
|
|
763
|
+
'/mgetservices',
|
|
764
|
+
RED.auth.needsPermission('serial.read'),
|
|
765
|
+
function (req, res) {
|
|
685
766
|
let conn = RED.nodes.getNode(req.query.mobius);
|
|
686
767
|
let hid = req.query.hid;
|
|
687
768
|
if (conn === null || !conn.connected) {
|
|
688
|
-
RED.log.error(
|
|
689
|
-
|
|
769
|
+
RED.log.error(
|
|
770
|
+
'Get services failed - could not to connect to MOBiUS hub.'
|
|
771
|
+
);
|
|
772
|
+
throw new Error(
|
|
773
|
+
'Get services failed - could not to connect to MOBiUS hub.'
|
|
774
|
+
);
|
|
690
775
|
} else {
|
|
691
776
|
uiFuncs
|
|
692
777
|
.getServiceList(conn, hid)
|
|
@@ -697,15 +782,23 @@ module.exports = function (RED) {
|
|
|
697
782
|
RED.log.warn(`Get services failed - ${err}`);
|
|
698
783
|
});
|
|
699
784
|
}
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
|
|
785
|
+
}
|
|
786
|
+
);
|
|
787
|
+
|
|
788
|
+
RED.httpAdmin.get(
|
|
789
|
+
'/mgetobjects',
|
|
790
|
+
RED.auth.needsPermission('serial.read'),
|
|
791
|
+
function (req, res) {
|
|
703
792
|
let conn = RED.nodes.getNode(req.query.mobius);
|
|
704
793
|
let hid = req.query.hid;
|
|
705
794
|
let sid = req.query.sid;
|
|
706
795
|
if (conn === null || !conn.connected) {
|
|
707
|
-
RED.log.error(
|
|
708
|
-
|
|
796
|
+
RED.log.error(
|
|
797
|
+
'Get objects failed - could not to connect to MOBiUS hub.'
|
|
798
|
+
);
|
|
799
|
+
throw new Error(
|
|
800
|
+
'Get objects failed - could not to connect to MOBiUS hub.'
|
|
801
|
+
);
|
|
709
802
|
} else {
|
|
710
803
|
uiFuncs
|
|
711
804
|
.getConfigObjectsList(conn, hid, sid)
|
|
@@ -713,12 +806,20 @@ module.exports = function (RED) {
|
|
|
713
806
|
res.json(response);
|
|
714
807
|
})
|
|
715
808
|
.catch((err) => {
|
|
716
|
-
RED.log.warn(
|
|
809
|
+
RED.log.warn(
|
|
810
|
+
`Get objects failed on service ${req.query.sid}: ${err.code}, ${
|
|
811
|
+
err.message ? err.message : ''
|
|
812
|
+
}`
|
|
813
|
+
);
|
|
717
814
|
});
|
|
718
815
|
}
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
|
|
816
|
+
}
|
|
817
|
+
);
|
|
818
|
+
|
|
819
|
+
RED.httpAdmin.get(
|
|
820
|
+
'/mgethid',
|
|
821
|
+
RED.auth.needsPermission('serial.read'),
|
|
822
|
+
function (req, res) {
|
|
722
823
|
let conn = RED.nodes.getNode(req.query.mobius);
|
|
723
824
|
if (conn === null || !conn.connected) {
|
|
724
825
|
RED.log.error('Get hid failed - could not to connect to MOBiUS hub.');
|
|
@@ -726,23 +827,27 @@ module.exports = function (RED) {
|
|
|
726
827
|
} else {
|
|
727
828
|
res.json(conn.hubId);
|
|
728
829
|
}
|
|
729
|
-
}
|
|
830
|
+
}
|
|
831
|
+
);
|
|
730
832
|
|
|
731
|
-
|
|
833
|
+
RED.httpAdmin.get(
|
|
834
|
+
'/mgetconnected',
|
|
835
|
+
RED.auth.needsPermission('serial.read'),
|
|
836
|
+
function (req, res) {
|
|
732
837
|
let conn = RED.nodes.getNode(req.query.mobius);
|
|
733
838
|
if (conn === null) {
|
|
734
839
|
res.json(false);
|
|
735
840
|
} else {
|
|
736
841
|
res.json(conn.connected);
|
|
737
842
|
}
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
RED.httpAdmin.get('/common/*', function (req, res) {
|
|
741
|
-
var options = {
|
|
742
|
-
root: __dirname + '/common/',
|
|
743
|
-
dotfiles: 'deny',
|
|
744
|
-
};
|
|
745
|
-
res.sendFile(req.params[0], options);
|
|
746
|
-
});
|
|
843
|
+
}
|
|
844
|
+
);
|
|
747
845
|
|
|
846
|
+
RED.httpAdmin.get('/common/*', function (req, res) {
|
|
847
|
+
var options = {
|
|
848
|
+
root: __dirname + '/common/',
|
|
849
|
+
dotfiles: 'deny',
|
|
850
|
+
};
|
|
851
|
+
res.sendFile(req.params[0], options);
|
|
852
|
+
});
|
|
748
853
|
};
|
|
@@ -24,7 +24,10 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
24
24
|
POSSIBILITY OF SUCH DAMAGE.
|
|
25
25
|
-->
|
|
26
26
|
|
|
27
|
-
<script
|
|
27
|
+
<script
|
|
28
|
+
type="text/x-red"
|
|
29
|
+
data-template-name="mobius discover object list"
|
|
30
|
+
>
|
|
28
31
|
<div class="form-row">
|
|
29
32
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
30
33
|
<input type="text" id="node-input-name" placeholder="Name">
|
|
@@ -138,7 +141,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|
|
138
141
|
},
|
|
139
142
|
oneditprepare: function () {
|
|
140
143
|
var node = this;
|
|
141
|
-
let mobiusSrvc = $(
|
|
144
|
+
let mobiusSrvc = $('#node-input-connection').val();
|
|
142
145
|
|
|
143
146
|
/** Create the subs container and populate it */
|
|
144
147
|
$('#node-input-subs-container')
|
|
@@ -167,15 +170,21 @@ POSSIBILITY OF SUCH DAMAGE.
|
|
|
167
170
|
}).appendTo(row);
|
|
168
171
|
|
|
169
172
|
// *** MOBSEARCH *** //
|
|
170
|
-
var searchField = $(
|
|
173
|
+
var searchField = $(
|
|
174
|
+
'<a class="searchbutton" style="margin-left: 5px; vertical-align: middle"><i id="node-lookup-instance-icon" class="fa fa-search"></i></a>'
|
|
175
|
+
).appendTo(row);
|
|
171
176
|
// *** END MOBSEARCH *** //
|
|
172
177
|
|
|
173
178
|
var typeField = $('<select/>', {
|
|
174
179
|
class: 'node-input-sub-type',
|
|
175
180
|
style: 'width:auto; margin-left: 5px; text-align: center;',
|
|
176
181
|
}).appendTo(row);
|
|
177
|
-
typeField.append(
|
|
178
|
-
|
|
182
|
+
typeField.append(
|
|
183
|
+
$('<option></option>').val('include').text('Include')
|
|
184
|
+
);
|
|
185
|
+
typeField.append(
|
|
186
|
+
$('<option></option>').val('exclude').text('Exclude')
|
|
187
|
+
);
|
|
179
188
|
|
|
180
189
|
// Populate the new stat
|
|
181
190
|
uriField.val(subscription.uri);
|
|
@@ -184,10 +193,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
|
|
184
193
|
// *** MOBSEARCH *** //
|
|
185
194
|
|
|
186
195
|
if (!node.subscriptions[i]) {
|
|
187
|
-
node.subscriptions[i] = {uri: '', type: 'include'}
|
|
196
|
+
node.subscriptions[i] = { uri: '', type: 'include' };
|
|
188
197
|
}
|
|
189
198
|
|
|
190
|
-
addMobsearchListButton(mobiusSrvc, searchField, i, mobsearchOpts)
|
|
199
|
+
addMobsearchListButton(mobiusSrvc, searchField, i, mobsearchOpts);
|
|
191
200
|
// *** END MOBSEARCH *** //
|
|
192
201
|
},
|
|
193
202
|
});
|
|
@@ -198,7 +207,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|
|
198
207
|
if (!node.subscriptions) {
|
|
199
208
|
node.subscriptions = [(subscription = { uri: '', type: 'include' })];
|
|
200
209
|
}
|
|
201
|
-
|
|
210
|
+
|
|
202
211
|
// *** MOBSEARCH *** //
|
|
203
212
|
|
|
204
213
|
mobsearchOpts = {
|
|
@@ -244,7 +253,9 @@ POSSIBILITY OF SUCH DAMAGE.
|
|
|
244
253
|
}
|
|
245
254
|
var editorRow = $('#dialog-form>div.node-input-subs-container-row');
|
|
246
255
|
height -=
|
|
247
|
-
4 *
|
|
256
|
+
4 *
|
|
257
|
+
(parseInt(editorRow.css('marginTop')) +
|
|
258
|
+
parseInt(editorRow.css('marginBottom')));
|
|
248
259
|
|
|
249
260
|
$('#node-input-subs-container').editableList('height', height);
|
|
250
261
|
},
|
|
@@ -270,7 +281,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
|
|
270
281
|
});
|
|
271
282
|
</script>
|
|
272
283
|
|
|
273
|
-
<script
|
|
284
|
+
<script
|
|
285
|
+
type="text/x-red"
|
|
286
|
+
data-help-name="mobius discover object list"
|
|
287
|
+
>
|
|
274
288
|
<p>Discover MOBiUS objects and return a filtered list of objects or URIs.</p>
|
|
275
289
|
|
|
276
290
|
<h3>Configuration Page</h3>
|
|
@@ -126,7 +126,11 @@ module.exports = function (RED) {
|
|
|
126
126
|
let objectList = [];
|
|
127
127
|
try {
|
|
128
128
|
const hid = node.hid === '' ? node.serviceConn.hubId : node.hid;
|
|
129
|
-
const profiles = await discoverProfiles(
|
|
129
|
+
const profiles = await discoverProfiles(
|
|
130
|
+
node.serviceConn,
|
|
131
|
+
hid,
|
|
132
|
+
node.subscriptions
|
|
133
|
+
);
|
|
130
134
|
|
|
131
135
|
for await (let entry of profiles.entries()) {
|
|
132
136
|
let discoverParams = {};
|
|
@@ -150,15 +154,28 @@ module.exports = function (RED) {
|
|
|
150
154
|
};
|
|
151
155
|
}
|
|
152
156
|
try {
|
|
153
|
-
let objects = await filterObjectsByRIDValue(
|
|
157
|
+
let objects = await filterObjectsByRIDValue(
|
|
158
|
+
node.serviceConn,
|
|
159
|
+
discoverParams
|
|
160
|
+
);
|
|
154
161
|
for (let lp = 0; lp < objects.value.length; lp++) {
|
|
155
162
|
objects.value[lp][
|
|
156
163
|
'uri'
|
|
157
164
|
] = `${serviceURI}/${objects.value[lp].pid}/${objects.value[lp].ins}`;
|
|
158
|
-
|
|
165
|
+
if (
|
|
166
|
+
isIncluded(
|
|
167
|
+
`${objects.value[lp]['uri']}`,
|
|
168
|
+
node.subscriptions
|
|
169
|
+
) &&
|
|
170
|
+
!isExcluded(`${objects.value[lp]['uri']}`, node.subscriptions)
|
|
171
|
+
) {
|
|
172
|
+
objectList.push(objects.value[lp]);
|
|
173
|
+
}
|
|
159
174
|
}
|
|
160
175
|
} catch (err) {
|
|
161
|
-
node.warn(
|
|
176
|
+
node.warn(
|
|
177
|
+
`Discover object failed for service (${serviceURI}) - ${err.message}`
|
|
178
|
+
);
|
|
162
179
|
}
|
|
163
180
|
}
|
|
164
181
|
|
|
@@ -185,10 +202,7 @@ module.exports = function (RED) {
|
|
|
185
202
|
let profiles = await discover(serviceConn, `${hid}/${sid}`);
|
|
186
203
|
let pids = [];
|
|
187
204
|
for (const pid of profiles.data) {
|
|
188
|
-
if (
|
|
189
|
-
isIncluded(`${hid}/${sid}/${pid}/#`, subscriptions) &&
|
|
190
|
-
!isExcluded(`${hid}/${sid}/${pid}/#`, subscriptions)
|
|
191
|
-
) {
|
|
205
|
+
if (isIncluded(`${hid}/${sid}/${pid}/#`, subscriptions)) {
|
|
192
206
|
pids.push(pid);
|
|
193
207
|
}
|
|
194
208
|
}
|
|
@@ -198,7 +212,9 @@ module.exports = function (RED) {
|
|
|
198
212
|
}
|
|
199
213
|
} else {
|
|
200
214
|
RED.log.warn(
|
|
201
|
-
`Failed to discover objects for service ${
|
|
215
|
+
`Failed to discover objects for service ${
|
|
216
|
+
service.id.split('/')[1]
|
|
217
|
+
} as it is offline.`
|
|
202
218
|
);
|
|
203
219
|
}
|
|
204
220
|
}
|
|
@@ -240,7 +256,10 @@ module.exports = function (RED) {
|
|
|
240
256
|
function isIncluded(uri, subscriptions) {
|
|
241
257
|
let include = false;
|
|
242
258
|
for (const subscription of subscriptions) {
|
|
243
|
-
if (
|
|
259
|
+
if (
|
|
260
|
+
subscription.type === 'include' &&
|
|
261
|
+
validateSubscription(subscription.uri)
|
|
262
|
+
) {
|
|
244
263
|
if (matchTopic(subscription.uri, uri)) {
|
|
245
264
|
include = true;
|
|
246
265
|
}
|
|
@@ -252,7 +271,10 @@ module.exports = function (RED) {
|
|
|
252
271
|
function isExcluded(uri, subscriptions) {
|
|
253
272
|
let exclude = false;
|
|
254
273
|
for (const subscription of subscriptions) {
|
|
255
|
-
if (
|
|
274
|
+
if (
|
|
275
|
+
subscription.type === 'exclude' &&
|
|
276
|
+
validateSubscription(subscription.uri)
|
|
277
|
+
) {
|
|
256
278
|
if (matchTopic(subscription.uri, uri)) {
|
|
257
279
|
exclude = true;
|
|
258
280
|
}
|
|
@@ -280,12 +302,23 @@ module.exports = function (RED) {
|
|
|
280
302
|
function matchTopic(filter, topic) {
|
|
281
303
|
const filterArray = filter.split('/');
|
|
282
304
|
const topicArray = topic.split('/');
|
|
283
|
-
const length =
|
|
305
|
+
const length =
|
|
306
|
+
filterArray.length < topicArray.length
|
|
307
|
+
? filterArray.length
|
|
308
|
+
: topicArray.length;
|
|
284
309
|
|
|
285
310
|
for (let i = 0; i < length; ++i) {
|
|
286
311
|
const left = filterArray[i];
|
|
287
312
|
const right = topicArray[i];
|
|
288
|
-
if (
|
|
313
|
+
if (
|
|
314
|
+
!(
|
|
315
|
+
left === right ||
|
|
316
|
+
left === '+' ||
|
|
317
|
+
left === '#' ||
|
|
318
|
+
right === '+' ||
|
|
319
|
+
right === '#'
|
|
320
|
+
)
|
|
321
|
+
) {
|
|
289
322
|
return false;
|
|
290
323
|
}
|
|
291
324
|
}
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
'use strict';
|
|
29
29
|
|
|
30
30
|
module.exports = function (RED) {
|
|
31
|
-
function MobiusFlowNode
|
|
31
|
+
function MobiusFlowNode(n) {
|
|
32
32
|
RED.nodes.createNode(this, n);
|
|
33
33
|
this.mobjects = n.mobjects;
|
|
34
34
|
this.serviceConn = RED.nodes.getNode(n.connection);
|
|
@@ -38,7 +38,7 @@ module.exports = function (RED) {
|
|
|
38
38
|
node.status({
|
|
39
39
|
fill: 'red',
|
|
40
40
|
shape: 'ring',
|
|
41
|
-
text: 'Disconnected'
|
|
41
|
+
text: 'Disconnected',
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
node.serviceConn.register(node);
|
|
@@ -47,7 +47,7 @@ module.exports = function (RED) {
|
|
|
47
47
|
node.status({
|
|
48
48
|
fill: 'green',
|
|
49
49
|
shape: 'ring',
|
|
50
|
-
text: 'Busy'
|
|
50
|
+
text: 'Busy',
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
for (const mobject of node.mobjects) {
|
|
@@ -55,7 +55,7 @@ module.exports = function (RED) {
|
|
|
55
55
|
node.status({
|
|
56
56
|
fill: 'yellow',
|
|
57
57
|
shape: 'dot',
|
|
58
|
-
text: 'URIs not Valid'
|
|
58
|
+
text: 'URIs not Valid',
|
|
59
59
|
});
|
|
60
60
|
if (done) {
|
|
61
61
|
return done();
|
|
@@ -71,17 +71,21 @@ module.exports = function (RED) {
|
|
|
71
71
|
node.status({
|
|
72
72
|
fill: 'green',
|
|
73
73
|
shape: 'dot',
|
|
74
|
-
text: 'Done'
|
|
74
|
+
text: 'Done',
|
|
75
75
|
});
|
|
76
|
-
node.send({ ...msg, topic: msg.topic, payload: values});
|
|
76
|
+
node.send({ ...msg, topic: msg.topic, payload: values });
|
|
77
77
|
})
|
|
78
78
|
.catch((err) => {
|
|
79
79
|
node.status({
|
|
80
80
|
fill: 'yellow',
|
|
81
81
|
shape: 'dot',
|
|
82
|
-
text: 'Error: ' + JSON.stringify(err.code)
|
|
82
|
+
text: 'Error: ' + JSON.stringify(err.code),
|
|
83
83
|
});
|
|
84
|
-
node.error(
|
|
84
|
+
node.error(
|
|
85
|
+
`Mobius error reading object: ${err.code}, ${
|
|
86
|
+
err.message ? err.message : ''
|
|
87
|
+
}`
|
|
88
|
+
);
|
|
85
89
|
})
|
|
86
90
|
.finally(() => {
|
|
87
91
|
if (done) {
|
|
@@ -98,7 +102,7 @@ module.exports = function (RED) {
|
|
|
98
102
|
}
|
|
99
103
|
}
|
|
100
104
|
|
|
101
|
-
function validateResourceURI
|
|
105
|
+
function validateResourceURI(uri) {
|
|
102
106
|
let parts = uri.split('/');
|
|
103
107
|
for (let lp = 0; lp < parts.length; lp++) {
|
|
104
108
|
if (parts[lp] === null || parts[lp] === '') {
|
|
@@ -111,7 +115,7 @@ module.exports = function (RED) {
|
|
|
111
115
|
return false;
|
|
112
116
|
}
|
|
113
117
|
|
|
114
|
-
function readObject
|
|
118
|
+
function readObject(node, uri) {
|
|
115
119
|
return new Promise((resolve, reject) => {
|
|
116
120
|
node.serviceConn.readObject(uri, (err, response) => {
|
|
117
121
|
if (err) {
|
|
@@ -90,7 +90,11 @@ module.exports = function (RED) {
|
|
|
90
90
|
shape: 'dot',
|
|
91
91
|
text: 'Error: ' + JSON.stringify(err.code),
|
|
92
92
|
});
|
|
93
|
-
node.error(
|
|
93
|
+
node.error(
|
|
94
|
+
`Mobius error reading resource: ${err.code}, ${
|
|
95
|
+
err.message ? err.message : ''
|
|
96
|
+
}`
|
|
97
|
+
);
|
|
94
98
|
})
|
|
95
99
|
.finally(() => {
|
|
96
100
|
if (done) {
|
|
@@ -129,7 +133,11 @@ module.exports = function (RED) {
|
|
|
129
133
|
if (node.sendFormat === 'array') {
|
|
130
134
|
resolve(response.data.pv);
|
|
131
135
|
} else {
|
|
132
|
-
resolve({
|
|
136
|
+
resolve({
|
|
137
|
+
uri: uri,
|
|
138
|
+
pv: response.data.pv,
|
|
139
|
+
name: response.data.name,
|
|
140
|
+
});
|
|
133
141
|
}
|
|
134
142
|
}
|
|
135
143
|
});
|