annotate recpt1/recpt1.c @ 43:9b36fdf7d5d0

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