def __init__(self, conn): super().__init__(conn) self.dsp = None self.dspLock = threading.Lock() self.sdr = None self.configSubs = [] self.bookmarkSub = None self.connectionProperties = {} try: ClientRegistry.getSharedInstance().addClient(self) except TooManyClientsException: self.write_backoff_message("Too many clients") self.close() raise self.setupGlobalConfig() self.stack = self.setupStack() self.setSdr() features = FeatureDetector().feature_availability() self.write_features(features) modes = Modes.getModes() self.write_modes(modes) self.configSubs.append(SdrService.getActiveSources().wire( self._onSdrDeviceChanges)) self.configSubs.append(SdrService.getAvailableProfiles().wire( self._sendProfiles)) self._sendProfiles() CpuUsageThread.getSharedInstance().add_client(self)
def setSdr(self, id=None): next = None if id is not None: next = SdrService.getSource(id) if next is None: next = SdrService.getFirstSource() # exit condition: no change if next == self.sdr and next is not None: return self.stopDsp() self.stack.removeLayerByPriority(0) if self.sdr is not None: self.sdr.removeClient(self) self.sdr = next if next is None: # exit condition: no sdrs available logger.warning("no more SDR devices available") self.handleNoSdrsAvailable() return self.sdr.addClient(self)
def start_receiver(): print(""" OpenWebRX - Open Source SDR Web App for Everyone! | for license see LICENSE file in the package _________________________________________________________________________________________________ Author contact info: Jakob Ketterl, DD5JFK <*****@*****.**> Documentation: https://github.com/jketterl/openwebrx/wiki Support and info: https://groups.io/g/openwebrx """) logger.info( "OpenWebRX version {0} starting up...".format(openwebrx_version)) for sig in [signal.SIGINT, signal.SIGTERM]: signal.signal(sig, handleSignal) # config warmup Config.validateConfig() coreConfig = CoreConfig() featureDetector = FeatureDetector() failed = featureDetector.get_failed_requirements("core") if failed: logger.error( "you are missing required dependencies to run openwebrx. " "please check that the following core requirements are installed and up to date: %s", ", ".join(failed)) for f in failed: description = featureDetector.get_requirement_description(f) if description: logger.error("description for %s:\n%s", f, description) return 1 # Get error messages about unknown / unavailable features as soon as possible # start up "always-on" sources right away SdrService.getAllSources() Services.start() try: server = ThreadedHttpServer(("0.0.0.0", coreConfig.get_web_port()), RequestHandler) server.serve_forever() except SignalException: pass WebSocketConnection.closeAll() Services.stop() SdrService.stopAllSources() ReportingEngine.stopAll() DecoderQueue.stopAll() return 0
def main(): print(""" OpenWebRX - Open Source SDR Web App for Everyone! | for license see LICENSE file in the package _________________________________________________________________________________________________ Author contact info: Jakob Ketterl, DD5JFK <*****@*****.**> Documentation: https://github.com/jketterl/openwebrx/wiki Support and info: https://groups.io/g/openwebrx """) logger.info( "OpenWebRX version {0} starting up...".format(openwebrx_version)) pm = Config.get() configErrors = Config.validateConfig() if configErrors: logger.error( "your configuration contains errors. please address the following errors:" ) for e in configErrors: logger.error(e) return featureDetector = FeatureDetector() if not featureDetector.is_available("core"): logger.error( "you are missing required dependencies to run openwebrx. " "please check that the following core requirements are installed and up to date:" ) logger.error(", ".join(featureDetector.get_requirements("core"))) return # Get error messages about unknown / unavailable features as soon as possible SdrService.loadProps() Services.start() try: server = ThreadedHttpServer(("0.0.0.0", pm["web_port"]), RequestHandler) server.serve_forever() except KeyboardInterrupt: WebSocketConnection.closeAll() Services.stop() PskReporter.stop()
def start(): if not Config.get()["services_enabled"]: return for source in SdrService.getSources().values(): props = source.getProps() if "services" not in props or props["services"] is not False: Services.handlers.append(ServiceHandler(source))
def start(): config = Config.get() config.wireProperty("services_enabled", Services._receiveEnabledEvent) activeSources = SdrService.getActiveSources() activeSources.wire(Services._receiveDeviceEvent) for key, source in activeSources.items(): Services.schedulers[key] = ServiceScheduler(source)
def __sendProfiles(self): 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)
def start(): if not PropertyManager.getSharedInstance()["services_enabled"]: return for source in SdrService.getSources().values(): props = source.getProps() if "services" not in props or props["services"] is not False: Services.handlers.append(ServiceHandler(source))
def _receiveEnabledEvent(state): if state: for key, source in SdrService.getActiveSources().__dict__().items(): Services.handlers[key] = ServiceHandler(source) else: for handler in list(Services.handlers.values()): handler.shutdown() Services.handlers = {}
def render_device(device_id, config): sources = SdrService.getAllSources() source = sources[device_id] if device_id in sources else None additional_info = "" state_info = "Unknown" if source is not None: profiles = source.getProfiles() currentProfile = profiles[source.getProfileId()] clients = {c: len(source.getClients(c)) for c in SdrClientClass} clients = {c: v for c, v in clients.items() if v} connections = len([c for c in source.getClients() if isinstance(c, OpenWebRxReceiverClient)]) additional_info = """ <div>{num_profiles} profile(s)</div> <div>Current profile: {current_profile}</div> <div>Clients: {clients}</div> <div>Connections: {connections}</div> """.format( num_profiles=len(config["profiles"]), current_profile=currentProfile["name"], clients=", ".join("{cls}: {count}".format(cls=c.name, count=v) for c, v in clients.items()), connections=connections, ) state_info = ", ".join( s for s in [ str(source.getState()), None if source.isEnabled() else "Disabled", "Failed" if source.isFailed() else None, ] if s is not None ) return """ <li class="list-group-item"> <div class="row"> <div class="col-6"> <a href="{device_link}"> <h3>{device_name}</h3> </a> <div>State: {state}</div> </div> <div class="col-6"> {additional_info} </div> </div> </li> """.format( device_name=config["name"] if config["name"] else "[Unnamed device]", device_link="{}settings/sdr/{}".format(self.get_document_root(), quote(device_id)), state=state_info, additional_info=additional_info, )
def main(): print(""" OpenWebRX - Open Source SDR Web App for Everyone! | for license see LICENSE file in the package _________________________________________________________________________________________________ Author contact info: Jakob Ketterl, DD5JFK <*****@*****.**> """) pm = PropertyManager.getSharedInstance().loadConfig() featureDetector = FeatureDetector() if not featureDetector.is_available("core"): print( "you are missing required dependencies to run openwebrx. " "please check that the following core requirements are installed:") print(", ".join(featureDetector.get_requirements("core"))) return # Get error messages about unknown / unavailable features as soon as possible SdrService.loadProps() if "sdrhu_key" in pm and pm["sdrhu_public_listing"]: updater = SdrHuUpdater() updater.start() Services.start() try: server = ThreadedHttpServer( ("0.0.0.0", pm.getPropertyValue("web_port")), RequestHandler) server.serve_forever() except KeyboardInterrupt: WebSocketConnection.closeAll() Services.stop() PskReporter.stop()
def indexAction(self): pm = Config.get() status = { "receiver": { "name": pm["receiver_name"], "admin": pm["receiver_admin"], "gps": pm["receiver_gps"], "asl": pm["receiver_asl"], "location": pm["receiver_location"], }, "max_clients": pm["max_clients"], "version": openwebrx_version, "sdrs": [self.getReceiverStats(r) for r in SdrService.getSources().values()] } self.send_response(json.dumps(status), content_type="application/json")
def indexAction(self): pm = Config.get() headers = None if "Authorization" in self.request.headers: try: headers = ReceiverId.getResponseHeader(self.request.headers["Authorization"]) except KeyException: logger.exception("error processing authorization header") status = { "receiver": { "name": pm["receiver_name"], "admin": pm["receiver_admin"], "gps": pm["receiver_gps"], "asl": pm["receiver_asl"], "location": pm["receiver_location"], }, "max_clients": pm["max_clients"], "version": openwebrx_version, "sdrs": [self.getReceiverStats(r) for r in SdrService.getSources().values()] } self.send_response(json.dumps(status), content_type="application/json", headers=headers)
def _sendProfiles(self, *args): profiles = [{ "id": pid, "name": name } for pid, name in SdrService.getAvailableProfiles().items()] self.write_profiles(profiles)
def setSdr(self, id=None): 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 # exit condition: no change if next == self.sdr: return self.stopDsp() if self.configSub is not None: self.configSub.cancel() self.configSub = None self.sdr = next self.startDsp() # keep trying until we find a suitable SDR if self.sdr.getState() == SdrSource.STATE_FAILED: self.write_log_message('SDR device "{0}" has failed, selecting new device'.format(self.sdr.getName())) else: break # send initial config self.setDspProperties(self.connectionProperties) configProps = ( self.sdr.getProps() .collect(*OpenWebRxReceiverClient.config_keys) .defaults(PropertyManager.getSharedInstance()) ) def sendConfig(key, value): config = dict((key, configProps[key]) for key in OpenWebRxReceiverClient.config_keys) # TODO mathematical properties? hmmmm config["start_offset_freq"] = configProps["start_freq"] - configProps["center_freq"] # TODO this is a hack to support multiple sdrs config["sdr_id"] = self.sdr.getId() self.write_config(config) cf = configProps["center_freq"] srh = configProps["samp_rate"] / 2 frequencyRange = (cf - srh, cf + srh) self.write_dial_frequendies(Bandplan.getSharedInstance().collectDialFrequencies(frequencyRange)) bookmarks = [b.__dict__() for b in Bookmarks.getSharedInstance().getBookmarks(frequencyRange)] self.write_bookmarks(bookmarks) self.configSub = configProps.wire(sendConfig) sendConfig(None, None) self.__sendProfiles() self.sdr.addSpectrumClient(self)
def setSdr(self, id=None): 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 logger.warning("no more SDR devices available") self.handleNoSdrsAvailable() return # exit condition: no change if next == self.sdr: return self.stopDsp() if self.configSub is not None: self.configSub.cancel() self.configSub = None self.sdr = next self.getDsp() # found a working sdr, exit the loop if self.sdr.getState() != SdrSource.STATE_FAILED: break logger.warning('SDR device "%s" has failed, selecing new device', self.sdr.getName()) self.write_log_message('SDR device "{0}" has failed, selecting new device'.format(self.sdr.getName())) # send initial config self.getDsp().setProperties(self.connectionProperties) stack = PropertyStack() stack.addLayer(0, self.sdr.getProps()) stack.addLayer(1, Config.get()) configProps = stack.filter(*OpenWebRxReceiverClient.config_keys) def sendConfig(key, value): config = configProps.__dict__() # TODO mathematical properties? hmmmm config["start_offset_freq"] = configProps["start_freq"] - configProps["center_freq"] # TODO this is a hack to support multiple sdrs config["sdr_id"] = self.sdr.getId() self.write_config(config) cf = configProps["center_freq"] srh = configProps["samp_rate"] / 2 frequencyRange = (cf - srh, cf + srh) self.write_dial_frequendies(Bandplan.getSharedInstance().collectDialFrequencies(frequencyRange)) bookmarks = [b.__dict__() for b in Bookmarks.getSharedInstance().getBookmarks(frequencyRange)] self.write_bookmarks(bookmarks) self.configSub = configProps.wire(sendConfig) sendConfig(None, None) self.__sendProfiles() self.sdr.addSpectrumClient(self)