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