2020-03-21 21:40:39 +00:00
|
|
|
from owrx.config import Config
|
2019-12-21 19:58:28 +00:00
|
|
|
from owrx.dsp import DspManager
|
|
|
|
from owrx.cpu import CpuUsageThread
|
|
|
|
from owrx.sdr import SdrService
|
2019-12-23 20:12:28 +00:00
|
|
|
from owrx.source import SdrSource
|
2020-01-10 20:38:46 +00:00
|
|
|
from owrx.client import ClientRegistry, TooManyClientsException
|
2019-05-13 17:19:15 +00:00
|
|
|
from owrx.feature import FeatureDetector
|
2019-07-01 09:47:07 +00:00
|
|
|
from owrx.version import openwebrx_version
|
2019-07-19 21:55:52 +00:00
|
|
|
from owrx.bands import Bandplan
|
2019-09-27 22:53:58 +00:00
|
|
|
from owrx.bookmarks import Bookmarks
|
2019-07-01 19:20:53 +00:00
|
|
|
from owrx.map import Map
|
2019-10-03 16:10:46 +00:00
|
|
|
from owrx.locator import Locator
|
2020-03-23 22:56:05 +00:00
|
|
|
from owrx.property import PropertyStack
|
2020-04-26 16:45:41 +00:00
|
|
|
from owrx.modes import Modes, DigitalMode
|
2019-09-21 20:10:16 +00:00
|
|
|
from multiprocessing import Queue
|
2019-12-08 20:11:36 +00:00
|
|
|
from queue import Full
|
2020-04-14 19:10:35 +00:00
|
|
|
from js8py import Js8Frame
|
2019-09-21 20:10:16 +00:00
|
|
|
import json
|
|
|
|
import threading
|
2019-05-12 13:56:18 +00:00
|
|
|
|
|
|
|
import logging
|
2019-07-21 17:40:28 +00:00
|
|
|
|
2019-05-12 13:56:18 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2019-07-01 19:20:53 +00:00
|
|
|
|
2019-07-01 17:49:58 +00:00
|
|
|
class Client(object):
|
|
|
|
def __init__(self, conn):
|
|
|
|
self.conn = conn
|
2019-11-26 19:10:56 +00:00
|
|
|
self.multiprocessingPipe = Queue(100)
|
2019-09-21 20:10:16 +00:00
|
|
|
|
|
|
|
def mp_passthru():
|
|
|
|
run = True
|
|
|
|
while run:
|
|
|
|
try:
|
|
|
|
data = self.multiprocessingPipe.get()
|
2019-09-22 11:16:24 +00:00
|
|
|
self.send(data)
|
2019-09-21 20:10:16 +00:00
|
|
|
except (EOFError, OSError):
|
|
|
|
run = False
|
|
|
|
|
2019-09-22 11:16:24 +00:00
|
|
|
threading.Thread(target=mp_passthru).start()
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-09-22 11:16:24 +00:00
|
|
|
def send(self, data):
|
|
|
|
self.conn.send(data)
|
2019-07-01 17:49:58 +00:00
|
|
|
|
|
|
|
def close(self):
|
|
|
|
self.conn.close()
|
2019-09-21 20:10:16 +00:00
|
|
|
self.multiprocessingPipe.close()
|
|
|
|
|
|
|
|
def mp_send(self, data):
|
2019-12-08 20:11:36 +00:00
|
|
|
try:
|
|
|
|
self.multiprocessingPipe.put(data, block=False)
|
|
|
|
except Full:
|
|
|
|
self.close()
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-09-27 22:27:42 +00:00
|
|
|
def handleTextMessage(self, conn, message):
|
|
|
|
pass
|
|
|
|
|
2019-09-27 22:25:36 +00:00
|
|
|
def handleBinaryMessage(self, conn, data):
|
|
|
|
logger.error("unsupported binary message, discarding")
|
|
|
|
|
|
|
|
def handleClose(self):
|
|
|
|
self.close()
|
|
|
|
|
2019-07-01 17:49:58 +00:00
|
|
|
|
|
|
|
class OpenWebRxReceiverClient(Client):
|
2019-07-21 17:40:28 +00:00
|
|
|
config_keys = [
|
|
|
|
"waterfall_colors",
|
|
|
|
"waterfall_min_level",
|
|
|
|
"waterfall_max_level",
|
|
|
|
"waterfall_auto_level_margin",
|
|
|
|
"samp_rate",
|
|
|
|
"fft_size",
|
|
|
|
"fft_fps",
|
|
|
|
"audio_compression",
|
|
|
|
"fft_compression",
|
|
|
|
"max_clients",
|
|
|
|
"start_mod",
|
|
|
|
"start_freq",
|
|
|
|
"center_freq",
|
2019-11-23 15:56:29 +00:00
|
|
|
"initial_squelch_level",
|
2019-11-23 16:22:20 +00:00
|
|
|
"profile_id",
|
2019-07-21 17:40:28 +00:00
|
|
|
]
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-05-12 13:56:18 +00:00
|
|
|
def __init__(self, conn):
|
2019-07-01 17:49:58 +00:00
|
|
|
super().__init__(conn)
|
2019-05-12 13:56:18 +00:00
|
|
|
|
|
|
|
self.dsp = None
|
|
|
|
self.sdr = None
|
2019-05-18 19:38:15 +00:00
|
|
|
self.configSub = None
|
2019-11-26 19:10:26 +00:00
|
|
|
self.connectionProperties = {}
|
2019-05-12 13:56:18 +00:00
|
|
|
|
2020-01-10 20:38:46 +00:00
|
|
|
try:
|
|
|
|
ClientRegistry.getSharedInstance().addClient(self)
|
|
|
|
except TooManyClientsException:
|
2020-01-10 20:43:21 +00:00
|
|
|
self.write_backoff_message("Too many clients")
|
2020-01-10 20:38:46 +00:00
|
|
|
self.close()
|
|
|
|
raise
|
2019-06-03 22:39:22 +00:00
|
|
|
|
2020-03-21 21:40:39 +00:00
|
|
|
pm = Config.get()
|
2019-05-12 13:56:18 +00:00
|
|
|
|
|
|
|
self.setSdr()
|
|
|
|
|
2020-03-26 22:34:25 +00:00
|
|
|
receiver_details = pm.filter(
|
2019-07-21 17:40:28 +00:00
|
|
|
"receiver_name",
|
|
|
|
"receiver_location",
|
|
|
|
"receiver_asl",
|
|
|
|
"receiver_gps",
|
|
|
|
"photo_title",
|
|
|
|
"photo_desc",
|
2020-03-26 22:34:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def send_receiver_info(*args):
|
|
|
|
receiver_info = receiver_details.__dict__()
|
|
|
|
receiver_info["locator"] = Locator.fromCoordinates(receiver_info["receiver_gps"])
|
|
|
|
self.write_receiver_details(receiver_info)
|
|
|
|
|
2019-12-23 20:12:28 +00:00
|
|
|
features = FeatureDetector().feature_availability()
|
|
|
|
self.write_features(features)
|
|
|
|
|
2020-04-26 13:17:03 +00:00
|
|
|
modes = Modes.getModes()
|
|
|
|
self.write_modes(modes)
|
|
|
|
|
2020-04-26 16:45:41 +00:00
|
|
|
# TODO unsubscribe
|
|
|
|
receiver_details.wire(send_receiver_info)
|
|
|
|
send_receiver_info()
|
|
|
|
|
|
|
|
self.__sendProfiles()
|
|
|
|
|
2019-12-23 20:12:28 +00:00
|
|
|
CpuUsageThread.getSharedInstance().add_client(self)
|
|
|
|
|
|
|
|
def __sendProfiles(self):
|
2019-07-21 17:40:28 +00:00
|
|
|
profiles = [
|
|
|
|
{"name": s.getName() + " " + p["name"], "id": sid + "|" + pid}
|
|
|
|
for (sid, s) in SdrService.getSources().items()
|
|
|
|
for (pid, p) in s.getProfiles().items()
|
|
|
|
]
|
2019-05-12 13:56:18 +00:00
|
|
|
self.write_profiles(profiles)
|
|
|
|
|
2019-09-27 22:25:36 +00:00
|
|
|
def handleTextMessage(self, conn, message):
|
|
|
|
try:
|
|
|
|
message = json.loads(message)
|
|
|
|
if "type" in message:
|
|
|
|
if message["type"] == "dspcontrol":
|
|
|
|
if "action" in message and message["action"] == "start":
|
|
|
|
self.startDsp()
|
|
|
|
|
|
|
|
if "params" in message:
|
|
|
|
params = message["params"]
|
|
|
|
self.setDspProperties(params)
|
|
|
|
|
2019-11-26 19:10:26 +00:00
|
|
|
elif message["type"] == "config":
|
2019-09-27 22:25:36 +00:00
|
|
|
if "params" in message:
|
|
|
|
self.setParams(message["params"])
|
2019-11-26 19:10:26 +00:00
|
|
|
elif message["type"] == "setsdr":
|
2019-09-27 22:25:36 +00:00
|
|
|
if "params" in message:
|
|
|
|
self.setSdr(message["params"]["sdr"])
|
2019-11-26 19:10:26 +00:00
|
|
|
elif message["type"] == "selectprofile":
|
2019-09-27 22:25:36 +00:00
|
|
|
if "params" in message and "profile" in message["params"]:
|
|
|
|
profile = message["params"]["profile"].split("|")
|
|
|
|
self.setSdr(profile[0])
|
|
|
|
self.sdr.activateProfile(profile[1])
|
2019-11-26 19:10:26 +00:00
|
|
|
elif message["type"] == "connectionproperties":
|
|
|
|
if "params" in message:
|
|
|
|
self.connectionProperties = message["params"]
|
|
|
|
if self.dsp:
|
|
|
|
self.setDspProperties(self.connectionProperties)
|
|
|
|
|
2019-09-27 22:25:36 +00:00
|
|
|
else:
|
|
|
|
logger.warning("received message without type: {0}".format(message))
|
|
|
|
|
|
|
|
except json.JSONDecodeError:
|
|
|
|
logger.warning("message is not json: {0}".format(message))
|
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
def setSdr(self, id=None):
|
2019-12-23 20:12:28 +00:00
|
|
|
while True:
|
|
|
|
next = None
|
|
|
|
if id is not None:
|
|
|
|
next = SdrService.getSource(id)
|
|
|
|
if next is None:
|
|
|
|
next = SdrService.getFirstSource()
|
|
|
|
if next is None:
|
|
|
|
# exit condition: no sdrs available
|
|
|
|
self.handleNoSdrsAvailable()
|
|
|
|
return
|
2019-10-13 12:17:32 +00:00
|
|
|
|
2019-12-23 20:12:28 +00:00
|
|
|
# exit condition: no change
|
|
|
|
if next == self.sdr:
|
|
|
|
return
|
2019-10-13 12:17:32 +00:00
|
|
|
|
2019-12-23 20:12:28 +00:00
|
|
|
self.stopDsp()
|
2019-05-12 13:56:18 +00:00
|
|
|
|
2019-12-23 20:12:28 +00:00
|
|
|
if self.configSub is not None:
|
|
|
|
self.configSub.cancel()
|
|
|
|
self.configSub = None
|
2019-05-12 13:56:18 +00:00
|
|
|
|
2019-12-23 20:12:28 +00:00
|
|
|
self.sdr = next
|
2019-05-12 13:56:18 +00:00
|
|
|
|
2019-12-23 20:12:28 +00:00
|
|
|
self.startDsp()
|
2019-05-12 13:56:18 +00:00
|
|
|
|
2019-12-23 20:12:28 +00:00
|
|
|
# keep trying until we find a suitable SDR
|
2019-12-23 20:18:06 +00:00
|
|
|
if self.sdr.getState() == SdrSource.STATE_FAILED:
|
2019-12-28 00:24:07 +00:00
|
|
|
self.write_log_message('SDR device "{0}" has failed, selecting new device'.format(self.sdr.getName()))
|
2019-12-23 20:18:06 +00:00
|
|
|
else:
|
2019-12-23 20:12:28 +00:00
|
|
|
break
|
2019-10-20 16:53:23 +00:00
|
|
|
|
2019-05-12 13:56:18 +00:00
|
|
|
# send initial config
|
2019-11-26 19:10:26 +00:00
|
|
|
self.setDspProperties(self.connectionProperties)
|
|
|
|
|
2020-03-23 22:56:05 +00:00
|
|
|
stack = PropertyStack()
|
|
|
|
stack.addLayer(0, self.sdr.getProps())
|
|
|
|
stack.addLayer(1, Config.get())
|
2020-03-24 21:16:11 +00:00
|
|
|
configProps = stack.filter(*OpenWebRxReceiverClient.config_keys)
|
2019-05-12 13:56:18 +00:00
|
|
|
|
2019-05-18 19:38:15 +00:00
|
|
|
def sendConfig(key, value):
|
2020-03-23 22:56:05 +00:00
|
|
|
config = configProps.__dict__()
|
2019-05-18 19:38:15 +00:00
|
|
|
# TODO mathematical properties? hmmmm
|
|
|
|
config["start_offset_freq"] = configProps["start_freq"] - configProps["center_freq"]
|
2019-11-23 16:22:20 +00:00
|
|
|
# TODO this is a hack to support multiple sdrs
|
|
|
|
config["sdr_id"] = self.sdr.getId()
|
2019-05-18 19:38:15 +00:00
|
|
|
self.write_config(config)
|
|
|
|
|
2019-07-19 21:55:52 +00:00
|
|
|
cf = configProps["center_freq"]
|
|
|
|
srh = configProps["samp_rate"] / 2
|
|
|
|
frequencyRange = (cf - srh, cf + srh)
|
2019-07-21 21:39:11 +00:00
|
|
|
self.write_dial_frequendies(Bandplan.getSharedInstance().collectDialFrequencies(frequencyRange))
|
2019-09-27 22:53:58 +00:00
|
|
|
bookmarks = [b.__dict__() for b in Bookmarks.getSharedInstance().getBookmarks(frequencyRange)]
|
|
|
|
self.write_bookmarks(bookmarks)
|
2019-07-19 21:55:52 +00:00
|
|
|
|
2019-05-18 19:38:15 +00:00
|
|
|
self.configSub = configProps.wire(sendConfig)
|
|
|
|
sendConfig(None, None)
|
2019-12-23 20:12:28 +00:00
|
|
|
self.__sendProfiles()
|
2019-05-12 13:56:18 +00:00
|
|
|
|
|
|
|
self.sdr.addSpectrumClient(self)
|
|
|
|
|
2019-12-23 20:12:28 +00:00
|
|
|
def handleNoSdrsAvailable(self):
|
|
|
|
self.write_sdr_error("No SDR Devices available")
|
2019-10-13 12:17:32 +00:00
|
|
|
|
2019-05-12 13:56:18 +00:00
|
|
|
def startDsp(self):
|
2019-12-21 22:29:56 +00:00
|
|
|
if self.dsp is None and self.sdr is not None:
|
2019-05-12 13:56:18 +00:00
|
|
|
self.dsp = DspManager(self, self.sdr)
|
|
|
|
self.dsp.start()
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
self.stopDsp()
|
|
|
|
CpuUsageThread.getSharedInstance().remove_client(self)
|
2019-05-12 16:10:24 +00:00
|
|
|
ClientRegistry.getSharedInstance().removeClient(self)
|
2019-05-18 19:38:15 +00:00
|
|
|
if self.configSub is not None:
|
|
|
|
self.configSub.cancel()
|
|
|
|
self.configSub = None
|
2019-07-01 17:49:58 +00:00
|
|
|
super().close()
|
2019-05-12 13:56:18 +00:00
|
|
|
|
|
|
|
def stopDsp(self):
|
|
|
|
if self.dsp is not None:
|
|
|
|
self.dsp.stop()
|
|
|
|
self.dsp = None
|
|
|
|
if self.sdr is not None:
|
|
|
|
self.sdr.removeSpectrumClient(self)
|
|
|
|
|
|
|
|
def setParams(self, params):
|
2020-03-21 21:40:39 +00:00
|
|
|
config = Config.get()
|
2020-02-08 17:29:48 +00:00
|
|
|
# allow direct configuration only if enabled in the config
|
2020-03-21 21:40:39 +00:00
|
|
|
keys = config["configurable_keys"]
|
2020-02-08 17:29:48 +00:00
|
|
|
if not keys:
|
|
|
|
return
|
2019-05-12 13:56:18 +00:00
|
|
|
# only the keys in the protected property manager can be overridden from the web
|
2020-03-23 22:56:05 +00:00
|
|
|
stack = PropertyStack()
|
|
|
|
stack.addLayer(0, self.sdr.getProps())
|
|
|
|
stack.addLayer(1, config)
|
2020-03-24 21:16:11 +00:00
|
|
|
protected = stack.filter(*keys)
|
2019-05-12 13:56:18 +00:00
|
|
|
for key, value in params.items():
|
|
|
|
protected[key] = value
|
|
|
|
|
|
|
|
def setDspProperties(self, params):
|
|
|
|
for key, value in params.items():
|
|
|
|
self.dsp.setProperty(key, value)
|
|
|
|
|
|
|
|
def write_spectrum_data(self, data):
|
2019-09-27 21:29:22 +00:00
|
|
|
self.mp_send(bytes([0x01]) + data)
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-05-12 13:56:18 +00:00
|
|
|
def write_dsp_data(self, data):
|
2019-09-22 11:16:24 +00:00
|
|
|
self.send(bytes([0x02]) + data)
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-05-12 13:56:18 +00:00
|
|
|
def write_s_meter_level(self, level):
|
2019-09-22 11:16:24 +00:00
|
|
|
self.send({"type": "smeter", "value": level})
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-05-12 13:56:18 +00:00
|
|
|
def write_cpu_usage(self, usage):
|
2019-09-21 20:10:16 +00:00
|
|
|
self.mp_send({"type": "cpuusage", "value": usage})
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-05-12 13:56:18 +00:00
|
|
|
def write_clients(self, clients):
|
2019-09-21 20:10:16 +00:00
|
|
|
self.mp_send({"type": "clients", "value": clients})
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-05-12 13:56:18 +00:00
|
|
|
def write_secondary_fft(self, data):
|
2019-09-22 11:16:24 +00:00
|
|
|
self.send(bytes([0x03]) + data)
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-05-12 13:56:18 +00:00
|
|
|
def write_secondary_demod(self, data):
|
2020-01-09 12:49:38 +00:00
|
|
|
message = data.decode("ascii", "replace")
|
2019-10-25 19:08:56 +00:00
|
|
|
self.send({"type": "secondary_demod", "value": message})
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-05-12 13:56:18 +00:00
|
|
|
def write_secondary_dsp_config(self, cfg):
|
2019-09-22 11:16:24 +00:00
|
|
|
self.send({"type": "secondary_config", "value": cfg})
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-05-12 13:56:18 +00:00
|
|
|
def write_config(self, cfg):
|
2019-09-22 11:16:24 +00:00
|
|
|
self.send({"type": "config", "value": cfg})
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-05-12 13:56:18 +00:00
|
|
|
def write_receiver_details(self, details):
|
2019-09-22 11:16:24 +00:00
|
|
|
self.send({"type": "receiver_details", "value": details})
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-05-12 13:56:18 +00:00
|
|
|
def write_profiles(self, profiles):
|
2019-09-22 11:16:24 +00:00
|
|
|
self.send({"type": "profiles", "value": profiles})
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-05-13 17:19:15 +00:00
|
|
|
def write_features(self, features):
|
2019-09-22 11:16:24 +00:00
|
|
|
self.send({"type": "features", "value": features})
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-05-14 21:30:03 +00:00
|
|
|
def write_metadata(self, metadata):
|
2019-09-22 11:16:24 +00:00
|
|
|
self.send({"type": "metadata", "value": metadata})
|
2019-05-12 13:56:18 +00:00
|
|
|
|
2019-07-06 18:03:17 +00:00
|
|
|
def write_wsjt_message(self, message):
|
2019-09-22 11:16:24 +00:00
|
|
|
self.send({"type": "wsjt_message", "value": message})
|
2019-07-06 18:03:17 +00:00
|
|
|
|
2019-07-19 21:55:52 +00:00
|
|
|
def write_dial_frequendies(self, frequencies):
|
2019-09-22 11:16:24 +00:00
|
|
|
self.send({"type": "dial_frequencies", "value": frequencies})
|
2019-07-19 21:55:52 +00:00
|
|
|
|
2019-09-27 22:53:58 +00:00
|
|
|
def write_bookmarks(self, bookmarks):
|
|
|
|
self.send({"type": "bookmarks", "value": bookmarks})
|
|
|
|
|
2019-08-15 13:45:15 +00:00
|
|
|
def write_aprs_data(self, data):
|
2019-09-22 11:16:24 +00:00
|
|
|
self.send({"type": "aprs_data", "value": data})
|
2019-08-11 14:37:30 +00:00
|
|
|
|
2019-12-23 20:18:06 +00:00
|
|
|
def write_log_message(self, message):
|
|
|
|
self.send({"type": "log_message", "value": message})
|
|
|
|
|
2019-10-12 18:46:32 +00:00
|
|
|
def write_sdr_error(self, message):
|
|
|
|
self.send({"type": "sdr_error", "value": message})
|
|
|
|
|
2020-01-09 14:12:51 +00:00
|
|
|
def write_pocsag_data(self, data):
|
|
|
|
self.send({"type": "pocsag_data", "value": data})
|
|
|
|
|
2020-01-10 20:38:46 +00:00
|
|
|
def write_backoff_message(self, reason):
|
|
|
|
self.send({"type": "backoff", "reason": reason})
|
|
|
|
|
2020-04-14 19:10:35 +00:00
|
|
|
def write_js8_message(self, frame: Js8Frame, freq: int):
|
|
|
|
self.send({"type": "js8_message", "value": {
|
|
|
|
"msg": str(frame),
|
|
|
|
"timestamp": frame.timestamp,
|
|
|
|
"db": frame.db,
|
|
|
|
"dt": frame.dt,
|
|
|
|
"freq": freq + frame.freq,
|
2020-04-24 21:47:05 +00:00
|
|
|
"thread_type": frame.thread_type,
|
|
|
|
"mode": frame.mode
|
2020-04-14 19:10:35 +00:00
|
|
|
}})
|
|
|
|
|
2020-04-26 13:17:03 +00:00
|
|
|
def write_modes(self, modes):
|
2020-04-26 16:45:41 +00:00
|
|
|
def to_json(m):
|
|
|
|
res = {
|
|
|
|
"modulation": m.modulation,
|
|
|
|
"name": m.name,
|
|
|
|
"type": "digimode" if isinstance(m, DigitalMode) else "analog",
|
|
|
|
"requirements": m.requirements
|
|
|
|
}
|
|
|
|
if m.bandpass is not None:
|
|
|
|
res["bandpass"] = {
|
|
|
|
"low_cut": m.bandpass.low_cut,
|
|
|
|
"high_cut": m.bandpass.high_cut
|
|
|
|
}
|
|
|
|
if isinstance(m, DigitalMode):
|
|
|
|
res["underlying"] = m.underlying
|
|
|
|
return res
|
|
|
|
|
|
|
|
self.send({"type": "modes", "value": [to_json(m) for m in modes]})
|
2020-04-26 13:17:03 +00:00
|
|
|
|
2019-07-01 17:49:58 +00:00
|
|
|
|
|
|
|
class MapConnection(Client):
|
|
|
|
def __init__(self, conn):
|
|
|
|
super().__init__(conn)
|
|
|
|
|
2020-03-21 21:40:39 +00:00
|
|
|
pm = Config.get()
|
2020-03-24 21:16:11 +00:00
|
|
|
self.write_config(pm.filter("google_maps_api_key", "receiver_gps", "map_position_retention_time").__dict__())
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-07-01 19:20:53 +00:00
|
|
|
Map.getSharedInstance().addClient(self)
|
|
|
|
|
2019-09-27 22:25:36 +00:00
|
|
|
def handleTextMessage(self, conn, message):
|
|
|
|
pass
|
|
|
|
|
2019-07-01 19:20:53 +00:00
|
|
|
def close(self):
|
|
|
|
Map.getSharedInstance().removeClient(self)
|
|
|
|
super().close()
|
|
|
|
|
2019-07-01 17:49:58 +00:00
|
|
|
def write_config(self, cfg):
|
2019-09-22 11:16:24 +00:00
|
|
|
self.send({"type": "config", "value": cfg})
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-07-01 19:20:53 +00:00
|
|
|
def write_update(self, update):
|
2019-09-21 20:10:16 +00:00
|
|
|
self.mp_send({"type": "update", "value": update})
|
2019-07-21 17:40:28 +00:00
|
|
|
|
2019-07-01 17:49:58 +00:00
|
|
|
|
2019-05-12 13:56:18 +00:00
|
|
|
class WebSocketMessageHandler(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.handshake = None
|
|
|
|
|
|
|
|
def handleTextMessage(self, conn, message):
|
2019-07-21 17:40:28 +00:00
|
|
|
if message[:16] == "SERVER DE CLIENT":
|
2019-07-01 09:47:07 +00:00
|
|
|
meta = message[17:].split(" ")
|
|
|
|
self.handshake = {v[0]: "=".join(v[1:]) for v in map(lambda x: x.split("="), meta)}
|
|
|
|
|
2019-07-21 17:40:28 +00:00
|
|
|
conn.send("CLIENT DE SERVER server=openwebrx version={version}".format(version=openwebrx_version))
|
2019-05-12 13:56:18 +00:00
|
|
|
logger.debug("client connection intitialized")
|
|
|
|
|
2019-07-01 09:47:07 +00:00
|
|
|
if "type" in self.handshake:
|
|
|
|
if self.handshake["type"] == "receiver":
|
2019-09-27 22:25:36 +00:00
|
|
|
client = OpenWebRxReceiverClient(conn)
|
2019-07-01 17:49:58 +00:00
|
|
|
if self.handshake["type"] == "map":
|
2019-09-27 22:25:36 +00:00
|
|
|
client = MapConnection(conn)
|
2019-07-01 09:47:07 +00:00
|
|
|
# backwards compatibility
|
|
|
|
else:
|
2019-09-27 22:25:36 +00:00
|
|
|
client = OpenWebRxReceiverClient(conn)
|
|
|
|
|
|
|
|
# hand off all further communication to the correspondig connection
|
|
|
|
conn.setMessageHandler(client)
|
2019-05-12 13:56:18 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
if not self.handshake:
|
|
|
|
logger.warning("not answering client request since handshake is not complete")
|
|
|
|
return
|
2019-09-27 22:27:42 +00:00
|
|
|
|
|
|
|
def handleBinaryMessage(self, conn, data):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def handleClose(self):
|
|
|
|
pass
|