annotate recpt1/checksignal.c @ 114:3eccf1ef4853

improve checksignal command: - retries MAX_RETRY times when tuning fails. if device is specified, reties forever. - notifies signal quality by audible beep.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Fri, 19 Mar 2010 16:42:32 +0900
parents e7b786c42ca0
children 91e71df37095
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1 /* -*- tab-width: 4; indent-tabs-mode: nil -*- */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
2 #include <stdio.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
3 #include <fcntl.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
4 #include <sys/types.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
5 #include <sys/stat.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
6 #include <time.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
7 #include <stdlib.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
8 #include <string.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
9 #include <pthread.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
10 #include <math.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
11 #include <unistd.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
12 #include <getopt.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
13 #include <signal.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
14 #include <errno.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
15 #include <sys/time.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
16 #include <ctype.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
17 #include <libgen.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
18
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
19 #include <netdb.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
20 #include <arpa/inet.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
21 #include <netinet/in.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
22
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
23 #include <sys/ioctl.h>
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
24 #include "pt1_ioctl.h"
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
25
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
26 #include "config.h"
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
27 #include "decoder.h"
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 typedef struct thread_data {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
43 int ch;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
44 int lnb; /* LNB voltage */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
45 int tfd; /* tuner fd */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
46 ISDB_T_FREQ_CONV_TABLE *table;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
47 } thread_data;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
48
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
49 /* globals */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
50 boolean f_exit = FALSE;
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
51 boolean use_bell = FALSE;
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 /* prototypes */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
54 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
55 int close_tuner(thread_data *tdata);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
56
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
57 void
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
58 cleanup(thread_data *tdata)
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
59 {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
60 f_exit = TRUE;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
61 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
62
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
63 /* will be signal handler thread */
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
64 void *
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
65 process_signals(void *data)
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 sigset_t waitset;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
68 int sig;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
69 thread_data *tdata = (thread_data *)data;
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 sigemptyset(&waitset);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
72 sigaddset(&waitset, SIGINT);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
73 sigaddset(&waitset, SIGTERM);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
74 sigaddset(&waitset, SIGUSR1);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
75
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
76 sigwait(&waitset, &sig);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
77
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
78 switch(sig) {
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
79 case SIGINT:
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
80 fprintf(stderr, "\nSIGINT received. cleaning up...\n");
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 case SIGTERM:
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
84 fprintf(stderr, "\nSIGTERM received. cleaning up...\n");
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
85 cleanup(tdata);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
86 break;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
87 case SIGUSR1: /* normal exit*/
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
88 cleanup(tdata);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
89 break;
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
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
92 return NULL; /* dummy */
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
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
95 void
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
96 init_signal_handlers(pthread_t *signal_thread, thread_data *tdata)
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 sigset_t blockset;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
99
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
100 sigemptyset(&blockset);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
101 sigaddset(&blockset, SIGINT);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
102 sigaddset(&blockset, SIGTERM);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
103 sigaddset(&blockset, SIGUSR1);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
104
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
105 if(pthread_sigmask(SIG_BLOCK, &blockset, NULL))
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
106 fprintf(stderr, "pthread_sigmask() failed.\n");
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
107
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
108 pthread_create(signal_thread, NULL, process_signals, tdata);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
109 }
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
110
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
111 /* lookup frequency conversion table*/
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
112 ISDB_T_FREQ_CONV_TABLE *
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
113 searchrecoff(char *channel)
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 int lp;
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 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
118 /* 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
119 * lengths are same. */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
120 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
121 strlen(channel)) == 0) &&
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
122 (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
123 return &isdb_t_conv_table[lp];
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 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
126 return NULL;
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_usage(char *cmd)
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
131 {
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
132 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
133 fprintf(stderr, "\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
134 }
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 void
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
137 show_options(void)
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
138 {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
139 fprintf(stderr, "Options:\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
140 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
141 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
142 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
143 fprintf(stderr, "--help: Show this help\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
144 fprintf(stderr, "--version: Show version\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
145 fprintf(stderr, "--list: Show channel list\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
146 }
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 void
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
149 show_channels(void)
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
150 {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
151 FILE *f;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
152 char *home;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
153 char buf[255], filename[255];
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
154
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
155 fprintf(stderr, "Available 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 home = getenv("HOME");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
158 sprintf(filename, "%s/.recpt1-channels", home);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
159 f = fopen(filename, "r");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
160 if(f) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
161 while(fgets(buf, 255, f))
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
162 fprintf(stderr, "%s", buf);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
163 fclose(f);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
164 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
165 else
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
166 fprintf(stderr, "13-62: Terrestrial Channels\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
167
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
168 fprintf(stderr, "101ch: NHK BS1\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
169 fprintf(stderr, "102ch: NHK BS2\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
170 fprintf(stderr, "103ch: NHK BShi\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
171 fprintf(stderr, "141ch: BS Nittele\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
172 fprintf(stderr, "151ch: BS Asahi\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
173 fprintf(stderr, "161ch: BS-TBS\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
174 fprintf(stderr, "171ch: BS Japan\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
175 fprintf(stderr, "181ch: BS Fuji\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
176 fprintf(stderr, "191ch: WOWOW\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
177 fprintf(stderr, "192ch: WOWOW2\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
178 fprintf(stderr, "193ch: WOWOW3\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
179 fprintf(stderr, "200ch: Star Channel\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
180 fprintf(stderr, "211ch: BS11 Digital\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
181 fprintf(stderr, "222ch: TwellV\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
182 fprintf(stderr, "C13-C63: CATV Channels\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
183 fprintf(stderr, "CS2-CS24: CS Channels\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
184 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
185
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
186 float
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
187 getsignal_isdb_s(int signal)
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
188 {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
189 /* apply linear interpolation */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
190 static const float afLevelTable[] = {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
191 24.07f, // 00 00 0 24.07dB
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
192 24.07f, // 10 00 4096 24.07dB
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
193 18.61f, // 20 00 8192 18.61dB
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
194 15.21f, // 30 00 12288 15.21dB
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
195 12.50f, // 40 00 16384 12.50dB
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
196 10.19f, // 50 00 20480 10.19dB
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
197 8.140f, // 60 00 24576 8.140dB
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
198 6.270f, // 70 00 28672 6.270dB
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
199 4.550f, // 80 00 32768 4.550dB
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
200 3.730f, // 88 00 34816 3.730dB
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
201 3.630f, // 88 FF 35071 3.630dB
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
202 2.940f, // 90 00 36864 2.940dB
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
203 1.420f, // A0 00 40960 1.420dB
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
204 0.000f // B0 00 45056 -0.01dB
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
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
207 unsigned char sigbuf[4];
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
208 memset(sigbuf, '\0', sizeof(sigbuf));
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
209 sigbuf[0] = (((signal & 0xFF00) >> 8) & 0XFF);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
210 sigbuf[1] = (signal & 0xFF);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
211
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
212 /* calculate signal level */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
213 if(sigbuf[0] <= 0x10U) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
214 /* clipped maximum */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
215 return 24.07f;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
216 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
217 else if (sigbuf[0] >= 0xB0U) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
218 /* clipped minimum */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
219 return 0.0f;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
220 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
221 else {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
222 /* linear interpolation */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
223 const float fMixRate =
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
224 (float)(((unsigned short)(sigbuf[0] & 0x0FU) << 8) |
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
225 (unsigned short)sigbuf[0]) / 4096.0f;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
226 return afLevelTable[sigbuf[0] >> 4] * (1.0f - fMixRate) +
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
227 afLevelTable[(sigbuf[0] >> 4) + 0x01U] * fMixRate;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
228 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
229 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
230
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
231 void
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
232 do_bell(int bell)
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 int i;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
235 for(i=0; i < bell; i++) {
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
236 fprintf(stderr, "\a");
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
237 usleep(400000);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
238 }
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
239 }
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
240
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
241 void
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
242 calc_cn(int fd, int type)
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
243 {
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
244 int rc;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
245 double P;
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
246 double CNR;
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
247 int bell = 0;
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
248
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
249 if(ioctl(fd, GET_SIGNAL_STRENGTH, &rc) < 0) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
250 fprintf(stderr, "Tuner Select Error\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
251 return ;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
252 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
253
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
254 if(type == CHTYPE_GROUND) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
255 P = log10(5505024/(double)rc) * 10;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
256 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
257 (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
258 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
259 else {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
260 CNR = getsignal_isdb_s(rc);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
261 }
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
262
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
263 if(CNR >= 30.0)
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
264 bell = 3;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
265 else if(CNR >= 15.0 && CNR < 30.0)
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
266 bell = 2;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
267 else if(CNR < 15.0)
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
268 bell = 1;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
269
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
270 fprintf(stderr, "\rC/N = %fdB", CNR);
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
271 if(use_bell)
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
272 do_bell(bell);
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
273 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
274
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
275 int
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
276 tune(char *channel, thread_data *tdata, char *device)
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 char **tuner;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
279 int num_devs;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
280 int lp;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
281 FREQUENCY freq;
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 /* get channel */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
284 tdata->table = searchrecoff(channel);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
285 if(tdata->table == NULL) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
286 fprintf(stderr, "Invalid Channel: %s\n", channel);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
287 return 1;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
288 }
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 freq.frequencyno = tdata->table->set_freq;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
291 freq.slot = tdata->table->add_freq;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
292
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
293 /* open tuner */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
294 /* case 1: specified tuner device */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
295 if(device) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
296 tdata->tfd = open(device, O_RDONLY);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
297 if(tdata->tfd < 0) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
298 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
299 return 1;
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 /* power on LNB */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
303 if(tdata->table->type == CHTYPE_SATELLITE) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
304 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
305 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
306 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
307 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
308
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
309 /* tune to specified channel */
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
310 while(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0) {
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
311 if(f_exit) {
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
312 close_tuner(tdata);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
313 return 1;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
314 }
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
315 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
316 }
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
317
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
318 fprintf(stderr, "device = %s\n", device);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
319 tdata->ch = atoi(channel);
113
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 else {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
322 /* case 2: loop around available devices */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
323 if(tdata->table->type == CHTYPE_SATELLITE) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
324 tuner = bsdev;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
325 num_devs = NUM_BSDEV;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
326 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
327 else {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
328 tuner = isdb_t_dev;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
329 num_devs = NUM_ISDB_T_DEV;
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 for(lp = 0; lp < num_devs; lp++) {
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
333 int count = 0;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
334
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
335 tdata->tfd = open(tuner[lp], O_RDONLY);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
336 if(tdata->tfd >= 0) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
337 /* power on LNB */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
338 if(tdata->table->type == CHTYPE_SATELLITE) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
339 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
340 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
341 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
342 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
343
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
344 /* tune to specified channel */
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
345 while(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0 &&
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
346 count < MAX_RETRY) {
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
347 if(f_exit) {
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
348 close_tuner(tdata);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
349 return 1;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
350 }
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
351 fprintf(stderr, "No signal. Still trying: %s\n", tuner[lp]);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
352 count++;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
353 }
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
354
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
355 if(count >= MAX_RETRY) {
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
356 close_tuner(tdata);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
357 count = 0;
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
358 continue;
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
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
361 fprintf(stderr, "device = %s\n", tuner[lp]);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
362 break; /* found suitable tuner */
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
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
366 /* all tuners cannot be used */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
367 if(tdata->tfd < 0) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
368 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
369 return 1;
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 else {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
372 tdata->ch = atoi(channel);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
373 }
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
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
376 return 0; /* success */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
377 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
378
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
379 int
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
380 close_tuner(thread_data *tdata)
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
381 {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
382 int rv = 0;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
383
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
384 if(tdata->tfd == -1)
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
385 return rv;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
386
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
387 if(tdata->table->type == CHTYPE_SATELLITE) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
388 if(ioctl(tdata->tfd, LNB_DISABLE, 0) < 0) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
389 rv = 1;
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 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
392 close(tdata->tfd);
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
393 tdata->tfd = -1;
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
394
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
395 return rv;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
396 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
397
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
398 int
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
399 main(int argc, char **argv)
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
400 {
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
401 pthread_t signal_thread;
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
402 static thread_data tdata;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
403 int result;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
404 int option_index;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
405 struct option long_options[] = {
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
406 { "bell", 1, NULL, 'b'},
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
407 { "LNB", 1, NULL, 'n'},
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
408 { "lnb", 1, NULL, 'n'},
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
409 { "device", 1, NULL, 'd'},
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
410 { "help", 0, NULL, 'h'},
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
411 { "version", 0, NULL, 'v'},
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
412 { "list", 0, NULL, 'l'},
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
413 {0, 0, NULL, 0} /* terminate */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
414 };
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
415
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
416 char *device = NULL;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
417 int val;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
418 char *voltage[] = {"0V", "11V", "15V"};
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
419
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
420 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
421 long_options, &option_index)) != -1) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
422 switch(result) {
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
423 case 'b':
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
424 use_bell = TRUE;
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
425 break;
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
426 case 'h':
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
427 fprintf(stderr, "\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
428 show_usage(argv[0]);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
429 fprintf(stderr, "\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
430 show_options();
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
431 fprintf(stderr, "\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
432 show_channels();
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
433 fprintf(stderr, "\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
434 exit(0);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
435 break;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
436 case 'v':
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
437 fprintf(stderr, "%s %s\n", argv[0], version);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
438 fprintf(stderr, "recorder command for PT1/2 digital tuner.\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
439 exit(0);
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 'l':
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
442 show_channels();
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
443 exit(0);
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 /* following options require argument */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
446 case 'n':
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
447 val = atoi(optarg);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
448 switch(val) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
449 case 11:
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
450 tdata.lnb = 1;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
451 break;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
452 case 15:
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
453 tdata.lnb = 2;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
454 break;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
455 default:
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
456 tdata.lnb = 0;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
457 break;
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 fprintf(stderr, "LNB = %s\n", voltage[tdata.lnb]);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
460 break;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
461 case 'd':
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
462 device = optarg;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
463 break;
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 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
466
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
467 if(argc - optind < 1) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
468 fprintf(stderr, "channel must be specified!\n");
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
469 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
470 return 1;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
471 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
472
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
473 /* spawn signal handler thread */
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
474 init_signal_handlers(&signal_thread, &tdata);
113
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 /* tune */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
477 if(tune(argv[optind], &tdata, device) != 0)
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
478 return 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 while(1) {
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
481 if(f_exit)
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
482 break;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
483 /* show signal strength */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
484 calc_cn(tdata.tfd, tdata.table->type);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
485 sleep(1);
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
486 }
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
487
114
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
488 /* wait for signal thread */
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
489 pthread_kill(signal_thread, SIGUSR1);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
490 pthread_join(signal_thread, NULL);
3eccf1ef4853 improve checksignal command:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 113
diff changeset
491
113
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
492 /* close tuner */
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
493 if(close_tuner(&tdata) != 0)
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
494 return 1;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
495
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
496 return 0;
e7b786c42ca0 add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
497 }