Mercurial > pt1
annotate recpt1/checksignal.c @ 113:e7b786c42ca0
add an utility to check signal strength.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Fri, 19 Mar 2010 01:01:35 +0900 |
parents | |
children | 3eccf1ef4853 |
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 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
37 /* type definitions */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
38 typedef int boolean; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
39 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
40 typedef struct thread_data { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
41 int ch; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
42 int lnb; /* LNB voltage */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
43 int tfd; /* tuner fd */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
44 ISDB_T_FREQ_CONV_TABLE *table; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
45 } thread_data; |
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 /* globals */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
48 boolean f_exit = FALSE; |
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 /* prototypes */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
51 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
|
52 int close_tuner(thread_data *tdata); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
53 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
54 /* signal handler */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
55 void |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
56 handler(int dummy) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
57 { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
58 f_exit = TRUE; |
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 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
61 /* lookup frequency conversion table*/ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
62 ISDB_T_FREQ_CONV_TABLE * |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
63 searchrecoff(char *channel) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
64 { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
65 int lp; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
66 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
67 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
|
68 /* 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
|
69 * lengths are same. */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
70 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
|
71 strlen(channel)) == 0) && |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
72 (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
|
73 return &isdb_t_conv_table[lp]; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
74 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
75 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
76 return NULL; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
77 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
78 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
79 void |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
80 show_usage(char *cmd) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
81 { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
82 fprintf(stderr, "Usage: \n%s [--device devicefile] [--lnb voltage] channel\n", cmd); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
83 fprintf(stderr, "\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
84 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
85 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
86 void |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
87 show_options(void) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
88 { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
89 fprintf(stderr, "Options:\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
90 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
|
91 fprintf(stderr, "--lnb voltage: Specify LNB voltage (0, 11, 15)\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
92 fprintf(stderr, "--help: Show this help\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
93 fprintf(stderr, "--version: Show version\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
94 fprintf(stderr, "--list: Show channel list\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
95 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
96 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
97 void |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
98 show_channels(void) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
99 { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
100 FILE *f; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
101 char *home; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
102 char buf[255], filename[255]; |
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 fprintf(stderr, "Available Channels:\n"); |
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 home = getenv("HOME"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
107 sprintf(filename, "%s/.recpt1-channels", home); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
108 f = fopen(filename, "r"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
109 if(f) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
110 while(fgets(buf, 255, f)) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
111 fprintf(stderr, "%s", buf); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
112 fclose(f); |
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 else |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
115 fprintf(stderr, "13-62: Terrestrial Channels\n"); |
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 fprintf(stderr, "101ch: NHK BS1\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
118 fprintf(stderr, "102ch: NHK BS2\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
119 fprintf(stderr, "103ch: NHK BShi\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
120 fprintf(stderr, "141ch: BS Nittele\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
121 fprintf(stderr, "151ch: BS Asahi\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
122 fprintf(stderr, "161ch: BS-TBS\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
123 fprintf(stderr, "171ch: BS Japan\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
124 fprintf(stderr, "181ch: BS Fuji\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
125 fprintf(stderr, "191ch: WOWOW\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
126 fprintf(stderr, "192ch: WOWOW2\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
127 fprintf(stderr, "193ch: WOWOW3\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
128 fprintf(stderr, "200ch: Star Channel\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
129 fprintf(stderr, "211ch: BS11 Digital\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
130 fprintf(stderr, "222ch: TwellV\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
131 fprintf(stderr, "C13-C63: CATV Channels\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
132 fprintf(stderr, "CS2-CS24: CS Channels\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
133 } |
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 float |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
136 getsignal_isdb_s(int signal) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
137 { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
138 /* apply linear interpolation */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
139 static const float afLevelTable[] = { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
140 24.07f, // 00 00 0 24.07dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
141 24.07f, // 10 00 4096 24.07dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
142 18.61f, // 20 00 8192 18.61dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
143 15.21f, // 30 00 12288 15.21dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
144 12.50f, // 40 00 16384 12.50dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
145 10.19f, // 50 00 20480 10.19dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
146 8.140f, // 60 00 24576 8.140dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
147 6.270f, // 70 00 28672 6.270dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
148 4.550f, // 80 00 32768 4.550dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
149 3.730f, // 88 00 34816 3.730dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
150 3.630f, // 88 FF 35071 3.630dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
151 2.940f, // 90 00 36864 2.940dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
152 1.420f, // A0 00 40960 1.420dB |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
153 0.000f // B0 00 45056 -0.01dB |
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 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
156 unsigned char sigbuf[4]; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
157 memset(sigbuf, '\0', sizeof(sigbuf)); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
158 sigbuf[0] = (((signal & 0xFF00) >> 8) & 0XFF); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
159 sigbuf[1] = (signal & 0xFF); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
160 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
161 /* calculate signal level */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
162 if(sigbuf[0] <= 0x10U) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
163 /* clipped maximum */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
164 return 24.07f; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
165 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
166 else if (sigbuf[0] >= 0xB0U) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
167 /* clipped minimum */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
168 return 0.0f; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
169 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
170 else { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
171 /* linear interpolation */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
172 const float fMixRate = |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
173 (float)(((unsigned short)(sigbuf[0] & 0x0FU) << 8) | |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
174 (unsigned short)sigbuf[0]) / 4096.0f; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
175 return afLevelTable[sigbuf[0] >> 4] * (1.0f - fMixRate) + |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
176 afLevelTable[(sigbuf[0] >> 4) + 0x01U] * fMixRate; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
177 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
178 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
179 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
180 void |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
181 calc_cn(int fd, int type) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
182 { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
183 int rc ; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
184 double P ; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
185 double CNR; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
186 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
187 if(ioctl(fd, GET_SIGNAL_STRENGTH, &rc) < 0) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
188 fprintf(stderr, "Tuner Select Error\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
189 return ; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
190 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
191 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
192 if(type == CHTYPE_GROUND) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
193 P = log10(5505024/(double)rc) * 10; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
194 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
|
195 (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
|
196 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
197 else { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
198 CNR = getsignal_isdb_s(rc); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
199 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
200 fprintf(stderr, "\rC/N = %fdB", CNR); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
201 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
202 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
203 int |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
204 tune(char *channel, thread_data *tdata, char *device) |
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 char **tuner; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
207 int num_devs; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
208 int lp; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
209 FREQUENCY freq; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
210 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
211 /* get channel */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
212 tdata->table = searchrecoff(channel); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
213 if(tdata->table == NULL) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
214 fprintf(stderr, "Invalid Channel: %s\n", channel); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
215 return 1; |
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 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
218 freq.frequencyno = tdata->table->set_freq; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
219 freq.slot = tdata->table->add_freq; |
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 /* open tuner */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
222 /* case 1: specified tuner device */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
223 if(device) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
224 fprintf(stderr, "device = %s\n", device); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
225 tdata->tfd = open(device, O_RDONLY); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
226 if(tdata->tfd < 0) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
227 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
|
228 return 1; |
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 /* power on LNB */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
232 if(tdata->table->type == CHTYPE_SATELLITE) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
233 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
|
234 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
|
235 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
236 } |
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 /* tune to specified channel */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
239 if(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
240 close(tdata->tfd); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
241 fprintf(stderr, "Cannot tune to the specified channel: %s\n", device); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
242 return 1; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
243 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
244 else { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
245 tdata->ch = atoi(channel); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
246 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
247 } |
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 /* case 2: loop around available devices */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
250 if(tdata->table->type == CHTYPE_SATELLITE) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
251 tuner = bsdev; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
252 num_devs = NUM_BSDEV; |
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 else { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
255 tuner = isdb_t_dev; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
256 num_devs = NUM_ISDB_T_DEV; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
257 } |
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 for(lp = 0; lp < num_devs; lp++) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
260 tdata->tfd = open(tuner[lp], O_RDONLY); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
261 if(tdata->tfd >= 0) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
262 /* power on LNB */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
263 if(tdata->table->type == CHTYPE_SATELLITE) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
264 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
|
265 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
|
266 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
267 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
268 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
269 /* tune to specified channel */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
270 if(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
271 close(tdata->tfd); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
272 tdata->tfd = -1; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
273 continue; |
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 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
276 fprintf(stderr, "device = %s\n", tuner[lp]); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
277 break; /* found suitable tuner */ |
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 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
280 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
281 /* all tuners cannot be used */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
282 if(tdata->tfd < 0) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
283 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
|
284 return 1; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
285 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
286 else { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
287 tdata->ch = atoi(channel); |
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 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
291 return 0; /* success */ |
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 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
294 int |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
295 close_tuner(thread_data *tdata) |
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 int rv = 0; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
298 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
299 if(tdata->table->type == CHTYPE_SATELLITE) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
300 if(ioctl(tdata->tfd, LNB_DISABLE, 0) < 0) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
301 rv = 1; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
302 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
303 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
304 close(tdata->tfd); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
305 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
306 return rv; |
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 int |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
310 main(int argc, char **argv) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
311 { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
312 static thread_data tdata; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
313 int result; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
314 int option_index; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
315 struct option long_options[] = { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
316 { "LNB", 1, NULL, 'n'}, |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
317 { "lnb", 1, NULL, 'n'}, |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
318 { "device", 1, NULL, 'd'}, |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
319 { "help", 0, NULL, 'h'}, |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
320 { "version", 0, NULL, 'v'}, |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
321 { "list", 0, NULL, 'l'}, |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
322 {0, 0, NULL, 0} /* terminate */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
323 }; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
324 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
325 char *device = NULL; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
326 int val; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
327 char *voltage[] = {"0V", "11V", "15V"}; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
328 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
329 while((result = getopt_long(argc, argv, "br:smn:ua:p:d:hvli:", |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
330 long_options, &option_index)) != -1) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
331 switch(result) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
332 case 'h': |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
333 fprintf(stderr, "\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
334 show_usage(argv[0]); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
335 fprintf(stderr, "\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
336 show_options(); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
337 fprintf(stderr, "\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
338 show_channels(); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
339 fprintf(stderr, "\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
340 exit(0); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
341 break; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
342 case 'v': |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
343 fprintf(stderr, "%s %s\n", argv[0], version); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
344 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
|
345 exit(0); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
346 break; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
347 case 'l': |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
348 show_channels(); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
349 exit(0); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
350 break; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
351 /* following options require argument */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
352 case 'n': |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
353 val = atoi(optarg); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
354 switch(val) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
355 case 11: |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
356 tdata.lnb = 1; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
357 break; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
358 case 15: |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
359 tdata.lnb = 2; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
360 break; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
361 default: |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
362 tdata.lnb = 0; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
363 break; |
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 fprintf(stderr, "LNB = %s\n", voltage[tdata.lnb]); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
366 break; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
367 case 'd': |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
368 device = optarg; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
369 break; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
370 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
371 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
372 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
373 if(argc - optind < 1) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
374 fprintf(stderr, "channel must be specified!\n"); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
375 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
|
376 return 1; |
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 /* add signal handler */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
380 signal(SIGTERM, handler); |
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 /* tune */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
383 if(tune(argv[optind], &tdata, device) != 0) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
384 return 1; |
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 while(1) { |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
387 if(f_exit) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
388 break; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
389 /* show signal strength */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
390 calc_cn(tdata.tfd, tdata.table->type); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
391 sleep(1); |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
392 } |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
393 |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
394 /* close tuner */ |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
395 if(close_tuner(&tdata) != 0) |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
396 return 1; |
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 return 0; |
e7b786c42ca0
add an utility to check signal strength.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff
changeset
|
399 } |