annotate recpt1/recpt1.c @ 11:4615eaf04415

support signal strength calculation.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Mon, 23 Feb 2009 14:53:12 +0900
parents 6da603afd363
children 003fe2470af8
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;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
154 int use_b25 = dec ? 1 : 0;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
155 int use_udp = data->sock_data ? 1 : 0;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
156 int sfd = 0;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
157 struct sockaddr *addr = NULL;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
158 BUFSZ *buf;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
159 ARIB_STD_B25_BUFFER sbuf, dbuf;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
160 int code;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
161
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
162 if(use_udp) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
163 sfd = data->sock_data->sfd;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
164 addr = (struct sockaddr *)&data->sock_data->addr;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
165 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
166
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
167 while(1) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
168 buf = dequeue(p_queue);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
169 /* no entry in the queue */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
170 if(buf == NULL){
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
171 close(wfd);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
172 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
173 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
174
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
175 sbuf.data = buf->buffer;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
176 sbuf.size = buf->size;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
177
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
178 if(use_b25) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
179 /* write data to output file*/
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
180 code = b25_decode(dec, &sbuf, &dbuf);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
181 if(code < 0) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
182 fprintf(stderr, "b25_decode failed\n");
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
183 close(wfd);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
184 break;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
185 }
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
186 write(wfd, dbuf.data, dbuf.size);
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
187
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
188 if(use_udp && sfd) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
189 sendto(sfd, dbuf.data, dbuf.size, 0,
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
190 addr, sizeof(struct sockaddr_in));
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
191 }
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
192 free(buf);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
193 } else {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
194 write(wfd, sbuf.data, sbuf.size);
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
195
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
196 if(use_udp && sfd) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
197 sendto(sfd, sbuf.data, sbuf.size, 0,
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
198 addr, sizeof(struct sockaddr_in));
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
199 }
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
200 free(buf);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
201 }
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
202
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
203 /* normal exit */
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
204 if((f_exit) && (!p_queue->no_empty)) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
205 if(use_b25) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
206 code = b25_finish(dec, &sbuf, &dbuf);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
207 if(code < 0) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
208 fprintf(stderr, "b25_finish failed\n");
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
209 close(wfd);
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
210 close(sfd);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
211 break;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
212 }
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
213 write(wfd, dbuf.data, dbuf.size);
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
214
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
215 if(use_udp && sfd) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
216 sendto(sfd, dbuf.data, dbuf.size, 0,
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
217 addr, sizeof(struct sockaddr_in));
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
218 }
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
219 }
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
220 close(wfd);
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
221 close(sfd);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
222 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
223 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
224 }
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
225
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
226 return NULL;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
227 }
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
228
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
229 void
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
230 show_usage(char *cmd)
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
231 {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
232 fprintf(stderr, "Usage: %s [--b25 [--round N] [--strip] [--EMM]] [--udp hostname [--port port]] channel recsec destfile\n", cmd);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
233 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
234
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
235 float
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
236 getsignal_isdb_s(int signal)
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
237 {
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
238 // Àþ·ÁÊä´°¤Ç¶á»÷¤¹¤ë
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
239 static const float afLevelTable[] = {
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
240 24.07f, // 00 00 0 24.07dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
241 24.07f, // 10 00 4096 24.07dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
242 18.61f, // 20 00 8192 18.61dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
243 15.21f, // 30 00 12288 15.21dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
244 12.50f, // 40 00 16384 12.50dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
245 10.19f, // 50 00 20480 10.19dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
246 8.140f, // 60 00 24576 8.140dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
247 6.270f, // 70 00 28672 6.270dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
248 4.550f, // 80 00 32768 4.550dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
249 3.730f, // 88 00 34816 3.730dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
250 3.630f, // 88 FF 35071 3.630dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
251 2.940f, // 90 00 36864 2.940dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
252 1.420f, // A0 00 40960 1.420dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
253 0.000f // B0 00 45056 -0.01dB
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
254 };
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
255
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
256 unsigned char sigbuf[4];
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
257 memset(sigbuf, '\0', sizeof(sigbuf));
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
258 sigbuf[0] = (((signal & 0xFF00) >> 8) & 0XFF);
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
259 sigbuf[1] = (signal & 0xFF);
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
260
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
261 // ¿®¹æ¥ì¥Ù¥ë·×»»
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
262 if(sigbuf[0] <= 0x10U){
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
263 // ºÇÂ祯¥ê¥Ã¥×
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
264 return 24.07f;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
265 } else if (sigbuf[0] >= 0xB0U) {
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
266 // ºÇ¾®¥¯¥ê¥Ã¥×
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
267 return 0.0f;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
268 } else {
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
269 // Àþ·ÁÊä´°
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
270 const float fMixRate =
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
271 (float)(((unsigned short)(sigbuf[0] & 0x0FU) << 8) |
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
272 (unsigned short)sigbuf[0]) / 4096.0f;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
273 return afLevelTable[sigbuf[0] >> 4] * (1.0f - fMixRate) +
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
274 afLevelTable[(sigbuf[0] >> 4) + 0x01U] * fMixRate;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
275 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
276 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
277
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
278 void
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
279 calc_cn(int fd, int type)
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
280 {
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
281
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
282 int rc ;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
283 double P ;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
284 double CNR;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
285
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
286 if(ioctl(fd, GET_SIGNAL_STRENGTH, &rc) < 0) {
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
287 printf("Tuner Select Error\n");
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
288 return ;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
289 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
290
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
291 if(type == CHTYPE_GROUND) {
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
292 P = log10(5505024/(double)rc) * 10;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
293 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
294 (0.0398 * P * P) + (0.5491 * P)+3.0965;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
295 printf("Signal=%fdB\n", CNR);
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
296 } else {
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
297 CNR = getsignal_isdb_s(rc);
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
298 printf("Signal=%fdB\n", CNR);
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
299 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
300 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
301
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
302 int
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
303 main(int argc, char **argv)
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
304 {
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
305 int tfd, wfd;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
306 int lp;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
307 int recsec;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
308 time_t start_time, cur_time;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
309 FREQUENCY freq;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
310 ISDB_T_FREQ_CONV_TABLE *ptr;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
311 pthread_t dequeue_threads;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
312 QUEUE_T *p_queue = create_queue(MAX_QUEUE);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
313 BUFSZ *bufptr;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
314 decoder *dec = NULL;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
315 thread_data tdata;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
316 decoder_options dopt = {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
317 4, /* round */
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
318 0, /* strip */
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
319 0 /* emm */
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
320 };
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
321
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
322 int result;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
323 int option_index;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
324 struct option long_options[] = {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
325 { "b25", 0, NULL, 'b'},
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
326 { "B25", 0, NULL, 'b'},
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
327 { "round", 1, NULL, 'r'},
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
328 { "strip", 0, NULL, 's'},
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
329 { "emm", 0, NULL, 'm'},
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
330 { "EMM", 0, NULL, 'm'},
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
331 { "udp", 1, NULL, 'u'},
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
332 { "port", 1, NULL, 'p'}
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
333 };
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
334
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
335 int use_b25 = 0;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
336 int use_udp = 0;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
337 char *host_to = NULL;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
338 int port_to = 1234;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
339 sock_data *sdata = NULL;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
340
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
341 while((result = getopt_long(argc, argv, "br:sm" "u:p:", long_options, &option_index)) != -1) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
342 switch(result) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
343 case 'b':
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
344 use_b25 = 1;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
345 fprintf(stderr, "using B25...\n");
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
346 break;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
347 case 's':
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
348 dopt.strip = 1;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
349 fprintf(stderr, "enable B25 strip\n");
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
350 break;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
351 case 'm':
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
352 dopt.emm = 1;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
353 fprintf(stderr, "enable B25 emm processing\n");
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
354 break;
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
355 case 'r':
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
356 dopt.round = atoi(optarg);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
357 fprintf(stderr, "set round %d\n", dopt.round);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
358 break;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
359 case ':':
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
360 fprintf(stderr, "%c needs value\n", result);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
361 break;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
362 case '?':
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
363 show_usage(argv[0]);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
364 break;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
365 case 'u':
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
366 use_udp = 1;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
367 host_to = optarg;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
368 fprintf(stderr, "UDP destination address: %s\n", host_to);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
369 break;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
370 case 'p':
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
371 port_to = atoi(optarg);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
372 fprintf(stderr, "UDP port: %d\n", port_to);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
373 break;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
374 }
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
375 }
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
376
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
377 if(argc - optind < 3) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
378 show_usage(argv[0]);
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
379 printf("channel =\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
380 printf("151ch¡§BSÄ«Æü\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
381 printf("161ch¡§BS-i\n");
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
382 printf("191ch¡§WOWOW\n");
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
383 printf("171ch¡§BS¥¸¥ã¥Ñ¥ó\n");
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
384 printf("200ch¡§¥¹¥¿¡¼¥Á¥ã¥ó¥Í¥ë\n");
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
385 printf("211ch¡§BS11¥Ç¥¸¥¿¥ë\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
386 printf("222ch¡§TwellV\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
387 printf("141ch¡§BSÆü¥Æ¥ì\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
388 printf("181ch¡§BS¥Õ¥¸\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
389 printf("101ch¡§NHK±ÒÀ±Âè1ÊüÁ÷(BS1)\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
390 printf("102ch¡§NHK±ÒÀ±Âè2ÊüÁ÷(BS2)\n");
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
391 printf("103ch¡§NHK¥Ï¥¤¥Ó¥¸¥ç¥ó(BShi)\n");
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
392 printf("CS2-CS24¡§CS¥Á¥ã¥ó¥Í¥ë\n");
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
393 return 1;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
394 }
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
395 ptr = searchrecoff(argv[optind]);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
396 if(ptr == NULL){
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
397 printf("Channel Select Error(%s)\n", argv[optind]);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
398 return 1;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
399 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
400
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
401 freq.frequencyno = ptr->set_freq;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
402 freq.slot = ptr->add_freq;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
403
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
404 if(ptr->type == CHTYPE_SATELLITE) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
405 for(lp = 0; lp < 2; lp++) {
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
406 tfd = open(bsdev[lp], O_RDONLY);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
407 if(tfd >= 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
408 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
409 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
410 }
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
411 if(tfd < 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
412 fprintf(stderr, "Device Open Error\n");
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
413 return 1;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
414 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
415 } else {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
416 for(lp = 0; lp < 2; lp++) {
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
417 tfd = open(isdb_t_dev[lp], O_RDONLY);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
418 if(tfd >= 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
419 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
420 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
421 }
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
422 if(tfd < 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
423 fprintf(stderr, "Device Open Error\n");
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
424 return 1;
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
425 }
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
426 }
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
427 recsec = atoi(argv[optind + 1]);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
428
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
429 /* initialize decoder */
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
430 if(use_b25) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
431 dec = b25_startup(&dopt);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
432 if(!dec) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
433 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
434 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
435 use_b25 = 0;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
436 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
437 }
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
438
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
439 /* initialize udp connection */
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
440 if(use_udp) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
441 sdata = calloc(1, sizeof(sock_data));
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
442 struct in_addr ia;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
443 ia.s_addr = inet_addr(host_to);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
444 if(ia.s_addr == INADDR_NONE) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
445 struct hostent *hoste = gethostbyname(host_to);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
446 if(!hoste) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
447 perror("failed to get host by name");
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
448 return 1;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
449 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
450 ia.s_addr = *(in_addr_t*) (hoste->h_addr_list[0]);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
451 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
452 sdata->addr.sin_family = AF_INET;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
453 sdata->addr.sin_port = htons (port_to);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
454 sdata->addr.sin_addr.s_addr = ia.s_addr;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
455 if((sdata->sfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
456 perror("socket");
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
457 return 1;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
458 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
459 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
460
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
461 /* open output file */
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
462 wfd = open(argv[optind + 2], (O_RDWR | O_CREAT | O_TRUNC), 0666);
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
463 if(wfd < 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
464 fprintf(stderr, "Output File Open Error(%s)\n", argv[optind + 2]);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
465 return 1;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
466 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
467
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
468 if(ptr->type == CHTYPE_SATELLITE){
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
469 if(ioctl(tfd, LNB_ENABLE, 0) < 0){
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
470 return 0 ;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
471 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
472 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
473
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
474 if(ioctl(tfd, SET_CHANNEL, &freq) < 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
475 fprintf(stderr, "Tuner Select Error\n");
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
476 calc_cn(tfd, ptr->type);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
477 return 1;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
478 }
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
479 calc_cn(tfd, ptr->type);
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
480
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
481 /* make reader thread */
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
482 tdata.queue = p_queue;
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
483 tdata.decoder = dec;
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
484 tdata.wfd = wfd;
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
485 tdata.sock_data = sdata;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
486 pthread_create(&dequeue_threads, NULL, write_func, &tdata);
3
6801fe7e04ff updated to ariv25v023
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2
diff changeset
487
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
488 /* start recording */
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
489 if(ioctl(tfd, START_REC, 0) < 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
490 fprintf(stderr, "Tuner Start Error\n");
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
491 return 1;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
492 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
493
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
494 time(&start_time);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
495
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
496 /* read from tuner */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
497 while(1) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
498 time(&cur_time);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
499 bufptr = malloc(sizeof(BUFSZ));
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
500 bufptr->size = read(tfd, bufptr->buffer, MAX_READ_SIZE);
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
501 if(bufptr->size <= 0) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
502 if((cur_time - start_time) >= recsec) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
503 f_exit = TRUE;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
504 enqueue(p_queue, NULL);
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
505 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
506 } else {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
507 continue;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
508 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
509 }
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
510 enqueue(p_queue, bufptr);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
511
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
512 /* stop recording */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
513 if((cur_time - start_time) >= recsec) {
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
514 ioctl(tfd, STOP_REC, 0);
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
515 /* read remaining data */
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
516 while(1) {
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
517 bufptr = malloc(sizeof(BUFSZ));
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
518 bufptr->size = read(tfd, bufptr->buffer, MAX_READ_SIZE);
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
519 if(bufptr->size <= 0) {
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
520 f_exit = TRUE;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
521 enqueue(p_queue, NULL);
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 enqueue(p_queue, bufptr);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
525 }
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
526 break;
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
527 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
528 }
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
529 /* close tuner */
11
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
530 if(ptr->type == CHTYPE_SATELLITE){
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
531 if(ioctl(tfd, LNB_DISABLE, 0) < 0){
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
532 return 0 ;
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
533 }
4615eaf04415 support signal strength calculation.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 8
diff changeset
534 }
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
535 close(tfd);
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
536
6
d898fd27547f cleanups
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 5
diff changeset
537 /* wait reader thread */
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
538 pthread_join(dequeue_threads, NULL);
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
539 destroy_queue(p_queue);
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
540
8
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
541 /* close socket */
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
542 if(use_udp) {
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
543 close(sdata->sfd);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
544 free(sdata);
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
545 }
6da603afd363 added udp capability
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 7
diff changeset
546
4
43d177fa65c9 fixed indentation
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 3
diff changeset
547 /* release decoder */
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
548 if(use_b25) {
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
549 b25_shutdown(dec);
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
550 }
2
8ac7c59fefc9 added b25 decode functionality
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1
diff changeset
551
5
97fd2315114e - now it can handle options.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 4
diff changeset
552 return 0;
0
67e8eca28a80 initial import
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
553 }