annotate src/checksignal.c @ 176:2ae60285f383

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