3 # Copyright 2004,2007,2008,2009 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.
23 Random notes on coding conventions, some explanations about why things
24 aren't done differently, etc, etc,
29 Until boost 1.35 or later is common in distributions, you'll need to
30 build boost from source yourself. See README.building-boost.
32 Also, when running make distcheck you'll need to provide the
33 DISTCHECK_CONFIGURE_FLAGS. E.g.,
35 $ make distcheck DISTCHECK_CONFIGURE_FLAGS=--with-boost=/opt/boost_1_36_0
40 GNU Radio is now a hybrid system. Some parts of the system are built
41 in C++ and some of it in Python. In general, prefer Python to C++.
42 Signal processing primitives are still built in C++ for performance.
47 In the cleanup process, I considered putting everything in the
48 gnuradio namespace and dropping the Gr|gr prefix. In fact, I think
49 it's probably the right idea, but when I tested it out, I ran into
50 problems with SWIG's handling of namespaces. Bottom line, SWIG
51 (1.3.21) got confused and generated bad code when I started playing
52 around with namespaces in a not particularly convoluted way. I saw
53 problems using the boost::shared_ptr template in combination with
54 classes defined in the gnuradio namespace. It wasn't pretty...
59 Death to CamelCaseNames! We've returned to a kinder, gentler era.
60 We're now using the "STL style" naming convention with a couple of
61 modifications since we're not using namespaces.
63 With the exception of macros and other constant values, all
64 identifiers shall be lower case with words_separated_like_this.
66 Macros and constant values (e.g., enumerated values,
67 static const int FOO = 23) shall be in UPPER_CASE.
72 All globally visible names (types, functions, variables, consts, etc)
73 shall begin with a "package prefix", followed by an '_'. The bulk of
74 the code in GNU Radio logically belongs to the "gr" package, hence
75 names look like gr_open_file (...).
77 Large coherent bodies of code may use other package prefixes, but
78 let's try to keep them to a well thought out list. See the list
83 These are the current package prefixes:
87 gri_ Implementation primitives. Sometimes we
88 have both a gr_<foo> and a gri_<foo>. In that case,
89 gr_<foo> would be derived from gr_block and gri_<foo>
90 would be the low level guts of the function.
92 atsc_ Code related to the Advanced Television
93 Standards Committee HDTV implementation
95 usrp_ Universal Software Radio Peripheral
97 qa_ Quality Assurance. Test code.
100 ** Class data members (instance variables)
102 All class data members shall begin with d_<foo>.
104 The big win is when you're staring at a block of code it's obvious
105 which of the things being assigned to persist outside of the block.
106 This also keeps you from having to be creative with parameter names
107 for methods and constructors. You just use the same name as the
108 instance variable, without the d_.
110 class gr_wonderfulness {
112 double d_wonderfulness_factor;
115 gr_wonderfulness (std::string name, double wonderfulness_factor)
116 : d_name (name), d_wonderfulness_factor (wonderfulness_factor)
124 ** Class static data members (class variables)
126 All class static data members shall begin with s_<foo>.
131 Each significant class shall be contained in it's own file. The
132 declaration of class gr_foo shall be in gr_foo.h, the definition in
139 Strongly consider using the boost smart pointer templates, scoped_ptr
140 and shared_ptr. scoped_ptr should be used for locals that contain
141 pointers to objects that we need to delete when we exit the current
142 scope. shared_ptr implements transparent reference counting and is a
143 major win. You never have to worry about calling delete. The right
146 See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
151 Build unit tests for everything non-trivial and run them after every
152 change. Check out Extreme Programming:
153 http://c2.com/cgi/wiki?ExtremeProgrammingRoadmap
155 Unit tests should also be written for all examples. This should kill
156 off the bit rot we've been plagued with.
160 For C++ we're using the cppunit framework. cppunit has its bad
161 smells, but it's mostly workable. http://cppunit.sf.net
163 Currently each directory <dirname> contains files qa_<dirname>.{h,cc}
164 that bring together all the qa_<foo> test suites in the directory.
165 We ought to be able to automate this without too much trouble.
167 The directory gnuradio-core/src/tests contains programs that run
168 the tests. test_all runs all of the registered C++ unit tests.
170 As far as I can tell, the cppunit TestFactoryRegistry maybe able to be
171 tricked into doing what we want. As is, I don't think it's enough by
172 itself, since there's nothing dragging the qa* files out of the
173 library and into the program. I haven't tested out this idea.
177 We use the standard unittest package for unit testing of Python code.
180 * Subversion line ending styles
182 All text files in the tree should have the subversion property
183 'svn:eol-style' set to 'native', with the following exceptions:
187 gr-howto-write-a-block/config/*.m4
188 gr-howto-write-a-block/configure.ac
190 The easiest way to ensure this is to add or edit the following lines in
191 your svn client configuration file (~/.subversion/config):
193 enable-auto-props=yes
196 *.c = svn:eol-style=native
197 *.cc = svn:eol-style=native
198 *.i = svn:eol-style=native
199 *.h = svn:eol-style=native
200 *.am = svn:eol-style=native
201 *.py = svn:eol-style=native
202 *.ac = svn:eol-style=LF
203 *.m4 = svn:eol-style=LF
207 ccache, a compiler cache, can really speed up your builds.
208 See http://ccache.samba.org/
210 Be sure to create links for gcc and g++
213 * Standard command line options
215 When writing programs that are executable from the command line,
216 please follow these guidelines for command line argument names (short
217 and long) and types of the arguments. We list them below using the
218 Python optparse syntax. In general, the default value should be coded
219 into the help string using the "... [default=%default]" syntax.
221 ** Mandatory options by gr_block
225 Any program using a USRP source (usrp.source_*) shall include:
227 add_option("", "--which-usrp", type="intx", default=0,
228 help="select which USRP to use [default=%default]")
230 add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0),
231 help="select USRP Rx side A or B [default=A]")
233 You are free to change the default if it makes sense in your application.
238 Any program using a USRP sink (usrp.sink_*) shall include:
240 add_option("", "--which-usrp", type="intx", default=0,
241 help="select which USRP to use [default=%default]")
243 add_option("-T", "--tx-subdev-spec", type="subdev", default=(0, 0),
244 help="select USRP Tx side A or B [default=A]")
246 You are free to change the default if it makes sense in your application.
251 Any program using an audio source shall include:
253 add_option("-I", "--audio-input", type="string", default="",
254 help="pcm input device name. E.g., hw:0,0 or /dev/dsp")
256 The default must be "". This allows an audio module-dependent default
257 to be specified in the user preferences file.
262 add_option("-O", "--audio-output", type="string", default="",
263 help="pcm output device name. E.g., hw:0,0 or /dev/dsp")
265 The default must be "". This allows an audio module-dependent default
266 to be specified in the user preferences file.
269 ** Standard options names by parameter
271 Whenever you want an integer, use the "intx" type. This allows the
272 user to input decimal, hex or octal numbers. E.g., 10, 012, 0xa.
274 Whenever you want a float, use the "eng_float" type. This allows the
275 user to input numbers with SI suffixes. E.g, 10000, 10k, 10M, 10m, 92.1M
277 If your program allows the user to specify values for any of the
278 following parameters, please use these options to specify them:
281 To specify a frequency (typically an RF center frequency) use:
283 add_option("-f", "--freq", type="eng_float", default=<your-default-here>,
284 help="set frequency to FREQ [default=%default]")
287 To specify a decimation factor use:
289 add_option("-d", "--decim", type="intx", default=<your-default-here>,
290 help="set decimation rate to DECIM [default=%default]")
293 To specify an interpolation factor use:
295 add_option("-i", "--interp", type="intx", default=<your-default-here>,
296 help="set interpolation rate to INTERP [default=%default]")
299 To specify a gain setting use:
301 add_option("-g", "--gain", type="eng_float", default=<your-default-here>,
302 help="set gain in dB [default=%default]")
305 If your application specifies both a tx and an rx gain, use:
307 add_option("", "--rx-gain", type="eng_float", default=<your-default-here>,
308 help="set receive gain in dB [default=%default]")
310 add_option("", "--tx-gain", type="eng_float", default=<your-default-here>,
311 help="set transmit gain in dB [default=%default]")
314 To specify the number of channels of something use:
316 add_option("-n", "--nchannels", type="intx", default=1,
317 help="specify number of channels [default=%default]")
320 To specify an output filename use:
322 add_option("-o", "--output-filename", type="string", default=<your-default-here>,
323 help="specify output-filename [default=%default]")
326 To specify a rate use:
328 add_option("-r", "--bit-rate", type="eng_float", default=<your-default-here>,
329 help="specify bit-rate [default=%default]")
332 add_option("-r", "--sample-rate", type="eng_float", default=<your-default-here>,
333 help="specify sample-rate [default=%default]")
336 If your application has a verbose option, use:
338 add_option('-v', '--verbose', action="store_true", default=False,
339 help="verbose output")
342 If your application allows the user to specify the "fast USB" options, use:
344 add_option("", "--fusb-block-size", type="intx", default=0,
345 help="specify fast usb block size [default=%default]")
347 add_option("", "--fusb-nblocks", type="intx", default=0,
348 help="specify number of fast usb blocks [default=%default]")