noptica2-sdr/dmi.py

66 lines
2.1 KiB
Python
Raw Normal View History

import SoapySDR
import numpy as np
2020-01-27 17:24:59 +08:00
import gc
2020-01-05 19:31:07 +08:00
2020-01-27 17:24:59 +08:00
from noptica import *
2020-08-10 19:22:58 +08:00
from gui import GUI
2020-01-05 19:31:07 +08:00
def main():
2020-01-27 17:24:59 +08:00
# For this PoC code, a small memory leak is less harmful than random overflows.
gc.disable()
2020-08-10 14:29:55 +08:00
freq_sample = 1e6
freq_base = 1088230e3
2020-08-10 19:22:58 +08:00
block_size = 4096
2020-01-11 16:06:54 +08:00
2020-08-10 19:55:34 +08:00
gui = GUI(freq_sample, freq_base, block_size)
2020-01-05 19:31:07 +08:00
try:
2020-08-10 19:22:58 +08:00
induction = InductionHeater("/dev/ttyUSB0", 350e3, 445e3)
induction.start()
2020-01-05 19:31:07 +08:00
try:
def stabilizer_cb(spectrum, peak_freq, locked, tuning):
2020-08-11 16:09:24 +08:00
gui.update_ref(spectrum, peak_freq, locked)
2020-08-10 19:22:58 +08:00
induction.set(tuning)
2020-08-11 14:59:52 +08:00
stabilizer = Stabilizer(freq_sample, block_size, 1088.1e6 - freq_base, stabilizer_cb)
2020-08-10 19:22:58 +08:00
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
2020-08-11 16:09:24 +08:00
# Update the MEAS GUI at the same time so it's synchronized
gui.update_meas(samples_meas)
2020-08-10 19:22:58 +08:00
#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()
2020-01-05 19:31:07 +08:00
finally:
2020-08-10 19:22:58 +08:00
induction.stop()
2020-01-05 19:31:07 +08:00
finally:
2020-08-10 19:22:58 +08:00
gui.close()
2020-01-05 19:31:07 +08:00
if __name__ == "__main__":
main()