comparison recpt1/recpt1.c @ 81:6e3bb2c0c5b6

add an option to specify LNB voltage
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Sat, 12 Dec 2009 22:30:43 +0900
parents 5a0126d8af17
children 1b61fd7c6fde
comparison
equal deleted inserted replaced
80:f336fd2dcf28 81:6e3bb2c0c5b6
48 typedef struct thread_data { 48 typedef struct thread_data {
49 QUEUE_T *queue; 49 QUEUE_T *queue;
50 decoder *decoder; 50 decoder *decoder;
51 decoder_options *dopt; 51 decoder_options *dopt;
52 int ch; 52 int ch;
53 int lnb; /* LNB voltage */
53 int tfd; /* tuner fd */ 54 int tfd; /* tuner fd */
54 int wfd; /* output file fd */ 55 int wfd; /* output file fd */
55 ISDB_T_FREQ_CONV_TABLE *table; 56 ISDB_T_FREQ_CONV_TABLE *table;
56 sock_data *sock_data; 57 sock_data *sock_data;
57 pthread_t signal_thread; 58 pthread_t signal_thread;
58 int recsec; 59 int recsec;
60 time_t start_time;
59 boolean indefinite; 61 boolean indefinite;
60 int msqid; 62 int msqid;
61 time_t start_time;
62 } thread_data; 63 } thread_data;
63 64
64 typedef struct msgbuf { 65 typedef struct msgbuf {
65 long mtype; 66 long mtype;
66 char mtext[MSGSZ]; 67 char mtext[MSGSZ];
398 } 399 }
399 } 400 }
400 401
401 time_t cur_time; 402 time_t cur_time;
402 time(&cur_time); 403 time(&cur_time);
403 fprintf(stderr, "Recorded %d sec\n", 404 fprintf(stderr, "Recorded %dsec\n",
404 (int)(cur_time - data->start_time)); 405 (int)(cur_time - data->start_time));
405 406
406 return NULL; 407 return NULL;
407 } 408 }
408 409
409 void 410 void
410 show_usage(char *cmd) 411 show_usage(char *cmd)
411 { 412 {
412 #ifdef HAVE_LIBARIB25 413 #ifdef HAVE_LIBARIB25
413 fprintf(stderr, "Usage: \n%s [--b25 [--round N] [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] channel rectime destfile\n", cmd); 414 fprintf(stderr, "Usage: \n%s [--b25 [--round N] [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] [--lnb voltage] channel rectime destfile\n", cmd);
414 #else 415 #else
415 fprintf(stderr, "Usage: \n%s [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] channel rectime destfile\n", cmd); 416 fprintf(stderr, "Usage: \n%s [--strip] [--EMM]] [--udp [--addr hostname --port portnumber]] [--device devicefile] [--lnb voltage] channel rectime destfile\n", cmd);
416 #endif 417 #endif
417 fprintf(stderr, "\n"); 418 fprintf(stderr, "\n");
418 fprintf(stderr, "Remarks:\n"); 419 fprintf(stderr, "Remarks:\n");
419 fprintf(stderr, "if rectime is '-', records indefinitely.\n"); 420 fprintf(stderr, "if rectime is '-', records indefinitely.\n");
420 fprintf(stderr, "if destfile is '-', stdout is used for output.\n"); 421 fprintf(stderr, "if destfile is '-', stdout is used for output.\n");
432 #endif 433 #endif
433 fprintf(stderr, "--udp: Turn on udp broadcasting\n"); 434 fprintf(stderr, "--udp: Turn on udp broadcasting\n");
434 fprintf(stderr, " --addr hostname: Hostname or address to connect\n"); 435 fprintf(stderr, " --addr hostname: Hostname or address to connect\n");
435 fprintf(stderr, " --port portnumber: Port number to connect\n"); 436 fprintf(stderr, " --port portnumber: Port number to connect\n");
436 fprintf(stderr, "--device devicefile: Specify devicefile to use\n"); 437 fprintf(stderr, "--device devicefile: Specify devicefile to use\n");
438 fprintf(stderr, "--lnb voltage: Specify LNB voltage (0, 11, 15)\n");
437 fprintf(stderr, "--help: Show this help\n"); 439 fprintf(stderr, "--help: Show this help\n");
438 fprintf(stderr, "--version: Show version\n"); 440 fprintf(stderr, "--version: Show version\n");
439 fprintf(stderr, "--list: Show channel list\n"); 441 fprintf(stderr, "--list: Show channel list\n");
440 } 442 }
441 443
533 535
534 if(type == CHTYPE_GROUND) { 536 if(type == CHTYPE_GROUND) {
535 P = log10(5505024/(double)rc) * 10; 537 P = log10(5505024/(double)rc) * 10;
536 CNR = (0.000024 * P * P * P * P) - (0.0016 * P * P * P) + 538 CNR = (0.000024 * P * P * P * P) - (0.0016 * P * P * P) +
537 (0.0398 * P * P) + (0.5491 * P)+3.0965; 539 (0.0398 * P * P) + (0.5491 * P)+3.0965;
538 fprintf(stderr, "Signal = %f dB\n", CNR); 540 fprintf(stderr, "C/N = %fdB\n", CNR);
539 } 541 }
540 else { 542 else {
541 CNR = getsignal_isdb_s(rc); 543 CNR = getsignal_isdb_s(rc);
542 fprintf(stderr, "Signal = %f dB\n", CNR); 544 fprintf(stderr, "C/N = %fdB\n", CNR);
543 } 545 }
544 } 546 }
545 547
546 void 548 void
547 cleanup(thread_data *tdata) 549 cleanup(thread_data *tdata)
548 { 550 {
549 /* stop recording */ 551 /* stop recording */
550 ioctl(tdata->tfd, STOP_REC, 0); 552 ioctl(tdata->tfd, STOP_REC, 0);
551 553
552 /* restore LNB state */
553 #if 0
554 if(ptr->type == CHTYPE_SATELLITE) {
555 if(ioctl(tfd, LNB_DISABLE, 0) < 0) {
556 return 0 ;
557 }
558 }
559 #endif
560 /* xxx need mutex? */ 554 /* xxx need mutex? */
561 f_exit = TRUE; 555 f_exit = TRUE;
562 556
563 pthread_cond_signal(&tdata->queue->cond_avail); 557 pthread_cond_signal(&tdata->queue->cond_avail);
564 pthread_cond_signal(&tdata->queue->cond_used); 558 pthread_cond_signal(&tdata->queue->cond_used);
651 return 1; 645 return 1;
652 } 646 }
653 647
654 /* power on LNB */ 648 /* power on LNB */
655 if(tdata->table->type == CHTYPE_SATELLITE) { 649 if(tdata->table->type == CHTYPE_SATELLITE) {
656 if(ioctl(tdata->tfd, LNB_ENABLE, 0) < 0) { 650 if(ioctl(tdata->tfd, LNB_ENABLE, tdata->lnb) < 0) {
657 close(tdata->tfd); 651 close(tdata->tfd);
658 fprintf(stderr, "Power on LNB failed: %s\n", device); 652 fprintf(stderr, "Power on LNB failed: %s\n", device);
659 return 1; 653 return 1;
660 } 654 }
661 } 655 }
684 for(lp = 0; lp < num_devs; lp++) { 678 for(lp = 0; lp < num_devs; lp++) {
685 tdata->tfd = open(tuner[lp], O_RDONLY); 679 tdata->tfd = open(tuner[lp], O_RDONLY);
686 if(tdata->tfd >= 0) { 680 if(tdata->tfd >= 0) {
687 /* power on LNB */ 681 /* power on LNB */
688 if(tdata->table->type == CHTYPE_SATELLITE) { 682 if(tdata->table->type == CHTYPE_SATELLITE) {
689 if(ioctl(tdata->tfd, LNB_ENABLE, 0) < 0) { 683 if(ioctl(tdata->tfd, LNB_ENABLE, tdata->lnb) < 0) {
690 close(tdata->tfd); 684 close(tdata->tfd);
691 tdata->tfd = -1; 685 tdata->tfd = -1;
692 continue; 686 continue;
693 } 687 }
694 } 688 }
801 4, /* round */ 795 4, /* round */
802 0, /* strip */ 796 0, /* strip */
803 0 /* emm */ 797 0 /* emm */
804 }; 798 };
805 tdata.dopt = &dopt; 799 tdata.dopt = &dopt;
800 tdata.lnb = 0;
806 801
807 int result; 802 int result;
808 int option_index; 803 int option_index;
809 struct option long_options[] = { 804 struct option long_options[] = {
810 #ifdef HAVE_LIBARIB25 805 #ifdef HAVE_LIBARIB25
811 { "b25", 0, NULL, 'b'}, 806 { "b25", 0, NULL, 'b'},
812 { "B25", 0, NULL, 'b'}, 807 { "B25", 0, NULL, 'b'},
813 #endif
814 { "round", 1, NULL, 'r'}, 808 { "round", 1, NULL, 'r'},
815 { "strip", 0, NULL, 's'}, 809 { "strip", 0, NULL, 's'},
816 { "emm", 0, NULL, 'm'}, 810 { "emm", 0, NULL, 'm'},
817 { "EMM", 0, NULL, 'm'}, 811 { "EMM", 0, NULL, 'm'},
812 #endif
813 { "LNB", 1, NULL, 'n'},
814 { "lnb", 1, NULL, 'n'},
818 { "udp", 0, NULL, 'u'}, 815 { "udp", 0, NULL, 'u'},
819 { "addr", 1, NULL, 'a'}, 816 { "addr", 1, NULL, 'a'},
820 { "port", 1, NULL, 'p'}, 817 { "port", 1, NULL, 'p'},
821 { "device", 1, NULL, 'd'}, 818 { "device", 1, NULL, 'd'},
822 { "help", 0, NULL, 'h'}, 819 { "help", 0, NULL, 'h'},
831 boolean use_stdout = FALSE; 828 boolean use_stdout = FALSE;
832 char *host_to = NULL; 829 char *host_to = NULL;
833 int port_to = 1234; 830 int port_to = 1234;
834 sock_data *sockdata = NULL; 831 sock_data *sockdata = NULL;
835 char *device = NULL; 832 char *device = NULL;
836 833 int val;
837 while((result = getopt_long(argc, argv, "br:smua:p:d:hvl", 834 char *voltage[] = {"0V", "11V", "15V"};
835
836 while((result = getopt_long(argc, argv, "br:smn:ua:p:d:hvl",
838 long_options, &option_index)) != -1) { 837 long_options, &option_index)) != -1) {
839 switch(result) { 838 switch(result) {
840 case 'b': 839 case 'b':
841 use_b25 = TRUE; 840 use_b25 = TRUE;
842 fprintf(stderr, "using B25...\n"); 841 fprintf(stderr, "using B25...\n");
872 case 'l': 871 case 'l':
873 show_channels(); 872 show_channels();
874 exit(0); 873 exit(0);
875 break; 874 break;
876 /* following options require argument */ 875 /* following options require argument */
876 case 'n':
877 val = atoi(optarg);
878 switch(val) {
879 case 11:
880 tdata.lnb = 1;
881 break;
882 case 15:
883 tdata.lnb = 2;
884 break;
885 default:
886 tdata.lnb = 0;
887 break;
888 }
889 fprintf(stderr, "LNB = %s\n", voltage[tdata.lnb]);
890 break;
877 case 'r': 891 case 'r':
878 dopt.round = atoi(optarg); 892 dopt.round = atoi(optarg);
879 fprintf(stderr, "set round %d\n", dopt.round); 893 fprintf(stderr, "set round %d\n", dopt.round);
880 break; 894 break;
881 case 'a': 895 case 'a':