From 33b527302ddfbd84d417afd8c62f445150cefd9d Mon Sep 17 00:00:00 2001 From: gael Date: Thu, 25 Sep 2025 11:28:00 -0400 Subject: [PATCH] Update gain_viz/app.py --- gain_viz/app.py | 52 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/gain_viz/app.py b/gain_viz/app.py index 87ed0cc..2576850 100644 --- a/gain_viz/app.py +++ b/gain_viz/app.py @@ -20,6 +20,13 @@ usrp_rx_gain = 30 scm_tx_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 ----------------- def connect_serial(port, baudrate=115200, timeout=1): """Connect to a serial port with even parity.""" @@ -112,13 +119,9 @@ def zmq_subscriber(host, port): # ----------------- Plot Generation ----------------- def generate_spectrum_plot(): - socket = zmq_subscriber("localhost", 5556) - - sample_rate = 23.04e6 # Hz - window_ms = 20 - center_freq = 3.415e9 + socket = zmq_subscriber("localhost", tcp_port) + global sample_rate, window_ms, center_freq, NFFT window_samples = int(sample_rate * window_ms / 1000) - NFFT = 1024 noverlap = 512 cmap = plt.get_cmap('twilight') @@ -216,6 +219,43 @@ def get_gains(): "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 ----------------- def main(): # Ensure placeholder image exists