Mercurial > pt1.oyama
annotate src/checksignal.c @ 148:da6ea0ef68ff
Fix comma was missing.
author | Naoya OYAMA <naoya.oyama@gmail.com> |
---|---|
date | Wed, 22 Aug 2012 22:06:09 +0900 |
parents | 4e39ce051c57 |
children | 7d8a5bb874ad |
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" |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
28 #include "recpt1.h" |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
29 #include "version.h" |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
30 #include "mkpath.h" |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
31 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
32 #include <sys/ipc.h> |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
33 #include <sys/msg.h> |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
34 #include "pt1_dev.h" |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
35 #include "tssplitter_lite.h" |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
36 |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
37 #define MAX_RETRY (2) |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
38 |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
39 /* type definitions */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
40 typedef int boolean; |
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 /* globals */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
43 boolean f_exit = FALSE; |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
44 boolean use_bell = FALSE; |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
45 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
46 /* prototypes */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
47 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
|
48 int close_tuner(thread_data *tdata); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
49 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
50 void |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
51 cleanup(thread_data *tdata) |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
52 { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
53 f_exit = TRUE; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
54 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
55 |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
56 /* will be signal handler thread */ |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
57 void * |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
58 process_signals(void *data) |
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 sigset_t waitset; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
61 int sig; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
62 thread_data *tdata = (thread_data *)data; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
63 |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
64 sigemptyset(&waitset); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
65 sigaddset(&waitset, SIGINT); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
66 sigaddset(&waitset, SIGTERM); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
67 sigaddset(&waitset, SIGUSR1); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
68 |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
69 sigwait(&waitset, &sig); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
70 |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
71 switch(sig) { |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
72 case SIGINT: |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
73 fprintf(stderr, "\nSIGINT received. cleaning up...\n"); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
74 cleanup(tdata); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
75 break; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
76 case SIGTERM: |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
77 fprintf(stderr, "\nSIGTERM received. cleaning up...\n"); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
78 cleanup(tdata); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
79 break; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
80 case SIGUSR1: /* normal exit*/ |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
81 cleanup(tdata); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
82 break; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
83 } |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
84 |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
85 return NULL; /* dummy */ |
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 |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
88 void |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
89 init_signal_handlers(pthread_t *signal_thread, thread_data *tdata) |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
90 { |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
91 sigset_t blockset; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
92 |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
93 sigemptyset(&blockset); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
94 sigaddset(&blockset, SIGINT); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
95 sigaddset(&blockset, SIGTERM); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
96 sigaddset(&blockset, SIGUSR1); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
97 |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
98 if(pthread_sigmask(SIG_BLOCK, &blockset, NULL)) |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
99 fprintf(stderr, "pthread_sigmask() failed.\n"); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
100 |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
101 pthread_create(signal_thread, NULL, process_signals, tdata); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
102 } |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
103 |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
104 /* lookup frequency conversion table*/ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
105 ISDB_T_FREQ_CONV_TABLE * |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
106 searchrecoff(char *channel) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
107 { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
108 int lp; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
109 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
110 for(lp = 0; isdb_t_conv_table[lp].parm_freq != NULL; lp++) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
111 /* return entry number in the table when strings match and |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
112 * lengths are same. */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
113 if((memcmp(isdb_t_conv_table[lp].parm_freq, channel, |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
114 strlen(channel)) == 0) && |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
115 (strlen(channel) == strlen(isdb_t_conv_table[lp].parm_freq))) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
116 return &isdb_t_conv_table[lp]; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
117 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
118 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
119 return NULL; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
120 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
121 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
122 void |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
123 show_usage(char *cmd) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
124 { |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
125 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
|
126 fprintf(stderr, "\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
127 } |
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 void |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
130 show_options(void) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
131 { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
132 fprintf(stderr, "Options:\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
133 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
|
134 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
|
135 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
|
136 fprintf(stderr, "--help: Show this help\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
137 fprintf(stderr, "--version: Show version\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
138 fprintf(stderr, "--list: Show channel list\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
139 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
140 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
141 void |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
142 show_channels(void) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
143 { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
144 FILE *f; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
145 char *home; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
146 char buf[255], filename[255]; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
147 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
148 fprintf(stderr, "Available Channels:\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
149 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
150 home = getenv("HOME"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
151 sprintf(filename, "%s/.recpt1-channels", home); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
152 f = fopen(filename, "r"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
153 if(f) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
154 while(fgets(buf, 255, f)) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
155 fprintf(stderr, "%s", buf); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
156 fclose(f); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
157 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
158 else |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
159 fprintf(stderr, "13-62: Terrestrial Channels\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
160 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
161 fprintf(stderr, "101ch: NHK BS1\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
162 fprintf(stderr, "102ch: NHK BS2\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
163 fprintf(stderr, "103ch: NHK BShi\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
164 fprintf(stderr, "141ch: BS Nittele\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
165 fprintf(stderr, "151ch: BS Asahi\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
166 fprintf(stderr, "161ch: BS-TBS\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
167 fprintf(stderr, "171ch: BS Japan\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
168 fprintf(stderr, "181ch: BS Fuji\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
169 fprintf(stderr, "191ch: WOWOW\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
170 fprintf(stderr, "192ch: WOWOW2\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
171 fprintf(stderr, "193ch: WOWOW3\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
172 fprintf(stderr, "200ch: Star Channel\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
173 fprintf(stderr, "211ch: BS11 Digital\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
174 fprintf(stderr, "222ch: TwellV\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
175 fprintf(stderr, "C13-C63: CATV Channels\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
176 fprintf(stderr, "CS2-CS24: CS Channels\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
177 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
178 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
179 float |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
180 getsignal_isdb_s(int signal) |
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 /* apply linear interpolation */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
183 static const float afLevelTable[] = { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
184 24.07f, // 00 00 0 24.07dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
185 24.07f, // 10 00 4096 24.07dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
186 18.61f, // 20 00 8192 18.61dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
187 15.21f, // 30 00 12288 15.21dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
188 12.50f, // 40 00 16384 12.50dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
189 10.19f, // 50 00 20480 10.19dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
190 8.140f, // 60 00 24576 8.140dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
191 6.270f, // 70 00 28672 6.270dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
192 4.550f, // 80 00 32768 4.550dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
193 3.730f, // 88 00 34816 3.730dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
194 3.630f, // 88 FF 35071 3.630dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
195 2.940f, // 90 00 36864 2.940dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
196 1.420f, // A0 00 40960 1.420dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
197 0.000f // B0 00 45056 -0.01dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
198 }; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
199 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
200 unsigned char sigbuf[4]; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
201 memset(sigbuf, '\0', sizeof(sigbuf)); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
202 sigbuf[0] = (((signal & 0xFF00) >> 8) & 0XFF); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
203 sigbuf[1] = (signal & 0xFF); |
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 /* calculate signal level */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
206 if(sigbuf[0] <= 0x10U) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
207 /* clipped maximum */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
208 return 24.07f; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
209 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
210 else if (sigbuf[0] >= 0xB0U) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
211 /* clipped minimum */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
212 return 0.0f; |
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 else { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
215 /* linear interpolation */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
216 const float fMixRate = |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
217 (float)(((unsigned short)(sigbuf[0] & 0x0FU) << 8) | |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
218 (unsigned short)sigbuf[0]) / 4096.0f; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
219 return afLevelTable[sigbuf[0] >> 4] * (1.0f - fMixRate) + |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
220 afLevelTable[(sigbuf[0] >> 4) + 0x01U] * fMixRate; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
221 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
222 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
223 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
224 void |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
225 do_bell(int bell) |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
226 { |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
227 int i; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
228 for(i=0; i < bell; i++) { |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
229 fprintf(stderr, "\a"); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
230 usleep(400000); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
231 } |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
232 } |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
233 |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
234 void |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
235 calc_cn(int fd, int type) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
236 { |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
237 int rc; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
238 double P; |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
239 double CNR; |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
240 int bell = 0; |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
241 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
242 if(ioctl(fd, GET_SIGNAL_STRENGTH, &rc) < 0) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
243 fprintf(stderr, "Tuner Select Error\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
244 return ; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
245 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
246 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
247 if(type == CHTYPE_GROUND) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
248 P = log10(5505024/(double)rc) * 10; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
249 CNR = (0.000024 * P * P * P * P) - (0.0016 * P * P * P) + |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
250 (0.0398 * P * P) + (0.5491 * P)+3.0965; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
251 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
252 else { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
253 CNR = getsignal_isdb_s(rc); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
254 } |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
255 |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
256 if(CNR >= 30.0) |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
257 bell = 3; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
258 else if(CNR >= 15.0 && CNR < 30.0) |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
259 bell = 2; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
260 else if(CNR < 15.0) |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
261 bell = 1; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
262 |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
263 fprintf(stderr, "\rC/N = %fdB", CNR); |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
264 if(use_bell) |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
265 do_bell(bell); |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
266 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
267 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
268 int |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
269 tune(char *channel, thread_data *tdata, char *device) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
270 { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
271 char **tuner; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
272 int num_devs; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
273 int lp; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
274 FREQUENCY freq; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
275 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
276 /* get channel */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
277 tdata->table = searchrecoff(channel); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
278 if(tdata->table == NULL) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
279 fprintf(stderr, "Invalid Channel: %s\n", channel); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
280 return 1; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
281 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
282 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
283 freq.frequencyno = tdata->table->set_freq; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
284 freq.slot = tdata->table->add_freq; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
285 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
286 /* open tuner */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
287 /* case 1: specified tuner device */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
288 if(device) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
289 tdata->tfd = open(device, O_RDONLY); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
290 if(tdata->tfd < 0) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
291 fprintf(stderr, "Cannot open tuner device: %s\n", device); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
292 return 1; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
293 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
294 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
295 /* power on LNB */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
296 if(tdata->table->type == CHTYPE_SATELLITE) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
297 if(ioctl(tdata->tfd, LNB_ENABLE, tdata->lnb) < 0) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
298 fprintf(stderr, "Power on LNB failed: %s\n", device); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
299 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
300 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
301 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
302 /* tune to specified channel */ |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
303 while(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0) { |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
304 if(f_exit) { |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
305 close_tuner(tdata); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
306 return 1; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
307 } |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
308 fprintf(stderr, "No signal. Still trying: %s\n", device); |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
309 } |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
310 |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
311 fprintf(stderr, "device = %s\n", device); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
312 tdata->ch = atoi(channel); |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
313 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
314 else { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
315 /* case 2: loop around available devices */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
316 if(tdata->table->type == CHTYPE_SATELLITE) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
317 tuner = bsdev; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
318 num_devs = NUM_BSDEV; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
319 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
320 else { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
321 tuner = isdb_t_dev; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
322 num_devs = NUM_ISDB_T_DEV; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
323 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
324 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
325 for(lp = 0; lp < num_devs; lp++) { |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
326 int count = 0; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
327 |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
328 tdata->tfd = open(tuner[lp], O_RDONLY); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
329 if(tdata->tfd >= 0) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
330 /* power on LNB */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
331 if(tdata->table->type == CHTYPE_SATELLITE) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
332 if(ioctl(tdata->tfd, LNB_ENABLE, tdata->lnb) < 0) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
333 fprintf(stderr, "Warning: Power on LNB failed: %s\n", tuner[lp]); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
334 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
335 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
336 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
337 /* tune to specified channel */ |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
338 while(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0 && |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
339 count < MAX_RETRY) { |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
340 if(f_exit) { |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
341 close_tuner(tdata); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
342 return 1; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
343 } |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
344 fprintf(stderr, "No signal. Still trying: %s\n", tuner[lp]); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
345 count++; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
346 } |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
347 |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
348 if(count >= MAX_RETRY) { |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
349 close_tuner(tdata); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
350 count = 0; |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
351 continue; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
352 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
353 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
354 fprintf(stderr, "device = %s\n", tuner[lp]); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
355 break; /* found suitable tuner */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
356 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
357 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
358 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
359 /* all tuners cannot be used */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
360 if(tdata->tfd < 0) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
361 fprintf(stderr, "Cannot tune to the specified channel\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
362 return 1; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
363 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
364 else { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
365 tdata->ch = atoi(channel); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
366 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
367 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
368 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
369 return 0; /* success */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
370 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
371 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
372 int |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
373 close_tuner(thread_data *tdata) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
374 { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
375 int rv = 0; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
376 |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
377 if(tdata->tfd == -1) |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
378 return rv; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
379 |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
380 if(tdata->table->type == CHTYPE_SATELLITE) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
381 if(ioctl(tdata->tfd, LNB_DISABLE, 0) < 0) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
382 rv = 1; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
383 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
384 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
385 close(tdata->tfd); |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
386 tdata->tfd = -1; |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
387 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
388 return rv; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
389 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
390 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
391 int |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
392 main(int argc, char **argv) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
393 { |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
394 pthread_t signal_thread; |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
395 static thread_data tdata; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
396 int result; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
397 int option_index; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
398 struct option long_options[] = { |
115 | 399 { "bell", 0, NULL, 'b'}, |
116 | 400 { "help", 0, NULL, 'h'}, |
401 { "version", 0, NULL, 'v'}, | |
402 { "list", 0, NULL, 'l'}, | |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
403 { "LNB", 1, NULL, 'n'}, |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
404 { "lnb", 1, NULL, 'n'}, |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
405 { "device", 1, NULL, 'd'}, |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
406 {0, 0, NULL, 0} /* terminate */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
407 }; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
408 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
409 char *device = NULL; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
410 int val; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
411 char *voltage[] = {"0V", "11V", "15V"}; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
412 |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
413 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
|
414 long_options, &option_index)) != -1) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
415 switch(result) { |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
416 case 'b': |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
417 use_bell = TRUE; |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
418 break; |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
419 case 'h': |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
420 fprintf(stderr, "\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
421 show_usage(argv[0]); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
422 fprintf(stderr, "\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
423 show_options(); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
424 fprintf(stderr, "\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
425 show_channels(); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
426 fprintf(stderr, "\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
427 exit(0); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
428 break; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
429 case 'v': |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
430 fprintf(stderr, "%s %s\n", argv[0], version); |
116 | 431 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
|
432 exit(0); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
433 break; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
434 case 'l': |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
435 show_channels(); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
436 exit(0); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
437 break; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
438 /* following options require argument */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
439 case 'n': |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
440 val = atoi(optarg); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
441 switch(val) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
442 case 11: |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
443 tdata.lnb = 1; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
444 break; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
445 case 15: |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
446 tdata.lnb = 2; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
447 break; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
448 default: |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
449 tdata.lnb = 0; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
450 break; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
451 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
452 fprintf(stderr, "LNB = %s\n", voltage[tdata.lnb]); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
453 break; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
454 case 'd': |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
455 device = optarg; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
456 break; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
457 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
458 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
459 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
460 if(argc - optind < 1) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
461 fprintf(stderr, "channel must be specified!\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
462 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
|
463 return 1; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
464 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
465 |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
466 /* spawn signal handler thread */ |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
467 init_signal_handlers(&signal_thread, &tdata); |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
468 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
469 /* tune */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
470 if(tune(argv[optind], &tdata, device) != 0) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
471 return 1; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
472 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
473 while(1) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
474 if(f_exit) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
475 break; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
476 /* show signal strength */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
477 calc_cn(tdata.tfd, tdata.table->type); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
478 sleep(1); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
479 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
480 |
114
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
481 /* wait for signal thread */ |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
482 pthread_kill(signal_thread, SIGUSR1); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
483 pthread_join(signal_thread, NULL); |
3eccf1ef4853
improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
113
diff
changeset
|
484 |
113
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
485 /* close tuner */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
486 if(close_tuner(&tdata) != 0) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
487 return 1; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
488 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
489 return 0; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
490 } |