Fix typo
[rfmod.git] / rfmod.c
blob41dbf7969e32d6956471dc8ee6b30e013db6a61d
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <unistd.h>
5 #include <time.h>
6 #include <string.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <fcntl.h>
10 #include <poll.h>
11 #include <unistd.h>
12 #include <getopt.h>
13 #include <sched.h>
14 #include <syslog.h>
15 #include <signal.h>
16 #include <errno.h>
17 #include <pthread.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
21 #include <net/if.h>
23 #include "rfmod.h"
24 #include "logging.h"
25 #include "socket.h"
27 #include "daemon.h"
29 #include "api.h"
31 #define MY_NAME "rfmod"
33 static int DevNo = 0;
34 static int DevType = EAGLEII;
37 static void usage(char *argv[]);
38 static void ts_output(unsigned char *p, int total);
39 static int init_modulator(
40 int frequency,
41 int bandwidth,
42 int gain,
43 int constellation,
44 int codeRate,
45 int guardInterval,
46 int transmissionMode,
47 int cellid
51 static void usage(char *argv[])
53 fprintf(stderr, "Usage: %s [-v] [-d] [-T deviceType] [-D deviceIndex] [-o timeout] [-S stamp_packets] [-F fequencykHz] [-g gain] [-B bandwidth] [-M transmissionMode] [-C connstellation] [-R codeRate] [-G guardInterval] [-L cellid] [-p port] [-f interface] ip_addr[:port]\n", argv[0]);
54 exit(EXIT_FAILURE);
57 static void sigsegv_handler(int sig, siginfo_t *si, void *unused)
59 logwrite(LOG_ERR, "Got SIGSEGV at address 0x%08x", (long)si->si_addr);
60 exit(EXIT_FAILURE);
63 static void sigusr1_handler(int sig, siginfo_t *si, void *unused)
65 logwrite(LOG_ERR, "Increment log verbosity.");
66 logwrite_inc_level();
70 static void sigusr2_handler(int sig, siginfo_t *si, void *unused)
72 logwrite(LOG_ERR, "Decrement log verbosity.");
73 logwrite_dec_level();
76 int main(int argc, char *argv[])
78 int fd;
79 int opt;
80 int nodaemon = 0;
81 int timeout = 1000; /* 1 second */
82 int stamp = 1701900; /* 15 minutes for 1891 packets per second */
84 char *remoteaddr = "";
85 int remoteport = 1234;
86 struct sched_param schedParam;
87 struct pollfd fds;
88 char *colon;
90 int port = 1234;
91 char *fromIf = NULL;
92 int fromIfIndex = 0;
94 int frequency = 730000;
95 int bandwidth = 8000;
96 int gain = -47;
98 int constellation = 2;
99 int codeRate = 1;
100 int guardInterval = 3;
101 int transmissionMode = 1;
102 int cellid = 0;
104 int seq;
105 char *inspec = "";
107 int buffer = 2*1024*1024;
109 openlog(MY_NAME, LOG_PID, LOG_LOCAL5);
110 logwrite(LOG_INFO, "starting");
112 while ((opt = getopt(argc, argv, "b:dvT:D:S:o:f:p:F:B:C:R:D:G:M:L:g:")) != -1) {
113 switch (opt) {
114 /* GENERAL OPTIONS */
115 case 'S':
116 stamp = atoi(optarg);
117 break;
118 case 'o':
119 timeout = atoi(optarg);
120 break;
121 case 'v':
122 logwrite_inc_level();
123 break;
125 case 'd':
126 nodaemon = 1;
127 break;
129 case 'p':
130 port = strtol(optarg, NULL, 0);
131 break;
133 case 'T':
134 DevType = strtol(optarg, NULL, 0);
135 break;
137 case 'D':
138 DevNo = strtol(optarg, NULL, 0);
139 break;
141 /* OUTPUT CONTROL */
142 case 'g':
143 gain = strtol(optarg, (char **)NULL, 0);
144 break;
146 case 'F':
147 frequency = strtol(optarg, (char **)NULL, 0);
148 break;
149 case 'B':
150 bandwidth = strtol(optarg, (char **)NULL, 0);
151 break;
152 case 'C':
153 constellation = strtol(optarg, (char **)NULL, 0);
154 break;
155 case 'R':
156 codeRate = strtol(optarg, (char **)NULL, 0);
157 break;
158 case 'G':
159 guardInterval = strtol(optarg, (char **)NULL, 0);
160 break;
161 case 'M':
162 transmissionMode = strtol(optarg, (char **)NULL, 0);
163 break;
164 case 'L':
165 cellid = strtol(optarg, (char **)NULL, 0);
166 break;
168 /* INPUT CONTROL */
169 case 'b':
170 buffer = strtol(optarg, (char **)NULL, 0);
171 break;
172 case 'f':
173 fromIf = strdup(optarg);
174 fromIfIndex = if_nametoindex(fromIf);
175 if (!fromIfIndex) {
176 logwrite(LOG_ERR, "Interface '%s' does not exist", fromIf);
178 break;
180 default: /* '?' */
181 fprintf(stderr, "Bad parameter %c\n", opt);
182 usage(argv);
186 if (argc-optind != 1) {
187 fprintf(stderr, "Bad parameters %d\n", argc-optind);
188 for (opt = optind; opt < argc; opt++) {
189 fprintf(stderr, "arg %d: %s\n", opt, argv[opt]);
191 usage(argv);
194 optarg = argv[optind];
195 seq = -1;
196 inspec = optarg;
197 colon = index(optarg, ':');
199 if (colon) {
200 remoteaddr = strndup(optarg, colon-optarg);
201 remoteport = strtol(colon+1, NULL, 0);
202 } else {
203 remoteaddr = optarg;
204 remoteport = port;
207 schedParam.sched_priority = sched_get_priority_max(SCHED_RR)/2-1;
208 if (pthread_setschedparam(pthread_self(), SCHED_RR, &schedParam)) {
209 logwrite(LOG_INFO, "setschedparam failed - running at normal priority");
212 /* init inputs */
213 logwrite(LOG_INFO, "inspec=[%s], remoteaddr=[%s], remoteport=%d", inspec, remoteaddr, remoteport);
214 fd = socket_open(remoteaddr, remoteport, fromIf, fromIfIndex, buffer, timeout);
215 if (fd < 0) {
216 logwrite(LOG_ERR, "Open socket %s: %d", inspec, errno);
217 return 1;
219 fds.fd = fd;
220 fds.events = POLLIN|POLLERR|POLLHUP;
223 /* init output */
224 init_modulator(frequency, bandwidth, gain, constellation, codeRate, guardInterval, transmissionMode, cellid);
226 /* now become a daemon */
227 if (!nodaemon) {
228 daemonize(NULL, NULL);
230 logwrite(LOG_ERR, "RESTART");
233 struct sigaction sa;
234 sa.sa_flags = SA_SIGINFO | SA_RESTART;
235 sigemptyset(&sa.sa_mask);
236 sa.sa_sigaction = sigsegv_handler;
237 if (sigaction(SIGSEGV, &sa, NULL) == -1) {
238 logwrite(LOG_ERR, "Failed to set SIGSEGV handler");
240 sa.sa_flags = SA_SIGINFO | SA_RESTART;
241 sigemptyset(&sa.sa_mask);
242 sa.sa_sigaction = sigusr1_handler;
243 if (sigaction(SIGUSR1, &sa, NULL) == -1) {
244 logwrite(LOG_ERR, "Failed to set SIGUSR1 handler");
246 sa.sa_flags = SA_SIGINFO | SA_RESTART;
247 sigemptyset(&sa.sa_mask);
248 sa.sa_sigaction = sigusr2_handler;
249 if (sigaction(SIGUSR2, &sa, NULL) == -1) {
250 logwrite(LOG_ERR, "Failed to set SIGUSR2 handler");
254 int n = 0;
255 for (;;) {
256 int len;
257 int ret;
259 if (n++ > stamp) {
260 logwrite(LOG_DEBUG, "tick");
261 n = 0;
263 ret = poll(&fds, 1, timeout);
264 if (ret > 0) {
265 if (fds.revents & POLLIN) {
266 unsigned char p[MAX_PACKET_SIZE];
268 len = read(fds.fd, p, sizeof(p));
269 if (len < 0) {
270 logwrite(LOG_ERR, "Receiving from socket %s: %d", inspec, errno);
271 break;
274 if (len > RTP_HEADROOM && p[RTP_VERSION_OFF] == 0x80 && p[RTP_PT_OFF] == RTP_PT_MP2T) {
275 static unsigned long good = 0;
276 uint16_t rseq = (p[RTP_SEQ_OFF] << 8)+p[RTP_SEQ_OFF+1];
277 if (seq >= 0 && seq != rseq) {
278 logwrite(LOG_INFO, "%s %lu RTP seq %d err: expected %u != received %u", inspec, good, rseq-seq, seq, rseq);
279 good = 0;
280 } else {
281 good++;
283 seq = (rseq+1) & 0xFFFF;
284 /* skip RTP header */
285 len -= RTP_HEADROOM;
286 memmove(p, p+RTP_HEADROOM, len);
288 /* send */
289 ts_output(p, len);
291 if (fds.revents & POLLHUP) {
292 logwrite(LOG_ERR, "remote %s died", inspec);
294 if (fds.revents & POLLERR) {
295 logwrite(LOG_ERR, "remote %s error", inspec);
297 } else if (ret == 0) {
298 logwrite(LOG_INFO, "Timeout");
299 } else if (errno != EINTR) {
300 logwrite(LOG_ERR, "poll failed: %d", errno);
303 logwrite(LOG_NOTICE, "terminated");
304 closelog();
305 return 0;
308 static Byte UT100_IQtable[] = {
309 0x20, 0x49, 0x51, 0x20, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x33, 0x00, 0x00, 0x00, 0x00, 0x5b,
310 0x50, 0xc3, 0x00, 0x00, 0x2d, 0x00, 0xf2, 0xfb, 0x60, 0xea, 0x00, 0x00, 0x11, 0x00, 0x68, 0xfd,
311 0x70, 0x11, 0x01, 0x00, 0x03, 0x00, 0xdd, 0xfe, 0x80, 0x38, 0x01, 0x00, 0x00, 0x00, 0x52, 0x00,
312 0x90, 0x5f, 0x01, 0x00, 0x06, 0x00, 0xa3, 0x01, 0xa0, 0x86, 0x01, 0x00, 0x17, 0x00, 0x06, 0x03,
313 0xb0, 0xad, 0x01, 0x00, 0x1a, 0x00, 0x21, 0x03, 0xc0, 0xd4, 0x01, 0x00, 0x16, 0x00, 0xe1, 0x02,
314 0xd0, 0xfb, 0x01, 0x00, 0x11, 0x00, 0x8f, 0x02, 0xe0, 0x22, 0x02, 0x00, 0x0c, 0x00, 0x34, 0x02,
315 0xf0, 0x49, 0x02, 0x00, 0x09, 0x00, 0xd9, 0x01, 0x00, 0x71, 0x02, 0x00, 0x06, 0x00, 0x7e, 0x01,
316 0x10, 0x98, 0x02, 0x00, 0x04, 0x00, 0x2c, 0x01, 0x20, 0xbf, 0x02, 0x00, 0x02, 0x00, 0xda, 0x00,
317 0x30, 0xe6, 0x02, 0x00, 0x01, 0x00, 0x92, 0x00, 0x40, 0x0d, 0x03, 0x00, 0x01, 0x00, 0x52, 0x00,
318 0x50, 0x34, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x60, 0x5b, 0x03, 0x00, 0x01, 0x00, 0xc9, 0xff,
319 0x70, 0x82, 0x03, 0x00, 0x01, 0x00, 0x93, 0xff, 0x80, 0xa9, 0x03, 0x00, 0x02, 0x00, 0x65, 0xff,
320 0x90, 0xd0, 0x03, 0x00, 0x02, 0x00, 0x38, 0xff, 0xa0, 0xf7, 0x03, 0x00, 0x03, 0x00, 0x13, 0xff,
321 0xb0, 0x1e, 0x04, 0x00, 0x03, 0x00, 0xef, 0xfe, 0xc0, 0x45, 0x04, 0x00, 0x04, 0x00, 0xd4, 0xfe,
322 0xd0, 0x6c, 0x04, 0x00, 0x04, 0x00, 0xc1, 0xfe, 0xe0, 0x93, 0x04, 0x00, 0x05, 0x00, 0xaf, 0xfe,
323 0xf0, 0xba, 0x04, 0x00, 0x05, 0x00, 0xaf, 0xfe, 0x00, 0xe2, 0x04, 0x00, 0x04, 0x00, 0xa6, 0xfe,
324 0x10, 0x09, 0x05, 0x00, 0x04, 0x00, 0xaf, 0xfe, 0x20, 0x30, 0x05, 0x00, 0x04, 0x00, 0xb8, 0xfe,
325 0x30, 0x57, 0x05, 0x00, 0x04, 0x00, 0xc1, 0xfe, 0x40, 0x7e, 0x05, 0x00, 0x04, 0x00, 0xd4, 0xfe,
326 0x50, 0xa5, 0x05, 0x00, 0x03, 0x00, 0xe6, 0xfe, 0x60, 0xcc, 0x05, 0x00, 0x02, 0x00, 0xef, 0xfe,
327 0x70, 0xf3, 0x05, 0x00, 0x02, 0x00, 0x13, 0xff, 0x80, 0x1a, 0x06, 0x00, 0x01, 0x00, 0x1c, 0xff,
328 0x90, 0x41, 0x06, 0x00, 0x01, 0x00, 0x41, 0xff, 0xa0, 0x68, 0x06, 0x00, 0x01, 0x00, 0x53, 0xff,
329 0xb0, 0x8f, 0x06, 0x00, 0x00, 0x00, 0x6e, 0xff, 0xc0, 0xb6, 0x06, 0x00, 0x00, 0x00, 0x8a, 0xff,
330 0xd0, 0xdd, 0x06, 0x00, 0x00, 0x00, 0xa5, 0xff, 0xe0, 0x04, 0x07, 0x00, 0x00, 0x00, 0xb7, 0xff,
331 0xf0, 0x2b, 0x07, 0x00, 0x00, 0x00, 0xc9, 0xff, 0x00, 0x53, 0x07, 0x00, 0x00, 0x00, 0xdc, 0xff,
332 0x10, 0x7a, 0x07, 0x00, 0x00, 0x00, 0xdc, 0xff, 0x20, 0xa1, 0x07, 0x00, 0xff, 0xff, 0xee, 0xff,
333 0x30, 0xc8, 0x07, 0x00, 0x00, 0x00, 0xf7, 0xff, 0x40, 0xef, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
334 0x50, 0x16, 0x08, 0x00, 0xff, 0xff, 0x00, 0x00, 0x60, 0x3d, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
335 0x70, 0x64, 0x08, 0x00, 0xff, 0xff, 0xf7, 0xff, 0x80, 0x8b, 0x08, 0x00, 0xff, 0xff, 0x12, 0x00,
336 0x90, 0xb2, 0x08, 0x00, 0xff, 0xff, 0xf7, 0xff, 0xa0, 0xd9, 0x08, 0x00, 0x00, 0x00, 0x09, 0x00,
337 0xb0, 0x00, 0x09, 0x00, 0x00, 0x00, 0x12, 0x00, 0xc0, 0x27, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
338 0xd0, 0x4e, 0x09, 0x00, 0x00, 0x00, 0x12, 0x00, 0xe0, 0x75, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
339 0xf0, 0x9c, 0x09, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xc4, 0x09, 0x00, 0x00, 0x00, 0xf7, 0xff,
340 0x10, 0xeb, 0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x20, 0x12, 0x0a, 0x00, 0x00, 0x00, 0xf7, 0xff,
341 0x30, 0x39, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x60, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
342 0x50, 0x87, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xae, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
343 0x70, 0xd5, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xfc, 0x0a, 0x00, 0x00, 0x00, 0x09, 0x00,
344 0x90, 0x23, 0x0b, 0x00, 0x00, 0x00, 0xf7, 0xff, 0xa0, 0x4a, 0x0b, 0x00, 0x00, 0x00, 0x09, 0x00,
345 0xb0, 0x71, 0x0b, 0x00, 0x00, 0x00, 0xee, 0xff, 0xc0, 0x98, 0x0b, 0x00, 0x00, 0x00, 0xe5, 0xff,
346 0xd0, 0xbf, 0x0b, 0x00, 0x02, 0x00, 0xee, 0xff, 0xe0, 0xe6, 0x0b, 0x00, 0x00, 0x00, 0xee, 0xff,
347 0xf0, 0x0d, 0x0c, 0x00, 0x02, 0x00, 0xee, 0xff, 0x00, 0x35, 0x0c, 0x00, 0x00, 0x00, 0xee, 0xff,
348 0x10, 0x5c, 0x0c, 0x00, 0x00, 0x00, 0xee, 0xff, 0x20, 0x83, 0x0c, 0x00, 0x01, 0x00, 0xee, 0xff,
349 0x30, 0xaa, 0x0c, 0x00, 0x00, 0x00, 0xe5, 0xff, 0x40, 0xd1, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
350 0x50, 0xf8, 0x0c, 0x00, 0x02, 0x00, 0xe5, 0xff, 0x60, 0x1f, 0x0d, 0x00, 0x00, 0x00, 0xe5, 0xff,
351 0x70, 0x46, 0x0d, 0x00, 0x01, 0x00, 0xe5, 0xff, 0x80, 0x6d, 0x0d, 0x00, 0x00, 0x00, 0xdc, 0xff,
352 0x90, 0x94, 0x0d, 0x00, 0x00, 0x00, 0xe5, 0xff, 0xa0, 0xbb, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
353 0xb0, 0xe2, 0x0d, 0x00, 0x01, 0x00, 0xee, 0xff, 0xc0, 0x09, 0x0e, 0x00, 0x01, 0x00, 0xe5, 0xff,
354 0xd0, 0x30, 0x0e, 0x00, 0x00, 0x00, 0xdc, 0xff, 0xe0, 0x57, 0x0e, 0x00, 0x00, 0x00, 0xe5, 0xff,
355 0xf0, 0x7e, 0x0e, 0x00, 0x00, 0x00, 0xe5, 0xff,
359 static Byte UT200_IQtable[] = {
360 0x49, 0x44, 0x3a, 0x39, 0x39, 0x39, 0x00, 0x01, 0x56, 0x3a, 0x02, 0x01, 0x00, 0x00, 0x00, 0x5c,
361 0x50, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x60, 0xea, 0x00, 0x00, 0x00, 0x00, 0xf9, 0xff,
362 0x70, 0x11, 0x01, 0x00, 0xff, 0xff, 0x00, 0x00, 0x80, 0x38, 0x01, 0x00, 0xff, 0xff, 0x05, 0x00,
363 0x90, 0x5f, 0x01, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xa0, 0x86, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00,
364 0xb0, 0xad, 0x01, 0x00, 0xff, 0xff, 0x09, 0x00, 0xc0, 0xd4, 0x01, 0x00, 0xff, 0xff, 0x09, 0x00,
365 0xd0, 0xfb, 0x01, 0x00, 0xff, 0xff, 0x05, 0x00, 0xe0, 0x22, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00,
366 0xf0, 0x49, 0x02, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x71, 0x02, 0x00, 0xff, 0xff, 0x07, 0x00,
367 0x10, 0x98, 0x02, 0x00, 0xff, 0xff, 0x0e, 0x00, 0x20, 0xbf, 0x02, 0x00, 0x00, 0x00, 0x0e, 0x00,
368 0x30, 0xe6, 0x02, 0x00, 0xff, 0xff, 0x09, 0x00, 0x40, 0x0d, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
369 0x50, 0x34, 0x03, 0x00, 0xff, 0xff, 0xce, 0xff, 0x60, 0x5b, 0x03, 0x00, 0x00, 0x00, 0xc5, 0xff,
370 0x70, 0x82, 0x03, 0x00, 0x00, 0x00, 0xce, 0xff, 0x80, 0xa9, 0x03, 0x00, 0xff, 0xff, 0xcc, 0xff,
371 0x90, 0xd0, 0x03, 0x00, 0xff, 0xff, 0xae, 0xff, 0xa0, 0xf7, 0x03, 0x00, 0xff, 0xff, 0xc9, 0xff,
372 0xb0, 0x1e, 0x04, 0x00, 0xff, 0xff, 0xbe, 0xff, 0xc0, 0x45, 0x04, 0x00, 0x00, 0x00, 0xb5, 0xff,
373 0xd0, 0x6c, 0x04, 0x00, 0x00, 0x00, 0xc9, 0xff, 0xe0, 0x93, 0x04, 0x00, 0xff, 0xff, 0xbe, 0xff,
374 0xf0, 0xba, 0x04, 0x00, 0xff, 0xff, 0xf2, 0xff, 0x00, 0xe2, 0x04, 0x00, 0xff, 0xff, 0xf7, 0xff,
375 0x10, 0x09, 0x05, 0x00, 0xff, 0xff, 0xf5, 0xff, 0x20, 0x30, 0x05, 0x00, 0xff, 0xff, 0xf2, 0xff,
376 0x30, 0x57, 0x05, 0x00, 0xfe, 0xff, 0xf7, 0xff, 0x40, 0x7e, 0x05, 0x00, 0xfe, 0xff, 0xec, 0xff,
377 0x50, 0xa5, 0x05, 0x00, 0xff, 0xff, 0xf7, 0xff, 0x60, 0xcc, 0x05, 0x00, 0xff, 0xff, 0xec, 0xff,
378 0x70, 0xf3, 0x05, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x80, 0x1a, 0x06, 0x00, 0xff, 0xff, 0xf0, 0xff,
379 0x90, 0x41, 0x06, 0x00, 0xff, 0xff, 0x2e, 0x00, 0xa0, 0x68, 0x06, 0x00, 0xff, 0xff, 0x3d, 0x00,
380 0xb0, 0x8f, 0x06, 0x00, 0xff, 0xff, 0x37, 0x00, 0xc0, 0xb6, 0x06, 0x00, 0xff, 0xff, 0x42, 0x00,
381 0xd0, 0xdd, 0x06, 0x00, 0xff, 0xff, 0x2e, 0x00, 0xe0, 0x04, 0x07, 0x00, 0xff, 0xff, 0x4b, 0x00,
382 0xf0, 0x2b, 0x07, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x53, 0x07, 0x00, 0xff, 0xff, 0x49, 0x00,
383 0x10, 0x7a, 0x07, 0x00, 0xff, 0xff, 0x5b, 0x00, 0x20, 0xa1, 0x07, 0x00, 0xfe, 0xff, 0x4b, 0x00,
384 0x30, 0xc8, 0x07, 0x00, 0xff, 0xff, 0x4d, 0x00, 0x40, 0xef, 0x07, 0x00, 0x01, 0x00, 0x47, 0x00,
385 0x50, 0x16, 0x08, 0x00, 0xff, 0xff, 0x64, 0x00, 0x60, 0x3d, 0x08, 0x00, 0x00, 0x00, 0x56, 0x00,
386 0x70, 0x64, 0x08, 0x00, 0xff, 0xff, 0x66, 0x00, 0x80, 0x8b, 0x08, 0x00, 0xff, 0xff, 0x52, 0x00,
387 0x90, 0xb2, 0x08, 0x00, 0xfe, 0xff, 0x44, 0x00, 0xa0, 0xd9, 0x08, 0x00, 0xff, 0xff, 0x59, 0x00,
388 0xb0, 0x00, 0x09, 0x00, 0xff, 0xff, 0x56, 0x00, 0xc0, 0x27, 0x09, 0x00, 0xff, 0xff, 0x66, 0x00,
389 0xd0, 0x4e, 0x09, 0x00, 0xff, 0xff, 0x62, 0x00, 0xe0, 0x75, 0x09, 0x00, 0xff, 0xff, 0x94, 0x00,
390 0xf0, 0x9c, 0x09, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00, 0xc4, 0x09, 0x00, 0xfe, 0xff, 0x82, 0x00,
391 0x10, 0xeb, 0x09, 0x00, 0xff, 0xff, 0x52, 0x00, 0x20, 0x12, 0x0a, 0x00, 0xff, 0xff, 0x98, 0x00,
392 0x30, 0x39, 0x0a, 0x00, 0x00, 0x00, 0x59, 0x00, 0x40, 0x60, 0x0a, 0x00, 0x00, 0x00, 0x79, 0x00,
393 0x50, 0x87, 0x0a, 0x00, 0x00, 0x00, 0x9d, 0x00, 0x60, 0xae, 0x0a, 0x00, 0xff, 0xff, 0x9d, 0x00,
394 0x70, 0xd5, 0x0a, 0x00, 0xff, 0xff, 0x8b, 0x00, 0x80, 0xfc, 0x0a, 0x00, 0xff, 0xff, 0xa2, 0x00,
395 0x90, 0x23, 0x0b, 0x00, 0xff, 0xff, 0x64, 0x00, 0xa0, 0x4a, 0x0b, 0x00, 0xff, 0xff, 0x9d, 0x00,
396 0xb0, 0x71, 0x0b, 0x00, 0xff, 0xff, 0x89, 0x00, 0xc0, 0x98, 0x0b, 0x00, 0xff, 0xff, 0x89, 0x00,
397 0xd0, 0xbf, 0x0b, 0x00, 0x00, 0x00, 0x89, 0x00, 0xe0, 0xe6, 0x0b, 0x00, 0xff, 0xff, 0x8b, 0x00,
398 0xf0, 0x0d, 0x0c, 0x00, 0xff, 0xff, 0x9f, 0x00, 0x00, 0x35, 0x0c, 0x00, 0xfe, 0xff, 0x8f, 0x00,
399 0x10, 0x5c, 0x0c, 0x00, 0x01, 0x00, 0x98, 0x00, 0x20, 0x83, 0x0c, 0x00, 0x00, 0x00, 0x84, 0x00,
400 0x30, 0xaa, 0x0c, 0x00, 0xff, 0xff, 0xb1, 0x00, 0x40, 0xd1, 0x0c, 0x00, 0x00, 0x00, 0xb4, 0x00,
401 0x50, 0xf8, 0x0c, 0x00, 0x00, 0x00, 0xad, 0x00, 0x60, 0x1f, 0x0d, 0x00, 0xff, 0xff, 0x9f, 0x00,
402 0x70, 0x46, 0x0d, 0x00, 0x00, 0x00, 0xc1, 0x00, 0x80, 0x6d, 0x0d, 0x00, 0xff, 0xff, 0xb8, 0x00,
403 0x90, 0x94, 0x0d, 0x00, 0xff, 0xff, 0xcd, 0x00, 0xa0, 0xbb, 0x0d, 0x00, 0xff, 0xff, 0xcb, 0x00,
404 0xb0, 0xe2, 0x0d, 0x00, 0xff, 0xff, 0xc6, 0x00, 0xc0, 0x09, 0x0e, 0x00, 0xff, 0xff, 0xda, 0x00,
405 0xd0, 0x30, 0x0e, 0x00, 0xff, 0xff, 0xc8, 0x00, 0xe0, 0x57, 0x0e, 0x00, 0xff, 0xff, 0xd4, 0x00,
406 0xf0, 0x7e, 0x0e, 0x00, 0xfe, 0xff, 0xd1, 0x00, 0xc0, 0xc6, 0x2d, 0x00, 0xfe, 0xff, 0xd1, 0x00,
409 static int init_modulator(
410 int frequency,
411 int bandwidth,
412 int gain,
413 int constellation,
414 int codeRate,
415 int guardInterval,
416 int transmissionMode,
417 int cellid
420 TPS tps;
421 int outgainvalue;
422 Dword dwError = ERR_NO_ERROR;
423 MODULATION_PARAM ChannelModulation_Setting;
425 /* Open handle Power On and Check device information */
426 if((dwError = g_ITEAPI_TxDeviceInit(DevType, DevNo)) != ERR_NO_ERROR) {
427 printf("g_ITEAPI_TxDeviceInit fail\n");
428 return 0;
431 if (DevType == EAGLEII) {
432 dwError = g_ITEAPI_TxSetIQTable(UT200_IQtable, sizeof(UT200_IQtable), DevNo);
433 if (dwError) {
434 fprintf(stderr, "Set IQ Calibration Table fail: 0x%08lx\n", dwError);
436 } else {
437 dwError = g_ITEAPI_TxSetIQTable(UT100_IQtable, sizeof(UT100_IQtable), DevNo);
438 if (dwError) {
439 fprintf(stderr, "Set IQ Calibration Table fail: 0x%08lx\n", dwError);
443 if ((dwError = g_ITEAPI_TxSetChannel(frequency, bandwidth, DevNo)) != ERR_NO_ERROR) {
444 fprintf(stderr, "g_ITEAPI_TxSetChannel error\n");
445 return 0;
448 if(g_ITEAPI_TxAdjustOutputGain(gain, &outgainvalue, DevNo) != ERR_NO_ERROR) {
449 fprintf(stderr, "g_ITEAPI_TxAdjustOutputGain error\n");
453 ChannelModulation_Setting.constellation = constellation;
454 ChannelModulation_Setting.highCodeRate = codeRate;
455 ChannelModulation_Setting.interval = guardInterval;
456 ChannelModulation_Setting.transmissionMode = transmissionMode;
458 if ((dwError = g_ITEAPI_TxSetChannelModulation(ChannelModulation_Setting, DevNo)) != ERR_NO_ERROR)
459 fprintf(stderr, "g_ITEAPI_TxSetChannelModulation error!!, %lu ******\n", dwError);
461 dwError = g_ITEAPI_TxGetTPS(&tps, DevNo);
462 if (dwError) {
463 fprintf(stderr, "\n****** g_ITEAPI_TxGetTPS error!!, %lu ******\n", dwError);
465 tps.cellid = cellid;
467 dwError = g_ITEAPI_TxSetTPS(tps, DevNo);
468 if (dwError) {
469 fprintf(stderr, "\n****** g_ITEAPI_TxSetTPS error!!, %lu ******\n", dwError);
472 g_ITEAPI_TxSetModeEnable(True, DevNo);
473 g_ITEAPI_StartTransfer(DevNo);
475 return 0;
478 static void ts_output(unsigned char *p, int total)
480 int len;
481 len = g_ITEAPI_TxSendTSData(p, total, DevNo);
482 again:
483 if (len < 0) {
484 if (errno == EWOULDBLOCK || errno == EAGAIN) {
485 logwrite(LOG_ERR, "Blocking write");
486 goto again;
487 } else {
488 logwrite(LOG_ERR, "Sending failed: %", errno);