Update gain_viz/app.py
This commit is contained in:
parent
666ae6ab5e
commit
33b527302d
|
|
@ -20,6 +20,13 @@ usrp_rx_gain = 30
|
||||||
scm_tx_gain = 30
|
scm_tx_gain = 30
|
||||||
scm_rx_gain = 30
|
scm_rx_gain = 30
|
||||||
|
|
||||||
|
# Global variables for plot settings
|
||||||
|
sample_rate = 23.04e6 # Hz
|
||||||
|
window_ms = 20
|
||||||
|
center_freq = 3.415e9
|
||||||
|
NFFT = 1024
|
||||||
|
tcp_port = 5556
|
||||||
|
|
||||||
# ----------------- Serial / SCM -----------------
|
# ----------------- Serial / SCM -----------------
|
||||||
def connect_serial(port, baudrate=115200, timeout=1):
|
def connect_serial(port, baudrate=115200, timeout=1):
|
||||||
"""Connect to a serial port with even parity."""
|
"""Connect to a serial port with even parity."""
|
||||||
|
|
@ -112,13 +119,9 @@ def zmq_subscriber(host, port):
|
||||||
|
|
||||||
# ----------------- Plot Generation -----------------
|
# ----------------- Plot Generation -----------------
|
||||||
def generate_spectrum_plot():
|
def generate_spectrum_plot():
|
||||||
socket = zmq_subscriber("localhost", 5556)
|
socket = zmq_subscriber("localhost", tcp_port)
|
||||||
|
global sample_rate, window_ms, center_freq, NFFT
|
||||||
sample_rate = 23.04e6 # Hz
|
|
||||||
window_ms = 20
|
|
||||||
center_freq = 3.415e9
|
|
||||||
window_samples = int(sample_rate * window_ms / 1000)
|
window_samples = int(sample_rate * window_ms / 1000)
|
||||||
NFFT = 1024
|
|
||||||
noverlap = 512
|
noverlap = 512
|
||||||
cmap = plt.get_cmap('twilight')
|
cmap = plt.get_cmap('twilight')
|
||||||
|
|
||||||
|
|
@ -216,6 +219,43 @@ def get_gains():
|
||||||
"scm_rx_gain": scm_rx_gain
|
"scm_rx_gain": scm_rx_gain
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@app.route('/update_params', methods=['POST'])
|
||||||
|
def update_params():
|
||||||
|
global sample_rate, window_ms, center_freq, NFFT
|
||||||
|
try:
|
||||||
|
# Get parameters from form data
|
||||||
|
center_freq = request.form.get('center_freq', type=float)
|
||||||
|
sample_rate = request.form.get('sample_rate', type=float)
|
||||||
|
NFFT = request.form.get('fft_size', type=int)
|
||||||
|
window_ms = request.form.get('window_ms', type=float)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Save to config file if needed
|
||||||
|
save_config()
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'status': 'success',
|
||||||
|
'message': 'Parameters updated successfully'
|
||||||
|
})
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({
|
||||||
|
'status': 'error',
|
||||||
|
'message': str(e)
|
||||||
|
}), 500
|
||||||
|
|
||||||
|
# Add to your config handling
|
||||||
|
def save_config():
|
||||||
|
config = {
|
||||||
|
'center_freq': center_freq,
|
||||||
|
'sample_rate': sample_rate,
|
||||||
|
'fft_size': NFFT,
|
||||||
|
'window_ms': window_ms
|
||||||
|
}
|
||||||
|
with open('/opt/gain-viz/config.json', 'w') as f:
|
||||||
|
json.dump(config, f)
|
||||||
|
|
||||||
# ----------------- Main -----------------
|
# ----------------- Main -----------------
|
||||||
def main():
|
def main():
|
||||||
# Ensure placeholder image exists
|
# Ensure placeholder image exists
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user