From 89c36c81556411183090fa62f59e7ee0d2b0b194 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Tue, 12 Sep 2023 12:52:49 -0500 Subject: [PATCH] add support for multiple PSN servers --- plugins/posistagenet/main.js | 41 ++++++++++------- plugins/posistagenet/template.ejs | 75 ++++++++++++++++--------------- 2 files changed, 62 insertions(+), 54 deletions(-) diff --git a/plugins/posistagenet/main.js b/plugins/posistagenet/main.js index 07f3db9..dc11cfc 100644 --- a/plugins/posistagenet/main.js +++ b/plugins/posistagenet/main.js @@ -10,43 +10,50 @@ exports.config = { heartbeatTimeout: 15000, searchOptions: { type: 'multicast', - address: getMulticastGroup(1), + address: `236.10.10.10`, port: 56565, validateResponse(msg, info) { + // TODO(jwetzell): find a way to check that this is a posistagenet message return true; }, }, }; exports.ready = function ready(_device) { - console.log('posistagenet is ready'); const device = _device; - device.psn = new Decoder(); - + device.data = {}; const networkInterfaces = device.getNetworkInterfaces(); Object.keys(networkInterfaces).forEach((networkInterfaceID) => { const networkInterface = networkInterfaces[networkInterfaceID]; - device.connection.addMembership(getMulticastGroup(1), networkInterface[0].address); + device.connection.addMembership(`236.10.10.10`, networkInterface[0].address); }); }; -exports.data = function data(_device, buf) { +exports.data = function data(_device, buf, info) { const device = _device; - if (device.psn) { - device.psn.decode(buf); - device.data = { - data: device.psn.data, - info: device.psn.info, - }; - device.draw(); + + if (!device.decoders) { + device.decoders = {}; } + + if (!device.decoders[info.address]) { + device.decoders[info.address] = new Decoder(); + } + + device.decoders[info.address].decode(buf); + + Object.keys(device.decoders).forEach((address) => { + if (!device.data[address]) { + device.data[address] = { + data: device.decoders[address].data, + info: device.decoders[address].info, + }; + } + }); + device.draw(); }; exports.heartbeat = function heartbeat(device) {}; exports.update = function update(_device, doc, updateType, updateData) {}; - -function getMulticastGroup(universe) { - return `236.10.10.10`; -} diff --git a/plugins/posistagenet/template.ejs b/plugins/posistagenet/template.ejs index 9d2a410..819d156 100644 --- a/plugins/posistagenet/template.ejs +++ b/plugins/posistagenet/template.ejs @@ -3,7 +3,11 @@
-

Tracker Count: <%= Object.keys(data.data.trackers).length %>

+ <% Object.keys(data).forEach((address) => { + const instanceData = data[address] + %> +

Server: <%= instanceData.info.system_name ? instanceData.info.system_name : ''%> (<%= address %>)

+

Tracker Count: <%= Object.keys(instanceData.data.trackers).length %>

@@ -15,43 +19,40 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - <% Object.entries(data.info.trackers).forEach(([trackerId,trackerInfo]) => { - const trackerData = data.data.trackers[trackerId] + <% Object.entries(instanceData.info.trackers).forEach(([trackerId,trackerInfo]) => { + const trackerData = instanceData.data.trackers[trackerId] %> - - + @@ -84,12 +85,12 @@ - - <% }); %> -
ACCEL TRGTPOS
IDNamexyzxyzxyzvalidityxyzxyztracker_timestamp
IDNamexyzxyzxyzvalidityxyzxyztracker_timestamp
<%= trackerId %> <%= trackerInfo.name %> <%= trackerData.tracker_timestamp %>
+<% + }); +%>
\ No newline at end of file