From 95c4dbfa95ea1e04ba2be73b76f0badcf22a360d Mon Sep 17 00:00:00 2001 From: Joseph Malloch Date: Tue, 5 Dec 2023 15:38:31 -0400 Subject: [PATCH] Filter local monitor signals at Python backend instead of js; use custom 'display' property instead of device name to indicate whether signals should be forwarded to front end. --- js/Graph.js | 4 ---- webmapper.py | 21 ++++++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/js/Graph.js b/js/Graph.js index f170096..4f7e858 100644 --- a/js/Graph.js +++ b/js/Graph.js @@ -353,8 +353,6 @@ function Graph() { let hidden = this.devices.some(d => d.hidden == true); let last = devs.length - 1; for (var i in devs) { - // Skip if webmapper device - if (devs[i].name.includes('webmapper')) continue; let dev = this.devices.add(devs[i], i == last); if (hidden) dev.hidden = true; @@ -386,8 +384,6 @@ function Graph() { this.add_signals = function(cmd, sigs) { let last = sigs.length - 1; for (var i in sigs) { - // Skip if from webmapper device - if (sigs[i].device.includes('webmapper')) continue; let dev = this.devices.find(sigs[i].device); if (!dev) { console.log("error adding signal: couldn't find device", sigs[i].device); diff --git a/webmapper.py b/webmapper.py index 3dae3a6..9f26daa 100644 --- a/webmapper.py +++ b/webmapper.py @@ -76,13 +76,16 @@ def launch(): launcher.start() graph = mpr.Graph() -webmapper_dev = mpr.Device("webmapper") +webmapper_dev = mpr.Device("webmapper", graph) +webmapper_dev['display'] = False def monitor_handler(sig, event, id, val, timetag): server.send_command("update_sig_monitor", val) -monitor_sig = webmapper_dev.add_signal(mpr.Direction.INCOMING, "monitor", 1, - mpr.Type.FLOAT, None, -100000, 100000, None, monitor_handler) +monitor_sig = webmapper_dev.add_signal(mpr.Direction.INCOMING, "monitor", 1, mpr.Type.FLOAT, + None, -100000, 100000, None, monitor_handler) +monitor_sig['display'] = False + if '--iface' in sys.argv: iface = sys.argv[sys.argv.index('--iface')+1] graph.set_interface(iface) @@ -168,7 +171,7 @@ def map_props(map): return props def on_device(type, dev, event): -# print('ON_DEVICE') +# print('ON_DEVICE:', event, dev) dev = dev_props(dev) if event == mpr.Graph.Event.NEW or event == mpr.Graph.Event.MODIFIED: new_devs[dev['key']] = dev @@ -177,7 +180,7 @@ def on_device(type, dev, event): del_devs[dev['key']] = dev def on_signal(type, sig, event): -# print('ON_SIGNAL') +# print('ON_SIGNAL:', event) sig = sig_props(sig) if event == mpr.Graph.Event.NEW or event == mpr.Graph.Event.MODIFIED: new_sigs[sig['key']] = sig @@ -185,7 +188,7 @@ def on_signal(type, sig, event): del_sigs[sig['key']] = sig def on_map(type, map, event): -# print('ON_MAP') +# print('ON_MAP:', event) map = map_props(map) if event == mpr.Graph.Event.NEW or event == mpr.Graph.Event.MODIFIED: new_maps[map['key']] = map @@ -399,8 +402,12 @@ def init_graph(arg): graph.subscribe(None, mpr.Type.OBJECT, -1) for d in graph.devices(): + if 'display' in d and d['display'] == False: + continue server.send_command("add_devices", [dev_props(d)]) for s in graph.signals(): + if 'display' in s and s['display'] == False: + continue server.send_command("add_signals", [sig_props(s)]) for m in graph.maps(): server.send_command("add_maps", [map_props(m)]) @@ -409,7 +416,7 @@ def init_graph(arg): init_graph(0) server.add_command_handler("add_devices", - lambda x: ("add_devices", [dev_props(d) for d in graph.devices()])) + lambda x: ("add_devices", [dev_props(d) for d in graph.devices().filter('display', True, mpr.Operator.NOT_EQUAL)])) def subscribe(device): if device == 'all_devices':