Imported Upstream version 3.0
[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 2, 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 private:
45   static const int      MAX_CHANNELS = 16;
46   enum scope_state      { HOLD_OFF, LOOK_FOR_TRIGGER, POST_TRIGGER };
47
48   int                   d_nchannels;            // how many channels
49   gr_msg_queue_sptr     d_msgq;                 // message queue we stuff output records into
50   gr_trigger_mode       d_trigger_mode;         
51   int                   d_trigger_channel;      // which channel to watch for trigger condition
52   double                d_sample_rate;          // input sample rate in Hz
53   double                d_update_rate;          // approx freq to produce an output record (Hz)
54   double                d_trigger_level;
55
56   int                   d_obi;                  // output buffer index 
57   float                *d_buffer[MAX_CHANNELS];
58
59   scope_state           d_state;
60   int                   d_decimator_count;
61   int                   d_decimator_count_init;
62   int                   d_hold_off_count;
63   int                   d_hold_off_count_init;
64   int                   d_post_trigger_count;
65   int                   d_post_trigger_count_init;
66   float                 d_prev_sample;                  // used for trigger checking
67
68   // NOT IMPLEMENTED
69   gr_oscope_guts (const gr_oscope_guts &rhs);                   // no copy constructor
70   gr_oscope_guts &operator= (const gr_oscope_guts &rhs);        // no assignment operator
71
72   void trigger_changed ();
73   void update_rate_or_decimation_changed ();
74   int  found_trigger (float sample);    // returns -1, 0, +1
75   void write_output_records ();
76
77   void enter_hold_off ();                       // called on state entry
78   void enter_look_for_trigger ();
79   void enter_post_trigger ();
80
81 public:
82   // CREATORS
83   gr_oscope_guts (int nchannels, double sample_rate, gr_msg_queue_sptr msgq);
84   ~gr_oscope_guts ();
85
86   // MANIPULATORS
87
88   /*!
89    * \p channel_data points to nchannels float values.  These are the values
90    * for each channel at this sample time.
91    */
92   void process_sample (const float *channel_data);
93
94   bool set_update_rate (double update_rate);
95   bool set_decimation_count (int decimation_count);
96   bool set_trigger_channel (int channel);
97   bool set_trigger_mode (gr_trigger_mode mode);
98   bool set_trigger_level (double trigger_level);
99   bool set_trigger_level_auto ();                               // set to 50% level
100   bool set_sample_rate(double sample_rate);
101
102
103   // ACCESSORS
104   int num_channels () const;
105   double sample_rate () const;
106   double update_rate () const;
107   int get_decimation_count () const;
108   int get_trigger_channel () const;
109   gr_trigger_mode get_trigger_mode () const;
110   double get_trigger_level () const;
111
112   // # of samples written to each output record.
113   int get_samples_per_output_record () const;
114 };
115
116 #endif /* INCLUDED_GR_OSCOPE_GUTS_H */