Mercurial > pt1.oyama
annotate recpt1/recpt1.c @ 9:07b2fc07ff48
updated to current driver to support signal strength.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Mon, 23 Feb 2009 14:28:35 +0900 |
parents | 6da603afd363 |
children | 4615eaf04415 |
rev | line source |
---|---|
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
1 #include <stdio.h> |
3 | 2 #include <fcntl.h> |
3 #include <sys/types.h> | |
4 #include <sys/stat.h> | |
5 #include <time.h> | |
6 #include <stdlib.h> | |
7 #include <string.h> | |
8 #include <pthread.h> | |
9 #include <unistd.h> | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
10 #include <getopt.h> |
0 | 11 |
8 | 12 #include <netdb.h> |
13 #include <arpa/inet.h> | |
14 #include <netinet/in.h> | |
15 | |
3 | 16 #include <sys/ioctl.h> |
17 #include "pt1_ioctl.h" | |
0 | 18 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
19 #include "recpt1.h" |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
20 #include "decoder.h" |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
21 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
22 /* globals */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
23 int f_exit = FALSE; |
0 | 24 |
8 | 25 typedef struct sock_data { |
26 int sfd; /* socket fd */ | |
27 struct sockaddr_in addr; | |
28 } sock_data; | |
29 | |
3 | 30 typedef struct thread_data { |
4 | 31 QUEUE_T *queue; |
32 decoder *decoder; | |
8 | 33 int wfd; /* output file fd */ |
34 sock_data *sock_data; | |
3 | 35 } thread_data; |
0 | 36 |
6 | 37 /* lookup frequency conversion table*/ |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
38 ISDB_T_FREQ_CONV_TABLE * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
39 searchrecoff(char *channel) |
0 | 40 { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
41 int lp; |
0 | 42 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
43 for(lp = 0; isdb_t_conv_table[lp].parm_freq != NULL; lp++){ |
6 | 44 /* return entry number in the table when strings match and |
45 * lengths are same. */ | |
4 | 46 if((memcmp(isdb_t_conv_table[lp].parm_freq, channel, |
47 strlen(channel)) == 0) && | |
48 (strlen(channel) == strlen(isdb_t_conv_table[lp].parm_freq))){ | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
49 return &isdb_t_conv_table[lp]; |
4 | 50 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
51 } |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
52 return NULL; |
0 | 53 } |
54 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
55 QUEUE_T * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
56 create_queue(size_t size) |
0 | 57 { |
4 | 58 QUEUE_T *p_queue; |
8 | 59 int memsize = sizeof(QUEUE_T) + size * sizeof(BUFSZ); |
0 | 60 |
4 | 61 p_queue = (QUEUE_T*)calloc(memsize, sizeof(char)); |
0 | 62 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
63 if(p_queue != NULL) { |
4 | 64 p_queue->size = size; |
65 p_queue->no_full = size; | |
66 p_queue->no_empty = 0; | |
67 pthread_mutex_init(&p_queue->mutex, NULL); | |
68 pthread_cond_init(&p_queue->cond_full, NULL); | |
69 pthread_cond_init(&p_queue->cond_empty, NULL); | |
70 } | |
0 | 71 |
4 | 72 return p_queue; |
0 | 73 } |
74 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
75 void |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
76 destroy_queue(QUEUE_T *p_queue) |
0 | 77 { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
78 if(!p_queue) |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
79 return; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
80 |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
81 pthread_mutex_destroy(&p_queue->mutex); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
82 pthread_cond_destroy(&p_queue->cond_full); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
83 pthread_cond_destroy(&p_queue->cond_empty); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
84 free(p_queue); |
0 | 85 } |
86 | |
3 | 87 /* enqueue data. this function will block if queue is full. */ |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
88 void |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
89 enqueue(QUEUE_T *p_queue, BUFSZ *data) |
0 | 90 { |
4 | 91 pthread_mutex_lock(&p_queue->mutex); |
92 /* entered critical section */ | |
0 | 93 |
4 | 94 /* wait until queue is not full */ |
95 while(!p_queue->no_full) { | |
96 pthread_cond_wait(&p_queue->cond_full, &p_queue->mutex); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
97 fprintf(stderr, "Full\n"); |
4 | 98 } |
0 | 99 |
4 | 100 p_queue->buffer[p_queue->in] = data; |
0 | 101 |
4 | 102 p_queue->in++; |
103 p_queue->in %= p_queue->size; | |
0 | 104 |
4 | 105 p_queue->no_full--; |
106 p_queue->no_empty++; | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
107 |
4 | 108 /* leaving critical section */ |
109 pthread_mutex_unlock(&p_queue->mutex); | |
110 pthread_cond_signal(&p_queue->cond_empty); | |
0 | 111 } |
112 | |
3 | 113 /* dequeue data. this function will block if queue is empty. */ |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
114 BUFSZ * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
115 dequeue(QUEUE_T *p_queue) |
0 | 116 { |
8 | 117 BUFSZ *buffer; |
0 | 118 |
4 | 119 pthread_mutex_lock(&p_queue->mutex); |
120 /* entered the critical section*/ | |
0 | 121 |
4 | 122 /* wait until queue is filled */ |
123 while (!p_queue->no_empty) { | |
124 pthread_cond_wait(&p_queue->cond_empty, &p_queue->mutex); | |
125 } | |
0 | 126 |
4 | 127 /* take buffer address */ |
128 buffer = p_queue->buffer[p_queue->out]; | |
0 | 129 |
6 | 130 /* move location marker to next position */ |
4 | 131 p_queue->out++; |
132 p_queue->out %= p_queue->size; | |
0 | 133 |
4 | 134 /* update flags */ |
135 p_queue->no_full++; | |
136 p_queue->no_empty--; | |
0 | 137 |
4 | 138 /* leaving the critical section */ |
139 pthread_mutex_unlock(&p_queue->mutex); | |
140 pthread_cond_signal(&p_queue->cond_full); | |
0 | 141 |
4 | 142 return buffer; |
0 | 143 } |
144 | |
6 | 145 /* this function will be reader thread */ |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
146 void * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
147 write_func(void *p) |
0 | 148 { |
4 | 149 thread_data *data = (thread_data *)p; |
150 QUEUE_T *p_queue = data->queue; | |
151 decoder *dec = data->decoder; | |
8 | 152 int wfd = data->wfd; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
153 int use_b25 = dec ? 1 : 0; |
8 | 154 int use_udp = data->sock_data ? 1 : 0; |
155 int sfd = 0; | |
156 struct sockaddr *addr = NULL; | |
157 BUFSZ *buf; | |
4 | 158 ARIB_STD_B25_BUFFER sbuf, dbuf; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
159 int code; |
4 | 160 |
8 | 161 if(use_udp) { |
162 sfd = data->sock_data->sfd; | |
163 addr = (struct sockaddr *)&data->sock_data->addr; | |
164 } | |
165 | |
4 | 166 while(1) { |
167 buf = dequeue(p_queue); | |
168 /* no entry in the queue */ | |
169 if(buf == NULL){ | |
170 close(wfd); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
171 break; |
4 | 172 } |
0 | 173 |
4 | 174 sbuf.data = buf->buffer; |
175 sbuf.size = buf->size; | |
176 | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
177 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
178 /* write data to output file*/ |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
179 code = b25_decode(dec, &sbuf, &dbuf); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
180 if(code < 0) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
181 fprintf(stderr, "b25_decode failed\n"); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
182 close(wfd); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
183 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
184 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
185 write(wfd, dbuf.data, dbuf.size); |
8 | 186 |
187 if(use_udp && sfd) { | |
188 sendto(sfd, dbuf.data, dbuf.size, 0, | |
189 addr, sizeof(struct sockaddr_in)); | |
190 } | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
191 free(buf); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
192 } else { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
193 write(wfd, sbuf.data, sbuf.size); |
8 | 194 |
195 if(use_udp && sfd) { | |
196 sendto(sfd, sbuf.data, sbuf.size, 0, | |
197 addr, sizeof(struct sockaddr_in)); | |
198 } | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
199 free(buf); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
200 } |
4 | 201 |
202 /* normal exit */ | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
203 if((f_exit) && (!p_queue->no_empty)) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
204 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
205 code = b25_finish(dec, &sbuf, &dbuf); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
206 if(code < 0) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
207 fprintf(stderr, "b25_finish failed\n"); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
208 close(wfd); |
8 | 209 close(sfd); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
210 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
211 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
212 write(wfd, dbuf.data, dbuf.size); |
8 | 213 |
214 if(use_udp && sfd) { | |
215 sendto(sfd, dbuf.data, dbuf.size, 0, | |
216 addr, sizeof(struct sockaddr_in)); | |
217 } | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
218 } |
4 | 219 close(wfd); |
8 | 220 close(sfd); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
221 break; |
4 | 222 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
223 } |
0 | 224 |
4 | 225 return NULL; |
0 | 226 } |
227 | |
8 | 228 void |
229 show_usage(char *cmd) | |
230 { | |
231 fprintf(stderr, "Usage: %s [--b25 [--round N] [--strip] [--EMM]] [--udp hostname [--port port]] channel recsec destfile\n", cmd); | |
232 } | |
233 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
234 int |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
235 main(int argc, char **argv) |
0 | 236 { |
8 | 237 int tfd, wfd; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
238 int lp; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
239 int recsec; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
240 time_t start_time, cur_time; |
4 | 241 FREQUENCY freq; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
242 ISDB_T_FREQ_CONV_TABLE *ptr; |
4 | 243 pthread_t dequeue_threads; |
244 QUEUE_T *p_queue = create_queue(MAX_QUEUE); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
245 BUFSZ *bufptr; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
246 decoder *dec = NULL; |
4 | 247 thread_data tdata; |
8 | 248 decoder_options dopt = { |
249 4, /* round */ | |
250 0, /* strip */ | |
251 0 /* emm */ | |
252 }; | |
0 | 253 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
254 int result; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
255 int option_index; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
256 struct option long_options[] = { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
257 { "b25", 0, NULL, 'b'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
258 { "B25", 0, NULL, 'b'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
259 { "round", 1, NULL, 'r'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
260 { "strip", 0, NULL, 's'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
261 { "emm", 0, NULL, 'm'}, |
8 | 262 { "EMM", 0, NULL, 'm'}, |
263 { "udp", 1, NULL, 'u'}, | |
264 { "port", 1, NULL, 'p'} | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
265 }; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
266 |
8 | 267 int use_b25 = 0; |
268 int use_udp = 0; | |
269 char *host_to = NULL; | |
270 int port_to = 1234; | |
271 sock_data *sdata = NULL; | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
272 |
8 | 273 while((result = getopt_long(argc, argv, "br:sm" "u:p:", long_options, &option_index)) != -1) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
274 switch(result) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
275 case 'b': |
8 | 276 use_b25 = 1; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
277 fprintf(stderr, "using B25...\n"); |
8 | 278 break; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
279 case 's': |
8 | 280 dopt.strip = 1; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
281 fprintf(stderr, "enable B25 strip\n"); |
8 | 282 break; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
283 case 'm': |
8 | 284 dopt.emm = 1; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
285 fprintf(stderr, "enable B25 emm processing\n"); |
8 | 286 break; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
287 case 'r': |
8 | 288 dopt.round = atoi(optarg); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
289 fprintf(stderr, "set round %d\n", dopt.round); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
290 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
291 case ':': |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
292 fprintf(stderr, "%c needs value\n", result); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
293 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
294 case '?': |
8 | 295 show_usage(argv[0]); |
296 break; | |
297 case 'u': | |
298 use_udp = 1; | |
299 host_to = optarg; | |
300 fprintf(stderr, "UDP destination address: %s\n", host_to); | |
301 break; | |
302 case 'p': | |
303 port_to = atoi(optarg); | |
304 fprintf(stderr, "UDP port: %d\n", port_to); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
305 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
306 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
307 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
308 |
8 | 309 if(argc - optind < 3) { |
310 show_usage(argv[0]); | |
4 | 311 printf("channel =\n"); |
312 printf("151ch¡§BSÄ«Æü\n"); | |
313 printf("161ch¡§BS-i\n"); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
314 printf("191ch¡§WOWOW\n"); |
4 | 315 printf("171ch¡§BS¥¸¥ã¥Ñ¥ó\n"); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
316 printf("200ch¡§¥¹¥¿¡¼¥Á¥ã¥ó¥Í¥ë\n"); |
4 | 317 printf("211ch¡§BS11¥Ç¥¸¥¿¥ë\n"); |
318 printf("222ch¡§TwellV\n"); | |
319 printf("141ch¡§BSÆü¥Æ¥ì\n"); | |
320 printf("181ch¡§BS¥Õ¥¸\n"); | |
321 printf("101ch¡§NHK±ÒÀ±Âè1ÊüÁ÷(BS1)\n"); | |
322 printf("102ch¡§NHK±ÒÀ±Âè2ÊüÁ÷(BS2)\n"); | |
323 printf("103ch¡§NHK¥Ï¥¤¥Ó¥¸¥ç¥ó(BShi)\n"); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
324 printf("CS2-CS24¡§CS¥Á¥ã¥ó¥Í¥ë\n"); |
4 | 325 return 1; |
326 } | |
8 | 327 ptr = searchrecoff(argv[optind]); |
328 if(ptr == NULL){ | |
329 printf("Channel Select Error(%s)\n", argv[optind]); | |
330 return 1; | |
331 } | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
332 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
333 freq.frequencyno = ptr->set_freq; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
334 freq.slot = ptr->add_freq; |
0 | 335 |
4 | 336 if(ptr->type == CHTYPE_SATELLITE) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
337 for(lp = 0; lp < 2; lp++) { |
8 | 338 tfd = open(bsdev[lp], O_RDONLY); |
339 if(tfd >= 0) { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
340 break; |
4 | 341 } |
342 } | |
8 | 343 if(tfd < 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
344 fprintf(stderr, "Device Open Error\n"); |
4 | 345 return 1; |
346 } | |
347 } else { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
348 for(lp = 0; lp < 2; lp++) { |
8 | 349 tfd = open(isdb_t_dev[lp], O_RDONLY); |
350 if(tfd >= 0) { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
351 break; |
4 | 352 } |
353 } | |
8 | 354 if(tfd < 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
355 fprintf(stderr, "Device Open Error\n"); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
356 return 1; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
357 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
358 } |
8 | 359 recsec = atoi(argv[optind + 1]); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
360 |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
361 /* initialize decoder */ |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
362 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
363 dec = b25_startup(&dopt); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
364 if(!dec) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
365 fprintf(stderr, "cannot start b25 decoder\n"); |
7
407af34cfbd9
now falls back to encrypted recording when b25 decoder is not available
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
6
diff
changeset
|
366 fprintf(stderr, "fall back to encrypted recording\n"); |
407af34cfbd9
now falls back to encrypted recording when b25 decoder is not available
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
6
diff
changeset
|
367 use_b25 = 0; |
4 | 368 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
369 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
370 |
8 | 371 /* initialize udp connection */ |
372 if(use_udp) { | |
373 sdata = calloc(1, sizeof(sock_data)); | |
374 struct in_addr ia; | |
375 ia.s_addr = inet_addr(host_to); | |
376 if(ia.s_addr == INADDR_NONE) { | |
377 struct hostent *hoste = gethostbyname(host_to); | |
378 if(!hoste) { | |
379 perror("failed to get host by name"); | |
380 return 1; | |
381 } | |
382 ia.s_addr = *(in_addr_t*) (hoste->h_addr_list[0]); | |
383 } | |
384 sdata->addr.sin_family = AF_INET; | |
385 sdata->addr.sin_port = htons (port_to); | |
386 sdata->addr.sin_addr.s_addr = ia.s_addr; | |
387 if((sdata->sfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { | |
388 perror("socket"); | |
389 return 1; | |
390 } | |
391 } | |
392 | |
4 | 393 /* open output file */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
394 wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666); |
4 | 395 if(wfd < 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
396 fprintf(stderr, "Output File Open Error(%s)\n", argv[optind + 2]); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
397 return 1; |
4 | 398 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
399 |
8 | 400 if(ioctl(tfd, SET_CHANNEL, &freq) < 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
401 fprintf(stderr, "Tuner Select Error\n"); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
402 return 1; |
4 | 403 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
404 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
405 /* make reader thread */ |
4 | 406 tdata.queue = p_queue; |
407 tdata.decoder = dec; | |
8 | 408 tdata.wfd = wfd; |
409 tdata.sock_data = sdata; | |
4 | 410 pthread_create(&dequeue_threads, NULL, write_func, &tdata); |
3 | 411 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
412 /* start recording */ |
8 | 413 if(ioctl(tfd, START_REC, 0) < 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
414 fprintf(stderr, "Tuner Start Error\n"); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
415 return 1; |
4 | 416 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
417 |
4 | 418 time(&start_time); |
0 | 419 |
4 | 420 /* read from tuner */ |
421 while(1) { | |
422 time(&cur_time); | |
423 bufptr = malloc(sizeof(BUFSZ)); | |
8 | 424 bufptr->size = read(tfd, bufptr->buffer, MAX_READ_SIZE); |
4 | 425 if(bufptr->size <= 0) { |
426 if((cur_time - start_time) >= recsec) { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
427 f_exit = TRUE; |
4 | 428 enqueue(p_queue, NULL); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
429 break; |
4 | 430 } else { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
431 continue; |
4 | 432 } |
433 } | |
434 enqueue(p_queue, bufptr); | |
0 | 435 |
4 | 436 /* stop recording */ |
437 if((cur_time - start_time) >= recsec) { | |
8 | 438 ioctl(tfd, STOP_REC, 0); |
4 | 439 /* read remaining data */ |
440 while(1) { | |
441 bufptr = malloc(sizeof(BUFSZ)); | |
8 | 442 bufptr->size = read(tfd, bufptr->buffer, MAX_READ_SIZE); |
4 | 443 if(bufptr->size <= 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
444 f_exit = TRUE; |
4 | 445 enqueue(p_queue, NULL); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
446 break; |
4 | 447 } |
448 enqueue(p_queue, bufptr); | |
449 } | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
450 break; |
4 | 451 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
452 } |
4 | 453 /* close tuner */ |
8 | 454 close(tfd); |
0 | 455 |
6 | 456 /* wait reader thread */ |
4 | 457 pthread_join(dequeue_threads, NULL); |
458 destroy_queue(p_queue); | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
459 |
8 | 460 /* close socket */ |
461 if(use_udp) { | |
462 close(sdata->sfd); | |
463 free(sdata); | |
464 } | |
465 | |
4 | 466 /* release decoder */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
467 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
468 b25_shutdown(dec); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
469 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
470 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
471 return 0; |
0 | 472 } |