annotate recpt1/checksignal.c @ 143:d56831676696

compile fix
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Mon, 16 Apr 2018 00:43:19 +0900
parents c9b1d21c5035
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1 /* -*- tab-width: 4; indent-tabs-mode: nil -*- */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
2 #include <stdio.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
3 #include <fcntl.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
4 #include <sys/types.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
5 #include <sys/stat.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
6 #include <time.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
7 #include <stdlib.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
8 #include <string.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
9 #include <pthread.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
10 #include <math.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
11 #include <unistd.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
12 #include <getopt.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
13 #include <signal.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
14 #include <errno.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
15 #include <sys/time.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
16 #include <ctype.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
17 #include <libgen.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
18
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
19 #include <netdb.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
20 #include <arpa/inet.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
21 #include <netinet/in.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
22
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
23 #include <sys/ioctl.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
24 #include "pt1_ioctl.h"
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
25
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
26 #include "config.h"
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
27 #include "decoder.h"
140
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 117
diff changeset
28 #include "recpt1core.h"
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
29 #include "mkpath.h"
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
30
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
31 #include <sys/ipc.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
32 #include <sys/msg.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
33 #include "tssplitter_lite.h"
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
34
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
35 /* prototypes */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
36 int tune(char *channel, thread_data *tdata, char *device);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
37 int close_tuner(thread_data *tdata);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
38
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
39 void
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
40 cleanup(thread_data *tdata)
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
41 {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
42 f_exit = TRUE;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
43 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
44
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
45 /* will be signal handler thread */
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
46 void *
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
47 process_signals(void *data)
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
48 {
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
49 sigset_t waitset;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
50 int sig;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
51 thread_data *tdata = (thread_data *)data;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
52
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
53 sigemptyset(&waitset);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
54 sigaddset(&waitset, SIGINT);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
55 sigaddset(&waitset, SIGTERM);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
56 sigaddset(&waitset, SIGUSR1);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
57
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
58 sigwait(&waitset, &sig);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
59
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
60 switch(sig) {
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
61 case SIGINT:
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
62 fprintf(stderr, "\nSIGINT received. cleaning up...\n");
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
63 cleanup(tdata);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
64 break;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
65 case SIGTERM:
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
66 fprintf(stderr, "\nSIGTERM received. cleaning up...\n");
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
67 cleanup(tdata);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
68 break;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
69 case SIGUSR1: /* normal exit*/
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
70 cleanup(tdata);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
71 break;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
72 }
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
73
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
74 return NULL; /* dummy */
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
75 }
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
76
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
77 void
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
78 init_signal_handlers(pthread_t *signal_thread, thread_data *tdata)
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
79 {
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
80 sigset_t blockset;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
81
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
82 sigemptyset(&blockset);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
83 sigaddset(&blockset, SIGINT);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
84 sigaddset(&blockset, SIGTERM);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
85 sigaddset(&blockset, SIGUSR1);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
86
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
87 if(pthread_sigmask(SIG_BLOCK, &blockset, NULL))
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
88 fprintf(stderr, "pthread_sigmask() failed.\n");
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
89
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
90 pthread_create(signal_thread, NULL, process_signals, tdata);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
91 }
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
92
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
93 void
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
94 show_usage(char *cmd)
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
95 {
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
96 fprintf(stderr, "Usage: \n%s [--device devicefile] [--lnb voltage] [--bell] channel\n", cmd);
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
97 fprintf(stderr, "\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
98 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
99
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
100 void
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
101 show_options(void)
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
102 {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
103 fprintf(stderr, "Options:\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
104 fprintf(stderr, "--device devicefile: Specify devicefile to use\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
105 fprintf(stderr, "--lnb voltage: Specify LNB voltage (0, 11, 15)\n");
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
106 fprintf(stderr, "--bell: Notify signal quality by bell\n");
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
107 fprintf(stderr, "--help: Show this help\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
108 fprintf(stderr, "--version: Show version\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
109 fprintf(stderr, "--list: Show channel list\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
110 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
111
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
112 int
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
113 main(int argc, char **argv)
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
114 {
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
115 pthread_t signal_thread;
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
116 static thread_data tdata;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
117 int result;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
118 int option_index;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
119 struct option long_options[] = {
115
91e71df37095 fix --bell option
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 114
diff changeset
120 { "bell", 0, NULL, 'b'},
116
38a793ac3d9d - fix version string
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 115
diff changeset
121 { "help", 0, NULL, 'h'},
38a793ac3d9d - fix version string
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 115
diff changeset
122 { "version", 0, NULL, 'v'},
38a793ac3d9d - fix version string
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 115
diff changeset
123 { "list", 0, NULL, 'l'},
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
124 { "LNB", 1, NULL, 'n'},
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
125 { "lnb", 1, NULL, 'n'},
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
126 { "device", 1, NULL, 'd'},
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
127 {0, 0, NULL, 0} /* terminate */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
128 };
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
129
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
130 char *device = NULL;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
131 int val;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
132 char *voltage[] = {"0V", "11V", "15V"};
140
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 117
diff changeset
133 boolean use_bell = FALSE;
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
134
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
135 while((result = getopt_long(argc, argv, "bhvln:d:",
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
136 long_options, &option_index)) != -1) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
137 switch(result) {
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
138 case 'b':
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
139 use_bell = TRUE;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
140 break;
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
141 case 'h':
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
142 fprintf(stderr, "\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
143 show_usage(argv[0]);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
144 fprintf(stderr, "\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
145 show_options();
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
146 fprintf(stderr, "\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
147 show_channels();
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
148 fprintf(stderr, "\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
149 exit(0);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
150 break;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
151 case 'v':
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
152 fprintf(stderr, "%s %s\n", argv[0], version);
116
38a793ac3d9d - fix version string
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 115
diff changeset
153 fprintf(stderr, "signal check utility for PT1/2 digital tuner.\n");
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
154 exit(0);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
155 break;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
156 case 'l':
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
157 show_channels();
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
158 exit(0);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
159 break;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
160 /* following options require argument */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
161 case 'n':
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
162 val = atoi(optarg);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
163 switch(val) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
164 case 11:
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
165 tdata.lnb = 1;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
166 break;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
167 case 15:
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
168 tdata.lnb = 2;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
169 break;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
170 default:
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
171 tdata.lnb = 0;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
172 break;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
173 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
174 fprintf(stderr, "LNB = %s\n", voltage[tdata.lnb]);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
175 break;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
176 case 'd':
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
177 device = optarg;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
178 break;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
179 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
180 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
181
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
182 if(argc - optind < 1) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
183 fprintf(stderr, "channel must be specified!\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
184 fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
185 return 1;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
186 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
187
140
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 117
diff changeset
188 /* set tune_persistent flag */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 117
diff changeset
189 tdata.tune_persistent = TRUE;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 117
diff changeset
190
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
191 /* spawn signal handler thread */
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
192 init_signal_handlers(&signal_thread, &tdata);
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
193
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
194 /* tune */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
195 if(tune(argv[optind], &tdata, device) != 0)
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
196 return 1;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
197
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
198 while(1) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
199 if(f_exit)
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
200 break;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
201 /* show signal strength */
140
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 117
diff changeset
202 calc_cn(tdata.tfd, tdata.table->type, use_bell);
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
203 sleep(1);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
204 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
205
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
206 /* wait for signal thread */
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
207 pthread_kill(signal_thread, SIGUSR1);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
208 pthread_join(signal_thread, NULL);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
209
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
210 /* close tuner */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
211 if(close_tuner(&tdata) != 0)
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
212 return 1;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
213
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
214 return 0;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
215 }