Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / io / gr_oscope_guts.h
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_trigger_mode.h>
28 #include <gr_msg_queue.h>
29
30 /*!
31  * \brief guts of oscilloscope trigger and buffer module
32  *
33  * This module processes sets of samples provided the \p process_sample
34  * method.  When appropriate given the updateRate, sampleRate and
35  * trigger conditions, process_sample will periodically write output
36  * records of captured data to output_fd.  For each trigger event,
37  * nchannels records will be written.  Each record consists of
38  * get_samples_per_output_record binary floats.  The trigger instant
39  * occurs at the 1/2 way point in the buffer.  Thus, output records
40  * consist of 50% pre-trigger data and 50% post-trigger data.
41  */
42
43 class gr_oscope_guts {
44 public:
45   static const int      MAX_CHANNELS = 8;
46 private:
47   enum scope_state      { HOLD_OFF, LOOK_FOR_TRIGGER, POST_TRIGGER };
48
49   int                   d_nchannels;            // how many channels
50   gr_msg_queue_sptr     d_msgq;                 // message queue we stuff output records into
51   gr_trigger_mode       d_trigger_mode;
52   gr_trigger_slope      d_trigger_slope;
53   int                   d_trigger_channel;      // which channel to watch for trigger condition
54   double                d_sample_rate;          // input sample rate in Hz
55   double                d_update_rate;          // approx freq to produce an output record (Hz)
56   double                d_trigger_level;
57
58   int                   d_obi;                  // output buffer index 
59   float                *d_buffer[MAX_CHANNELS];
60
61   scope_state           d_state;
62   int                   d_decimator_count;
63   int                   d_decimator_count_init;
64   int                   d_hold_off_count;
65   int                   d_hold_off_count_init;
66   int                   d_pre_trigger_count;
67   int                   d_post_trigger_count;
68   int                   d_post_trigger_count_init;
69   float                 d_trigger_off;                  //%sample trigger is off
70
71   // NOT IMPLEMENTED
72   gr_oscope_guts (const gr_oscope_guts &rhs);                   // no copy constructor
73   gr_oscope_guts &operator= (const gr_oscope_guts &rhs);        // no assignment operator
74
75   void trigger_changed ();
76   void update_rate_or_decimation_changed ();
77   bool found_trigger ();        // returns true if found
78   void write_output_records ();
79
80   void enter_hold_off ();                       // called on state entry
81   void enter_look_for_trigger ();
82   void enter_post_trigger ();
83
84 public:
85   // CREATORS
86   gr_oscope_guts (double sample_rate, gr_msg_queue_sptr msgq);
87   ~gr_oscope_guts ();
88
89   // MANIPULATORS
90
91   /*!
92    * \p channel_data points to nchannels float values.  These are the values
93    * for each channel at this sample time.
94    */
95   void process_sample (const float *channel_data);
96
97   bool set_update_rate (double update_rate);
98   bool set_decimation_count (int decimation_count);
99   bool set_trigger_channel (int channel);
100   bool set_trigger_mode (gr_trigger_mode mode);
101   bool set_trigger_slope (gr_trigger_slope slope);
102   bool set_trigger_level (double trigger_level);
103   bool set_trigger_level_auto ();                               // set to 50% level
104   bool set_sample_rate(double sample_rate);
105   bool set_num_channels(int nchannels);
106
107
108   // ACCESSORS
109   int num_channels () const;
110   double sample_rate () const;
111   double update_rate () const;
112   int get_decimation_count () const;
113   int get_trigger_channel () const;
114   gr_trigger_mode get_trigger_mode () const;
115   gr_trigger_slope get_trigger_slope () const;
116   double get_trigger_level () const;
117
118   // # of samples written to each output record.
119   int get_samples_per_output_record () const;
120 };
121
122 #endif /* INCLUDED_GR_OSCOPE_GUTS_H */