sdr profile selection frontend

This commit is contained in:
Jakob Ketterl
2019-05-10 16:14:16 +02:00
parent 1cf4a879f7
commit 7427fa3608
6 changed files with 118 additions and 23 deletions

View File

@ -83,6 +83,9 @@ class OpenWebRxClient(object):
receiver_details = dict((key, pm.getPropertyValue(key)) for key in receiver_keys)
self.write_receiver_details(receiver_details)
profiles = [{"name": s.getName() + " " + p["name"], "id":sid + "|" + pid} for (sid, s) in SdrService.getSources().items() for (pid, p) in s.getProfiles().items()]
self.write_profiles(profiles)
CpuUsageThread.getSharedInstance().add_client(self)
def sendConfig(self, key, value):
@ -149,6 +152,8 @@ class OpenWebRxClient(object):
self.conn.send({"type":"config","value":cfg})
def write_receiver_details(self, details):
self.conn.send({"type":"receiver_details","value":details})
def write_profiles(self, profiles):
self.conn.send({"type":"profiles","value":profiles})
class WebSocketMessageHandler(object):
def __init__(self):
@ -187,6 +192,11 @@ class WebSocketMessageHandler(object):
if message["type"] == "setsdr":
if "params" in message:
self.client.setSdr(message["params"]["sdr"])
if message["type"] == "selectprofile":
if "params" in message and "profile" in message["params"]:
profile = message["params"]["profile"].split("|")
self.client.setSdr(profile[0])
self.client.sdr.activateProfile(profile[1])
else:
print("received message without type: {0}".format(message))

View File

@ -52,16 +52,24 @@ class SdrService(object):
if id is None:
# TODO: configure default sdr in config? right now it will pick the first one off the list.
id = list(SdrService.sdrProps.keys())[0]
if not id in SdrService.sources:
props = SdrService.sdrProps[id]
className = ''.join(x for x in props["type"].title() if x.isalnum()) + "Source"
cls = getattr(sys.modules[__name__], className)
SdrService.sources[id] = cls(props, SdrService.getNextPort())
return SdrService.sources[id]
sources = SdrService.getSources()
return sources[id]
@staticmethod
def getSources():
SdrService.loadProps()
for id in SdrService.sdrProps.keys():
if not id in SdrService.sources:
props = SdrService.sdrProps[id]
className = ''.join(x for x in props["type"].title() if x.isalnum()) + "Source"
cls = getattr(sys.modules[__name__], className)
SdrService.sources[id] = cls(props, SdrService.getNextPort())
return SdrService.sources
class SdrSource(object):
def __init__(self, props, port):
self.props = props
self.activateProfile()
self.rtlProps = self.props.collect(
"type", "samp_rate", "nmux_memory", "center_freq", "ppm", "rf_gain", "lna_gain", "rf_amp"
).defaults(PropertyManager.getSharedInstance())
@ -85,6 +93,23 @@ class SdrSource(object):
self.command = None
self.format_conversion = None
def activateProfile(self, id = None):
profiles = self.props["profiles"]
if id is None:
id = list(profiles.keys())[0]
print("activating profile {0}".format(id))
profile = profiles[id]
for (key, value) in profile.items():
# skip the name, that would overwrite the source name.
if key == "name": continue
self.props[key] = value
def getProfiles(self):
return self.props["profiles"]
def getName(self):
return self.props["name"]
def getProps(self):
return self.props