From 91f18267cd90fdeaea0a5f57543fa149019b251a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 20 Aug 2009 16:20:31 -0700 Subject: added get band select --- gr-vrt/src/vrt_quadradio_source_32fc.cc | 6 ++++++ gr-vrt/src/vrt_quadradio_source_32fc.h | 1 + vrt/include/vrt/quadradio.h | 3 ++- vrt/lib/quadradio.cc | 21 ++++++++++++--------- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/gr-vrt/src/vrt_quadradio_source_32fc.cc b/gr-vrt/src/vrt_quadradio_source_32fc.cc index 0321062aa..77e61cf04 100644 --- a/gr-vrt/src/vrt_quadradio_source_32fc.cc +++ b/gr-vrt/src/vrt_quadradio_source_32fc.cc @@ -91,6 +91,12 @@ vrt_quadradio_source_32fc::set_band_select(const std::string &band) return d_qr->set_band_select(band); } +std::string +vrt_quadradio_source_32fc::get_band_select(void) +{ + return d_qr->get_band_select(); +} + //void //vrt_quadradio_source_32fc::set_10dB_atten(bool on) //{ diff --git a/gr-vrt/src/vrt_quadradio_source_32fc.h b/gr-vrt/src/vrt_quadradio_source_32fc.h index 6ad63f7be..c7d5b9c50 100644 --- a/gr-vrt/src/vrt_quadradio_source_32fc.h +++ b/gr-vrt/src/vrt_quadradio_source_32fc.h @@ -71,6 +71,7 @@ public: * \param band "A", "B", "C", "D" */ bool set_band_select(const std::string &band); + std::string get_band_select(void); /*! * \brief Turn the 10 dB attenuation on/off. diff --git a/vrt/include/vrt/quadradio.h b/vrt/include/vrt/quadradio.h index 747ca8ef4..86039aa37 100644 --- a/vrt/include/vrt/quadradio.h +++ b/vrt/include/vrt/quadradio.h @@ -53,7 +53,7 @@ namespace vrt { int d_data_port; // our data port number vrt::rx::sptr d_rx; // has-a rx - int d_band_select; // band select setting + std::string d_band_select; // band select setting int d_rx_antenna; // antenna type rf/cal int d_attenuation0; // attenuation setting int d_attenuation1; // attenuation setting @@ -93,6 +93,7 @@ namespace vrt { /* convenience methods that ultimately write the dboard pins */ bool set_center_freq(double target_freq); bool set_band_select(const std::string &band); + std::string get_band_select(void){return d_band_select;} //void set_10dB_atten(bool on); bool set_attenuation0(int attenuation); bool select_rx_antenna(const std::string &ant); diff --git a/vrt/lib/quadradio.cc b/vrt/lib/quadradio.cc index ab5de89b8..d4b466b21 100644 --- a/vrt/lib/quadradio.cc +++ b/vrt/lib/quadradio.cc @@ -51,7 +51,7 @@ send_and_check(int fd, void *buf, size_t len) vrt::quadradio::quadradio(const std::string &ip, size_t rx_bufsize) : d_ctrl_fd(0), d_data_fd(0), d_data_port(0), - d_band_select(0), d_rx_antenna(0), d_attenuation0(0), d_attenuation1(0)//d_10dB_atten(true) + d_band_select("A"), d_rx_antenna(0), d_attenuation0(0), d_attenuation1(0)//d_10dB_atten(true) { if (!open(ip.c_str())) throw std::runtime_error("vrt::quadradio: failed to open " + ip + "\n"); @@ -98,11 +98,7 @@ vrt::quadradio::set_center_freq(double target_freq){ bool vrt::quadradio::set_band_select(const std::string &band){ - if (band == "A") d_band_select = 3; - else if (band == "B") d_band_select = 2; - else if (band == "C") d_band_select = 1; - else if (band == "D") d_band_select = 0; - else return false; + d_band_select = band; update_dboard_pins(); return true; } @@ -149,11 +145,18 @@ static int reverse_bits(int input, int len){ void vrt::quadradio::update_dboard_pins(void){ + //convert the band ID to bits + int band_select; + if (d_band_select == "A") band_select = 3; + else if (d_band_select == "B") band_select = 2; + else if (d_band_select == "C") band_select = 1; + else if (d_band_select == "D") band_select = 0; + //calculate the control bits int db_ctrl = \ - ((reverse_bits(d_attenuation0, 5) & 0x1f) << 10) | \ + ((reverse_bits(d_attenuation0, 5) & 0x1f) << 10) | \ ((reverse_bits(~d_attenuation1, 5) & 0x1f) << 03) | \ - ((d_band_select & 0x03) << 01) | \ - ((d_rx_antenna & 0x01) << 00); + ((band_select & 0x03) << 01) | \ + ((d_rx_antenna & 0x01) << 00); set_dboard_pins(ALL_DBOARDS, db_ctrl); // FIXME sets them all } -- cgit From 4256cde50ae0f3c52f415f45e9cc6274f51c6ce2 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 20 Aug 2009 17:17:56 -0700 Subject: use enum for band select --- gr-vrt/src/vrt_quadradio_source_32fc.cc | 8 ++++---- gr-vrt/src/vrt_quadradio_source_32fc.h | 5 ++--- vrt/include/vrt/quadradio.h | 14 +++++++++++--- vrt/lib/quadradio.cc | 23 +++++++++++++---------- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/gr-vrt/src/vrt_quadradio_source_32fc.cc b/gr-vrt/src/vrt_quadradio_source_32fc.cc index 77e61cf04..3769f9124 100644 --- a/gr-vrt/src/vrt_quadradio_source_32fc.cc +++ b/gr-vrt/src/vrt_quadradio_source_32fc.cc @@ -86,15 +86,15 @@ vrt_quadradio_source_32fc::set_center_freq(double target_freq) } bool -vrt_quadradio_source_32fc::set_band_select(const std::string &band) +vrt_quadradio_source_32fc::set_band_select(int band) { - return d_qr->set_band_select(band); + return d_qr->set_band_select(static_cast(band)); } -std::string +int vrt_quadradio_source_32fc::get_band_select(void) { - return d_qr->get_band_select(); + return static_cast(d_qr->get_band_select()); } //void diff --git a/gr-vrt/src/vrt_quadradio_source_32fc.h b/gr-vrt/src/vrt_quadradio_source_32fc.h index c7d5b9c50..862afc5eb 100644 --- a/gr-vrt/src/vrt_quadradio_source_32fc.h +++ b/gr-vrt/src/vrt_quadradio_source_32fc.h @@ -68,10 +68,9 @@ public: /*! * \brief Set the band select dboard bits. - * \param band "A", "B", "C", "D" */ - bool set_band_select(const std::string &band); - std::string get_band_select(void); + bool set_band_select(int band); + int get_band_select(void); /*! * \brief Turn the 10 dB attenuation on/off. diff --git a/vrt/include/vrt/quadradio.h b/vrt/include/vrt/quadradio.h index 86039aa37..9ad8b2a9f 100644 --- a/vrt/include/vrt/quadradio.h +++ b/vrt/include/vrt/quadradio.h @@ -38,6 +38,14 @@ typedef enum{ } vrt_test_sig_t; +typedef enum{ + VRT_BAND_SEL_A='A', + VRT_BAND_SEL_B='B', + VRT_BAND_SEL_C='C', + VRT_BAND_SEL_D='D', + + } vrt_band_sel_t; + namespace vrt { /* @@ -53,7 +61,7 @@ namespace vrt { int d_data_port; // our data port number vrt::rx::sptr d_rx; // has-a rx - std::string d_band_select; // band select setting + vrt_band_sel_t d_band_select; // band select setting int d_rx_antenna; // antenna type rf/cal int d_attenuation0; // attenuation setting int d_attenuation1; // attenuation setting @@ -92,8 +100,8 @@ namespace vrt { /* convenience methods that ultimately write the dboard pins */ bool set_center_freq(double target_freq); - bool set_band_select(const std::string &band); - std::string get_band_select(void){return d_band_select;} + bool set_band_select(vrt_band_sel_t band); + vrt_band_sel_t get_band_select(void){return d_band_select;} //void set_10dB_atten(bool on); bool set_attenuation0(int attenuation); bool select_rx_antenna(const std::string &ant); diff --git a/vrt/lib/quadradio.cc b/vrt/lib/quadradio.cc index d4b466b21..14fc18473 100644 --- a/vrt/lib/quadradio.cc +++ b/vrt/lib/quadradio.cc @@ -51,7 +51,7 @@ send_and_check(int fd, void *buf, size_t len) vrt::quadradio::quadradio(const std::string &ip, size_t rx_bufsize) : d_ctrl_fd(0), d_data_fd(0), d_data_port(0), - d_band_select("A"), d_rx_antenna(0), d_attenuation0(0), d_attenuation1(0)//d_10dB_atten(true) + d_band_select(VRT_BAND_SEL_A), d_rx_antenna(0), d_attenuation0(0), d_attenuation1(0)//d_10dB_atten(true) { if (!open(ip.c_str())) throw std::runtime_error("vrt::quadradio: failed to open " + ip + "\n"); @@ -89,15 +89,15 @@ vrt::quadradio::stop_streaming() bool vrt::quadradio::set_center_freq(double target_freq){ if (target_freq < 700e6) return false; - if (target_freq <= 1.0e9) return set_band_select("A"); - if (target_freq <= 1.5e9) return set_band_select("B"); - if (target_freq <= 2.2e9) return set_band_select("C"); - if (target_freq <= 3.0e9) return set_band_select("D"); + if (target_freq <= 1.0e9) return set_band_select(VRT_BAND_SEL_A); + if (target_freq <= 1.5e9) return set_band_select(VRT_BAND_SEL_B); + if (target_freq <= 2.2e9) return set_band_select(VRT_BAND_SEL_C); + if (target_freq <= 3.0e9) return set_band_select(VRT_BAND_SEL_D); return false; } bool -vrt::quadradio::set_band_select(const std::string &band){ +vrt::quadradio::set_band_select(vrt_band_sel_t band){ d_band_select = band; update_dboard_pins(); return true; @@ -147,10 +147,13 @@ void vrt::quadradio::update_dboard_pins(void){ //convert the band ID to bits int band_select; - if (d_band_select == "A") band_select = 3; - else if (d_band_select == "B") band_select = 2; - else if (d_band_select == "C") band_select = 1; - else if (d_band_select == "D") band_select = 0; + switch (d_band_select){ + case VRT_BAND_SEL_A: band_select = 3; break; + case VRT_BAND_SEL_B: band_select = 2; break; + case VRT_BAND_SEL_C: band_select = 1; break; + case VRT_BAND_SEL_D: band_select = 0; break; + default: band_select = 0; + } //calculate the control bits int db_ctrl = \ ((reverse_bits(d_attenuation0, 5) & 0x1f) << 10) | \ -- cgit From 7b09198e2330d59de7d55030bef342afd217368a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 20 Aug 2009 19:12:07 -0700 Subject: added quadradio method to enable/disable cal --- gr-vrt/src/vrt_quadradio_source_32fc.cc | 4 ++++ gr-vrt/src/vrt_quadradio_source_32fc.h | 1 + vrt/include/vrt/quadradio.h | 1 + vrt/lib/quadradio.cc | 10 ++++++++++ 4 files changed, 16 insertions(+) diff --git a/gr-vrt/src/vrt_quadradio_source_32fc.cc b/gr-vrt/src/vrt_quadradio_source_32fc.cc index 3769f9124..0aac86991 100644 --- a/gr-vrt/src/vrt_quadradio_source_32fc.cc +++ b/gr-vrt/src/vrt_quadradio_source_32fc.cc @@ -216,3 +216,7 @@ vrt_quadradio_source_32fc::set_beamforming(std::vector gains){ return d_qr->set_beamforming(gains_ints); } +bool +vrt_quadradio_source_32fc::set_cal_enb(bool enb){ + return d_qr->set_cal_enb(enb); +} diff --git a/gr-vrt/src/vrt_quadradio_source_32fc.h b/gr-vrt/src/vrt_quadradio_source_32fc.h index 862afc5eb..6193efa10 100644 --- a/gr-vrt/src/vrt_quadradio_source_32fc.h +++ b/gr-vrt/src/vrt_quadradio_source_32fc.h @@ -109,6 +109,7 @@ public: bool set_lo_freq(double freq); bool set_cal_freq(double freq); bool set_beamforming(std::vector gains); + bool set_cal_enb(bool enb); }; diff --git a/vrt/include/vrt/quadradio.h b/vrt/include/vrt/quadradio.h index 9ad8b2a9f..83323f093 100644 --- a/vrt/include/vrt/quadradio.h +++ b/vrt/include/vrt/quadradio.h @@ -119,6 +119,7 @@ namespace vrt { bool set_lo_freq(double freq); bool set_cal_freq(double freq); bool set_beamforming(int32_t gains[8]); + bool set_cal_enb(bool enb); /* * The first parameter for these is a bitmask which indicates which * daughterboard or daughterboards to apply the operation to. diff --git a/vrt/lib/quadradio.cc b/vrt/lib/quadradio.cc index 14fc18473..8cf542e0f 100644 --- a/vrt/lib/quadradio.cc +++ b/vrt/lib/quadradio.cc @@ -412,3 +412,13 @@ vrt::quadradio::set_beamforming(int32_t gains[8]){ return send_and_check(d_ctrl_fd, cmd, sizeof(cmd)); } +bool +vrt::quadradio::set_cal_enb(bool enb) +{ + uint32_t cmd[3]; + cmd[0] = htonl(0); // verb: set + cmd[1] = htonl(9); // id: cal enb + cmd[2] = htonl(enb); + + return send_and_check(d_ctrl_fd, cmd, sizeof(cmd)); +} -- cgit From f3c5010f9c9e8b82048a6d631418c9b5b482e593 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 22 Aug 2009 15:08:40 -0700 Subject: added traces to fft window --- gr-wxgui/src/python/constants.py | 2 ++ gr-wxgui/src/python/fft_window.py | 71 ++++++++++++++++++++++++++++++++------- 2 files changed, 60 insertions(+), 13 deletions(-) diff --git a/gr-wxgui/src/python/constants.py b/gr-wxgui/src/python/constants.py index 5e1395701..8ff7fa8fe 100644 --- a/gr-wxgui/src/python/constants.py +++ b/gr-wxgui/src/python/constants.py @@ -41,6 +41,8 @@ MSG_KEY = 'msg' NUM_LINES_KEY = 'num_lines' OMEGA_KEY = 'omega' PEAK_HOLD_KEY = 'peak_hold' +TRACE_STORE_KEY = 'trace_store' +TRACE_SHOW_KEY = 'trace_show' REF_LEVEL_KEY = 'ref_level' RUNNING_KEY = 'running' SAMPLE_RATE_KEY = 'sample_rate' diff --git a/gr-wxgui/src/python/fft_window.py b/gr-wxgui/src/python/fft_window.py index ba5711d10..87712b1e2 100644 --- a/gr-wxgui/src/python/fft_window.py +++ b/gr-wxgui/src/python/fft_window.py @@ -39,10 +39,15 @@ SLIDER_STEPS = 100 AVG_ALPHA_MIN_EXP, AVG_ALPHA_MAX_EXP = -3, 0 DEFAULT_WIN_SIZE = (600, 300) DEFAULT_FRAME_RATE = gr.prefs().get_long('wxgui', 'fft_rate', 30) -DIV_LEVELS = (1, 2, 5, 10, 20) +DB_DIV_MIN, DB_DIV_MAX = 1, 20 FFT_PLOT_COLOR_SPEC = (0.3, 0.3, 1.0) PEAK_VALS_COLOR_SPEC = (0.0, 0.8, 0.0) -NO_PEAK_VALS = list() +EMPTY_TRACE = list() +TRACES = ('A', 'B') +TRACES_COLOR_SPEC = { + 'A': (1.0, 0.0, 0.0), + 'B': (0.8, 0.0, 0.8), +} ################################################## # FFT window control panel @@ -63,7 +68,7 @@ class control_panel(wx.Panel): control_box.AddStretchSpacer() #checkboxes for average and peak hold options_box = forms.static_box_sizer( - parent=self, sizer=control_box, label='Options', + parent=self, sizer=control_box, label='Trace Options', bold=True, orient=wx.VERTICAL, ) forms.check_box( @@ -90,17 +95,32 @@ class control_panel(wx.Panel): for widget in (avg_alpha_text, avg_alpha_slider): parent.subscribe(AVERAGE_KEY, widget.Enable) widget.Enable(parent[AVERAGE_KEY]) + + #trace menu + for trace in TRACES: + trace_box = wx.BoxSizer(wx.HORIZONTAL) + options_box.Add(trace_box, 0, wx.EXPAND) + forms.check_box( + sizer=trace_box, parent=self, + ps=parent, key=TRACE_SHOW_KEY+trace, + label='Trace %s'%trace, + ) + trace_box.AddSpacer(10) + forms.single_button( + sizer=trace_box, parent=self, + ps=parent, key=TRACE_STORE_KEY+trace, + label='Store', style=wx.BU_EXACTFIT, + ) + trace_box.AddSpacer(10) #radio buttons for div size control_box.AddStretchSpacer() y_ctrl_box = forms.static_box_sizer( parent=self, sizer=control_box, label='Axis Options', bold=True, orient=wx.VERTICAL, ) - forms.radio_buttons( - sizer=y_ctrl_box, parent=self, - ps=parent, key=Y_PER_DIV_KEY, - style=wx.RA_VERTICAL|wx.NO_BORDER, choices=DIV_LEVELS, - labels=map(lambda x: '%s dB/div'%x, DIV_LEVELS), + forms.incr_decr_buttons( + parent=self, sizer=y_ctrl_box, label='dB/Div', + on_incr=self._on_incr_db_div, on_decr=self._on_decr_db_div, ) #ref lvl buttons forms.incr_decr_buttons( @@ -135,6 +155,10 @@ class control_panel(wx.Panel): self.parent[REF_LEVEL_KEY] = self.parent[REF_LEVEL_KEY] + self.parent[Y_PER_DIV_KEY] def _on_decr_ref_level(self, event): self.parent[REF_LEVEL_KEY] = self.parent[REF_LEVEL_KEY] - self.parent[Y_PER_DIV_KEY] + def _on_incr_db_div(self, event): + self.parent[Y_PER_DIV_KEY] = min(DB_DIV_MAX, self.parent[Y_PER_DIV_KEY]*2) + def _on_decr_db_div(self, event): + self.parent[Y_PER_DIV_KEY] = max(DB_DIV_MIN, self.parent[Y_PER_DIV_KEY]/2) ################################################## # FFT window with plotter and control panel @@ -159,13 +183,12 @@ class fft_window(wx.Panel, pubsub.pubsub): msg_key, ): pubsub.pubsub.__init__(self) - #ensure y_per_div - if y_per_div not in DIV_LEVELS: y_per_div = DIV_LEVELS[0] #setup - self.samples = list() + self.samples = EMPTY_TRACE self.real = real self.fft_size = fft_size self._reset_peak_vals() + self._traces = dict() #proxy the keys self.proxy(MSG_KEY, controller, msg_key) self.proxy(AVERAGE_KEY, controller, average_key) @@ -179,6 +202,19 @@ class fft_window(wx.Panel, pubsub.pubsub): self[REF_LEVEL_KEY] = ref_level self[BASEBAND_FREQ_KEY] = baseband_freq self[RUNNING_KEY] = True + for trace in TRACES: + #a function that returns a function + #so the function wont use local trace + def new_store_trace(my_trace): + def store_trace(*args): + self._traces[my_trace] = self.samples + self.update_grid() + return store_trace + self._traces[trace] = EMPTY_TRACE + self[TRACE_STORE_KEY+trace] = False + self[TRACE_SHOW_KEY+trace] = True + self.subscribe(TRACE_STORE_KEY+trace, new_store_trace(trace)) + self.subscribe(TRACE_SHOW_KEY+trace, self.update_grid) #init panel and plot wx.Panel.__init__(self, parent, style=wx.SIMPLE_BORDER) self.plotter = plotter.channel_plotter(self) @@ -194,7 +230,7 @@ class fft_window(wx.Panel, pubsub.pubsub): main_box.Add(self.control_panel, 0, wx.EXPAND) self.SetSizerAndFit(main_box) #register events - self.subscribe(AVERAGE_KEY, lambda x: self._reset_peak_vals()) + self.subscribe(AVERAGE_KEY, self._reset_peak_vals) self.subscribe(MSG_KEY, self.handle_msg) self.subscribe(SAMPLE_RATE_KEY, self.update_grid) for key in ( @@ -223,7 +259,7 @@ class fft_window(wx.Panel, pubsub.pubsub): #set the range to a clean number of the dynamic range self[Y_PER_DIV_KEY] = common.get_clean_num((peak_level - noise_floor)/self[Y_DIVS_KEY]) - def _reset_peak_vals(self): self.peak_vals = NO_PEAK_VALS + def _reset_peak_vals(self, *args): self.peak_vals = EMPTY_TRACE def handle_msg(self, msg): """ @@ -272,6 +308,15 @@ class fft_window(wx.Panel, pubsub.pubsub): The x axis depends on sample rate, baseband freq, and x divs. The y axis depends on y per div, y divs, and ref level. """ + for trace in TRACES: + channel = '%s'%trace.upper() + if self[TRACE_SHOW_KEY+trace]: + self.plotter.set_waveform( + channel=channel, + samples=self._traces[trace], + color_spec=TRACES_COLOR_SPEC[trace], + ) + else: self.plotter.clear_waveform(channel=channel) #grid parameters sample_rate = self[SAMPLE_RATE_KEY] baseband_freq = self[BASEBAND_FREQ_KEY] -- cgit From b6c19491d34357ab2d6332f91733afe7367da92a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 22 Aug 2009 22:01:55 -0700 Subject: automatic store for empty traces on enable --- gr-wxgui/src/python/fft_window.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gr-wxgui/src/python/fft_window.py b/gr-wxgui/src/python/fft_window.py index 87712b1e2..0529e6a5d 100644 --- a/gr-wxgui/src/python/fft_window.py +++ b/gr-wxgui/src/python/fft_window.py @@ -210,11 +210,18 @@ class fft_window(wx.Panel, pubsub.pubsub): self._traces[my_trace] = self.samples self.update_grid() return store_trace + def new_toggle_trace(my_trace): + def toggle_trace(toggle): + #do an automatic store if toggled on and empty trace + if toggle and not len(self._traces[my_trace]): + self._traces[my_trace] = self.samples + self.update_grid() + return toggle_trace self._traces[trace] = EMPTY_TRACE self[TRACE_STORE_KEY+trace] = False - self[TRACE_SHOW_KEY+trace] = True + self[TRACE_SHOW_KEY+trace] = False self.subscribe(TRACE_STORE_KEY+trace, new_store_trace(trace)) - self.subscribe(TRACE_SHOW_KEY+trace, self.update_grid) + self.subscribe(TRACE_SHOW_KEY+trace, new_toggle_trace(trace)) #init panel and plot wx.Panel.__init__(self, parent, style=wx.SIMPLE_BORDER) self.plotter = plotter.channel_plotter(self) -- cgit