Updated FSF address in all files. Fixes ticket:51
[debian/gnuradio] / ezdop / src / host / tests / dopper.cc
1 /*
2  * Copyright 2006 Free Software Foundation, Inc.
3  * 
4  * This file is part of GNU Radio
5  * 
6  * GNU Radio is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  * 
11  * GNU Radio is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with GNU Radio; see the file COPYING.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #include <cstdio>
23 #include <ezdop.h>
24
25 int chunks = 3600;
26 const static int samples = 250;
27 int rate = 250;
28
29 static complex<float> buffer[samples];
30
31 int main(int argc, char *argv)
32 {
33     ezdop *dop = new ezdop();
34
35     printf("Initializing EZDOP...");
36     if (dop->init())
37         printf("done.\n");
38     else
39         printf("failed.\n");
40     printf("EZDOP reports %s.\n", dop->is_online() ? "online" : "offline");
41     
42     printf("Setting EZDOP rate...");
43     if (dop->set_rate(rate))
44         printf("done.\n");
45     else
46         printf("failed.\n");
47
48     printf("Telling EZDOP to rotate...");
49     if (dop->rotate())
50         printf("done.\n");
51     else
52         printf("failed.\n");
53
54     printf("Telling EZDOP to stream...");
55     if (dop->stream())
56         printf("done.\n");
57     else
58         printf("failed.\n");
59
60     float volume;
61
62     for (int i = 0; i < chunks; i++) {
63         printf("Asking EZDOP for %i samples...", samples);
64         int rd = dop->read_iq(buffer, samples, volume);
65         printf("got %i --- ", rd);
66         if (rd != samples)
67             printf("*****\n");
68         
69         complex<float> average = complex<float>(0.0, 0.0);
70         for (int j = 0; j < rd; j++) {
71             average += buffer[j];
72         }
73
74         float I = average.real()/rd;
75         float Q = average.imag()/rd;
76         float M = std::sqrt(I*I+Q*Q);
77         float dbfs = 20*std::log(M/1.4142135);
78                 
79         printf("I=%f Q=%f M=%f dbfs=%f\n", I, Q, M, dbfs);      
80     }
81
82     printf("Telling EZDOP to stop streaming...");
83     if (dop->stop_streaming())
84         printf("done.\n");
85     else
86         printf("failed.\n");
87
88     printf("Telling EZDOP to stop stop rotating...");
89     if (dop->stop_rotating())
90         printf("done.\n");
91     else
92         printf("failed.\n");
93
94     printf("Releasing EZDOP...");
95     if (dop->finish())
96         printf("done.\n");
97     else
98         printf("failed.\n");
99
100     delete dop;
101 }