import SoapySDR import numpy as np import gc from noptica import * from gui import GUI def main(): # For this PoC code, a small memory leak is less harmful than random overflows. gc.disable() freq_sample = 1e6 freq_base = 1088230e3 block_size = 4096 gui = GUI(freq_sample, freq_base, block_size) try: induction = InductionHeater("/dev/ttyUSB0", 350e3, 445e3) induction.start() try: def stabilizer_cb(spectrum, peak_freq, locked, tuning): gui.update_ref(spectrum, peak_freq, locked) induction.set(tuning) stabilizer = Stabilizer(freq_sample, block_size, 1088.1e6 - freq_base, stabilizer_cb) position_tracker = PositionTracker(int(0.1*freq_sample/block_size)) sdr = SoapySDR.Device() for channel in range(2): sdr.setSampleRate(SoapySDR.SOAPY_SDR_RX, channel, freq_sample) sdr.setFrequency(SoapySDR.SOAPY_SDR_RX, channel, freq_base) buf_sdr = BufferedSDR(sdr, [0, 1], block_size, 256) buf_sdr.start() try: stabilizer_throttle = 0 while True: buffers = buf_sdr.get() try: samples_ref, samples_meas = buffers # We can't update faster than the MHS5200A serial interface stabilizer_throttle += 1 if stabilizer_throttle == 8: stabilizer.input(samples_ref) stabilizer_throttle = 0 # Update the MEAS GUI at the same time so it's synchronized gui.update_meas(samples_meas) #position, leakage = position_tracker.input(samples_ref, samples_meas) #print(np.sum(position)/len(position), leakage) finally: buf_sdr.dispose(buffers) finally: buf_sdr.stop() finally: induction.stop() finally: gui.close() if __name__ == "__main__": main()