def go(): if len(sys.argv) <= 1: print "You must enter a test mode!" printUsage() sys.exit() funcs = { 'radio' : audioTest, 'status' : testDeviceStatusQueries, 'raw-pipe' : testRawPipeMode, 'callback' : testCallback, 'traces' : testSweeps, 'int-traces' : interruptedSweeping, 'gps' : testGpsSweeps, 'reset' : resetDevice, 'iq' : testIqStreaming } if sys.argv[1] in funcs: logSetup.initLogging() sh = SignalHound() # sh.preset() # testDeviceStatusQueries(sh) # testRawPipeMode(sh) if len(sys.argv) == 2: funcs[sys.argv[1]](sh) if len(sys.argv) == 3: funcs[sys.argv[1]](sh, float(sys.argv[2])) # testCallback(sh) sh.closeDevice() else: print "Error! You must enter a valid test-mode!" printUsage()
def sweepSource(statusMessageQueue, ctrlNs, printQueue, ringBuf): from SignalHound import SignalHound logSetup.initLogging(printQ = printQueue) loop_timer = time.time() print "Starting sweep-logger!" log = logging.getLogger("Main.AcqProcess") loop_timer = time.time() seq_num = 0 sh = SignalHound() startAcquisition(sh, statusMessageQueue) temperature = sh.getDeviceDiagnostics()["temperature"] while ctrlNs.run: bufPtr, lock = ringBuf.getAddPointer() try: sh.fetchRaw_s(ctDataBufPtr=bufPtr) except Exception: log.error("IOError in Acquisition Thread!") log.error(traceback.format_exc()) statusMessageQueue.put({"status" : (time.time(), "Error: Device interface crashed. Reinitializing")}) log.error("Resetting hardware!") # sh.preset() sh.forceClose() try: while 1: log.warning("Freeing python device handle") del(sh) except UnboundLocalError: pass log.error("Hardware shut down, completely re-initializing device interface!") # sys.exit() sh = SignalHound() startAcquisition(sh, statusMessageQueue) finally: lock.release() if seq_num % PRINT_LOOP_CNT == 0: now = time.time() delta = now-loop_timer updateInterval = delta / PRINT_LOOP_CNT freq = 1 / updateInterval log.info("Elapsed Time = %0.5f, Frequency = %s. Items in buffer = %s", delta, freq, ringBuf.getItemsNum()) loop_timer = now # print if seq_num % CAL_CHK_LOOP_CNT == 0: diags = sh.getDeviceDiagnostics() statusMessageQueue.put({"status" : (time.time(), diags)}) temptmp = diags["temperature"] if abs(temperature - temptmp) > 2.0: # Temperature deviations of > 2° cause IF shifts. Therefore, we do a re-cal if they're detected statusMessageQueue.put({"status" : (time.time(), "Recalibrating IF due to temperature change")}) sh.selfCal() startAcquisition(sh, statusMessageQueue) log.warning("Temperature changed > 2.0 C. Delta is %f. Recalibrated!", abs(temperature - temptmp)) temperature = temptmp else: log.info("Temperature deviation = %f. Not doing recal, since drift < 2C", abs(temperature - temptmp)) seq_num += 1 sh.abort() sh.closeDevice() del(sh) ctrlNs.acqRunning = False log.info("Acquisition-thread exiting!")
def sweepSource(dataQueues, ctrlNs, printQueue): dataQueue, plotQueue = dataQueues from SignalHound import SignalHound logSetup.initLogging(printQ=printQueue) loop_timer = time.time() print "Starting sweep-logger!" log = logging.getLogger("Main.AcqProcess") loop_timer = time.time() loops = 0 sh = SignalHound() startAcquisition(sh, dataQueue, plotQueue) # Send the trace size to the acq thread so I can properly set up the data-log file numPoints = sh.queryTraceInfo()["arr-size"] dataQueue.put({"arrSize": numPoints}) temperature = sh.getDeviceDiagnostics()["temperature"] runningSum = np.array(()) runningSumItems = 0 startFreq = 0 while 1: try: trace = sh.fetchTrace() traceInfo = sh.queryTraceInfo() dataDict = {"info": traceInfo, "data": trace} acqInfo = dataDict["info"] if runningSum.shape != dataDict["data"]["max"].shape: runningSum = np.zeros_like(dataDict["data"]["max"]) runningSumItems = 0 startFreq = acqInfo["ret-start-freq"] binSize = acqInfo["arr-bin-size"] log.info( "Running average array size changed! Either the system just started, or something is seriously wrong!" ) changed = False if startFreq != acqInfo["ret-start-freq"]: changed = True else: runningSum += dataDict["data"]["max"] runningSumItems += 1 # if we've reached the number of average items per output array, or the frequency has changed, requiring an early dump of the specra data. if runningSumItems == NUM_AVERAGE or changed: # Divide down to the average arr = runningSum / runningSumItems # Build array to write out. saveTime = time.time() # log.info("Saving data record with timestamp %f", saveTime) # Only write out to the file if we actually have data if runningSumItems != 0: dataQueue.put({ "row": (saveTime, startFreq, binSize, runningSumItems, arr) }) if plotQueue: plotQueue.put({ "row": (saveTime, startFreq, binSize, runningSumItems, arr) }) del (trace) runningSum = np.zeros_like(runningSum) log.info("Estimated items in processing queue %s", dataQueue.qsize()) log.info("Running sum shape = %s, items = %s", runningSum.shape, runningSumItems) runningSumItems = 0 # now = time.time() # delta = now-loop_timer # freq = 1 / (delta) # log.info("Elapsed Time = %0.5f, Frequency = %s", delta, freq) # loop_timer = now # If we wrote the output because the current spectra has changed, we need to update the running acq info variables with the new frequencies. if changed: log.info("Retuned! Old freq = %s, new freq = %s", startFreq, acqInfo["ret-start-freq"]) runningSum += dataDict["data"]["max"] startFreq = acqInfo["ret-start-freq"] binSize = acqInfo["arr-bin-size"] runningSumItems = 1 except Exception: log.error("IOError in Acquisition Thread!") log.error(traceback.format_exc()) dataQueue.put( {"status": "Error: Device interface crashed. Reinitializing"}) log.error("Resetting hardware!") # sh.preset() sh.forceClose() try: while 1: log.warning("Freeing python device handle") del (sh) except UnboundLocalError: pass log.error( "Hardware shut down, completely re-initializing device interface!" ) # sys.exit() sh = SignalHound() startAcquisition(sh, dataQueue, plotQueue) if loops % PRINT_LOOP_CNT == 0: now = time.time() delta = now - loop_timer freq = 1 / (delta / PRINT_LOOP_CNT) # log.info("Elapsed Time = %0.5f, Frequency = %s", delta, freq) loop_timer = now if loops % CAL_CHK_LOOP_CNT == 0: diags = sh.getDeviceDiagnostics() dataQueue.put({"status": diags}) temptmp = diags["temperature"] if abs( temperature - temptmp ) > 2.0: # Temperature deviations of > 2° cause IF shifts. Therefore, we do a re-cal if they're detected dataQueue.put({"status": "Recalibrating IF"}) sh.selfCal() startAcquisition(sh, dataQueue, plotQueue) log.warning( "Temperature changed > 2.0 C. Delta is %f. Recalibrated!", abs(temperature - temptmp)) temperature = temptmp else: log.info( "Temperature deviation = %f. Not doing recal, since drift < 2C", abs(temperature - temptmp)) loops += 1 if ctrlNs.run == False: log.info("Stopping Acq-thread!") break sh.abort() sh.closeDevice() del (sh) log.info("Acq-thread closing dataQueue!") dataQueue.close() dataQueue.join_thread() if plotQueue: plotQueue.close() plotQueue.cancel_join_thread() ctrlNs.acqRunning = False log.info("Acq-thread exiting!") printQueue.close() printQueue.join_thread()