Compare commits
5 Commits
6d0d2cb253
...
6feda538cc
Author | SHA1 | Date |
---|---|---|
Sebastien Bourdeauducq | 6feda538cc | |
Sebastien Bourdeauducq | 970838f6e7 | |
Sebastien Bourdeauducq | 8a8a271c9c | |
Sebastien Bourdeauducq | 8f1b13d0c1 | |
Sebastien Bourdeauducq | c6b13866bc |
36
dmi.py
36
dmi.py
|
@ -1,18 +1,22 @@
|
||||||
import SoapySDR
|
import SoapySDR
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import gc
|
||||||
|
|
||||||
from noptica import InductionHeater, Stabilizer, PositionTracker
|
from noptica import *
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
# For this PoC code, a small memory leak is less harmful than random overflows.
|
||||||
|
gc.disable()
|
||||||
|
|
||||||
freq_sample = 5e6
|
freq_sample = 5e6
|
||||||
freq_base = 1086e6
|
freq_base = 1086e6
|
||||||
bufsize = 4096
|
bufsize = 4096
|
||||||
|
|
||||||
induction = InductionHeater("/dev/ttyUSB0", 430e3, 445e3)
|
induction = InductionHeater("/dev/ttyUSB0", 350e3, 445e3)
|
||||||
induction.start()
|
induction.start()
|
||||||
try:
|
try:
|
||||||
stabilizer = Stabilizer(freq_sample, 0.4, 1088.3e6 - freq_base, 200e-6, induction)
|
stabilizer = Stabilizer(freq_sample, 0.4, 1088.1e6 - freq_base, 50e-6, induction)
|
||||||
position_tracker = PositionTracker(int(0.1*freq_sample/bufsize))
|
position_tracker = PositionTracker(int(0.1*freq_sample/bufsize))
|
||||||
|
|
||||||
sdr = SoapySDR.Device()
|
sdr = SoapySDR.Device()
|
||||||
|
@ -20,31 +24,27 @@ def main():
|
||||||
sdr.setSampleRate(SoapySDR.SOAPY_SDR_RX, channel, freq_sample)
|
sdr.setSampleRate(SoapySDR.SOAPY_SDR_RX, channel, freq_sample)
|
||||||
sdr.setFrequency(SoapySDR.SOAPY_SDR_RX, channel, freq_base)
|
sdr.setFrequency(SoapySDR.SOAPY_SDR_RX, channel, freq_base)
|
||||||
|
|
||||||
samples_ref = np.array([0]*bufsize, np.complex64)
|
buf_sdr = BufferedSDR(sdr, [0, 1], bufsize, 256)
|
||||||
samples_meas = np.array([0]*bufsize, np.complex64)
|
buf_sdr.start()
|
||||||
rx_stream = sdr.setupStream(SoapySDR.SOAPY_SDR_RX, SoapySDR.SOAPY_SDR_CF32, [0, 1])
|
|
||||||
try:
|
try:
|
||||||
sdr.activateStream(rx_stream)
|
stabilizer_throttle = 0
|
||||||
try:
|
while True:
|
||||||
stabilizer_throttle = 0
|
buffers = buf_sdr.get()
|
||||||
while True:
|
try:
|
||||||
sr = sdr.readStream(rx_stream, [samples_ref, samples_meas], bufsize)
|
samples_ref, samples_meas = buffers
|
||||||
if sr.ret != bufsize:
|
|
||||||
print("SDR sampling error")
|
|
||||||
return
|
|
||||||
|
|
||||||
# We can't update faster than the MHS5200A serial interface
|
# We can't update faster than the MHS5200A serial interface
|
||||||
stabilizer_throttle += 1
|
stabilizer_throttle += 1
|
||||||
if stabilizer_throttle == 30:
|
if stabilizer_throttle == 40:
|
||||||
stabilizer.input(samples_ref)
|
stabilizer.input(samples_ref)
|
||||||
stabilizer_throttle = 0
|
stabilizer_throttle = 0
|
||||||
|
|
||||||
position, leakage = position_tracker.input(samples_ref, samples_meas)
|
position, leakage = position_tracker.input(samples_ref, samples_meas)
|
||||||
print(np.sum(position)/len(position), leakage)
|
print(np.sum(position)/len(position), leakage)
|
||||||
finally:
|
finally:
|
||||||
sdr.deactivateStream(rx_stream)
|
buf_sdr.dispose(buffers)
|
||||||
finally:
|
finally:
|
||||||
sdr.closeStream(rx_stream)
|
buf_sdr.stop()
|
||||||
finally:
|
finally:
|
||||||
induction.stop()
|
induction.stop()
|
||||||
|
|
||||||
|
|
63
noptica.py
63
noptica.py
|
@ -2,10 +2,73 @@ import serial
|
||||||
import queue
|
import queue
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
import SoapySDR
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from scipy.signal import blackmanharris
|
from scipy.signal import blackmanharris
|
||||||
|
|
||||||
|
|
||||||
|
class BufferedSDR:
|
||||||
|
def __init__(self, sdr, channels, bufsize, nbufs):
|
||||||
|
self.sdr = sdr
|
||||||
|
self.channels = channels
|
||||||
|
self.bufsize = bufsize
|
||||||
|
|
||||||
|
self.stream = None
|
||||||
|
self.terminate = False
|
||||||
|
self.thread = None
|
||||||
|
self.queue = queue.Queue(nbufs)
|
||||||
|
self.available_buffers = queue.Queue(nbufs)
|
||||||
|
for _ in range(nbufs):
|
||||||
|
self.available_buffers.put([np.array([0]*bufsize, np.complex64) for _ in self.channels])
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
self.stream = self.sdr.setupStream(SoapySDR.SOAPY_SDR_RX, SoapySDR.SOAPY_SDR_CF32, self.channels)
|
||||||
|
try:
|
||||||
|
self.thread = threading.Thread(target=self.thread_target)
|
||||||
|
self.thread.start()
|
||||||
|
except:
|
||||||
|
self.sdr.closeStream(self.stream)
|
||||||
|
raise
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self.terminate = True
|
||||||
|
self.thread.join()
|
||||||
|
self.sdr.closeStream(self.stream)
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
return self.queue.get()
|
||||||
|
|
||||||
|
def dispose(self, buffers):
|
||||||
|
self.available_buffers.put(buffers)
|
||||||
|
|
||||||
|
def thread_target(self):
|
||||||
|
self.sdr.activateStream(self.stream)
|
||||||
|
try:
|
||||||
|
while not self.terminate:
|
||||||
|
buffers = self.available_buffers.get()
|
||||||
|
sr = self.sdr.readStream(self.stream, buffers, self.bufsize)
|
||||||
|
if sr.ret != self.bufsize:
|
||||||
|
print("SDR sampling error")
|
||||||
|
return
|
||||||
|
self.queue.put(buffers)
|
||||||
|
finally:
|
||||||
|
self.sdr.deactivateStream(self.stream)
|
||||||
|
|
||||||
|
|
||||||
|
class DummyInductionHeater:
|
||||||
|
def __init__(self, port, induction_min, induction_max):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def set(self, amount):
|
||||||
|
print("induction", amount)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class InductionHeater:
|
class InductionHeater:
|
||||||
"""Interface to the MHS5200A function generator driving the LC tank"""
|
"""Interface to the MHS5200A function generator driving the LC tank"""
|
||||||
def __init__(self, port, induction_min, induction_max):
|
def __init__(self, port, induction_min, induction_max):
|
||||||
|
|
|
@ -12,9 +12,18 @@ let
|
||||||
};
|
};
|
||||||
propagatedBuildInputs = with pkgs.python3Packages; [ scipy numpy pyqt5 pyopengl ];
|
propagatedBuildInputs = with pkgs.python3Packages; [ scipy numpy pyqt5 pyopengl ];
|
||||||
};
|
};
|
||||||
|
bitstream = pkgs.fetchurl {
|
||||||
|
url = "https://www.nuand.com/fpga/v0.11.0/hostedxA4.rbf";
|
||||||
|
sha256 = "c172e35c4a92cf1e0ca3b37347a84d8376b275ece16cb9c5142b72b82b16fe8e";
|
||||||
|
};
|
||||||
in
|
in
|
||||||
pkgs.mkShell {
|
pkgs.mkShell {
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
(pkgs.python3.withPackages(ps: [ps.soapysdr-with-plugins ps.scipy ps.pyserial ps.quamash ps.pyqt5 pyqtgraph-qt5]))
|
(pkgs.python3.withPackages(ps: [ps.soapysdr-with-plugins ps.scipy ps.pyserial ps.quamash ps.pyqt5 pyqtgraph-qt5]))
|
||||||
|
pkgs.libbladeRF pkgs.gqrx
|
||||||
];
|
];
|
||||||
|
shellHook = ''
|
||||||
|
${pkgs.libbladeRF}/bin/bladeRF-cli -l ${bitstream}
|
||||||
|
${pkgs.libbladeRF}/bin/bladeRF-cli -e "set biastee rx on"
|
||||||
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue