annotate recpt1/recpt1.c @ 15:1b0883b02b4f

fixed typo
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 24 Feb 2009 23:26:22 +0900
parents cad940a903f5
children ecb85bde67b1
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>
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
12
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
13 #include <netdb.h>
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
14 #include <arpa/inet.h>
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
15 #include <netinet/in.h>
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
16
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
17 #include <sys/ioctl.h>
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
18 #include "pt1_ioctl.h"
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
19
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
20 #include "recpt1.h"
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
21 #include "decoder.h"
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
22
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
23 /* globals */
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
24 int f_exit = FALSE;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
25
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
26 typedef struct sock_data {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
27 int sfd; /* socket fd */
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
28 struct sockaddr_in addr;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
29 } sock_data;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
30
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
31 typedef struct thread_data {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
32 QUEUE_T *queue;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
33 decoder *decoder;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
34 int wfd; /* output file fd */
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
35 sock_data *sock_data;
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
36 } thread_data;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
37
6
d898fd27547f cleanups
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 5
diff changeset
38 /* lookup frequency conversion table*/
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
39 ISDB_T_FREQ_CONV_TABLE *
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
40 searchrecoff(char *channel)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
41 {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
42 int lp;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
43
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
44 for(lp = 0; isdb_t_conv_table[lp].parm_freq != NULL; lp++){
6
d898fd27547f cleanups
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 5
diff changeset
45 /* return entry number in the table when strings match and
d898fd27547f cleanups
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 5
diff changeset
46 * lengths are same. */
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
47 if((memcmp(isdb_t_conv_table[lp].parm_freq, channel,
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
48 strlen(channel)) == 0) &&
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
49 (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
50 return &isdb_t_conv_table[lp];
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
51 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
52 }
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
53 return NULL;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
54 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
55
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
56 QUEUE_T *
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
57 create_queue(size_t size)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
58 {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
59 QUEUE_T *p_queue;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
60 int memsize = sizeof(QUEUE_T) + size * sizeof(BUFSZ);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
61
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
62 p_queue = (QUEUE_T*)calloc(memsize, sizeof(char));
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
63
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
64 if(p_queue != NULL) {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
65 p_queue->size = size;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
66 p_queue->no_full = size;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
67 p_queue->no_empty = 0;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
68 pthread_mutex_init(&p_queue->mutex, NULL);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
69 pthread_cond_init(&p_queue->cond_full, NULL);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
70 pthread_cond_init(&p_queue->cond_empty, NULL);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
71 }
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 return p_queue;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
74 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
75
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
76 void
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
77 destroy_queue(QUEUE_T *p_queue)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
78 {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
79 if(!p_queue)
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
80 return;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
81
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
82 pthread_mutex_destroy(&p_queue->mutex);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
83 pthread_cond_destroy(&p_queue->cond_full);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
84 pthread_cond_destroy(&p_queue->cond_empty);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
85 free(p_queue);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
86 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
87
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
88 /* 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
89 void
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
90 enqueue(QUEUE_T *p_queue, BUFSZ *data)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
91 {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
92 pthread_mutex_lock(&p_queue->mutex);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
93 /* entered critical section */
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
94
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
95 /* wait until queue is not full */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
96 while(!p_queue->no_full) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
97 pthread_cond_wait(&p_queue->cond_full, &p_queue->mutex);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
98 fprintf(stderr, "Full\n");
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
99 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
100
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
101 p_queue->buffer[p_queue->in] = data;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
102
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
103 p_queue->in++;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
104 p_queue->in %= p_queue->size;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
105
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
106 p_queue->no_full--;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
107 p_queue->no_empty++;
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
108
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
109 /* leaving critical section */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
110 pthread_mutex_unlock(&p_queue->mutex);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
111 pthread_cond_signal(&p_queue->cond_empty);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
112 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
113
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
114 /* 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
115 BUFSZ *
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
116 dequeue(QUEUE_T *p_queue)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
117 {
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
118 BUFSZ *buffer;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
119
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
120 pthread_mutex_lock(&p_queue->mutex);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
121 /* entered the critical section*/
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
122
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
123 /* wait until queue is filled */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
124 while (!p_queue->no_empty) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
125 pthread_cond_wait(&p_queue->cond_empty, &p_queue->mutex);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
126 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
127
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
128 /* take buffer address */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
129 buffer = p_queue->buffer[p_queue->out];
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
130
6
d898fd27547f cleanups
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 5
diff changeset
131 /* move location marker to next position */
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
132 p_queue->out++;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
133 p_queue->out %= p_queue->size;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
134
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
135 /* update flags */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
136 p_queue->no_full++;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
137 p_queue->no_empty--;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
138
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
139 /* leaving the critical section */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
140 pthread_mutex_unlock(&p_queue->mutex);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
141 pthread_cond_signal(&p_queue->cond_full);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
142
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
143 return buffer;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
144 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
145
6
d898fd27547f cleanups
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 5
diff changeset
146 /* this function will be reader thread */
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
147 void *
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
148 write_func(void *p)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
149 {
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
150 thread_data *data = (thread_data *)p;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
151 QUEUE_T *p_queue = data->queue;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
152 decoder *dec = data->decoder;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
153 int wfd = data->wfd;
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
154 int use_b25 = dec ? TRUE : FALSE;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
155 int use_udp = data->sock_data ? TRUE : FALSE;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
156 int fileless = FALSE;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
157 int sfd = -1;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
158 struct sockaddr *addr = NULL;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
159 BUFSZ *buf;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
160 ARIB_STD_B25_BUFFER sbuf, dbuf;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
161 int code;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
162
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
163 if(wfd == -1)
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
164 fileless = TRUE;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
165
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
166 if(use_udp) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
167 sfd = data->sock_data->sfd;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
168 addr = (struct sockaddr *)&data->sock_data->addr;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
169 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
170
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
171 while(1) {
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
172
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
173 if(fileless) {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
174
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
175 buf = dequeue(p_queue);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
176 /* no entry in the queue */
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
177 if(buf == NULL) {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
178 break;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
179 }
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
180
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
181 sbuf.data = buf->buffer;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
182 sbuf.size = buf->size;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
183
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
184 if(use_b25) {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
185 /* write data to output file*/
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
186 code = b25_decode(dec, &sbuf, &dbuf);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
187 if(code < 0) {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
188 fprintf(stderr, "b25_decode failed\n");
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
189 break;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
190 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
191
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
192 if(use_udp && sfd != -1) {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
193 sendto(sfd, dbuf.data, dbuf.size, 0,
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
194 addr, sizeof(struct sockaddr_in));
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
195 }
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
196 free(buf);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
197 } else {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
198 if(use_udp && sfd != -1) {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
199 sendto(sfd, sbuf.data, sbuf.size, 0,
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
200 addr, sizeof(struct sockaddr_in));
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
201 }
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
202 free(buf);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
203 }
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
204
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
205 /* normal exit */
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
206 if((f_exit) && (!p_queue->no_empty)) {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
207 if(use_b25) {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
208 code = b25_finish(dec, &sbuf, &dbuf);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
209 if(code < 0) {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
210 fprintf(stderr, "b25_finish failed\n");
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
211 close(sfd);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
212 break;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
213 }
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
214
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
215 if(use_udp && sfd != -1) {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
216 sendto(sfd, dbuf.data, dbuf.size, 0,
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
217 addr, sizeof(struct sockaddr_in));
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
218 }
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
219 }
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
220 close(sfd);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
221 break;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
222 }
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
223 } /* fileless */
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
224 else {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
225
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
226 buf = dequeue(p_queue);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
227 /* no entry in the queue */
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
228 if(buf == NULL) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
229 close(wfd);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
230 break;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
231 }
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
232
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
233 sbuf.data = buf->buffer;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
234 sbuf.size = buf->size;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
235
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
236 if(use_b25) {
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
237 /* write data to output file*/
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
238 code = b25_decode(dec, &sbuf, &dbuf);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
239 if(code < 0) {
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
240 fprintf(stderr, "b25_decode failed\n");
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
241 close(wfd);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
242 break;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
243 }
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
244 write(wfd, dbuf.data, dbuf.size);
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
245
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
246 if(use_udp && sfd != -1) {
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
247 sendto(sfd, dbuf.data, dbuf.size, 0,
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
248 addr, sizeof(struct sockaddr_in));
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
249 }
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
250 free(buf);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
251 } else {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
252 write(wfd, sbuf.data, sbuf.size);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
253
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
254 if(use_udp && sfd != -1) {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
255 sendto(sfd, sbuf.data, sbuf.size, 0,
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
256 addr, sizeof(struct sockaddr_in));
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
257 }
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
258 free(buf);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
259 }
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
260
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
261 /* normal exit */
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
262 if((f_exit) && (!p_queue->no_empty)) {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
263 if(use_b25) {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
264 code = b25_finish(dec, &sbuf, &dbuf);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
265 if(code < 0) {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
266 fprintf(stderr, "b25_finish failed\n");
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
267 close(wfd);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
268 close(sfd);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
269 break;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
270 }
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
271 write(wfd, dbuf.data, dbuf.size);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
272
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
273 if(use_udp && sfd != -1) {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
274 sendto(sfd, dbuf.data, dbuf.size, 0,
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
275 addr, sizeof(struct sockaddr_in));
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
276 }
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
277 }
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
278 close(wfd);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
279 close(sfd);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
280 break;
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 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
283 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
284
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
285 return NULL;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
286 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
287
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
288 void
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
289 show_usage(char *cmd)
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
290 {
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
291 fprintf(stderr, "\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
292 fprintf(stderr, "Usage: \n%s [--b25 [--round N] [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] channel recsec destfile\n", cmd);
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
293 fprintf(stderr, "\n");
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
294 }
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
295
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
296 void
15
1b0883b02b4f fixed typo
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 14
diff changeset
297 show_options(void)
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
298 {
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
299 fprintf(stderr, "Options:\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
300 fprintf(stderr, "--b25: Decrypt using BCAS card\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
301 fprintf(stderr, " --round N: Specify round number\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
302 fprintf(stderr, " --strip: Strip null stream\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
303 fprintf(stderr, " --EMM: Instruct EMM operation\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
304 fprintf(stderr, "--udp: Turn on udp broadcasting\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
305 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
306 fprintf(stderr, " --port portnumber: Port number to connect\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
307 fprintf(stderr, "--help: Show this help\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
308 fprintf(stderr, "\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
309 }
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
310 void
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
311 show_channels(void)
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
312 {
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
313 fprintf(stderr, "Available Channels:\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
314 fprintf(stderr, "13-52¡§Terrestrial Channels\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
315 fprintf(stderr, "151ch¡§BS Asahi\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
316 fprintf(stderr, "161ch¡§BS-i\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
317 fprintf(stderr, "191ch¡§WOWOW\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
318 fprintf(stderr, "171ch¡§BS Japan\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
319 fprintf(stderr, "200ch¡§Star Channel\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
320 fprintf(stderr, "211ch¡§BS11 Digital\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
321 fprintf(stderr, "222ch¡§TwellV\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
322 fprintf(stderr, "141ch¡§BS Nittele\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
323 fprintf(stderr, "181ch¡§BS Fuji\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
324 fprintf(stderr, "101ch¡§NHK BS1\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
325 fprintf(stderr, "102ch¡§NHK BS2\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
326 fprintf(stderr, "103ch¡§NHK BShi\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
327 fprintf(stderr, "CS2-CS24¡§CS Channels\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
328 fprintf(stderr, "\n");
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
329 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
330
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
331 float
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
332 getsignal_isdb_s(int signal)
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
333 {
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
334 /* apply linear interpolation */
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
335 static const float afLevelTable[] = {
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
336 24.07f, // 00 00 0 24.07dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
337 24.07f, // 10 00 4096 24.07dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
338 18.61f, // 20 00 8192 18.61dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
339 15.21f, // 30 00 12288 15.21dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
340 12.50f, // 40 00 16384 12.50dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
341 10.19f, // 50 00 20480 10.19dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
342 8.140f, // 60 00 24576 8.140dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
343 6.270f, // 70 00 28672 6.270dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
344 4.550f, // 80 00 32768 4.550dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
345 3.730f, // 88 00 34816 3.730dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
346 3.630f, // 88 FF 35071 3.630dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
347 2.940f, // 90 00 36864 2.940dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
348 1.420f, // A0 00 40960 1.420dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
349 0.000f // B0 00 45056 -0.01dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
350 };
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
351
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
352 unsigned char sigbuf[4];
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
353 memset(sigbuf, '\0', sizeof(sigbuf));
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
354 sigbuf[0] = (((signal & 0xFF00) >> 8) & 0XFF);
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
355 sigbuf[1] = (signal & 0xFF);
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
356
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
357 /* calculate signal level */
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
358 if(sigbuf[0] <= 0x10U){
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
359 /* clipped maximum */
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
360 return 24.07f;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
361 } else if (sigbuf[0] >= 0xB0U) {
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
362 /* clipped minimum */
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
363 return 0.0f;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
364 } else {
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
365 /* linear interpolation */
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
366 const float fMixRate =
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
367 (float)(((unsigned short)(sigbuf[0] & 0x0FU) << 8) |
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
368 (unsigned short)sigbuf[0]) / 4096.0f;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
369 return afLevelTable[sigbuf[0] >> 4] * (1.0f - fMixRate) +
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
370 afLevelTable[(sigbuf[0] >> 4) + 0x01U] * fMixRate;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
371 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
372 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
373
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
374 void
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
375 calc_cn(int fd, int type)
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 int rc ;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
378 double P ;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
379 double CNR;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
380
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
381 if(ioctl(fd, GET_SIGNAL_STRENGTH, &rc) < 0) {
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
382 printf("Tuner Select Error\n");
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
383 return ;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
384 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
385
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
386 if(type == CHTYPE_GROUND) {
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
387 P = log10(5505024/(double)rc) * 10;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
388 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
389 (0.0398 * P * P) + (0.5491 * P)+3.0965;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
390 printf("Signal=%fdB\n", CNR);
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
391 } else {
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
392 CNR = getsignal_isdb_s(rc);
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
393 printf("Signal=%fdB\n", CNR);
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
394 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
395 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
396
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
397 int
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
398 main(int argc, char **argv)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
399 {
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
400 int tfd, wfd;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
401 int lp;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
402 int recsec;
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
403 int indefinite = FALSE;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
404 time_t start_time, cur_time;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
405 FREQUENCY freq;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
406 ISDB_T_FREQ_CONV_TABLE *ptr;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
407 pthread_t dequeue_threads;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
408 QUEUE_T *p_queue = create_queue(MAX_QUEUE);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
409 BUFSZ *bufptr;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
410 decoder *dec = NULL;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
411 thread_data tdata;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
412 decoder_options dopt = {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
413 4, /* round */
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
414 0, /* strip */
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
415 0 /* emm */
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
416 };
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
417
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
418 int result;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
419 int option_index;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
420 struct option long_options[] = {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
421 { "b25", 0, NULL, 'b'},
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
422 { "B25", 0, NULL, 'b'},
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
423 { "round", 1, NULL, 'r'},
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
424 { "strip", 0, NULL, 's'},
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
425 { "emm", 0, NULL, 'm'},
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
426 { "EMM", 0, NULL, 'm'},
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
427 { "udp", 0, NULL, 'u'},
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
428 { "addr", 1, NULL, 'a'},
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
429 { "port", 1, NULL, 'p'},
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
430 { "help", 0, NULL, 'h'},
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
431 {0, 0, 0, 0} /* terminate */
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
432 };
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
433
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
434 int use_b25 = FALSE;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
435 int use_udp = FALSE;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
436 int fileless = FALSE;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
437 char *host_to = NULL;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
438 int port_to = 1234;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
439 sock_data *sdata = NULL;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
440
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
441 while((result = getopt_long(argc, argv, "br:smua:p:h",
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
442 long_options, &option_index)) != -1) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
443 switch(result) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
444 case 'b':
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
445 use_b25 = TRUE;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
446 fprintf(stderr, "using B25...\n");
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
447 break;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
448 case 's':
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
449 dopt.strip = TRUE;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
450 fprintf(stderr, "enable B25 strip\n");
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
451 break;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
452 case 'm':
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
453 dopt.emm = TRUE;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
454 fprintf(stderr, "enable B25 emm processing\n");
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
455 break;
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
456 case 'u':
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
457 use_udp = TRUE;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
458 host_to = "localhost";
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
459 fprintf(stderr, "enable UDP broadcasting\n");
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
460 break;
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
461 case 'h':
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
462 show_usage(argv[0]);
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
463 show_options();
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
464 show_channels();
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
465 exit(0);
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
466 break;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
467 /* following options require argument */
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
468 case 'r':
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
469 dopt.round = atoi(optarg);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
470 fprintf(stderr, "set round %d\n", dopt.round);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
471 break;
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
472 case 'a':
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
473 use_udp = TRUE;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
474 host_to = optarg;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
475 fprintf(stderr, "UDP destination address: %s\n", host_to);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
476 break;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
477 case 'p':
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
478 port_to = atoi(optarg);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
479 fprintf(stderr, "UDP port: %d\n", port_to);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
480 break;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
481 }
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
482 }
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
483
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
484 if(argc - optind < 3) {
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
485 if(argc - optind == 2 && use_udp) {
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
486 fprintf(stderr, "Fileless UDP broadcasting\n");
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
487 fileless = TRUE;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
488 wfd = -1;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
489 }
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
490 else {
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
491 fprintf(stderr, "Arguments are necessary!\n");
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
492 fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
493 return 1;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
494 }
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
495 }
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
496
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
497 /* get channel */
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
498 ptr = searchrecoff(argv[optind]);
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
499 if(ptr == NULL) {
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
500 fprintf(stderr, "Channel Select Error(%s)\n", argv[optind]);
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
501 return 1;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
502 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
503
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
504 freq.frequencyno = ptr->set_freq;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
505 freq.slot = ptr->add_freq;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
506
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
507 if(ptr->type == CHTYPE_SATELLITE) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
508 for(lp = 0; lp < 2; lp++) {
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
509 tfd = open(bsdev[lp], O_RDONLY);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
510 if(tfd >= 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
511 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
512 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
513 }
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
514 if(tfd < 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
515 fprintf(stderr, "Device Open Error\n");
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
516 return 1;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
517 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
518 } else {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
519 for(lp = 0; lp < 2; lp++) {
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
520 tfd = open(isdb_t_dev[lp], O_RDONLY);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
521 if(tfd >= 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
522 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
523 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
524 }
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
525 if(tfd < 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
526 fprintf(stderr, "Device Open Error\n");
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
527 return 1;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
528 }
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
529 }
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
530
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
531 /* get recsec */
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
532 recsec = atoi(argv[optind + 1]);
14
cad940a903f5 - replace host option with addr option.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 13
diff changeset
533 if(recsec <= 0)
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
534 indefinite = TRUE;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
535
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
536 /* initialize decoder */
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
537 if(use_b25) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
538 dec = b25_startup(&dopt);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
539 if(!dec) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
540 fprintf(stderr, "cannot start b25 decoder\n");
7
407af34cfbd9 now falls back to encrypted recording when b25 decoder is not available
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 6
diff changeset
541 fprintf(stderr, "fall back to encrypted recording\n");
407af34cfbd9 now falls back to encrypted recording when b25 decoder is not available
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 6
diff changeset
542 use_b25 = 0;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
543 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
544 }
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
545
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
546 /* initialize udp connection */
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
547 if(use_udp) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
548 sdata = calloc(1, sizeof(sock_data));
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
549 struct in_addr ia;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
550 ia.s_addr = inet_addr(host_to);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
551 if(ia.s_addr == INADDR_NONE) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
552 struct hostent *hoste = gethostbyname(host_to);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
553 if(!hoste) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
554 perror("failed to get host by name");
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
555 return 1;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
556 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
557 ia.s_addr = *(in_addr_t*) (hoste->h_addr_list[0]);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
558 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
559 sdata->addr.sin_family = AF_INET;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
560 sdata->addr.sin_port = htons (port_to);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
561 sdata->addr.sin_addr.s_addr = ia.s_addr;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
562 if((sdata->sfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
563 perror("socket");
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
564 return 1;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
565 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
566 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
567
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
568 /* open output file */
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
569 if(!fileless) {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
570 wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
571 if(wfd < 0) {
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
572 fprintf(stderr, "Output File Open Error(%s)\n", argv[optind + 2]);
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
573 return 1;
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
574 }
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
575 }
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
576 if(ptr->type == CHTYPE_SATELLITE){
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
577 if(ioctl(tfd, LNB_ENABLE, 0) < 0){
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
578 return 0 ;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
579 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
580 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
581
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
582 if(ioctl(tfd, SET_CHANNEL, &freq) < 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
583 fprintf(stderr, "Tuner Select Error\n");
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
584 calc_cn(tfd, ptr->type);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
585 return 1;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
586 }
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
587 calc_cn(tfd, ptr->type);
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
588
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
589 /* make reader thread */
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
590 tdata.queue = p_queue;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
591 tdata.decoder = dec;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
592 tdata.wfd = wfd;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
593 tdata.sock_data = sdata;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
594 pthread_create(&dequeue_threads, NULL, write_func, &tdata);
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
595
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
596 /* start recording */
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
597 if(ioctl(tfd, START_REC, 0) < 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
598 fprintf(stderr, "Tuner Start Error\n");
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
599 return 1;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
600 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
601
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
602 time(&start_time);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
603
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
604 /* read from tuner */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
605 while(1) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
606 time(&cur_time);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
607 bufptr = malloc(sizeof(BUFSZ));
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
608 bufptr->size = read(tfd, bufptr->buffer, MAX_READ_SIZE);
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
609 if(bufptr->size <= 0) {
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
610 if((cur_time - start_time) >= recsec && !indefinite) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
611 f_exit = TRUE;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
612 enqueue(p_queue, NULL);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
613 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
614 } else {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
615 continue;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
616 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
617 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
618 enqueue(p_queue, bufptr);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
619
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
620 /* stop recording */
13
003fe2470af8 reorganized options:
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 11
diff changeset
621 if((cur_time - start_time) >= recsec && !indefinite) {
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
622 ioctl(tfd, STOP_REC, 0);
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
623 /* read remaining data */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
624 while(1) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
625 bufptr = malloc(sizeof(BUFSZ));
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
626 bufptr->size = read(tfd, bufptr->buffer, MAX_READ_SIZE);
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
627 if(bufptr->size <= 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
628 f_exit = TRUE;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
629 enqueue(p_queue, NULL);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
630 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
631 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
632 enqueue(p_queue, bufptr);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
633 }
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
634 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
635 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
636 }
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
637 /* close tuner */
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
638 if(ptr->type == CHTYPE_SATELLITE){
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
639 if(ioctl(tfd, LNB_DISABLE, 0) < 0){
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
640 return 0 ;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
641 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
642 }
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
643 close(tfd);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
644
6
d898fd27547f cleanups
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 5
diff changeset
645 /* wait reader thread */
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
646 pthread_join(dequeue_threads, NULL);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
647 destroy_queue(p_queue);
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
648
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
649 /* close socket */
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
650 if(use_udp) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
651 close(sdata->sfd);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
652 free(sdata);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
653 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
654
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
655 /* release decoder */
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
656 if(use_b25) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
657 b25_shutdown(dec);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
658 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
659
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
660 return 0;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
661 }