def setTunerCenterFrequency(self, allocation_id, freq): idx = self.getTunerMapping(allocation_id) if idx < 0: raise FRONTEND.FrontendException("Invalid allocation id") if allocation_id != self.getControlAllocationId(idx): raise FRONTEND.FrontendException( ("ID " + str(allocation_id) + " does not have authorization to modify the tuner")) if freq < 0: raise FRONTEND.BadParameterException("Bad CF") # set hardware to new value. Raise an exception if it's not possible #Check Frequency again min/max Range #Convert CF based on RFInfo. tuneFreq = self.convert_rf_to_if(freq) # Check the CF if not (validateRequestSingle(self.MINFREQ, self.MAXFREQ, tuneFreq)): self._log.debug("Center Freq Does not fit %s, %s, %s" % (tuneFreq, self.MINFREQ, self.MAXFREQ)) raise FRONTEND.BadParameterException( "Radio Center Freq of %s Does not fit in %s, %s" % (tuneFreq, self.MINFREQ, self.MAXFREQ)) #set tuner new freq self.datagenerators[idx].cf = tuneFreq self.datagenerators[idx].keyword_dict['COL_RF'] = freq self.datagenerators[idx].keyword_dict['CHAN_RF'] = freq self.datagenerators[idx].updateandPushSRI() self.frontend_tuner_status[idx].center_frequency = freq
def validateRequestVsDevice(request, upstream_sri, max_device_frame_rate): # check if request can be satisfied using the available upstream data if not validateRequestVsSRI(request, upstream_sri): raise FRONTEND.BadParameterException( "INVALID REQUEST -- falls outside of input data stream") # check device constraints # check vs. device frame rate capability (ensure 0 <= request <= max device capability) if not validateRequest(0, max_device_sample_rate, request.fps): raise FRONTEND.BadParameterException( "INVALID REQUEST -- device capabilities cannot support fr request") return True
def fe_setTunerOutputSampleRate(self, alloc_id, sr): tuner_id = self.getTunerMapping(alloc_id) if tuner_id < 0: raise FRONTEND.FrontendException("ERROR: ID: %s IS NOT ASSOCIATED WITH ANY TUNER!"%(alloc_id)) if alloc_id != self.tunerChannels[tuner_id].control_allocation_id: raise FRONTEND.FrontendException("ERROR: ID: %s DOES NOT HAVE AUTHORIZATION TO MODIFY TUNER!"%(alloc_id)) try: self.tunerChannels[tuner_id].lock.acquire() try: if not self._valid_sample_rate(sr,tuner_id): # TODO: add log message raise FRONTEND.BadParameterException("INVALID SAMPLE RATE") try: self._dev_set_sample_rate(sr,tuner_id) except: #TODO: add back log messages raise FRONTEND.FrontendException("WARNING: failed when configuring device hardware") try: self.tunerChannels[tuner_id].frontend_status.sample_rate = self._dev_get_sample_rate(tuner_id) except: #TODO: add back log messages raise FRONTEND.FrontendException("WARNING: failed when querying device hardware") finally: self.tunerChannels[tuner_id].lock.release() except Exception, e: raise FRONTEND.FrontendException("WARNING: %s"%(e))
def fe_setTunerCenterFrequency(self, alloc_id, freq): tuner_id = self.getTunerMapping(alloc_id) if tuner_id < 0: raise FRONTEND.FrontendException("ERROR: ID: %s IS NOT ASSOCIATED WITH ANY TUNER!"%(alloc_id)) if alloc_id != self.tunerChannels[tuner_id].control_allocation_id: raise FRONTEND.FrontendException("ERROR: ID: %s DOES NOT HAVE AUTHORIZATION TO MODIFY TUNER!"%(alloc_id)) try: # If the freq has changed (change in stream) or the tuner is disabled, then set it as disabled isTunerEnabled = self.tunerChannels[tuner_id].frontend_status.enabled if not isTunerEnabled or self.tunerChannels[tuner_id].frontend_status.center_frequency != freq: self.enableTuner(tuner_id, False) # TODO: is this a generic thing we can assume is desired when changing any tuner device? self.tunerChannels[tuner_id].lock.acquire() try: if not self._valid_center_frequency(freq,tuner_id): # TODO: add log message raise FRONTEND.BadParameterException("INVALID FREQUENCY") try: self._dev_set_center_frequency(freq,tuner_id) except: #TODO: add back log messages raise FRONTEND.FrontendException("WARNING: failed when configuring device hardware") try: self.tunerChannels[tuner_id].frontend_status.center_frequency = self._dev_get_center_frequency(tuner_id) except: #TODO: add back log messages raise FRONTEND.FrontendException("WARNING: failed when querying device hardware") finally: self.tunerChannels[tuner_id].lock.release() if isTunerEnabled: self.enableTuner(tuner_id, True) except Exception, e: raise FRONTEND.FrontendException("WARNING: %s"%(e))
def validateRequestVsDevice(request, max_device_frame_rate): # check device constraints # check vs. device frame rate capability (ensure 0 <= request <= max device capability) if not validateRequest(0, max_device_frame_rate, request.fps): raise FRONTEND.BadParameterException( "INVALID REQUEST -- device capabilities cannot support fr request") return True
def setTunerBandwidth(self, allocation_id, bw): idx = self.getTunerMapping(allocation_id) if idx < 0: raise FRONTEND.FrontendException("Invalid allocation id") if allocation_id != self.getControlAllocationId(idx): raise FRONTEND.FrontendException( ("ID " + str(allocation_id) + " does not have authorization to modify the tuner")) if bw < 0: raise FRONTEND.BadParameterException("Invalid BW") newbw, newsr, decimation = self.findBestBWSR(bw, 0) if not newbw: self._log.debug("Can't Satisfy BW and SR request") raise FRONTEND.BadParameterException( "Can't Satisfy BW and SR request") # set hardware to new value. Raise an exception if it's not possible self.datagenerators[idx].keyword_dict['FRONTEND::BANDWIDTH'] = newbw self.datagenerators[idx].updateandPushSRI() self.frontend_tuner_status[idx].bandwidth = newsr self.frontend_tuner_status[idx].bandwidth = newbw self.frontend_tuner_status[idx].decimation = decimation
def setTunerGain(self, allocation_id, gain): idx = self.getTunerMapping(allocation_id) if idx < 0: raise FRONTEND.FrontendException("Invalid allocation id") if allocation_id != self.getControlAllocationId(idx): raise FRONTEND.FrontendException( ("ID " + str(allocation_id) + " does not have authorization to modify the tuner")) if (gain < 0 or gain > 10): raise FRONTEND.BadParameterException("Invalid Gain") gain = round(gain, 1) # magnitude on data generators is 100+gain*10 self.datagenerators[idx].magnitude = 100 + gain * 10 self.frontend_tuner_status[idx].gain = gain
def setTunerOutputSampleRate(self, allocation_id, sr): idx = self.getTunerMapping(allocation_id) if idx < 0: raise FRONTEND.FrontendException("Invalid allocation id") if allocation_id != self.getControlAllocationId(idx): raise FRONTEND.FrontendException( ("ID " + str(allocation_id) + " does not have authorization to modify the tuner")) if sr < 0: raise FRONTEND.BadParameterException("Invalid SR") newbw, newsr, decimation = self.findBestBWSR(0, sr) if not newbw: self._log.debug("Can't Satisfy BW and SR request") raise FRONTEND.BadParameterException( "Can't Satisfy BW and SR request") self._log.debug("Setting BW and Sample Rate %s, %s " % (newbw, newsr)) #set new SR self.datagenerators[idx].sr = sr self.datagenerators[idx].keyword_dict['FRONTEND::BANDWIDTH'] = newbw self.datagenerators[idx].updateandPushSRI() self.frontend_tuner_status[idx].sample_rate = newsr self.frontend_tuner_status[idx].bandwidth = newbw self.frontend_tuner_status[idx].decimation = decimation
def validateRequestVsSRI(request, upstream_sri): # check if the upstream sample rate falls within the requested tolerable frame rate upstream_sr = 1 / upstream_sri.xdelta upstream_frame_rate = upstream_sr / ( request.frame_height * request.frame_width * request.channels) min_requested_sample_rate = request.sample_rate max_requested_sample_rate = request.sample_rate + request.sample_rate * request.sample_rate_tolerance / 100.0 if not validateRequest(min_requested_sample_rate, max_requested_sample_rate, upstream_frame_rate): raise FRONTEND.BadParameterException( "INVALID REQUEST -- input data stream cannot support fr request") return True
def allocate_frontend_listener_allocation(self, frontend_listener_allocation): try: # Check validity of allocation_id's if not frontend_listener_allocation.existing_allocation_id: self._log.info( "allocate_frontend_listener_allocation: MISSING EXISTING ALLOCATION ID" ) raise CF.Device.InvalidCapacity( "MISSING EXISTING ALLOCATION ID", frontend_listener_allocation) if not frontend_listener_allocation.listener_allocation_id: self._log.info( "allocate_frontend_listener_allocation: MISSING LISTENER ALLOCATION ID" ) raise CF.Device.InvalidCapacity( "MISSING LISTENER ALLOCATION ID", frontend_listener_allocation) # Check if listener allocation ID has already been used if self.getVideoDeviceMapping( frontend_listener_allocation.listener_allocation_id) >= 0: self._log.info( "allocate_frontend_listener_allocation: LISTENER ALLOCATION ID ALREADY IN USE" ) raise CF.Device.InvalidCapacity( "LISTENER ALLOCATION ID ALREADY IN USE", frontend_listener_allocation) #self.video_allocation_ids[video_device_id].lock.acquire() # Check if listener allocation ID has already been used if self.getVideoDeviceMapping( frontend_listener_allocation.listener_allocation_id) >= 0: self._log.info( "allocate_frontend_listener_allocation: LISTENER ALLOCATION ID ALREADY IN USE: [" + str(frontend_listener_allocation.listener_allocation_id << "]")) raise AllocationAlreadyExists( "LISTENER ALLOCATION ID ALREADY IN USE", frontend_listener_allocation) # Do not allocate if existing allocation ID does not exist video_device_id = self.getVideoDeviceMapping( frontend_listener_allocation.existing_allocation_id) if video_device_id < 0: self._log.info( "allocate_frontend_listener_allocation: UNKNOWN CONTROL ALLOCATION ID: [" + str(frontend_listener_allocation.existing_allocation_id) + "]") raise FRONTEND.BadParameterException( "UNKNOWN CONTROL ALLOCATION ID") # listener allocations are not permitted for playback if self.frontend_video_status[ video_device_id].video_type == "PLAYBACK": eout = "allocate_frontend_listener_allocation: listener allocations are not permitted for " + str( self.frontend_video_status[video_device_id].video_type ) + " video type" self._log.debug(eout) raise CF.Device.InvalidCapacity(eout, frontend_listener_allocation) self.video_allocation_ids[ video_device_id].listener_allocation_ids.append( frontend_listener_allocation.listener_allocation_id) self.allocation_id_to_video_device_id[ frontend_listener_allocation. listener_allocation_id] = video_device_id self.frontend_video_status[ video_device_id].allocation_id_csv = self.createAllocationIdCsv( video_device_id) self.assignListener( frontend_listener_allocation.listener_allocation_id, frontend_listener_allocation.existing_allocation_id) return True #self.video_allocation_ids[video_device_id].lock.release() except RuntimeError, e: return False