forked from TLeconte/vdlm2dec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
190 lines (166 loc) · 3.93 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
* Copyright (c) 2016 Thierry Leconte
*
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License version 2
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <string.h>
#include <getopt.h>
#include <math.h>
#include <sys/types.h>
#include "vdlm2.h"
int verbose = 1;
int jsonout = 0;
char *Rawaddr = NULL;
char *idstation = NULL ;
FILE *logfd;
#ifdef WITH_RTL
int gain = 1000;
int ppm = 0;
#endif
#ifdef WITH_AIR
int gain = 21;
#endif
int nbch;
thread_param_t tparam[MAXNBCHANNELS];
pthread_barrier_t Bar1, Bar2;
static void usage(void)
{
fprintf(stderr,
"vdlm2dec V2.0 Copyright (c) 2016-2018 Thierry Leconte \n\n");
fprintf(stderr, "Usage: vdlm2dec [-J] [-q] [-j addr:port ] [-l logfile] [-g gain]");
#ifdef WITH_RTL
fprintf(stderr, " [-p ppm] -r rtldevicenumber");
#endif
fprintf(stderr, " Frequencies(Mhz)\n");
#ifdef WITH_RTL
fprintf(stderr,
" -r rtldevicenumber :\tdecode from rtl dongle number rtldevicenumber.(MANDATORY parameter)\n");
fprintf(stderr,
" -g gain :\t\tset rtl preamp gain in tenth of db (ie -g 90 for +9db).By default use maximum gain\n");
fprintf(stderr, " -p ppm :\t\tppm frequency correction\n");
#endif
#ifdef WITH_AIR
fprintf(stderr,
" -g gain :\t\tset linearity gain (0 to 21).By default use maximum gain\n");
#endif
fprintf(stderr, " -J :\t\t\tjson output\n");
fprintf(stderr, " -q :\t\t\tquiet\n");
fprintf(stderr, " -j addr:port :\t\tsend to addr:port UDP packets in json\n");
fprintf(stderr, " -l logfile :\t\toutput log (stdout by default)\n");
exit(1);
}
static void sighandler(int signum)
{
stopVdlm2();
exit(1);
}
int main(int argc, char **argv)
{
int n,c;
int res=0;
struct sigaction sigact;
char sys_hostname[8];
gethostname(sys_hostname, sizeof(sys_hostname));
idstation = strndup(sys_hostname, 8);
nbch = 0;
logfd = stdout;
while ((c = getopt(argc, argv, "vqrp:g:l:Jj:i")) != EOF) {
switch (c) {
case 'v':
verbose = 2;
break;
case 'q':
verbose = 0;
break;
case 'l':
logfd = fopen(optarg, "a+");
if (logfd == NULL) {
fprintf(stderr, "unable top open %s\n", optarg);
exit(1);
}
break;
#ifdef WITH_RTL
case 'r':
res = initRtl(argv, optind, tparam);
break;
case 'p':
ppm = atoi(optarg);
break;
case 'g':
gain = atoi(optarg);
break;
#endif
#ifdef WITH_AIR
case 'g':
gain = atoi(optarg);
break;
#endif
case 'j':
Rawaddr = optarg;
initOutput(Rawaddr);
break;
case 'J':
jsonout = 1;
break;
case 'i':
idstation = strndup(optarg, 8);
break;
default:
usage();
return (1);
}
}
if(jsonout)
verbose=0;
if(jsonout || Rawaddr)
initJson();
#ifdef WITH_AIR
res=initAirspy(argv, optind, tparam);
#endif
if (res) {
fprintf(stderr, "Unable to init input\n");
exit(-1);
}
sigact.sa_handler = sighandler;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
sigaction(SIGINT, &sigact, NULL);
sigaction(SIGTERM, &sigact, NULL);
sigaction(SIGQUIT, &sigact, NULL);
pthread_barrier_init(&Bar1, NULL, nbch + 1);
pthread_barrier_init(&Bar2, NULL, nbch + 1);
for (n = 0; n < nbch; n++) {
pthread_t th;
pthread_create(&th, NULL, rcv_thread, &(tparam[n]));
}
#if DEBUG
initSndWrite();
#endif
#ifdef WITH_RTL
runRtlSample();
#endif
#ifdef WITH_AIR
runAirspySample();
#endif
stopVdlm2();
exit(1);
}