Mercurial > pt1.oyama
annotate recpt1/recpt1.c @ 18:84ff6ef710ea
- support stdout for output
- changed representation for indefinite recording to '-'
- handles EPIPE error
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Wed, 25 Feb 2009 17:22:31 +0900 |
parents | 52c7c7c64ba6 |
children | b63f5c100e5a |
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> | |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
9 #include <math.h> |
3 | 10 #include <unistd.h> |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
11 #include <getopt.h> |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
12 #include <signal.h> |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
13 #include <errno.h> |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
14 #include <sys/time.h> |
0 | 15 |
8 | 16 #include <netdb.h> |
17 #include <arpa/inet.h> | |
18 #include <netinet/in.h> | |
19 | |
3 | 20 #include <sys/ioctl.h> |
21 #include "pt1_ioctl.h" | |
0 | 22 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
23 #include "recpt1.h" |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
24 #include "decoder.h" |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
25 |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
26 /* globals */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
27 int f_exit = FALSE; |
0 | 28 |
8 | 29 typedef struct sock_data { |
30 int sfd; /* socket fd */ | |
31 struct sockaddr_in addr; | |
32 } sock_data; | |
33 | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
34 typedef struct reader_thread_data { |
4 | 35 QUEUE_T *queue; |
36 decoder *decoder; | |
8 | 37 int wfd; /* output file fd */ |
38 sock_data *sock_data; | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
39 pthread_t signal_thread; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
40 } reader_thread_data; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
41 |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
42 typedef struct signal_thread_data { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
43 QUEUE_T *queue; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
44 int tfd; /* tuner fd */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
45 } signal_thread_data; |
0 | 46 |
6 | 47 /* lookup frequency conversion table*/ |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
48 ISDB_T_FREQ_CONV_TABLE * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
49 searchrecoff(char *channel) |
0 | 50 { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
51 int lp; |
0 | 52 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
53 for(lp = 0; isdb_t_conv_table[lp].parm_freq != NULL; lp++) { |
6 | 54 /* return entry number in the table when strings match and |
55 * lengths are same. */ | |
4 | 56 if((memcmp(isdb_t_conv_table[lp].parm_freq, channel, |
57 strlen(channel)) == 0) && | |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
58 (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
|
59 return &isdb_t_conv_table[lp]; |
4 | 60 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
61 } |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
62 return NULL; |
0 | 63 } |
64 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
65 QUEUE_T * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
66 create_queue(size_t size) |
0 | 67 { |
4 | 68 QUEUE_T *p_queue; |
8 | 69 int memsize = sizeof(QUEUE_T) + size * sizeof(BUFSZ); |
0 | 70 |
4 | 71 p_queue = (QUEUE_T*)calloc(memsize, sizeof(char)); |
0 | 72 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
73 if(p_queue != NULL) { |
4 | 74 p_queue->size = size; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
75 p_queue->num_avail = size; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
76 p_queue->num_used = 0; |
4 | 77 pthread_mutex_init(&p_queue->mutex, NULL); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
78 pthread_cond_init(&p_queue->cond_avail, NULL); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
79 pthread_cond_init(&p_queue->cond_used, NULL); |
4 | 80 } |
0 | 81 |
4 | 82 return p_queue; |
0 | 83 } |
84 | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
85 void |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
86 destroy_queue(QUEUE_T *p_queue) |
0 | 87 { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
88 if(!p_queue) |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
89 return; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
90 |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
91 pthread_mutex_destroy(&p_queue->mutex); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
92 pthread_cond_destroy(&p_queue->cond_avail); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
93 pthread_cond_destroy(&p_queue->cond_used); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
94 free(p_queue); |
0 | 95 } |
96 | |
3 | 97 /* 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
|
98 void |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
99 enqueue(QUEUE_T *p_queue, BUFSZ *data) |
0 | 100 { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
101 struct timeval now; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
102 struct timespec spec; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
103 |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
104 gettimeofday(&now, NULL); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
105 spec.tv_sec = now.tv_sec + 1; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
106 spec.tv_nsec = now.tv_usec * 1000; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
107 |
4 | 108 pthread_mutex_lock(&p_queue->mutex); |
109 /* entered critical section */ | |
0 | 110 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
111 /* wait while queue is full */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
112 while(p_queue->num_avail == 0) { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
113 pthread_cond_timedwait(&p_queue->cond_avail, |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
114 &p_queue->mutex, &spec); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
115 if(f_exit) |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
116 return; |
4 | 117 } |
0 | 118 |
4 | 119 p_queue->buffer[p_queue->in] = data; |
0 | 120 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
121 /* move position marker for input to next position */ |
4 | 122 p_queue->in++; |
123 p_queue->in %= p_queue->size; | |
0 | 124 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
125 /* update counters */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
126 p_queue->num_avail--; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
127 p_queue->num_used++; |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
128 |
4 | 129 /* leaving critical section */ |
130 pthread_mutex_unlock(&p_queue->mutex); | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
131 pthread_cond_signal(&p_queue->cond_used); |
0 | 132 } |
133 | |
3 | 134 /* 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
|
135 BUFSZ * |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
136 dequeue(QUEUE_T *p_queue) |
0 | 137 { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
138 struct timeval now; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
139 struct timespec spec; |
8 | 140 BUFSZ *buffer; |
0 | 141 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
142 gettimeofday(&now, NULL); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
143 spec.tv_sec = now.tv_sec + 1; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
144 spec.tv_nsec = now.tv_usec * 1000; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
145 |
4 | 146 pthread_mutex_lock(&p_queue->mutex); |
147 /* entered the critical section*/ | |
0 | 148 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
149 /* wait while queue is empty */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
150 while(p_queue->num_used == 0) { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
151 pthread_cond_timedwait(&p_queue->cond_avail, |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
152 &p_queue->mutex, &spec); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
153 if(f_exit) |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
154 return NULL; |
4 | 155 } |
0 | 156 |
4 | 157 /* take buffer address */ |
158 buffer = p_queue->buffer[p_queue->out]; | |
0 | 159 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
160 /* move position marker for output to next position */ |
4 | 161 p_queue->out++; |
162 p_queue->out %= p_queue->size; | |
0 | 163 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
164 /* update counters */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
165 p_queue->num_avail++; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
166 p_queue->num_used--; |
0 | 167 |
4 | 168 /* leaving the critical section */ |
169 pthread_mutex_unlock(&p_queue->mutex); | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
170 pthread_cond_signal(&p_queue->cond_avail); |
0 | 171 |
4 | 172 return buffer; |
0 | 173 } |
174 | |
6 | 175 /* this function will be reader thread */ |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
176 void * |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
177 reader_func(void *p) |
0 | 178 { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
179 reader_thread_data *data = (reader_thread_data *)p; |
4 | 180 QUEUE_T *p_queue = data->queue; |
181 decoder *dec = data->decoder; | |
8 | 182 int wfd = data->wfd; |
13 | 183 int use_b25 = dec ? TRUE : FALSE; |
184 int use_udp = data->sock_data ? TRUE : FALSE; | |
185 int fileless = FALSE; | |
186 int sfd = -1; | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
187 pthread_t signal_thread = data->signal_thread; |
8 | 188 struct sockaddr *addr = NULL; |
189 BUFSZ *buf; | |
4 | 190 ARIB_STD_B25_BUFFER sbuf, dbuf; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
191 int code; |
4 | 192 |
13 | 193 if(wfd == -1) |
194 fileless = TRUE; | |
195 | |
8 | 196 if(use_udp) { |
197 sfd = data->sock_data->sfd; | |
198 addr = (struct sockaddr *)&data->sock_data->addr; | |
199 } | |
200 | |
4 | 201 while(1) { |
13 | 202 |
203 if(fileless) { | |
204 | |
205 buf = dequeue(p_queue); | |
206 /* no entry in the queue */ | |
207 if(buf == NULL) { | |
208 break; | |
209 } | |
210 | |
211 sbuf.data = buf->buffer; | |
212 sbuf.size = buf->size; | |
213 | |
214 if(use_b25) { | |
215 /* write data to output file*/ | |
216 code = b25_decode(dec, &sbuf, &dbuf); | |
217 if(code < 0) { | |
218 fprintf(stderr, "b25_decode failed\n"); | |
219 break; | |
220 } | |
0 | 221 |
13 | 222 if(use_udp && sfd != -1) { |
223 sendto(sfd, dbuf.data, dbuf.size, 0, | |
224 addr, sizeof(struct sockaddr_in)); | |
225 } | |
226 free(buf); | |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
227 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
228 else { |
13 | 229 if(use_udp && sfd != -1) { |
230 sendto(sfd, sbuf.data, sbuf.size, 0, | |
231 addr, sizeof(struct sockaddr_in)); | |
232 } | |
233 free(buf); | |
234 } | |
4 | 235 |
13 | 236 /* normal exit */ |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
237 if((f_exit) && (!p_queue->num_used)) { |
13 | 238 if(use_b25) { |
239 code = b25_finish(dec, &sbuf, &dbuf); | |
240 if(code < 0) { | |
241 fprintf(stderr, "b25_finish failed\n"); | |
242 break; | |
243 } | |
244 | |
245 if(use_udp && sfd != -1) { | |
246 sendto(sfd, dbuf.data, dbuf.size, 0, | |
247 addr, sizeof(struct sockaddr_in)); | |
248 } | |
249 } | |
250 break; | |
251 } | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
252 } /* end of fileless */ |
13 | 253 else { |
254 | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
255 ssize_t wc; |
13 | 256 buf = dequeue(p_queue); |
257 /* no entry in the queue */ | |
258 if(buf == NULL) { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
259 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
260 } |
8 | 261 |
13 | 262 sbuf.data = buf->buffer; |
263 sbuf.size = buf->size; | |
8 | 264 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
265 if(use_b25) { |
13 | 266 /* write data to output file*/ |
267 code = b25_decode(dec, &sbuf, &dbuf); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
268 if(code < 0) { |
13 | 269 fprintf(stderr, "b25_decode failed\n"); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
270 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
271 } |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
272 wc = write(wfd, dbuf.data, dbuf.size); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
273 if(wc <= 0 && errno == EPIPE) { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
274 pthread_kill(signal_thread, SIGPIPE); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
275 } |
8 | 276 |
13 | 277 if(use_udp && sfd != -1) { |
8 | 278 sendto(sfd, dbuf.data, dbuf.size, 0, |
279 addr, sizeof(struct sockaddr_in)); | |
280 } | |
13 | 281 free(buf); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
282 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
283 else { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
284 wc = write(wfd, sbuf.data, sbuf.size); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
285 if(wc <= 0 && errno == EPIPE) { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
286 pthread_kill(signal_thread, SIGPIPE); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
287 } |
13 | 288 |
289 if(use_udp && sfd != -1) { | |
290 sendto(sfd, sbuf.data, sbuf.size, 0, | |
291 addr, sizeof(struct sockaddr_in)); | |
292 } | |
293 free(buf); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
294 } |
13 | 295 |
296 /* normal exit */ | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
297 if((f_exit) && (!p_queue->num_used)) { |
13 | 298 if(use_b25) { |
299 code = b25_finish(dec, &sbuf, &dbuf); | |
300 if(code < 0) { | |
301 fprintf(stderr, "b25_finish failed\n"); | |
302 break; | |
303 } | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
304 wc = write(wfd, dbuf.data, dbuf.size); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
305 if(wc <= 0 && errno == EPIPE) { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
306 pthread_kill(signal_thread, SIGPIPE); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
307 } |
13 | 308 |
309 if(use_udp && sfd != -1) { | |
310 sendto(sfd, dbuf.data, dbuf.size, 0, | |
311 addr, sizeof(struct sockaddr_in)); | |
312 } | |
313 } | |
314 break; | |
315 } | |
4 | 316 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
317 } |
0 | 318 |
4 | 319 return NULL; |
0 | 320 } |
321 | |
8 | 322 void |
323 show_usage(char *cmd) | |
324 { | |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
325 fprintf(stderr, "\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
326 fprintf(stderr, "Usage: \n%s [--b25 [--round N] [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] channel recsec destfile\n", cmd); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
327 fprintf(stderr, "\n"); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
328 fprintf(stderr, "Remarks:\n"); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
329 fprintf(stderr, "if recsec is '-', records indefinitely.\n"); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
330 fprintf(stderr, "if destfile is '-', stdout is used for output.\n"); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
331 fprintf(stderr, "\n"); |
13 | 332 } |
333 | |
334 void | |
15 | 335 show_options(void) |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
336 { |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
337 fprintf(stderr, "Options:\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
338 fprintf(stderr, "--b25: Decrypt using BCAS card\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
339 fprintf(stderr, " --round N: Specify round number\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
340 fprintf(stderr, " --strip: Strip null stream\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
341 fprintf(stderr, " --EMM: Instruct EMM operation\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
342 fprintf(stderr, "--udp: Turn on udp broadcasting\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
343 fprintf(stderr, " --addr hostname: Hostname or address to connect\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
344 fprintf(stderr, " --port portnumber: Port number to connect\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
345 fprintf(stderr, "--help: Show this help\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
346 fprintf(stderr, "\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
347 } |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
348 void |
13 | 349 show_channels(void) |
350 { | |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
351 fprintf(stderr, "Available Channels:\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
352 fprintf(stderr, "13-52¡§Terrestrial Channels\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
353 fprintf(stderr, "151ch¡§BS Asahi\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
354 fprintf(stderr, "161ch¡§BS-i\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
355 fprintf(stderr, "191ch¡§WOWOW\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
356 fprintf(stderr, "171ch¡§BS Japan\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
357 fprintf(stderr, "200ch¡§Star Channel\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
358 fprintf(stderr, "211ch¡§BS11 Digital\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
359 fprintf(stderr, "222ch¡§TwellV\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
360 fprintf(stderr, "141ch¡§BS Nittele\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
361 fprintf(stderr, "181ch¡§BS Fuji\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
362 fprintf(stderr, "101ch¡§NHK BS1\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
363 fprintf(stderr, "102ch¡§NHK BS2\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
364 fprintf(stderr, "103ch¡§NHK BShi\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
365 fprintf(stderr, "CS2-CS24¡§CS Channels\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
366 fprintf(stderr, "\n"); |
8 | 367 } |
368 | |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
369 float |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
370 getsignal_isdb_s(int signal) |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
371 { |
13 | 372 /* apply linear interpolation */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
373 static const float afLevelTable[] = { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
374 24.07f, // 00 00 0 24.07dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
375 24.07f, // 10 00 4096 24.07dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
376 18.61f, // 20 00 8192 18.61dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
377 15.21f, // 30 00 12288 15.21dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
378 12.50f, // 40 00 16384 12.50dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
379 10.19f, // 50 00 20480 10.19dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
380 8.140f, // 60 00 24576 8.140dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
381 6.270f, // 70 00 28672 6.270dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
382 4.550f, // 80 00 32768 4.550dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
383 3.730f, // 88 00 34816 3.730dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
384 3.630f, // 88 FF 35071 3.630dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
385 2.940f, // 90 00 36864 2.940dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
386 1.420f, // A0 00 40960 1.420dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
387 0.000f // B0 00 45056 -0.01dB |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
388 }; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
389 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
390 unsigned char sigbuf[4]; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
391 memset(sigbuf, '\0', sizeof(sigbuf)); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
392 sigbuf[0] = (((signal & 0xFF00) >> 8) & 0XFF); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
393 sigbuf[1] = (signal & 0xFF); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
394 |
13 | 395 /* calculate signal level */ |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
396 if(sigbuf[0] <= 0x10U) { |
13 | 397 /* clipped maximum */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
398 return 24.07f; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
399 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
400 else if (sigbuf[0] >= 0xB0U) { |
13 | 401 /* clipped minimum */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
402 return 0.0f; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
403 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
404 else { |
13 | 405 /* linear interpolation */ |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
406 const float fMixRate = |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
407 (float)(((unsigned short)(sigbuf[0] & 0x0FU) << 8) | |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
408 (unsigned short)sigbuf[0]) / 4096.0f; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
409 return afLevelTable[sigbuf[0] >> 4] * (1.0f - fMixRate) + |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
410 afLevelTable[(sigbuf[0] >> 4) + 0x01U] * fMixRate; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
411 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
412 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
413 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
414 void |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
415 calc_cn(int fd, int type) |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
416 { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
417 int rc ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
418 double P ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
419 double CNR; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
420 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
421 if(ioctl(fd, GET_SIGNAL_STRENGTH, &rc) < 0) { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
422 printf("Tuner Select Error\n"); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
423 return ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
424 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
425 |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
426 if(type == CHTYPE_GROUND) { |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
427 P = log10(5505024/(double)rc) * 10; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
428 CNR = (0.000024 * P * P * P * P) - (0.0016 * P * P * P) + |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
429 (0.0398 * P * P) + (0.5491 * P)+3.0965; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
430 printf("Signal=%fdB\n", CNR); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
431 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
432 else { |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
433 CNR = getsignal_isdb_s(rc); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
434 printf("Signal=%fdB\n", CNR); |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
435 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
436 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
437 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
438 void |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
439 cleanup(signal_thread_data *sdata) |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
440 { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
441 /* stop recording */ |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
442 ioctl(sdata->tfd, STOP_REC, 0); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
443 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
444 /* restore LNB state */ |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
445 #if 0 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
446 if(ptr->type == CHTYPE_SATELLITE) { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
447 if(ioctl(tfd, LNB_DISABLE, 0) < 0) { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
448 return 0 ; |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
449 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
450 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
451 #endif |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
452 /* xxx need mutex? */ |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
453 f_exit = TRUE; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
454 |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
455 pthread_cond_signal(&sdata->queue->cond_avail); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
456 pthread_cond_signal(&sdata->queue->cond_used); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
457 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
458 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
459 /* will be signal handler thread */ |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
460 void * |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
461 process_signals(void *data) |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
462 { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
463 sigset_t waitset; |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
464 int sig; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
465 signal_thread_data *sdata; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
466 sdata = (signal_thread_data *)data; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
467 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
468 sigemptyset(&waitset); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
469 sigaddset(&waitset, SIGPIPE); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
470 sigaddset(&waitset, SIGINT); |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
471 sigaddset(&waitset, SIGTERM); |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
472 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
473 sigwait(&waitset, &sig); |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
474 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
475 switch(sig) { |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
476 case SIGPIPE: |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
477 fprintf(stderr, "\nSIGPIPE received. cleaning up...\n"); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
478 cleanup(sdata); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
479 break; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
480 case SIGINT: |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
481 fprintf(stderr, "\nSIGINT received. cleaning up...\n"); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
482 cleanup(sdata); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
483 break; |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
484 case SIGTERM: |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
485 fprintf(stderr, "\nSIGTERM received. cleaning up...\n"); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
486 cleanup(sdata); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
487 break; |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
488 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
489 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
490 return NULL; /* dummy */ |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
491 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
492 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
493 void |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
494 init_signal_handlers(pthread_t *signal_thread, signal_thread_data *sdata) |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
495 { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
496 sigset_t blockset; |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
497 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
498 sigemptyset(&blockset); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
499 sigaddset(&blockset, SIGPIPE); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
500 sigaddset(&blockset, SIGINT); |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
501 sigaddset(&blockset, SIGTERM); |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
502 |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
503 if(pthread_sigmask(SIG_BLOCK, &blockset, NULL)) |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
504 fprintf(stderr, "pthread_sigmask() failed.\n"); |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
505 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
506 pthread_create(signal_thread, NULL, process_signals, sdata); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
507 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
508 |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
509 int |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
510 main(int argc, char **argv) |
0 | 511 { |
8 | 512 int tfd, wfd; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
513 int lp; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
514 int recsec; |
13 | 515 int indefinite = FALSE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
516 time_t start_time, cur_time; |
4 | 517 FREQUENCY freq; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
518 ISDB_T_FREQ_CONV_TABLE *ptr; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
519 pthread_t dequeue_thread; |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
520 pthread_t signal_thread; |
4 | 521 QUEUE_T *p_queue = create_queue(MAX_QUEUE); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
522 BUFSZ *bufptr; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
523 decoder *dec = NULL; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
524 static reader_thread_data tdata; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
525 static signal_thread_data sdata; |
8 | 526 decoder_options dopt = { |
527 4, /* round */ | |
528 0, /* strip */ | |
529 0 /* emm */ | |
530 }; | |
0 | 531 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
532 int result; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
533 int option_index; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
534 struct option long_options[] = { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
535 { "b25", 0, NULL, 'b'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
536 { "B25", 0, NULL, 'b'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
537 { "round", 1, NULL, 'r'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
538 { "strip", 0, NULL, 's'}, |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
539 { "emm", 0, NULL, 'm'}, |
8 | 540 { "EMM", 0, NULL, 'm'}, |
13 | 541 { "udp", 0, NULL, 'u'}, |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
542 { "addr", 1, NULL, 'a'}, |
13 | 543 { "port", 1, NULL, 'p'}, |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
544 { "help", 0, NULL, 'h'}, |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
545 {0, 0, NULL, 0} /* terminate */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
546 }; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
547 |
13 | 548 int use_b25 = FALSE; |
549 int use_udp = FALSE; | |
550 int fileless = FALSE; | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
551 int use_stdout = FALSE; |
8 | 552 char *host_to = NULL; |
553 int port_to = 1234; | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
554 sock_data *sockdata = NULL; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
555 |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
556 while((result = getopt_long(argc, argv, "br:smua:p:h", |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
557 long_options, &option_index)) != -1) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
558 switch(result) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
559 case 'b': |
13 | 560 use_b25 = TRUE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
561 fprintf(stderr, "using B25...\n"); |
8 | 562 break; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
563 case 's': |
13 | 564 dopt.strip = TRUE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
565 fprintf(stderr, "enable B25 strip\n"); |
8 | 566 break; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
567 case 'm': |
13 | 568 dopt.emm = TRUE; |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
569 fprintf(stderr, "enable B25 emm processing\n"); |
8 | 570 break; |
13 | 571 case 'u': |
572 use_udp = TRUE; | |
573 host_to = "localhost"; | |
574 fprintf(stderr, "enable UDP broadcasting\n"); | |
575 break; | |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
576 case 'h': |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
577 show_usage(argv[0]); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
578 show_options(); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
579 show_channels(); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
580 exit(0); |
13 | 581 break; |
582 /* following options require argument */ | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
583 case 'r': |
8 | 584 dopt.round = atoi(optarg); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
585 fprintf(stderr, "set round %d\n", dopt.round); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
586 break; |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
587 case 'a': |
13 | 588 use_udp = TRUE; |
8 | 589 host_to = optarg; |
590 fprintf(stderr, "UDP destination address: %s\n", host_to); | |
591 break; | |
592 case 'p': | |
593 port_to = atoi(optarg); | |
594 fprintf(stderr, "UDP port: %d\n", port_to); | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
595 break; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
596 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
597 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
598 |
8 | 599 if(argc - optind < 3) { |
13 | 600 if(argc - optind == 2 && use_udp) { |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
601 fprintf(stderr, "Fileless UDP broadcasting\n"); |
13 | 602 fileless = TRUE; |
603 wfd = -1; | |
604 } | |
605 else { | |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
606 fprintf(stderr, "Arguments are necessary!\n"); |
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
607 fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]); |
13 | 608 return 1; |
609 } | |
4 | 610 } |
13 | 611 |
612 /* get channel */ | |
8 | 613 ptr = searchrecoff(argv[optind]); |
14
cad940a903f5
- replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
13
diff
changeset
|
614 if(ptr == NULL) { |
13 | 615 fprintf(stderr, "Channel Select Error(%s)\n", argv[optind]); |
8 | 616 return 1; |
617 } | |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
618 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
619 freq.frequencyno = ptr->set_freq; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
620 freq.slot = ptr->add_freq; |
0 | 621 |
4 | 622 if(ptr->type == CHTYPE_SATELLITE) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
623 for(lp = 0; lp < 2; lp++) { |
8 | 624 tfd = open(bsdev[lp], O_RDONLY); |
625 if(tfd >= 0) { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
626 break; |
4 | 627 } |
628 } | |
8 | 629 if(tfd < 0) { |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
630 fprintf(stderr, "Cannot open tuner\n"); |
4 | 631 return 1; |
632 } | |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
633 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
634 else { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
635 for(lp = 0; lp < 2; lp++) { |
8 | 636 tfd = open(isdb_t_dev[lp], O_RDONLY); |
637 if(tfd >= 0) { | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
638 break; |
4 | 639 } |
640 } | |
8 | 641 if(tfd < 0) { |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
642 fprintf(stderr, "Cannot open tuner\n"); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
643 return 1; |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
644 } |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
645 } |
13 | 646 |
647 /* get recsec */ | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
648 char *recsecstr = argv[optind + 1]; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
649 if(!strcmp("-", recsecstr)) { |
13 | 650 indefinite = TRUE; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
651 recsec = -1; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
652 } |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
653 else { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
654 recsec = atoi(recsecstr); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
655 } |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
656 |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
657 /* open output file */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
658 char *destfile = argv[optind + 2]; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
659 if(!strcmp("-", destfile)) { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
660 use_stdout = TRUE; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
661 wfd = 1; /* stdout */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
662 } |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
663 else { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
664 if(!fileless) { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
665 wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
666 if(wfd < 0) { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
667 fprintf(stderr, "Could not open output file(%s)\n", argv[optind + 2]); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
668 return 1; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
669 } |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
670 } |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
671 } |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
672 |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
673 /* initialize decoder */ |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
674 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
675 dec = b25_startup(&dopt); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
676 if(!dec) { |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
677 fprintf(stderr, "Could not start b25 decoder\n"); |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
678 fprintf(stderr, "Fall back to encrypted recording\n"); |
7
407af34cfbd9
now falls back to encrypted recording when b25 decoder is not available
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
6
diff
changeset
|
679 use_b25 = 0; |
4 | 680 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
681 } |
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
682 |
8 | 683 /* initialize udp connection */ |
684 if(use_udp) { | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
685 sockdata = calloc(1, sizeof(sock_data)); |
8 | 686 struct in_addr ia; |
687 ia.s_addr = inet_addr(host_to); | |
688 if(ia.s_addr == INADDR_NONE) { | |
689 struct hostent *hoste = gethostbyname(host_to); | |
690 if(!hoste) { | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
691 perror("gethostbyname"); |
8 | 692 return 1; |
693 } | |
694 ia.s_addr = *(in_addr_t*) (hoste->h_addr_list[0]); | |
695 } | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
696 sockdata->addr.sin_family = AF_INET; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
697 sockdata->addr.sin_port = htons (port_to); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
698 sockdata->addr.sin_addr.s_addr = ia.s_addr; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
699 if((sockdata->sfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { |
8 | 700 perror("socket"); |
701 return 1; | |
702 } | |
703 } | |
704 | |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
705 /* setup tuner */ |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
706 if(ptr->type == CHTYPE_SATELLITE) { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
707 if(ioctl(tfd, LNB_ENABLE, 0) < 0) { |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
708 return 0 ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
709 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
710 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
711 |
8 | 712 if(ioctl(tfd, SET_CHANNEL, &freq) < 0) { |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
713 fprintf(stderr, "Could not tune to the specified channel\n"); |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
714 calc_cn(tfd, ptr->type); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
715 return 1; |
4 | 716 } |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
717 calc_cn(tfd, ptr->type); |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
718 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
719 /* init signal handler thread */ |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
720 sdata.queue = p_queue; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
721 sdata.tfd = tfd; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
722 init_signal_handlers(&signal_thread, &sdata); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
723 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
724 /* make reader thread */ |
4 | 725 tdata.queue = p_queue; |
726 tdata.decoder = dec; | |
8 | 727 tdata.wfd = wfd; |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
728 tdata.sock_data = sockdata; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
729 tdata.signal_thread = signal_thread; |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
730 pthread_create(&dequeue_thread, NULL, reader_func, &tdata); |
3 | 731 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
732 /* start recording */ |
8 | 733 if(ioctl(tfd, START_REC, 0) < 0) { |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
734 fprintf(stderr, "Tuner could not start recording\n"); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
735 return 1; |
4 | 736 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
737 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
738 fprintf(stderr, "Recording...\n"); |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
739 |
4 | 740 time(&start_time); |
0 | 741 |
4 | 742 /* read from tuner */ |
743 while(1) { | |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
744 if(f_exit) |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
745 break; |
4 | 746 time(&cur_time); |
747 bufptr = malloc(sizeof(BUFSZ)); | |
8 | 748 bufptr->size = read(tfd, bufptr->buffer, MAX_READ_SIZE); |
4 | 749 if(bufptr->size <= 0) { |
13 | 750 if((cur_time - start_time) >= recsec && !indefinite) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
751 f_exit = TRUE; |
4 | 752 enqueue(p_queue, NULL); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
753 break; |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
754 } |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
755 else { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
756 continue; |
4 | 757 } |
758 } | |
759 enqueue(p_queue, bufptr); | |
0 | 760 |
4 | 761 /* stop recording */ |
13 | 762 if((cur_time - start_time) >= recsec && !indefinite) { |
8 | 763 ioctl(tfd, STOP_REC, 0); |
4 | 764 /* read remaining data */ |
765 while(1) { | |
766 bufptr = malloc(sizeof(BUFSZ)); | |
8 | 767 bufptr->size = read(tfd, bufptr->buffer, MAX_READ_SIZE); |
4 | 768 if(bufptr->size <= 0) { |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
769 f_exit = TRUE; |
4 | 770 enqueue(p_queue, NULL); |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
771 break; |
4 | 772 } |
773 enqueue(p_queue, bufptr); | |
774 } | |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
775 break; |
4 | 776 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
777 } |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
778 |
4 | 779 /* close tuner */ |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
780 if(ptr->type == CHTYPE_SATELLITE) { |
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
781 if(ioctl(tfd, LNB_DISABLE, 0) < 0) { |
11
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
782 return 0 ; |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
783 } |
4615eaf04415
support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
784 } |
8 | 785 close(tfd); |
0 | 786 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
787 /* wait for threads */ |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
788 pthread_join(dequeue_thread, NULL); |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
789 pthread_join(signal_thread, NULL); |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
790 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
791 /* release queue */ |
4 | 792 destroy_queue(p_queue); |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
793 |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
794 /* close output file */ |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
795 if(!use_stdout) |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
796 close(wfd); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
797 |
16
ecb85bde67b1
added signal handler to perform cleaning up when it receives a signal.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
15
diff
changeset
|
798 /* free socket data */ |
18
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
799 if(use_udp) { |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
800 close(sockdata->sfd); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
801 free(sockdata); |
84ff6ef710ea
- support stdout for output
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
17
diff
changeset
|
802 } |
8 | 803 |
4 | 804 /* release decoder */ |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
805 if(use_b25) { |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
806 b25_shutdown(dec); |
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
807 } |
2
8ac7c59fefc9
added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
1
diff
changeset
|
808 |
5
97fd2315114e
- now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
4
diff
changeset
|
809 return 0; |
0 | 810 } |