kopia lustrzana https://github.com/projecthorus/radiosonde_auto_rx
Get web client to request initial set of data when connected.
rodzic
6a769499a3
commit
6a5478b15d
|
|
@ -524,19 +524,28 @@ class SondeScanner(object):
|
||||||
# Append on any frequencies in the supplied greylist
|
# Append on any frequencies in the supplied greylist
|
||||||
peak_frequencies = np.append(np.array(self.greylist)*1e6, peak_frequencies)
|
peak_frequencies = np.append(np.array(self.greylist)*1e6, peak_frequencies)
|
||||||
|
|
||||||
# Emit a notification to the client that a scan is complete.
|
# Get the level of our peak search results, to send to the web client.
|
||||||
# We need to format our peak results in an odd manner for chart.js to read them.
|
# This is actually a bit of a pain to do...
|
||||||
_peak_freq = []
|
_peak_freq = []
|
||||||
_peak_lvl = []
|
_peak_lvl = []
|
||||||
for _peak in peak_frequencies:
|
for _peak in peak_frequencies:
|
||||||
try:
|
try:
|
||||||
|
# Find the index of the peak within our decimated frequency array.
|
||||||
|
_peak_power_idx = np.argmin(np.abs(scan_result['freq']-_peak/1e6))
|
||||||
|
# Because we've decimated the freq & power data, the peak location may
|
||||||
|
# not be exactly at this frequency, so we take the maximum of an area
|
||||||
|
# around this location.
|
||||||
|
_peak_search_min = max(0,_peak_power_idx-5)
|
||||||
|
_peak_search_max = min(len(scan_result['freq'])-1, _peak_power_idx+5)
|
||||||
|
# Grab the maximum value, and append it and the frequency to the output arrays
|
||||||
|
_peak_lvl.append(max(scan_result['power'][_peak_search_min:_peak_search_max]))
|
||||||
_peak_freq.append(_peak/1e6)
|
_peak_freq.append(_peak/1e6)
|
||||||
_peak_lvl.append(power[np.argmin(np.abs(freq-_peak))])
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
# Add the peak results to our global scan result dictionary.
|
||||||
scan_result['peak_freq'] = _peak_freq
|
scan_result['peak_freq'] = _peak_freq
|
||||||
scan_result['peak_lvl'] = _peak_lvl
|
scan_result['peak_lvl'] = _peak_lvl
|
||||||
|
# Tell the web client we have new data.
|
||||||
flask_emit_event('scan_event')
|
flask_emit_event('scan_event')
|
||||||
|
|
||||||
if len(peak_frequencies) == 0:
|
if len(peak_frequencies) == 0:
|
||||||
|
|
|
||||||
|
|
@ -47,13 +47,6 @@
|
||||||
// http[s]://<domain>:<port>[/<namespace>]
|
// http[s]://<domain>:<port>[/<namespace>]
|
||||||
var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port + namespace);
|
var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port + namespace);
|
||||||
|
|
||||||
// Event handler for new connections.
|
|
||||||
// The callback function is invoked when a connection with the
|
|
||||||
// server is established.
|
|
||||||
socket.on('connect', function() {
|
|
||||||
socket.emit('my_event', {data: 'I\'m connected!'});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Grab the System config.
|
// Grab the System config.
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/get_config",
|
url: "/get_config",
|
||||||
|
|
@ -148,15 +141,21 @@
|
||||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||||
}).addTo(sondemap);
|
}).addTo(sondemap);
|
||||||
// Add a new marker, but set it to hidden initially.
|
// Add a new marker, but set it to hidden initially.
|
||||||
var marker = L.marker(sondemap.getCenter()).addTo(sondemap);
|
var home_marker = L.marker(sondemap.getCenter()).addTo(sondemap);
|
||||||
|
var sonde_marker = L.marker([0.0,0.0]).addTo(sondemap);
|
||||||
|
|
||||||
socket.on('telemetry_event', function(msg) {
|
socket.on('telemetry_event', function(msg) {
|
||||||
$('#telemetry').html('<b>ID: </b>' + msg.id + ' <b> Frame: </b> ' + msg.frame + '<b> Position: </b>' + msg.lat + ',' + msg.lon + '<b> Alt: </b>' + msg.alt);
|
$('#telemetry').html('<b>ID: </b>' + msg.id + ' <b> Frame: </b> ' + msg.frame + '<b> Position: </b>' + msg.lat + ',' + msg.lon + '<b> Alt: </b>' + msg.alt);
|
||||||
marker.setLatLng([msg.lat,msg.lon]).update();
|
sonde_marker.setLatLng([msg.lat,msg.lon]).update();
|
||||||
sondemap.setView([msg.lat, msg.lon], 10);
|
sondemap.setView([msg.lat, msg.lon], 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Tell the server we are connected and ready for data.
|
||||||
|
socket.on('connect', function() {
|
||||||
|
socket.emit('client_connected', {data: 'I\'m connected!'});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,23 @@ def shutdown_flask(shutdown_key):
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
#
|
||||||
|
# Globally called 'emit' function
|
||||||
|
#
|
||||||
|
def flask_emit_event(event_name="none", data={}):
|
||||||
|
""" Emit a socketio event to any clients. """
|
||||||
|
socketio.emit(event_name, data, namespace='/update_status')
|
||||||
|
|
||||||
|
|
||||||
|
@socketio.on('client_connected', namespace='/update_status')
|
||||||
|
def refresh_client(arg1):
|
||||||
|
""" A client has connected, let them know to grab data."""
|
||||||
|
logging.info("Flask - New Web Client connected!")
|
||||||
|
# Tell them to get a copy of the latest scan results.
|
||||||
|
flask_emit_event('scan_event')
|
||||||
|
# TODO: Send last few log entries
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Flask Startup & Shutdown Helper Scripts
|
# Flask Startup & Shutdown Helper Scripts
|
||||||
#
|
#
|
||||||
|
|
@ -125,12 +142,6 @@ def stop_flask(host='0.0.0.0', port=5000):
|
||||||
# TODO: Cleanup errors
|
# TODO: Cleanup errors
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
#
|
|
||||||
# Globally called 'emit' function
|
|
||||||
#
|
|
||||||
def flask_emit_event(event_name="none", data={}):
|
|
||||||
""" Emit a socketio event to any clients. """
|
|
||||||
socketio.emit(event_name, data, namespace='/update_status')
|
|
||||||
|
|
||||||
|
|
||||||
class WebHandler(logging.Handler):
|
class WebHandler(logging.Handler):
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue