add google maps
This commit is contained in:
parent
893f69ad18
commit
2324a2c837
4
htdocs/map.css
Normal file
4
htdocs/map.css
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
html, body {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
@ -4,7 +4,7 @@
|
|||||||
<title>OpenWebRX | Open Source SDR Web App for Everyone!</title>
|
<title>OpenWebRX | Open Source SDR Web App for Everyone!</title>
|
||||||
<script src="static/jquery-3.2.1.min.js"></script>
|
<script src="static/jquery-3.2.1.min.js"></script>
|
||||||
<script src="static/map.js"></script>
|
<script src="static/map.js"></script>
|
||||||
<link rel="stylesheet" type="text/css" href="static/nanoscroller.css" />
|
<link rel="stylesheet" type="text/css" href="static/map.css" />
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -9,11 +9,38 @@
|
|||||||
|
|
||||||
var ws = new WebSocket(ws_url);
|
var ws = new WebSocket(ws_url);
|
||||||
ws.onopen = function(){
|
ws.onopen = function(){
|
||||||
console.info("onopen");
|
|
||||||
ws.send("SERVER DE CLIENT client=map.js type=map");
|
ws.send("SERVER DE CLIENT client=map.js type=map");
|
||||||
};
|
};
|
||||||
ws.onmessage = function(){
|
|
||||||
console.info("onmessage");
|
ws.onmessage = function(e){
|
||||||
|
if (typeof e.data != 'string') {
|
||||||
|
console.error("unsupported binary data on websocket; ignoring");
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (e.data.substr(0, 16) == "CLIENT DE SERVER") {
|
||||||
|
console.log("Server acknowledged WebSocket connection.");
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
json = JSON.parse(e.data);
|
||||||
|
switch (json.type) {
|
||||||
|
case "config":
|
||||||
|
var config = json.value;
|
||||||
|
$.getScript("https://maps.googleapis.com/maps/api/js?key=" + config.google_maps_api_key).done(function(){
|
||||||
|
var map = new google.maps.Map($('body')[0], {
|
||||||
|
center: {
|
||||||
|
lat: config.receiver_gps[0],
|
||||||
|
lng: config.receiver_gps[1]
|
||||||
|
},
|
||||||
|
zoom: 8
|
||||||
|
});
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// don't lose exception
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
ws.onclose = function(){
|
ws.onclose = function(){
|
||||||
console.info("onclose");
|
console.info("onclose");
|
||||||
|
@ -7,14 +7,33 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class OpenWebRxReceiverClient(object):
|
class Client(object):
|
||||||
|
def __init__(self, conn):
|
||||||
|
self.conn = conn
|
||||||
|
|
||||||
|
def protected_send(self, data):
|
||||||
|
try:
|
||||||
|
self.conn.send(data)
|
||||||
|
# these exception happen when the socket is closed
|
||||||
|
except OSError:
|
||||||
|
self.close()
|
||||||
|
except ValueError:
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.conn.close()
|
||||||
|
logger.debug("connection closed")
|
||||||
|
|
||||||
|
|
||||||
|
class OpenWebRxReceiverClient(Client):
|
||||||
config_keys = ["waterfall_colors", "waterfall_min_level", "waterfall_max_level",
|
config_keys = ["waterfall_colors", "waterfall_min_level", "waterfall_max_level",
|
||||||
"waterfall_auto_level_margin", "lfo_offset", "samp_rate", "fft_size", "fft_fps",
|
"waterfall_auto_level_margin", "lfo_offset", "samp_rate", "fft_size", "fft_fps",
|
||||||
"audio_compression", "fft_compression", "max_clients", "start_mod",
|
"audio_compression", "fft_compression", "max_clients", "start_mod",
|
||||||
"client_audio_buffer_size", "start_freq", "center_freq", "mathbox_waterfall_colors",
|
"client_audio_buffer_size", "start_freq", "center_freq", "mathbox_waterfall_colors",
|
||||||
"mathbox_waterfall_history_length", "mathbox_waterfall_frequency_resolution"]
|
"mathbox_waterfall_history_length", "mathbox_waterfall_frequency_resolution"]
|
||||||
|
|
||||||
def __init__(self, conn):
|
def __init__(self, conn):
|
||||||
self.conn = conn
|
super().__init__(conn)
|
||||||
|
|
||||||
self.dsp = None
|
self.dsp = None
|
||||||
self.sdr = None
|
self.sdr = None
|
||||||
@ -79,8 +98,7 @@ class OpenWebRxReceiverClient(object):
|
|||||||
if self.configSub is not None:
|
if self.configSub is not None:
|
||||||
self.configSub.cancel()
|
self.configSub.cancel()
|
||||||
self.configSub = None
|
self.configSub = None
|
||||||
self.conn.close()
|
super().close()
|
||||||
logger.debug("connection closed")
|
|
||||||
|
|
||||||
def stopDsp(self):
|
def stopDsp(self):
|
||||||
if self.dsp is not None:
|
if self.dsp is not None:
|
||||||
@ -100,42 +118,57 @@ class OpenWebRxReceiverClient(object):
|
|||||||
for key, value in params.items():
|
for key, value in params.items():
|
||||||
self.dsp.setProperty(key, value)
|
self.dsp.setProperty(key, value)
|
||||||
|
|
||||||
def protected_send(self, data):
|
|
||||||
try:
|
|
||||||
self.conn.send(data)
|
|
||||||
# these exception happen when the socket is closed
|
|
||||||
except OSError:
|
|
||||||
self.close()
|
|
||||||
except ValueError:
|
|
||||||
self.close()
|
|
||||||
|
|
||||||
def write_spectrum_data(self, data):
|
def write_spectrum_data(self, data):
|
||||||
self.protected_send(bytes([0x01]) + data)
|
self.protected_send(bytes([0x01]) + data)
|
||||||
|
|
||||||
def write_dsp_data(self, data):
|
def write_dsp_data(self, data):
|
||||||
self.protected_send(bytes([0x02]) + data)
|
self.protected_send(bytes([0x02]) + data)
|
||||||
|
|
||||||
def write_s_meter_level(self, level):
|
def write_s_meter_level(self, level):
|
||||||
self.protected_send({"type":"smeter","value":level})
|
self.protected_send({"type":"smeter","value":level})
|
||||||
|
|
||||||
def write_cpu_usage(self, usage):
|
def write_cpu_usage(self, usage):
|
||||||
self.protected_send({"type":"cpuusage","value":usage})
|
self.protected_send({"type":"cpuusage","value":usage})
|
||||||
|
|
||||||
def write_clients(self, clients):
|
def write_clients(self, clients):
|
||||||
self.protected_send({"type":"clients","value":clients})
|
self.protected_send({"type":"clients","value":clients})
|
||||||
|
|
||||||
def write_secondary_fft(self, data):
|
def write_secondary_fft(self, data):
|
||||||
self.protected_send(bytes([0x03]) + data)
|
self.protected_send(bytes([0x03]) + data)
|
||||||
|
|
||||||
def write_secondary_demod(self, data):
|
def write_secondary_demod(self, data):
|
||||||
self.protected_send(bytes([0x04]) + data)
|
self.protected_send(bytes([0x04]) + data)
|
||||||
|
|
||||||
def write_secondary_dsp_config(self, cfg):
|
def write_secondary_dsp_config(self, cfg):
|
||||||
self.protected_send({"type":"secondary_config", "value":cfg})
|
self.protected_send({"type":"secondary_config", "value":cfg})
|
||||||
|
|
||||||
def write_config(self, cfg):
|
def write_config(self, cfg):
|
||||||
self.protected_send({"type":"config","value":cfg})
|
self.protected_send({"type":"config","value":cfg})
|
||||||
|
|
||||||
def write_receiver_details(self, details):
|
def write_receiver_details(self, details):
|
||||||
self.protected_send({"type":"receiver_details","value":details})
|
self.protected_send({"type":"receiver_details","value":details})
|
||||||
|
|
||||||
def write_profiles(self, profiles):
|
def write_profiles(self, profiles):
|
||||||
self.protected_send({"type":"profiles","value":profiles})
|
self.protected_send({"type":"profiles","value":profiles})
|
||||||
|
|
||||||
def write_features(self, features):
|
def write_features(self, features):
|
||||||
self.protected_send({"type":"features","value":features})
|
self.protected_send({"type":"features","value":features})
|
||||||
|
|
||||||
def write_metadata(self, metadata):
|
def write_metadata(self, metadata):
|
||||||
self.protected_send({"type":"metadata","value":metadata})
|
self.protected_send({"type":"metadata","value":metadata})
|
||||||
|
|
||||||
|
|
||||||
|
class MapConnection(Client):
|
||||||
|
def __init__(self, conn):
|
||||||
|
super().__init__(conn)
|
||||||
|
|
||||||
|
pm = PropertyManager.getSharedInstance()
|
||||||
|
self.write_config(pm.collect("google_maps_api_key", "receiver_gps").__dict__())
|
||||||
|
|
||||||
|
def write_config(self, cfg):
|
||||||
|
self.protected_send({"type":"config","value":cfg})
|
||||||
|
|
||||||
|
|
||||||
class WebSocketMessageHandler(object):
|
class WebSocketMessageHandler(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.handshake = None
|
self.handshake = None
|
||||||
@ -153,6 +186,8 @@ class WebSocketMessageHandler(object):
|
|||||||
if "type" in self.handshake:
|
if "type" in self.handshake:
|
||||||
if self.handshake["type"] == "receiver":
|
if self.handshake["type"] == "receiver":
|
||||||
self.client = OpenWebRxReceiverClient(conn)
|
self.client = OpenWebRxReceiverClient(conn)
|
||||||
|
if self.handshake["type"] == "map":
|
||||||
|
self.client = MapConnection(conn)
|
||||||
# backwards compatibility
|
# backwards compatibility
|
||||||
else:
|
else:
|
||||||
self.client = OpenWebRxReceiverClient(conn)
|
self.client = OpenWebRxReceiverClient(conn)
|
||||||
|
@ -81,6 +81,7 @@ class IndexController(AssetsController):
|
|||||||
|
|
||||||
class MapController(AssetsController):
|
class MapController(AssetsController):
|
||||||
def handle_request(self):
|
def handle_request(self):
|
||||||
|
#TODO check if we have a google maps api key first?
|
||||||
self.serve_file("map.html", content_type = "text/html")
|
self.serve_file("map.html", content_type = "text/html")
|
||||||
|
|
||||||
class WebSocketController(Controller):
|
class WebSocketController(Controller):
|
||||||
|
Loading…
Reference in New Issue
Block a user