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 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)