Mercurial > pt1.oyama
comparison 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 |
comparison
equal
deleted
inserted
replaced
10:e3059e3cf5e7 | 11:4615eaf04415 |
---|---|
4 #include <sys/stat.h> | 4 #include <sys/stat.h> |
5 #include <time.h> | 5 #include <time.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <string.h> | 7 #include <string.h> |
8 #include <pthread.h> | 8 #include <pthread.h> |
9 #include <math.h> | |
9 #include <unistd.h> | 10 #include <unistd.h> |
10 #include <getopt.h> | 11 #include <getopt.h> |
11 | 12 |
12 #include <netdb.h> | 13 #include <netdb.h> |
13 #include <arpa/inet.h> | 14 #include <arpa/inet.h> |
227 | 228 |
228 void | 229 void |
229 show_usage(char *cmd) | 230 show_usage(char *cmd) |
230 { | 231 { |
231 fprintf(stderr, "Usage: %s [--b25 [--round N] [--strip] [--EMM]] [--udp hostname [--port port]] channel recsec destfile\n", cmd); | 232 fprintf(stderr, "Usage: %s [--b25 [--round N] [--strip] [--EMM]] [--udp hostname [--port port]] channel recsec destfile\n", cmd); |
233 } | |
234 | |
235 float | |
236 getsignal_isdb_s(int signal) | |
237 { | |
238 // 線形補完で近似する | |
239 static const float afLevelTable[] = { | |
240 24.07f, // 00 00 0 24.07dB | |
241 24.07f, // 10 00 4096 24.07dB | |
242 18.61f, // 20 00 8192 18.61dB | |
243 15.21f, // 30 00 12288 15.21dB | |
244 12.50f, // 40 00 16384 12.50dB | |
245 10.19f, // 50 00 20480 10.19dB | |
246 8.140f, // 60 00 24576 8.140dB | |
247 6.270f, // 70 00 28672 6.270dB | |
248 4.550f, // 80 00 32768 4.550dB | |
249 3.730f, // 88 00 34816 3.730dB | |
250 3.630f, // 88 FF 35071 3.630dB | |
251 2.940f, // 90 00 36864 2.940dB | |
252 1.420f, // A0 00 40960 1.420dB | |
253 0.000f // B0 00 45056 -0.01dB | |
254 }; | |
255 | |
256 unsigned char sigbuf[4]; | |
257 memset(sigbuf, '\0', sizeof(sigbuf)); | |
258 sigbuf[0] = (((signal & 0xFF00) >> 8) & 0XFF); | |
259 sigbuf[1] = (signal & 0xFF); | |
260 | |
261 // 信号レベル計算 | |
262 if(sigbuf[0] <= 0x10U){ | |
263 // 最大クリップ | |
264 return 24.07f; | |
265 } else if (sigbuf[0] >= 0xB0U) { | |
266 // 最小クリップ | |
267 return 0.0f; | |
268 } else { | |
269 // 線形補完 | |
270 const float fMixRate = | |
271 (float)(((unsigned short)(sigbuf[0] & 0x0FU) << 8) | | |
272 (unsigned short)sigbuf[0]) / 4096.0f; | |
273 return afLevelTable[sigbuf[0] >> 4] * (1.0f - fMixRate) + | |
274 afLevelTable[(sigbuf[0] >> 4) + 0x01U] * fMixRate; | |
275 } | |
276 } | |
277 | |
278 void | |
279 calc_cn(int fd, int type) | |
280 { | |
281 | |
282 int rc ; | |
283 double P ; | |
284 double CNR; | |
285 | |
286 if(ioctl(fd, GET_SIGNAL_STRENGTH, &rc) < 0) { | |
287 printf("Tuner Select Error\n"); | |
288 return ; | |
289 } | |
290 | |
291 if(type == CHTYPE_GROUND) { | |
292 P = log10(5505024/(double)rc) * 10; | |
293 CNR = (0.000024 * P * P * P * P) - (0.0016 * P * P * P) + | |
294 (0.0398 * P * P) + (0.5491 * P)+3.0965; | |
295 printf("Signal=%fdB\n", CNR); | |
296 } else { | |
297 CNR = getsignal_isdb_s(rc); | |
298 printf("Signal=%fdB\n", CNR); | |
299 } | |
232 } | 300 } |
233 | 301 |
234 int | 302 int |
235 main(int argc, char **argv) | 303 main(int argc, char **argv) |
236 { | 304 { |
395 if(wfd < 0) { | 463 if(wfd < 0) { |
396 fprintf(stderr, "Output File Open Error(%s)\n", argv[optind + 2]); | 464 fprintf(stderr, "Output File Open Error(%s)\n", argv[optind + 2]); |
397 return 1; | 465 return 1; |
398 } | 466 } |
399 | 467 |
468 if(ptr->type == CHTYPE_SATELLITE){ | |
469 if(ioctl(tfd, LNB_ENABLE, 0) < 0){ | |
470 return 0 ; | |
471 } | |
472 } | |
473 | |
400 if(ioctl(tfd, SET_CHANNEL, &freq) < 0) { | 474 if(ioctl(tfd, SET_CHANNEL, &freq) < 0) { |
401 fprintf(stderr, "Tuner Select Error\n"); | 475 fprintf(stderr, "Tuner Select Error\n"); |
476 calc_cn(tfd, ptr->type); | |
402 return 1; | 477 return 1; |
403 } | 478 } |
479 calc_cn(tfd, ptr->type); | |
404 | 480 |
405 /* make reader thread */ | 481 /* make reader thread */ |
406 tdata.queue = p_queue; | 482 tdata.queue = p_queue; |
407 tdata.decoder = dec; | 483 tdata.decoder = dec; |
408 tdata.wfd = wfd; | 484 tdata.wfd = wfd; |
449 } | 525 } |
450 break; | 526 break; |
451 } | 527 } |
452 } | 528 } |
453 /* close tuner */ | 529 /* close tuner */ |
530 if(ptr->type == CHTYPE_SATELLITE){ | |
531 if(ioctl(tfd, LNB_DISABLE, 0) < 0){ | |
532 return 0 ; | |
533 } | |
534 } | |
454 close(tfd); | 535 close(tfd); |
455 | 536 |
456 /* wait reader thread */ | 537 /* wait reader thread */ |
457 pthread_join(dequeue_threads, NULL); | 538 pthread_join(dequeue_threads, NULL); |
458 destroy_queue(p_queue); | 539 destroy_queue(p_queue); |