From 9fde3bff203e6bf71cdcf03ca8cd9bf580e1c7fd Mon Sep 17 00:00:00 2001 From: thavinga Date: Mon, 28 Mar 2022 16:53:07 +0200 Subject: [PATCH] Displaying side channel plots with interactive mode to avoid jumping to foreground on update Plus small fix for file closing --- user_space/side_ch_ctl_src/iq_capture.py | 13 ++++++------- user_space/side_ch_ctl_src/iq_capture_2ant.py | 7 ++++--- user_space/side_ch_ctl_src/side_info_display.py | 11 +++++------ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/user_space/side_ch_ctl_src/iq_capture.py b/user_space/side_ch_ctl_src/iq_capture.py index 54156a7..cd1afc4 100755 --- a/user_space/side_ch_ctl_src/iq_capture.py +++ b/user_space/side_ch_ctl_src/iq_capture.py @@ -18,8 +18,7 @@ def display_iq(iq_capture, agc_gain, rssi_half_db): plt.plot(iq_capture.real, 'b') plt.plot(iq_capture.imag, 'r') plt.ylim(-32767, 32767) - fig_iq_capture.show() - plt.pause(0.0001) + fig_iq_capture.canvas.flush_events() agc_gain_lock = np.copy(agc_gain) agc_gain_lock[agc_gain>127] = 80 # agc lock @@ -36,8 +35,7 @@ def display_iq(iq_capture, agc_gain, rssi_half_db): plt.plot(agc_gain_value, 'b') plt.plot(agc_gain_lock, 'r') plt.ylim(0, 82) - fig_agc_gain.show() - plt.pause(0.0001) + fig_agc_gain.canvas.flush_events() fig_rssi_half_db = plt.figure(2) fig_rssi_half_db.clf() @@ -46,8 +44,7 @@ def display_iq(iq_capture, agc_gain, rssi_half_db): plt.title("RSSI half dB (uncalibrated)") plt.plot(rssi_half_db) plt.ylim(100, 270) - fig_rssi_half_db.show() - plt.pause(0.0001) + fig_rssi_half_db.canvas.flush_events() def parse_iq(iq, iq_len): # print(len(iq), iq_len) @@ -98,6 +95,8 @@ if os.path.exists("iq.txt"): os.remove("iq.txt") iq_fd=open('iq.txt','a') +plt.ion() + while True: try: data, addr = sock.recvfrom(MAX_NUM_DMA_SYMBOL*8) # buffer size @@ -119,5 +118,5 @@ while True: break print('close()') -side_info_fd.close() +iq_fd.close() sock.close() diff --git a/user_space/side_ch_ctl_src/iq_capture_2ant.py b/user_space/side_ch_ctl_src/iq_capture_2ant.py index f42f295..807564e 100755 --- a/user_space/side_ch_ctl_src/iq_capture_2ant.py +++ b/user_space/side_ch_ctl_src/iq_capture_2ant.py @@ -27,8 +27,7 @@ def display_iq(iq0_capture, iq1_capture): plt.plot(iq1_capture.real, 'b') plt.plot(iq1_capture.imag, 'r') plt.ylim(-32767, 32767) - fig_iq_capture.show() - plt.pause(0.0001) + fig_iq_capture.canvas.flush_events() def parse_iq(iq, iq_len): # print(len(iq), iq_len) @@ -77,6 +76,8 @@ if os.path.exists("iq_2ant.txt"): os.remove("iq_2ant.txt") iq_fd=open('iq_2ant.txt','a') +plt.ion() + while True: try: data, addr = sock.recvfrom(MAX_NUM_DMA_SYMBOL*8) # buffer size @@ -98,5 +99,5 @@ while True: break print('close()') -side_info_fd.close() +iq_fd.close() sock.close() diff --git a/user_space/side_ch_ctl_src/side_info_display.py b/user_space/side_ch_ctl_src/side_info_display.py index 67aad6e..0449d8b 100755 --- a/user_space/side_ch_ctl_src/side_info_display.py +++ b/user_space/side_ch_ctl_src/side_info_display.py @@ -22,8 +22,7 @@ def display_side_info(freq_offset, csi, equalizer, CSI_LEN, EQUALIZER_LEN): plt.ylabel("Hz") plt.title("freq offset") plt.plot(display_side_info.freq_offset_store) - fig_freq_offset.show() - plt.pause(0.0001) + fig_freq_offset.canvas.flush_events() good_row_idx = 0 if ( len(equalizer)==0 ): @@ -60,8 +59,7 @@ def display_side_info(freq_offset, csi, equalizer, CSI_LEN, EQUALIZER_LEN): ax_phase_csi.set_xlabel("subcarrier idx") ax_phase_csi.set_ylabel("phase") plt.plot(np.angle(csi_for_plot)) - fig_csi.show() - plt.pause(0.0001) + fig_csi.canvas.flush_events() if ( (len(equalizer)>0) and (good_row_idx>0) ): fig_equalizer = plt.figure(2) @@ -70,8 +68,7 @@ def display_side_info(freq_offset, csi, equalizer, CSI_LEN, EQUALIZER_LEN): plt.ylabel("Q") plt.title("equalizer") plt.scatter(equalizer_for_plot.real, equalizer_for_plot.imag) - fig_freq_offset.show() - plt.pause(0.0001) + fig_freq_offset.canvas.flush_events() def parse_side_info(side_info, num_eq, CSI_LEN, EQUALIZER_LEN, HEADER_LEN): # print(len(side_info), num_eq, CSI_LEN, EQUALIZER_LEN, HEADER_LEN) @@ -135,6 +132,8 @@ if os.path.exists("side_info.txt"): os.remove("side_info.txt") side_info_fd=open('side_info.txt','a') +plt.ion() + while True: try: data, addr = sock.recvfrom(MAX_NUM_DMA_SYMBOL*8) # buffer size