|
1 | | -#include <stdio.h> |
2 | | -#include <stdlib.h> |
3 | | -#include <unistd.h> |
4 | 1 | #include <cstring> |
5 | 2 | #include <errno.h> |
6 | | -#include <stdarg.h> |
7 | | -#include <stdint.h> |
| 3 | +#include <fcntl.h> |
8 | 4 | #include <math.h> |
9 | | -#include <time.h> |
10 | 5 | #include <signal.h> |
11 | | -#include <sys/types.h> |
12 | | -#include <sys/stat.h> |
13 | | -#include <fcntl.h> |
| 6 | +#include <stdarg.h> |
| 7 | +#include <stdint.h> |
| 8 | +#include <stdio.h> |
| 9 | +#include <stdlib.h> |
14 | 10 | #include <sys/mman.h> |
15 | | - |
| 11 | +#include <sys/stat.h> |
| 12 | +#include <sys/types.h> |
| 13 | +#include <time.h> |
| 14 | +#include <unistd.h> |
16 | 15 |
|
17 | 16 | #include <librpitx/librpitx.h> |
18 | 17 |
|
19 | | - |
20 | 18 | int FileFreqTiming; |
21 | 19 |
|
22 | 20 | ngfmdmasync *fmmod; |
23 | | -static double GlobalTuningFrequency=00000.0; |
24 | | -int FifoSize=10000; //10ms |
25 | | -double frequencyshift=20000; |
26 | | -bool running=true; |
| 21 | +static double GlobalTuningFrequency = 00000.0; |
| 22 | +int FifoSize = 10000; // 10ms |
| 23 | +double frequencyshift = 20000; |
| 24 | +bool running = true; |
27 | 25 |
|
28 | | -void playtone(double Frequency,uint32_t Timing)//Timing in 0.1us |
| 26 | +void playtone(double Frequency, uint32_t Timing) // Timing in 0.1us |
29 | 27 | { |
30 | | - uint32_t SumTiming=0; |
31 | | - SumTiming+=Timing%100; |
32 | | - if(SumTiming>=100) |
33 | | - { |
34 | | - Timing+=100; |
35 | | - SumTiming=SumTiming-100; |
36 | | - } |
37 | | - int NbSamples=(Timing/100); |
38 | | - |
39 | | - while(NbSamples>0) |
40 | | - { |
41 | | - usleep(10); |
42 | | - int Available=fmmod->GetBufferAvailable(); |
43 | | - if(Available>FifoSize/2) |
44 | | - { |
45 | | - int Index=fmmod->GetUserMemIndex(); |
46 | | - if(Available>NbSamples) Available=NbSamples; |
47 | | - for(int j=0;j<Available;j++) |
48 | | - { |
49 | | - fmmod->SetFrequencySample(Index+j,Frequency); |
50 | | - NbSamples--; |
51 | | - |
52 | | - } |
53 | | - } |
54 | | - } |
| 28 | + uint32_t SumTiming = 0; |
| 29 | + SumTiming += Timing % 100; |
| 30 | + if (SumTiming >= 100) { |
| 31 | + Timing += 100; |
| 32 | + SumTiming = SumTiming - 100; |
| 33 | + } |
| 34 | + int NbSamples = (Timing / 100); |
| 35 | + |
| 36 | + while (NbSamples > 0) { |
| 37 | + usleep(10); |
| 38 | + int Available = fmmod->GetBufferAvailable(); |
| 39 | + if (Available > FifoSize / 2) { |
| 40 | + int Index = fmmod->GetUserMemIndex(); |
| 41 | + if (Available > NbSamples) |
| 42 | + Available = NbSamples; |
| 43 | + for (int j = 0; j < Available; j++) { |
| 44 | + fmmod->SetFrequencySample(Index + j, Frequency); |
| 45 | + NbSamples--; |
| 46 | + } |
| 47 | + } |
| 48 | + } |
55 | 49 | } |
56 | 50 |
|
57 | | - |
58 | | - |
59 | | - |
60 | | - |
61 | | -static void SendTones() |
62 | | -{ |
63 | | -double basefreq = 1100; |
64 | | -double freq2 = 1100 + frequencyshift; |
65 | | -while(running) |
66 | | -{ |
67 | | - playtone( 1100 , 10000000) ; |
68 | | - playtone( freq2 , 10000000) ; |
69 | | -} |
| 51 | +static void SendTones() { |
| 52 | + double basefreq = 1100; |
| 53 | + double freq2 = 1100 + frequencyshift; |
| 54 | + while (running) { |
| 55 | + playtone(1100, 10000000); |
| 56 | + playtone(freq2, 10000000); |
| 57 | + } |
70 | 58 | } |
71 | 59 |
|
72 | | -static void |
73 | | -terminate(int num) |
74 | | -{ |
75 | | - running=false; |
76 | | - fprintf(stderr,"Caught signal - Terminating %x\n",num); |
77 | | - |
| 60 | +static void terminate(int num) { |
| 61 | + running = false; |
| 62 | + fprintf(stderr, "Caught signal - Terminating %x\n", num); |
78 | 63 | } |
79 | 64 |
|
80 | | -int main(int argc, char **argv) |
81 | | -{ |
82 | | - float frequency=144.5e6; |
83 | | - if (argc > 1) |
84 | | - { |
85 | | - |
86 | | - |
87 | | - frequency=atof(argv[1]); |
88 | | - frequencyshift=atof(argv[2]); |
89 | | - |
90 | | - } |
91 | | - else |
92 | | - { |
93 | | - printf("usage : foxhunt frequency(Hz) frequency shift(Hz)\n"); |
94 | | - exit(0); |
95 | | - } |
96 | | - |
97 | | - for (int i = 0; i < 64; i++) { |
98 | | - struct sigaction sa; |
99 | | - |
100 | | - std::memset(&sa, 0, sizeof(sa)); |
101 | | - sa.sa_handler = terminate; |
102 | | - sigaction(i, &sa, NULL); |
103 | | - } |
104 | | - |
105 | | - fmmod=new ngfmdmasync(frequency,100000,14,FifoSize); |
106 | | - SendTones(); |
107 | | - delete fmmod; |
108 | | - return 0; |
| 65 | +int main(int argc, char **argv) { |
| 66 | + float frequency = 144.5e6; |
| 67 | + if (argc > 1) { |
| 68 | + frequency = atof(argv[1]); |
| 69 | + frequencyshift = atof(argv[2]); |
| 70 | + } else { |
| 71 | + printf("usage : foxhunt frequency(Hz) frequency shift(Hz)\n"); |
| 72 | + exit(0); |
| 73 | + } |
| 74 | + |
| 75 | + for (int i = 0; i < 64; i++) { |
| 76 | + struct sigaction sa; |
| 77 | + |
| 78 | + std::memset(&sa, 0, sizeof(sa)); |
| 79 | + sa.sa_handler = terminate; |
| 80 | + sigaction(i, &sa, NULL); |
| 81 | + } |
| 82 | + |
| 83 | + fmmod = new ngfmdmasync(frequency, 100000, 14, FifoSize); |
| 84 | + SendTones(); |
| 85 | + delete fmmod; |
| 86 | + return 0; |
109 | 87 | } |
110 | | - |
111 | | - |
112 | | - |
113 | | - |
0 commit comments