annotate recpt1/recpt1core.c @ 144:5e4290a4cd01

follow BS Japan's transponder migration
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Mon, 16 Apr 2018 01:24:18 +0900
parents c8688d7d6382
children 75423932bfaa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
140
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1 #include <stdio.h>
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
2 #include <stdlib.h>
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
3 #include "recpt1core.h"
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
4 #include "version.h"
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
5 #include "pt1_dev.h"
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
6
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
7 #define ISDB_T_NODE_LIMIT 24 // 32:ARIB limit 24:program maximum
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
8 #define ISDB_T_SLOT_LIMIT 8
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
9
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
10 /* globals */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
11 boolean f_exit = FALSE;
144
5e4290a4cd01 follow BS Japan's transponder migration
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 141
diff changeset
12 char bs_channel_buf[20];
140
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
13 ISDB_T_FREQ_CONV_TABLE isdb_t_conv_set = { 0, CHTYPE_SATELLITE, 0, bs_channel_buf };
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
14
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
15
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
16 #if 0
144
5e4290a4cd01 follow BS Japan's transponder migration
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 141
diff changeset
17 /* lookup frequency conversion table */
140
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
18 ISDB_T_FREQ_CONV_TABLE *
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
19 searchrecoff(char *channel)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
20 {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
21 int lp;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
22
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
23 for(lp = 0; isdb_t_conv_table[lp].parm_freq != NULL; lp++) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
24 /* return entry number in the table when strings match and
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
25 * lengths are same. */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
26 if((memcmp(isdb_t_conv_table[lp].parm_freq, channel,
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
27 strlen(channel)) == 0) &&
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
28 (strlen(channel) == strlen(isdb_t_conv_table[lp].parm_freq))) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
29 return &isdb_t_conv_table[lp];
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
30 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
31 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
32 return NULL;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
33 }
144
5e4290a4cd01 follow BS Japan's transponder migration
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 141
diff changeset
34 #else
5e4290a4cd01 follow BS Japan's transponder migration
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 141
diff changeset
35 /* lookup frequency conversion table */
140
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
36 ISDB_T_FREQ_CONV_TABLE *
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
37 searchrecoff(char *channel)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
38 {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
39 int lp;
144
5e4290a4cd01 follow BS Japan's transponder migration
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 141
diff changeset
40 printf("channel = %s\n", channel);
140
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
41 if(channel[0] == 'B' && channel[1] == 'S') {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
42 int node = 0;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
43 int slot = 0;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
44 char *bs_ch;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
45
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
46 bs_ch = channel + 2;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
47 while(isdigit(*bs_ch)) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
48 node *= 10;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
49 node += *bs_ch++ - '0';
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
50 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
51 if(*bs_ch == '_' && (node&0x01) && node < ISDB_T_NODE_LIMIT) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
52 if(isdigit(*++bs_ch)) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
53 slot = *bs_ch - '0';
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
54 if(*++bs_ch == '\0' && slot < ISDB_T_SLOT_LIMIT) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
55 isdb_t_conv_set.set_freq = node / 2;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
56 isdb_t_conv_set.add_freq = slot;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
57 sprintf(bs_channel_buf, "BS%d_%d", node, slot);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
58 return &isdb_t_conv_set;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
59 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
60 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
61 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
62 return NULL;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
63 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
64 for(lp = 0; isdb_t_conv_table[lp].parm_freq != NULL; lp++) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
65 /* return entry number in the table when strings match and
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
66 * lengths are same. */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
67 if((memcmp(isdb_t_conv_table[lp].parm_freq, channel,
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
68 strlen(channel)) == 0) &&
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
69 (strlen(channel) == strlen(isdb_t_conv_table[lp].parm_freq))) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
70 return &isdb_t_conv_table[lp];
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
71 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
72 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
73 return NULL;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
74 }
144
5e4290a4cd01 follow BS Japan's transponder migration
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 141
diff changeset
75 #endif
140
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
76
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
77 int
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
78 close_tuner(thread_data *tdata)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
79 {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
80 int rv = 0;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
81
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
82 if(tdata->tfd == -1)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
83 return rv;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
84
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
85 if(tdata->table->type == CHTYPE_SATELLITE) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
86 if(ioctl(tdata->tfd, LNB_DISABLE, 0) < 0) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
87 rv = 1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
88 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
89 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
90 close(tdata->tfd);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
91 tdata->tfd = -1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
92
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
93 return rv;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
94 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
95
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
96 float
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
97 getsignal_isdb_s(int signal)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
98 {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
99 /* apply linear interpolation */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
100 static const float afLevelTable[] = {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
101 24.07f, // 00 00 0 24.07dB
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
102 24.07f, // 10 00 4096 24.07dB
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
103 18.61f, // 20 00 8192 18.61dB
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
104 15.21f, // 30 00 12288 15.21dB
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
105 12.50f, // 40 00 16384 12.50dB
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
106 10.19f, // 50 00 20480 10.19dB
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
107 8.140f, // 60 00 24576 8.140dB
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
108 6.270f, // 70 00 28672 6.270dB
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
109 4.550f, // 80 00 32768 4.550dB
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
110 3.730f, // 88 00 34816 3.730dB
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
111 3.630f, // 88 FF 35071 3.630dB
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
112 2.940f, // 90 00 36864 2.940dB
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
113 1.420f, // A0 00 40960 1.420dB
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
114 0.000f // B0 00 45056 -0.01dB
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
115 };
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
116
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
117 unsigned char sigbuf[4];
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
118 memset(sigbuf, '\0', sizeof(sigbuf));
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
119 sigbuf[0] = (((signal & 0xFF00) >> 8) & 0XFF);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
120 sigbuf[1] = (signal & 0xFF);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
121
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
122 /* calculate signal level */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
123 if(sigbuf[0] <= 0x10U) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
124 /* clipped maximum */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
125 return 24.07f;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
126 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
127 else if (sigbuf[0] >= 0xB0U) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
128 /* clipped minimum */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
129 return 0.0f;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
130 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
131 else {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
132 /* linear interpolation */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
133 const float fMixRate =
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
134 (float)(((unsigned short)(sigbuf[0] & 0x0FU) << 8) |
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
135 (unsigned short)sigbuf[0]) / 4096.0f;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
136 return afLevelTable[sigbuf[0] >> 4] * (1.0f - fMixRate) +
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
137 afLevelTable[(sigbuf[0] >> 4) + 0x01U] * fMixRate;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
138 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
139 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
140
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
141 void
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
142 calc_cn(int fd, int type, boolean use_bell)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
143 {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
144 int rc;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
145 double P;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
146 double CNR;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
147 int bell = 0;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
148
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
149 if(ioctl(fd, GET_SIGNAL_STRENGTH, &rc) < 0) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
150 fprintf(stderr, "Tuner Select Error\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
151 return ;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
152 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
153
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
154 if(type == CHTYPE_GROUND) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
155 P = log10(5505024/(double)rc) * 10;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
156 CNR = (0.000024 * P * P * P * P) - (0.0016 * P * P * P) +
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
157 (0.0398 * P * P) + (0.5491 * P)+3.0965;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
158 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
159 else {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
160 CNR = getsignal_isdb_s(rc);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
161 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
162
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
163 if(use_bell) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
164 if(CNR >= 30.0)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
165 bell = 3;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
166 else if(CNR >= 15.0 && CNR < 30.0)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
167 bell = 2;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
168 else if(CNR < 15.0)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
169 bell = 1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
170 fprintf(stderr, "\rC/N = %fdB ", CNR);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
171 do_bell(bell);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
172 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
173 else {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
174 fprintf(stderr, "\rC/N = %fdB", CNR);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
175 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
176 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
177
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
178 void
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
179 show_channels(void)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
180 {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
181 FILE *f;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
182 char *home;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
183 char buf[255], filename[255];
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
184
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
185 fprintf(stderr, "Available Channels:\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
186
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
187 home = getenv("HOME");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
188 sprintf(filename, "%s/.recpt1-channels", home);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
189 f = fopen(filename, "r");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
190 if(f) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
191 while(fgets(buf, 255, f))
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
192 fprintf(stderr, "%s", buf);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
193 fclose(f);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
194 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
195 else
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
196 fprintf(stderr, "13-62: Terrestrial Channels\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
197
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
198 fprintf(stderr, "101ch: NHK BS1\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
199 fprintf(stderr, "103ch: NHK BS Premium\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
200 fprintf(stderr, "141ch: BS Nittele\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
201 fprintf(stderr, "151ch: BS Asahi\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
202 fprintf(stderr, "161ch: BS-TBS\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
203 fprintf(stderr, "171ch: BS Japan\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
204 fprintf(stderr, "181ch: BS Fuji\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
205 fprintf(stderr, "191ch: WOWOW Prime\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
206 fprintf(stderr, "192ch: WOWOW Live\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
207 fprintf(stderr, "193ch: WOWOW Cinema\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
208 fprintf(stderr, "200ch: Star Channel1\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
209 fprintf(stderr, "201ch: Star Channel2\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
210 fprintf(stderr, "202ch: Star Channel3\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
211 fprintf(stderr, "211ch: BS11 Digital\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
212 fprintf(stderr, "222ch: TwellV\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
213 fprintf(stderr, "231ch: Housou Daigaku 1\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
214 fprintf(stderr, "232ch: Housou Daigaku 2\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
215 fprintf(stderr, "233ch: Housou Daigaku 3\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
216 fprintf(stderr, "234ch: Green Channel\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
217 fprintf(stderr, "236ch: BS Animax\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
218 fprintf(stderr, "238ch: FOX bs238\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
219 fprintf(stderr, "241ch: BS SkyPer!\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
220 fprintf(stderr, "242ch: J SPORTS 1\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
221 fprintf(stderr, "243ch: J SPORTS 2\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
222 fprintf(stderr, "244ch: J SPORTS 3\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
223 fprintf(stderr, "245ch: J SPORTS 4\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
224 fprintf(stderr, "251ch: BS Tsuri Vision\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
225 fprintf(stderr, "252ch: IMAGICA BS\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
226 fprintf(stderr, "255ch: Nihon Eiga Senmon Channel\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
227 fprintf(stderr, "256ch: Disney Channel\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
228 fprintf(stderr, "258ch: Dlife\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
229 fprintf(stderr, "C13-C63: CATV Channels\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
230 fprintf(stderr, "CS2-CS24: CS Channels\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
231 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
232
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
233
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
234 #if 0
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
235 int
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
236 parse_time(char *rectimestr, thread_data *tdata)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
237 {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
238 /* indefinite */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
239 if(!strcmp("-", rectimestr)) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
240 tdata->indefinite = TRUE;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
241 tdata->recsec = -1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
242 return 0;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
243 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
244 /* colon */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
245 else if(strchr(rectimestr, ':')) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
246 int n1, n2, n3;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
247 if(sscanf(rectimestr, "%d:%d:%d", &n1, &n2, &n3) == 3)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
248 tdata->recsec = n1 * 3600 + n2 * 60 + n3;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
249 else if(sscanf(rectimestr, "%d:%d", &n1, &n2) == 2)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
250 tdata->recsec = n1 * 3600 + n2 * 60;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
251 else
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
252 return 1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
253 return 0;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
254 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
255 /* HMS */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
256 else {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
257 char *tmpstr;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
258 char *p1, *p2;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
259
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
260 tmpstr = strdup(rectimestr);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
261 p1 = tmpstr;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
262 while(*p1 && !isdigit(*p1))
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
263 p1++;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
264
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
265 /* hour */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
266 if((p2 = strchr(p1, 'H')) || (p2 = strchr(p1, 'h'))) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
267 *p2 = '\0';
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
268 tdata->recsec += atoi(p1) * 3600;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
269 p1 = p2 + 1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
270 while(*p1 && !isdigit(*p1))
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
271 p1++;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
272 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
273
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
274 /* minute */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
275 if((p2 = strchr(p1, 'M')) || (p2 = strchr(p1, 'm'))) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
276 *p2 = '\0';
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
277 tdata->recsec += atoi(p1) * 60;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
278 p1 = p2 + 1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
279 while(*p1 && !isdigit(*p1))
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
280 p1++;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
281 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
282
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
283 /* second */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
284 tdata->recsec += atoi(p1);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
285
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
286 free(tmpstr);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
287 return 0;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
288 } /* else */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
289
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
290 return 1; /* unsuccessful */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
291 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
292 #endif
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
293
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
294 int
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
295 parse_time(char *rectimestr, int *recsec)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
296 {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
297 /* indefinite */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
298 if(!strcmp("-", rectimestr)) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
299 *recsec = -1;
141
c8688d7d6382 fix for the problem that an indefinite recording quits immediately.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 140
diff changeset
300 return 0;
140
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
301 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
302 /* colon */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
303 else if(strchr(rectimestr, ':')) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
304 int n1, n2, n3;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
305 if(sscanf(rectimestr, "%d:%d:%d", &n1, &n2, &n3) == 3)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
306 *recsec = n1 * 3600 + n2 * 60 + n3;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
307 else if(sscanf(rectimestr, "%d:%d", &n1, &n2) == 2)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
308 *recsec = n1 * 3600 + n2 * 60;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
309 else
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
310 return 1; /* unsuccessful */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
311
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
312 return 0;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
313 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
314 /* HMS */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
315 else {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
316 char *tmpstr;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
317 char *p1, *p2;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
318
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
319 tmpstr = strdup(rectimestr);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
320 p1 = tmpstr;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
321 while(*p1 && !isdigit(*p1))
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
322 p1++;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
323
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
324 /* hour */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
325 if((p2 = strchr(p1, 'H')) || (p2 = strchr(p1, 'h'))) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
326 *p2 = '\0';
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
327 *recsec += atoi(p1) * 3600;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
328 p1 = p2 + 1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
329 while(*p1 && !isdigit(*p1))
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
330 p1++;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
331 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
332
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
333 /* minute */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
334 if((p2 = strchr(p1, 'M')) || (p2 = strchr(p1, 'm'))) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
335 *p2 = '\0';
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
336 *recsec += atoi(p1) * 60;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
337 p1 = p2 + 1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
338 while(*p1 && !isdigit(*p1))
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
339 p1++;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
340 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
341
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
342 /* second */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
343 *recsec += atoi(p1);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
344
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
345 free(tmpstr);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
346
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
347 return 0;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
348 } /* else */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
349
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
350 return 1; /* unsuccessful */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
351 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
352
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
353 void
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
354 do_bell(int bell)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
355 {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
356 int i;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
357 for(i=0; i < bell; i++) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
358 fprintf(stderr, "\a");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
359 usleep(400000);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
360 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
361 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
362
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
363 /* from checksignal.c */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
364 int
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
365 tune(char *channel, thread_data *tdata, char *device)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
366 {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
367 char **tuner;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
368 int num_devs;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
369 int lp;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
370 FREQUENCY freq;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
371
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
372 /* get channel */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
373 tdata->table = searchrecoff(channel);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
374 if(tdata->table == NULL) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
375 fprintf(stderr, "Invalid Channel: %s\n", channel);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
376 return 1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
377 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
378
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
379 freq.frequencyno = tdata->table->set_freq;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
380 freq.slot = tdata->table->add_freq;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
381
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
382 /* open tuner */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
383 /* case 1: specified tuner device */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
384 if(device) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
385 tdata->tfd = open(device, O_RDONLY);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
386 if(tdata->tfd < 0) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
387 fprintf(stderr, "Cannot open tuner device: %s\n", device);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
388 return 1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
389 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
390
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
391 /* power on LNB */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
392 if(tdata->table->type == CHTYPE_SATELLITE) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
393 if(ioctl(tdata->tfd, LNB_ENABLE, tdata->lnb) < 0) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
394 fprintf(stderr, "Power on LNB failed: %s\n", device);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
395 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
396 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
397
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
398 /* tune to specified channel */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
399 while(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
400 if(tdata->tune_persistent) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
401 if(f_exit) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
402 close_tuner(tdata);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
403 return 1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
404 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
405 fprintf(stderr, "No signal. Still trying: %s\n", device);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
406 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
407 else {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
408 close(tdata->tfd);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
409 fprintf(stderr, "Cannot tune to the specified channel: %s\n", device);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
410 return 1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
411 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
412 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
413
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
414 fprintf(stderr, "device = %s\n", device);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
415 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
416 else {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
417 /* case 2: loop around available devices */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
418 if(tdata->table->type == CHTYPE_SATELLITE) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
419 tuner = bsdev;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
420 num_devs = NUM_BSDEV;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
421 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
422 else {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
423 tuner = isdb_t_dev;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
424 num_devs = NUM_ISDB_T_DEV;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
425 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
426
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
427 for(lp = 0; lp < num_devs; lp++) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
428 int count = 0;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
429
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
430 tdata->tfd = open(tuner[lp], O_RDONLY);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
431 if(tdata->tfd >= 0) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
432 /* power on LNB */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
433 if(tdata->table->type == CHTYPE_SATELLITE) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
434 if(ioctl(tdata->tfd, LNB_ENABLE, tdata->lnb) < 0) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
435 fprintf(stderr, "Warning: Power on LNB failed: %s\n", tuner[lp]);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
436 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
437 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
438
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
439 /* tune to specified channel */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
440 if(tdata->tune_persistent) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
441 while(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0 &&
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
442 count < MAX_RETRY) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
443 if(f_exit) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
444 close_tuner(tdata);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
445 return 1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
446 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
447 fprintf(stderr, "No signal. Still trying: %s\n", tuner[lp]);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
448 count++;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
449 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
450
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
451 if(count >= MAX_RETRY) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
452 close_tuner(tdata);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
453 count = 0;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
454 continue;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
455 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
456 } /* tune_persistent */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
457 else {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
458 if(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
459 close(tdata->tfd);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
460 tdata->tfd = -1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
461 continue;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
462 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
463 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
464
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
465 if(tdata->tune_persistent)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
466 fprintf(stderr, "device = %s\n", tuner[lp]);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
467 break; /* found suitable tuner */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
468 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
469 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
470
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
471 /* all tuners cannot be used */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
472 if(tdata->tfd < 0) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
473 fprintf(stderr, "Cannot tune to the specified channel\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
474 return 1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
475 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
476 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
477
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
478 if(!tdata->tune_persistent) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
479 /* show signal strength */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
480 calc_cn(tdata->tfd, tdata->table->type, FALSE);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
481 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
482
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
483 return 0; /* success */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
484 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
485
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
486
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
487 #if 0
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
488 /* from recpt1.c */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
489 int
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
490 tune(char *channel, thread_data *tdata, char *device)
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
491 {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
492 char **tuner;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
493 int num_devs;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
494 int lp;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
495 FREQUENCY freq;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
496
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
497 /* get channel */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
498 tdata->table = searchrecoff(channel);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
499 if(tdata->table == NULL) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
500 fprintf(stderr, "Invalid Channel: %s\n", channel);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
501 return 1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
502 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
503
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
504 freq.frequencyno = tdata->table->set_freq;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
505 freq.slot = tdata->table->add_freq;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
506
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
507 /* open tuner */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
508 /* case 1: specified tuner device */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
509 if(device) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
510 tdata->tfd = open(device, O_RDONLY);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
511 if(tdata->tfd < 0) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
512 fprintf(stderr, "Cannot open tuner device: %s\n", device);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
513 return 1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
514 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
515
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
516 /* power on LNB */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
517 if(tdata->table->type == CHTYPE_SATELLITE) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
518 if(ioctl(tdata->tfd, LNB_ENABLE, tdata->lnb) < 0) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
519 fprintf(stderr, "Power on LNB failed: %s\n", device);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
520 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
521 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
522
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
523 /* tune to specified channel */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
524 if(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
525 close(tdata->tfd);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
526 fprintf(stderr, "Cannot tune to the specified channel: %s\n", device);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
527 return 1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
528 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
529 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
530 else {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
531 /* case 2: loop around available devices */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
532 if(tdata->table->type == CHTYPE_SATELLITE) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
533 tuner = bsdev;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
534 num_devs = NUM_BSDEV;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
535 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
536 else {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
537 tuner = isdb_t_dev;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
538 num_devs = NUM_ISDB_T_DEV;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
539 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
540
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
541 for(lp = 0; lp < num_devs; lp++) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
542 tdata->tfd = open(tuner[lp], O_RDONLY);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
543 if(tdata->tfd >= 0) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
544 /* power on LNB */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
545 if(tdata->table->type == CHTYPE_SATELLITE) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
546 if(ioctl(tdata->tfd, LNB_ENABLE, tdata->lnb) < 0) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
547 fprintf(stderr, "Warning: Power on LNB failed: %s\n", tuner[lp]);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
548 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
549 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
550
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
551 /* tune to specified channel */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
552 if(ioctl(tdata->tfd, SET_CHANNEL, &freq) < 0) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
553 close(tdata->tfd);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
554 tdata->tfd = -1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
555 continue;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
556 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
557
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
558 break; /* found suitable tuner */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
559 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
560 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
561
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
562 /* all tuners cannot be used */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
563 if(tdata->tfd < 0) {
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
564 fprintf(stderr, "Cannot tune to the specified channel\n");
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
565 return 1;
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
566 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
567 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
568
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
569 /* show signal strength */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
570 calc_cn(tdata->tfd, tdata->table->type, FALSE);
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
571
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
572 return 0; /* success */
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
573 }
c9b1d21c5035 separate common function to core library
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
574 #endif