GNU Radio C++ API
gr_oscope_guts.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2003,2005 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 
24 #ifndef INCLUDED_GR_OSCOPE_GUTS_H
25 #define INCLUDED_GR_OSCOPE_GUTS_H
26 
27 #include <gr_core_api.h>
28 #include <gr_trigger_mode.h>
29 #include <gr_msg_queue.h>
30 
31 /*!
32  * \brief guts of oscilloscope trigger and buffer module
33  *
34  * This module processes sets of samples provided the \p process_sample
35  * method. When appropriate given the updateRate, sampleRate and
36  * trigger conditions, process_sample will periodically write output
37  * records of captured data to output_fd. For each trigger event,
38  * nchannels records will be written. Each record consists of
39  * get_samples_per_output_record binary floats. The trigger instant
40  * occurs at the 1/2 way point in the buffer. Thus, output records
41  * consist of 50% pre-trigger data and 50% post-trigger data.
42  */
43 
45 public:
46  static const int MAX_CHANNELS = 8;
47 private:
48  enum scope_state { HOLD_OFF, LOOK_FOR_TRIGGER, POST_TRIGGER };
49 
50  int d_nchannels; // how many channels
51  gr_msg_queue_sptr d_msgq; // message queue we stuff output records into
52  gr_trigger_mode d_trigger_mode;
53  gr_trigger_slope d_trigger_slope;
54  int d_trigger_channel; // which channel to watch for trigger condition
55  double d_sample_rate; // input sample rate in Hz
56  double d_update_rate; // approx freq to produce an output record (Hz)
57  double d_trigger_level;
58 
59  int d_obi; // output buffer index
60  float *d_buffer[MAX_CHANNELS];
61 
62  scope_state d_state;
63  int d_decimator_count;
64  int d_decimator_count_init;
65  int d_hold_off_count;
66  int d_hold_off_count_init;
67  int d_pre_trigger_count;
68  int d_post_trigger_count;
69  int d_post_trigger_count_init;
70  float d_trigger_off; //%sample trigger is off
71 
72  // NOT IMPLEMENTED
73  gr_oscope_guts (const gr_oscope_guts &rhs); // no copy constructor
74  gr_oscope_guts &operator= (const gr_oscope_guts &rhs); // no assignment operator
75 
76  void trigger_changed ();
77  void update_rate_or_decimation_changed ();
78  bool found_trigger (); // returns true if found
79  void write_output_records ();
80 
81  void enter_hold_off (); // called on state entry
82  void enter_look_for_trigger ();
83  void enter_post_trigger ();
84 
85 public:
86  // CREATORS
87  gr_oscope_guts (double sample_rate, gr_msg_queue_sptr msgq);
88  ~gr_oscope_guts ();
89 
90  // MANIPULATORS
91 
92  /*!
93  * \p channel_data points to nchannels float values. These are the values
94  * for each channel at this sample time.
95  */
96  void process_sample (const float *channel_data);
97 
98  bool set_update_rate (double update_rate);
99  bool set_decimation_count (int decimation_count);
100  bool set_trigger_channel (int channel);
101  bool set_trigger_mode (gr_trigger_mode mode);
102  bool set_trigger_slope (gr_trigger_slope slope);
103  bool set_trigger_level (double trigger_level);
104  bool set_trigger_level_auto (); // set to 50% level
105  bool set_sample_rate(double sample_rate);
106  bool set_num_channels(int nchannels);
107 
108 
109  // ACCESSORS
110  int num_channels () const;
111  double sample_rate () const;
112  double update_rate () const;
113  int get_decimation_count () const;
114  int get_trigger_channel () const;
115  gr_trigger_mode get_trigger_mode () const;
116  gr_trigger_slope get_trigger_slope () const;
117  double get_trigger_level () const;
118 
119  // # of samples written to each output record.
120  int get_samples_per_output_record () const;
121 };
122 
123 #endif /* INCLUDED_GR_OSCOPE_GUTS_H */