gr-baz Package
baz_burster.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2004 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 * gr-baz by Balint Seeber (http://spench.net/contact)
25 * Information, documentation & samples: http://wiki.spench.net/wiki/gr-baz
26 */
27
28#ifndef INCLUDED_BAZ_BURSTER_H
29#define INCLUDED_BAZ_BURSTER_H
30
31//#include <sys/time.h>
32#include <boost/thread/thread.hpp>
33
34#include <string>
35#include <vector>
36#include <map>
37
38#include <gnuradio/sync_block.h>
39#include <gnuradio/msg_queue.h>
40#include <pmt/pmt.h>
41
42#include "baz_burster_config.h"
43
45
46/*
47 * We use boost::shared_ptr's instead of raw pointers for all access
48 * to gr::blocks (and many other data structures). The shared_ptr gets
49 * us transparent reference counting, which greatly simplifies storage
50 * management issues. This is especially helpful in our hybrid
51 * C++ / Python system.
52 *
53 * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
54 *
55 * As a convention, the _sptr suffix indicates a boost::shared_ptr
56 */
57typedef boost::shared_ptr<baz_burster> baz_burster_sptr;
58
59/*!
60 * \brief Return a shared_ptr to a new instance of baz_burster.
61 *
62 * To avoid accidental use of raw pointers, baz_burster's
63 * constructor is private. baz_make_burster is the public
64 * interface for creating new instances.
65 */
66BAZ_API baz_burster_sptr baz_make_burster (const baz_burster_config& config);
67
68/*!
69 * \brief burster a stream of floats.
70 * \ingroup block
71 *
72 * This uses the preferred technique: subclassing gr::sync_block.
73 */
74class BAZ_API baz_burster : public gr::block
75{
76private:
77 friend BAZ_API baz_burster_sptr baz_make_burster (const baz_burster_config& config);
78
79 baz_burster (const baz_burster_config& config); // private constructor
80
81 baz_burster_config d_config;
82
83 typedef struct burst_time_t
84 {
85 uint64_t seconds;
86 double fractional_seconds;
87 uint64_t sample_offset;
88 int sample_rate;
89 } burst_time;
90
91 inline static burst_time burst_time_absorb_whole_samples(const burst_time& t)
92 {
93 burst_time _t(t);
94 uint64_t s = t.sample_offset / t.sample_rate;
95 _t.seconds += s;
96 _t.sample_offset -= (s * t.sample_rate);
97 return _t;
98 }
99
100 inline static burst_time burst_time_absorb_samples(const burst_time& t)
101 {
102 burst_time _t(t);
103 double d = (double)t.sample_offset / (double)t.sample_rate;
104 _t.seconds += (int)d;
105 _t.fractional_seconds += (d - (int)d);
106 _t.sample_offset = 0;
107 return _t;
108 }
109
110 inline static burst_time burst_time_difference(const burst_time& t1, const burst_time& t2, bool relative_to_second = true)
111 {
112 burst_time t;
113
114 if ((t1.sample_rate == t2.sample_rate)/* && (t1.seconds == t2.seconds) && (t1.fractional_seconds == t2.fractional_seconds)*/)
115 {
116 t.sample_rate = t1.sample_rate;
117 t.seconds = 0;
118 t.fractional_seconds = 0;
119 t.sample_offset =
120 (t1.sample_rate * (t1.seconds - t2.seconds)) +
121 (uint64_t)((double)t1.sample_rate * (t1.fractional_seconds - t2.fractional_seconds)) +
122 (t1.sample_offset - t2.sample_offset);
123 return t;
124 }
125
126 if ((t1.sample_rate != t2.sample_rate) && ((t1.sample_offset > 0) || (t2.sample_offset > 0)))
127 {
128 return burst_time_difference(burst_time_absorb_samples(t1), burst_time_absorb_samples(t2));
129 }
130
131 t.seconds = 0;
132 t.fractional_seconds = 0;
133
134 if (relative_to_second)
135 {
136 t.sample_rate = t2.sample_rate;
137 }
138 else
139 {
140 t.sample_rate = t1.sample_rate;
141 }
142
143 t.sample_offset = (t.sample_rate * (t1.seconds - t2.seconds)) + (uint64_t)((double)t.sample_rate * (t1.fractional_seconds - t2.fractional_seconds));
144
145 return t;
146 }
147
148 bool send_pending_msg(void);
149 void set_burst_length(int length);
150//////////////////// ZERO
151 union {
153 //uint64_t d_last_time_seconds;
154 burst_time d_stream_time;
155 };
156 //double d_last_time_fractional_seconds;
157 burst_time d_last_burst_time;
158 int d_burst_message_sample_index;
159 //bool d_msg_ready;
160 bool d_in_burst;
161 int d_burst_count; // Incremented when new one is started (not when it is transmitted)
162 bool d_last_burst_system_time_valid;
163 int d_time_tags;
164 uint64_t d_current_burst_length;
165 char* d_message_buffer;
166 int d_message_buffer_length;
167 int d_system_time_ticks_per_second;
168 // Next must come last
169 char d_dummy_zero_last;
170////////////////////
171 //uint64_t d_last_burst_sample_time;
172 //double d_last_burst_time;
173 boost::system_time d_system_time;
174 boost::system_time d_last_burst_system_time;
175 //uint64_t d_samples_since_last_time_tag;
176 //gr::message::sptr d_current_msg;
177 gr::message::sptr d_pending_msg;
178 std::vector<gr::tag_t> d_incoming_time_tags;
179public:
180 ~baz_burster (); // public destructor
181
182 //
183
184 void forecast(int noutput_items, gr_vector_int &ninput_items_required);
185 int general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items);
186};
187
188#endif /* INCLUDED_BAZ_BURSTER_H */
#define BAZ_API
Definition api.h:19
BAZ_API baz_burster_sptr baz_make_burster(const baz_burster_config &config)
Return a shared_ptr to a new instance of baz_burster.
burster a stream of floats.
Definition baz_burster.h:75
int general_work(int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
char d_dummy_zero_first
Definition baz_burster.h:152
burst_time d_stream_time
Definition baz_burster.h:154
friend BAZ_API baz_burster_sptr baz_make_burster(const baz_burster_config &config)
Return a shared_ptr to a new instance of baz_burster.
void forecast(int noutput_items, gr_vector_int &ninput_items_required)
Definition baz_burster_config.h:32