3 * Copyright 2003,2005 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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)
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.
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.
24 #ifndef INCLUDED_GR_OSCOPE_GUTS_H
25 #define INCLUDED_GR_OSCOPE_GUTS_H
27 #include <gr_trigger_mode.h>
28 #include <gr_msg_queue.h>
31 * \brief guts of oscilloscope trigger and buffer module
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.
43 class gr_oscope_guts {
45 static const int MAX_CHANNELS = 16;
46 enum scope_state { HOLD_OFF, LOOK_FOR_TRIGGER, POST_TRIGGER };
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;
56 int d_obi; // output buffer index
57 float *d_buffer[MAX_CHANNELS];
60 int d_decimator_count;
61 int d_decimator_count_init;
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
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
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 ();
77 void enter_hold_off (); // called on state entry
78 void enter_look_for_trigger ();
79 void enter_post_trigger ();
83 gr_oscope_guts (int nchannels, double sample_rate, gr_msg_queue_sptr msgq);
89 * \p channel_data points to nchannels float values. These are the values
90 * for each channel at this sample time.
92 void process_sample (const float *channel_data);
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);
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;
112 // # of samples written to each output record.
113 int get_samples_per_output_record () const;
116 #endif /* INCLUDED_GR_OSCOPE_GUTS_H */