int main(int argc, char **argv) { struct dvb_frontend_parameters frontend_param; char *homedir = getenv ("HOME"); char *confname = NULL; char *channel = NULL; int adapter = 0, frontend = 0, demux = 0, dvr = 0; int vpid, apid, sid, pmtpid = 0; int pat_fd, pmt_fd; int frontend_fd, audio_fd, video_fd; int opt; int rec_psi = 0; while ((opt = getopt(argc, argv, "hrpn:a:f:d:c:")) != -1) { switch (opt) { case 'a': adapter = strtoul(optarg, NULL, 0); break; case 'f': frontend = strtoul(optarg, NULL, 0); break; case 'd': demux = strtoul(optarg, NULL, 0); break; case 'r': dvr = 1; break; case 'p': rec_psi = 1; break; case 'c': confname = optarg; break; case '?': case 'h': default: fprintf (stderr, usage, argv[0]); return -1; }; } if (optind < argc) channel = argv[optind]; if (!channel) { fprintf (stderr, usage, argv[0]); return -1; } snprintf (FRONTEND_DEV, sizeof(FRONTEND_DEV), "/dev/dvb/adapter%i/frontend%i", adapter, frontend); snprintf (DEMUX_DEV, sizeof(DEMUX_DEV), "/dev/dvb/adapter%i/demux%i", adapter, demux); printf ("using '%s' and '%s'\n", FRONTEND_DEV, DEMUX_DEV); if (!confname) { if (!homedir) ERROR ("$HOME not set"); confname = malloc (strlen(homedir) + strlen(CHANNEL_FILE) + 1); memcpy (confname, homedir, strlen(homedir)); memcpy (confname + strlen(homedir), CHANNEL_FILE, strlen(CHANNEL_FILE) + 1); } memset(&frontend_param, 0, sizeof(struct dvb_frontend_parameters)); if (parse (confname, channel, &frontend_param, &vpid, &apid, &sid)) return -1; if ((frontend_fd = open(FRONTEND_DEV, O_RDWR | O_NONBLOCK)) < 0) { PERROR ("failed opening '%s'", FRONTEND_DEV); return -1; } if (setup_frontend (frontend_fd, &frontend_param) < 0) return -1; if (rec_psi) { pmtpid = get_pmt_pid(DEMUX_DEV, sid); if (pmtpid <= 0) { fprintf(stderr,"couldn't find pmt-pid for sid %04x\n",sid); return -1; } if ((pat_fd = open(DEMUX_DEV, O_RDWR)) < 0) { perror("opening pat demux failed"); return -1; } if (set_pesfilter(pat_fd, 0, DMX_PES_OTHER, dvr) < 0) return -1; if ((pmt_fd = open(DEMUX_DEV, O_RDWR)) < 0) { perror("opening pmt demux failed"); return -1; } if (set_pesfilter(pmt_fd, pmtpid, DMX_PES_OTHER, dvr) < 0) return -1; } if ((video_fd = open(DEMUX_DEV, O_RDWR)) < 0) { PERROR("failed opening '%s'", DEMUX_DEV); return -1; } printf ("video pid 0x%04x, audio pid 0x%04x\n", vpid, apid); if (set_pesfilter (video_fd, vpid, DMX_PES_VIDEO, dvr) < 0) return -1; if ((audio_fd = open(DEMUX_DEV, O_RDWR)) < 0) { PERROR("failed opening '%s'", DEMUX_DEV); return -1; } if (set_pesfilter (audio_fd, apid, DMX_PES_AUDIO, dvr) < 0) return -1; monitor_frontend (frontend_fd); close (pat_fd); close (pmt_fd); close (audio_fd); close (video_fd); close (frontend_fd); return 0; }
int main(int argc, char **argv) { struct arguments args; char *homedir = getenv("HOME"); char *channel = NULL; int lnb = -1, idx = -1; int vpid = -1, apid = -1, sid = -1; int pmtpid = 0; int pat_fd = -1, pmt_fd = -1; int audio_fd = 0, video_fd = 0; int dvr_fd, file_fd; struct dvb_v5_fe_parms *parms; const struct argp argp = { .options = options, .parser = parse_opt, .doc = "DVB zap utility", .args_doc = "<initial file>", }; memset(&args, 0, sizeof(args)); args.sat_number = -1; argp_parse(&argp, argc, argv, 0, &idx, &args); if (idx < argc) channel = argv[idx]; if (!channel) { argp_help(&argp, stderr, ARGP_HELP_STD_HELP, PROGRAM_NAME); return -1; } if (args.input_format == FILE_UNKNOWN) { fprintf(stderr, "ERROR: Please specify a valid format\n"); argp_help(&argp, stderr, ARGP_HELP_STD_HELP, PROGRAM_NAME); return -1; } if (args.lnb_name) { lnb = search_lnb(args.lnb_name); if (lnb < 0) { printf("Please select one of the LNBf's below:\n"); print_all_lnb(); exit(1); } else { printf("Using LNBf "); print_lnb(lnb); } } asprintf(&args.demux_dev, "/dev/dvb/adapter%i/demux%i", args.adapter, args.demux); asprintf(&args.dvr_dev, "/dev/dvb/adapter%i/dvr%i", args.adapter, args.demux); if (args.silent < 2) fprintf(stderr, "using demux '%s'\n", args.demux_dev); if (!args.confname) { if (!homedir) ERROR("$HOME not set"); asprintf(&args.confname, "%s/.tzap/%i/%s", homedir, args.adapter, CHANNEL_FILE); if (access(args.confname, R_OK)) asprintf(&args.confname, "%s/.tzap/%s", homedir, CHANNEL_FILE); } printf("reading channels from file '%s'\n", args.confname); parms = dvb_fe_open(args.adapter, args.frontend, 0, 0); if (!parms) return -1; if (lnb) parms->lnb = get_lnb(lnb); if (args.sat_number > 0) parms->sat_number = args.sat_number % 3; parms->diseqc_wait = args.diseqc_wait; parms->freq_bpf = args.freq_bpf; if (parse(&args, parms, channel, &vpid, &apid, &sid)) return -1; if (setup_frontend(&args, parms) < 0) return -1; if (args.frontend_only) { check_frontend(&args, parms); dvb_fe_close(parms); return 0; } if (args.rec_psi) { if (sid < 0) { fprintf(stderr, "Service id 0x%04x was not specified at the file\n", sid); return -1; } pmtpid = get_pmt_pid(args.demux_dev, sid); if (pmtpid <= 0) { fprintf(stderr, "couldn't find pmt-pid for sid %04x\n", sid); return -1; } if ((pat_fd = open(args.demux_dev, O_RDWR)) < 0) { perror("opening pat demux failed"); return -1; } if (set_pesfilter(pat_fd, 0, DMX_PES_OTHER, args.dvr) < 0) return -1; if ((pmt_fd = open(args.demux_dev, O_RDWR)) < 0) { perror("opening pmt demux failed"); return -1; } if (set_pesfilter(pmt_fd, pmtpid, DMX_PES_OTHER, args.dvr) < 0) return -1; } if (vpid >= 0) { if (args.silent < 2) fprintf(stderr, "video pid %d\n", vpid); if ((video_fd = open(args.demux_dev, O_RDWR)) < 0) { PERROR("failed opening '%s'", args.demux_dev); return -1; } if (set_pesfilter(video_fd, vpid, DMX_PES_VIDEO, args.dvr) < 0) return -1; } if (apid >= 0) { if (args.silent < 2) fprintf(stderr, "audio pid %d\n", apid); if ((audio_fd = open(args.demux_dev, O_RDWR)) < 0) { PERROR("failed opening '%s'", args.demux_dev); return -1; } if (set_pesfilter(audio_fd, apid, DMX_PES_AUDIO, args.dvr) < 0) return -1; } signal(SIGALRM, do_timeout); if (args.timeout > 0) alarm(args.timeout); if (args.record) { if (args.filename != NULL) { if (strcmp(args.filename, "-") != 0) { file_fd = open(args.filename, O_WRONLY | O_LARGEFILE | O_CREAT, 0644); if (file_fd < 0) { PERROR("open of '%s' failed", args.filename); return -1; } } else { file_fd = 1; } } else { PERROR("Record mode but no filename!"); return -1; } if ((dvr_fd = open(args.dvr_dev, O_RDONLY)) < 0) { PERROR("failed opening '%s'", args.dvr_dev); return -1; } if (args.silent < 2) print_frontend_stats(parms, args.human_readable); copy_to_file(dvr_fd, file_fd, args.timeout, args.silent); if (args.silent < 2) print_frontend_stats(parms, args.human_readable); } else { check_frontend(&args, parms); } close(pat_fd); close(pmt_fd); close(audio_fd); close(video_fd); dvb_fe_close(parms); return 0; }
int main(int argc, char **argv) { struct dvb_frontend_parameters frontend_param; char *homedir = getenv("HOME"); char *confname = NULL; char *channel = NULL; int adapter = 0, frontend = 0, demux = 0, dvr = 0; int vpid, apid, sid, pmtpid = 0; int pat_fd, pmt_fd; int frontend_fd, audio_fd = 0, video_fd = 0, dvr_fd, file_fd; int opt; int record = 0; int frontend_only = 0; char *filename = NULL; int human_readable = 0, rec_psi = 0; while ((opt = getopt(argc, argv, "H?hrpxRsFSn:a:f:d:c:t:o:")) != -1) { switch (opt) { case 'a': adapter = strtoul(optarg, NULL, 0); break; case 'f': frontend = strtoul(optarg, NULL, 0); break; case 'd': demux = strtoul(optarg, NULL, 0); break; case 't': timeout = strtoul(optarg, NULL, 0); break; case 'o': filename = strdup(optarg); record=1; /* fall through */ case 'r': dvr = 1; break; case 'p': rec_psi = 1; break; case 'x': exit_after_tuning = 1; break; case 'c': confname = optarg; break; case 's': silent = 1; break; case 'S': silent = 2; break; case 'F': frontend_only = 1; break; case 'H': human_readable = 1; break; case '?': case 'h': default: fprintf (stderr, usage, argv[0]); return -1; }; } if (optind < argc) channel = argv[optind]; if (!channel) { fprintf (stderr, usage, argv[0]); return -1; } #if defined(ANDROID) snprintf(FRONTEND_DEV, sizeof(FRONTEND_DEV), "/dev/dvb%i.frontend%i", adapter, frontend); snprintf(DEMUX_DEV, sizeof(DEMUX_DEV), "/dev/dvb%i.demux%i", adapter, demux); snprintf(DVR_DEV, sizeof(DVR_DEV), "/dev/dvb%i.dvr%i", adapter, demux); #else snprintf(FRONTEND_DEV, sizeof(FRONTEND_DEV), "/dev/dvb/adapter%i/frontend%i", adapter, frontend); snprintf(DEMUX_DEV, sizeof(DEMUX_DEV), "/dev/dvb/adapter%i/demux%i", adapter, demux); snprintf(DVR_DEV, sizeof(DVR_DEV), "/dev/dvb/adapter%i/dvr%i", adapter, demux); #endif if (silent < 2) fprintf (stderr,"using '%s' and '%s'\n", FRONTEND_DEV, DEMUX_DEV); if (!confname) { int len = strlen(homedir) + strlen(CHANNEL_FILE) + 18; if (!homedir) ERROR ("$HOME not set"); confname = malloc (len); snprintf(confname, len, "%s/.tzap/%i/%s", homedir, adapter, CHANNEL_FILE); if (access (confname, R_OK)) snprintf(confname, len, "%s/.tzap/%s", homedir, CHANNEL_FILE); } printf("reading channels from file '%s'\n", confname); memset(&frontend_param, 0, sizeof(struct dvb_frontend_parameters)); if (parse (confname, channel, &frontend_param, &vpid, &apid, &sid)) return -1; if ((frontend_fd = open(FRONTEND_DEV, O_RDWR | O_NONBLOCK)) < 0) { PERROR ("failed opening '%s'", FRONTEND_DEV); return -1; } if (setup_frontend (frontend_fd, &frontend_param) < 0) return -1; if (frontend_only) goto just_the_frontend_dude; if (rec_psi) { pmtpid = get_pmt_pid(DEMUX_DEV, sid); if (pmtpid <= 0) { fprintf(stderr,"couldn't find pmt-pid for sid %04x\n",sid); return -1; } if ((pat_fd = open(DEMUX_DEV, O_RDWR)) < 0) { perror("opening pat demux failed"); return -1; } if (set_pesfilter(pat_fd, 0, DMX_PES_OTHER, dvr) < 0) return -1; if ((pmt_fd = open(DEMUX_DEV, O_RDWR)) < 0) { perror("opening pmt demux failed"); return -1; } if (set_pesfilter(pmt_fd, pmtpid, DMX_PES_OTHER, dvr) < 0) return -1; } if ((video_fd = open(DEMUX_DEV, O_RDWR)) < 0) { PERROR("failed opening '%s'", DEMUX_DEV); return -1; } if (silent<2) fprintf(stderr,"video pid 0x%04x, audio pid 0x%04x\n", vpid, apid); if (set_pesfilter(video_fd, vpid, DMX_PES_VIDEO, dvr) < 0) return -1; if ((audio_fd = open(DEMUX_DEV, O_RDWR)) < 0) { PERROR("failed opening '%s'", DEMUX_DEV); return -1; } if (set_pesfilter(audio_fd, apid, DMX_PES_AUDIO, dvr) < 0) return -1; signal(SIGALRM,do_timeout); if (timeout > 0) alarm(timeout); if (record) { if (filename!=NULL) { if (strcmp(filename,"-")!=0) { file_fd = open(filename,O_WRONLY|O_LARGEFILE|O_CREAT,0644); if (file_fd<0) { PERROR("open of '%s' failed",filename); return -1; } } else { file_fd=1; } } else { PERROR("Record mode but no filename!"); return -1; } if ((dvr_fd = open(DVR_DEV, O_RDONLY)) < 0) { PERROR("failed opening '%s'", DVR_DEV); return -1; } if (silent<2) print_frontend_stats(frontend_fd, human_readable); copy_to_file(dvr_fd,file_fd); if (silent<2) print_frontend_stats(frontend_fd, human_readable); } else { just_the_frontend_dude: monitor_frontend(frontend_fd, human_readable); } close(pat_fd); close(pmt_fd); close(audio_fd); close(video_fd); close(frontend_fd); return 0; }
int main (int argc, char *argv[]) { fd_set readset; fd_set writeset; int n, sel; int c, errflg=0; struct sigaction sigact; sigset_t sigmask; char *scratch, *next_scratch; char nmea_buf[1024]; char send_buf[1024]; int gps_buf[15]; int nmea_index = 0; int send_len = 0; /* Set default options */ outfile = stdout; int sAnt = 0; memset(gps_buf, 0, 15); memset(send_buf, 0, 1024); send_len = 0; /* Process options */ while ((c = getopt(argc, argv, "Vlqvs:o:p:t:m:u:g:/:")) != EOF) switch (c) { case 'q': quiet=1; break; case 'v': verbose = 1; break; case 'l': linebuff = 1; break; case 'p': opt_ptyname = optarg; break; case 't': opt_ttyname = optarg; break; case 'm': /* mode for pty: [user,[group,]]mode */ scratch = strdup(optarg); if ((next_scratch = strchr(scratch,',')) != NULL) { /* Username */ *next_scratch = '\0'; next_scratch++; frontend_owner = find_uid(scratch); scratch = next_scratch; if ((next_scratch = strchr(scratch,',')) != NULL) { /* Group */ *next_scratch = '\0'; next_scratch++; frontend_group = find_gid(scratch); scratch = next_scratch; } } frontend_mode = strtol(scratch,NULL,8); break; case 'u': switch_uid = find_uid(optarg); break; case 'g': switch_gid = find_gid(optarg); break; case '/': switch_root = strdup(optarg); break; case 's': settings = optarg; break; case 'o': outfilename=optarg; if ( (outfile = fopen(outfilename,"w")) == NULL) errorf("Couldn't open output file '%s' for write: %s\n",outfilename,strerror(errno)); break; case 'V': puts(VERSION); exit(0); case '?': default: errflg++; break; } if (errflg || ((argc-optind) < 1) || ((argc-optind) > 2)) { usage(argv[0]); exit (2); } /* Process the two non-flag options */ backend = argv[optind]; if ((argc-optind) == 2) frontend = argv[optind+1]; if (strcmp(frontend,"-") == 0) frontend = NULL; if (linebuff) setlinebuf(outfile); atexit (closedown); /* Do some initialization */ stty_initstore(); sendudp_open(); /* Setup backend */ if (setup_backend(backfd) < 0) errorf ("select failed. errno = %d\n", errno); /* Setup frontend */ if ((setup_frontend(frontfd)) < 0) errorf("setup_frontend failed: %s\n",strerror(errno)); /* Drop privileges if we've been asked to */ if (switch_root) { if (chroot(switch_root) != 0) errorf("chroot(%s) failed: %s\n",switch_root,strerror(errno)); } if (switch_gid != -1) { if (setgroups(1,&switch_gid) == -1) errorf("setgroups(1,[%d]) failed: %s\n",switch_gid, strerror(errno)); if (setregid(switch_gid, switch_gid) == -1) errorf("setregid(%d,%d) failed: %s\n",switch_gid,switch_gid); if (getgid() != switch_gid) errorf("setregid succeeded, but we're the wrong gid!"); if (getegid() != switch_gid) errorf("setregid succeeded, but we're the wrong effective gid!"); } if (switch_uid != -1) { if (setreuid(switch_uid, switch_uid) == -1) errorf("setreuid(%d,%d) failed: %s\n",switch_uid,switch_uid,strerror(errno)); if (getuid() != switch_uid) errorf("setreuid succeeded, but we're the wrong uid!"); if (geteuid() != switch_uid) errorf("setregid succeeded, but we're the wrong effective uid!"); } /* calc (initial) max file descriptor to use in select() */ fdmax = max(backfd[0], frontfd[0]); /* Set up signal handlers and such */ sigemptyset(&sigmask); memset(&sigact,0,sizeof sigact); sigact.sa_handler = sigdeath; sigact.sa_mask = sigmask; sigaction(SIGHUP,&sigact,NULL); sigaction(SIGINT,&sigact,NULL); sigaction(SIGQUIT,&sigact,NULL); sigaction(SIGPIPE,&sigact,NULL); sigaction(SIGTERM,&sigact,NULL); sigact.sa_handler = sigchld; sigaction(SIGCHLD,&sigact,NULL); pthread_t udp_recv; pthread_create(&udp_recv, NULL, udp_recv_gnssmode_thread, NULL); pthread_detach(udp_recv); struct tm p; time_t timep; while (!please_die_now) { do { FD_ZERO (&readset); FD_SET (backfd[0], &readset); FD_SET (frontfd[0], &readset); FD_ZERO (&writeset); FD_SET (backfd[1], &writeset); FD_SET (frontfd[1], &writeset); sel = select(fdmax + 1, &readset, &writeset, NULL, NULL); } while (sel == -1 && errno == EINTR && !please_die_now); if (sel == -1 && errno != EINTR) errorf ("select failed. errno = %d\n", errno); else if (please_die_now) break; if (FD_ISSET(backfd[0], &readset)) { if ((n = read(backfd[0], buff, BUFF_SIZE)) == 0) { /* Serial port has closed. This doesn't really make sense for * a real serial port, but for sockets and programs, probably * we should just exit. */ if (!quiet) errorf("Backend device was closed.\n"); break; } else if (n < 0) { if ( (errno != EAGAIN) && (errno != EINTR) ) { errorf("Error reading from backend device: %s\n",strerror(errno)); } break; } else { /* We should handle this better. FIX */ if(FD_ISSET(frontfd[1], &writeset)) { if (write (frontfd[1], buff, n) != n) errorf("Error writing to frontend device: %s\n",strerror(errno)); } // if (!quiet) // dumpbuff(1,buff,n); //nmea decode { tNmea_Msg nmeamsg ; int i=0; int ret = 0; for(i=0; i<n; i++) { if(buff[i] == '$') nmea_index = 0; nmea_buf[nmea_index] = buff[i]; if(buff[i] == '\r') nmea_buf[nmea_index] = 0; if(buff[i] == '\n') { nmea_buf[nmea_index] = 0; #if 0 if (!quiet) fprintf(outfile,"%s\n",nmea_buf); #endif #if 1 ret = NmeaDecode(nmea_buf,&nmeamsg); if(nmeamsg.nMsgMask == GGA_DECODE) { memset(send_buf, 0, 1024); send_len = 0; } memcpy(send_buf+send_len, nmea_buf, nmea_index); send_len += strlen(nmea_buf); send_buf[send_len] = 0x0D; send_len ++; if(nmeamsg.nMsgMask & ANT_DECODE) { sAnt = nmeamsg.nAnttenaStatus; //sendudp(1011,&sAnt, 4); //gui sAnt |= (nmeamsg.version<<8); } if(nmeamsg.nMsgMask & RMC_DECODE) { if (nmea_buf[3] == 'R' && nmea_buf[4] == 'M' && nmea_buf[5] == 'C' ) { if (!quiet) fprintf(outfile,"%s=len=%d\n",nmea_buf, strlen(nmea_buf)); sendudp(1014,nmea_buf, strlen(nmea_buf)); //busdemaon } } if(nmeamsg.nMsgMask >= 0x8F) { sendudp(1012, send_buf, send_len); sendudp(1011,&nmeamsg.aSvInfo, 2*sizeof(tSVData)); //gui satelite display if (!quiet) { //fprintf(outfile,"\r\n\r\n%s---------send_len=%d\n\n",send_buf,send_len); fprintf(outfile,"nAnttenaStatus=%d,position=%c mode=%d fy=%f fx=%f (%d-%d-%d)(%d:%d:%f)\n", sAnt, nmeamsg.cFixFlag, NmeaGetRxRunMode(), nmeamsg.fLatInDegree, nmeamsg.fLonInDegree, nmeamsg.usYear, nmeamsg.ucMonth, nmeamsg.ucDay, nmeamsg.usHours, nmeamsg.usMinutes, nmeamsg.fSeconds); } #if 1 localtime_r(&timep, &p); p.tm_sec = (int)nmeamsg.fSeconds; p.tm_min = nmeamsg.usMinutes; p.tm_hour = nmeamsg.usHours+8; p.tm_mday = nmeamsg.ucDay; p.tm_mon = nmeamsg.ucMonth-1; p.tm_year = nmeamsg.usYear + 100; timep = mktime(&p); if(nmeamsg.cFixFlag == 'A') gps_buf[0] = 1; else gps_buf[0] = 0; gps_buf[1] = nmeamsg.fLonInDegree*1000000; gps_buf[2] = nmeamsg.fLatInDegree*1000000; gps_buf[3] = (int)timep; gps_buf[4] = (int)timep; gps_buf[5] = nmeamsg.fHeading; gps_buf[6] = nmeamsg.fGroundVel*1.85; if(nmeamsg.cLatIdx == 'S') gps_buf[7] = 1; else gps_buf[7] = 0; if(nmeamsg.cLonIdx == 'W') gps_buf[8] = 1; else gps_buf[8] = 0; gps_buf[9] = nmeamsg.fAltitude; gps_buf[10] = NmeaGetRxRunMode(); gps_buf[11] = nmeamsg.aSvInfo[1].nSvsUsed; gps_buf[12] = nmeamsg.aSvInfo[0].nSvsUsed; gps_buf[13] = sAnt; #if 0 printf("position=%d, flon=%d, flat=%d, %d, %d, iOrientation=%d, vel=%d, s=%d, w=%d, alt=%d, mode=%d, gps=%d, bd=%d\n", gps_buf[0], gps_buf[1],gps_buf[2],gps_buf[3], gps_buf[4],gps_buf[5], gps_buf[6],gps_buf[7], gps_buf[8],gps_buf[9], gps_buf[10], gps_buf[11], gps_buf[12]); #endif sendudp(1013, gps_buf, 4*14); sendudp(1015, gps_buf, 4*14); //busdemaon memset(gps_buf, 0 , 15); #endif memset(send_buf, 0, 1024); send_len = 0; } #endif } nmea_index++; // fprintf(outfile,"nmea_index = %d\n",nmea_index); if(nmea_index >= 1024) nmea_index = 0; } } } } if (please_die_now) break; if (FD_ISSET(frontfd[0], &readset)) { if ((n = read(frontfd[0], buff, BUFF_SIZE)) == 0) { if (listenfd) { if (close(frontfd[0]) < 0) errorf("Couldn't close old frontfd: %s\n",strerror(errno)); if ((frontfd[0]=frontfd[1]=accept(listenfd,NULL,NULL)) < 0) errorf("Couldn't accept new socket connection: %s\n",strerror(errno)); } } else if (n <= 0) { if ( (errno == EAGAIN) || (errno == EINTR) ) { /* No real error */ } else { errorf("Error reading from frontend device: %s\n",strerror(errno)); } } else { if (write (backfd[1], buff, n) != n) errorf("Error writing to backend device: %s\n",strerror(errno)); if (!quiet) dumpbuff(0,buff,n); } } } stty_orig(); exit(0); }
int main(int argc, char **argv) { struct arguments args; char *homedir = getenv("HOME"); char *channel = NULL; int lnb = -1, idx = -1; int vpid = -1, apid = -1, sid = -1; int pmtpid = 0; int pat_fd = -1, pmt_fd = -1, sid_fd = -1; int audio_fd = -1, video_fd = -1; int dvr_fd = -1, file_fd = -1; int err = -1; int r; struct dvb_v5_fe_parms *parms = NULL; const struct argp argp = { .options = options, .parser = parse_opt, .doc = N_("DVB zap utility"), .args_doc = N_("<channel name> [or <frequency> if in monitor mode]"), }; #ifdef ENABLE_NLS setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); #endif memset(&args, 0, sizeof(args)); args.sat_number = -1; args.lna = LNA_AUTO; args.input_format = FILE_DVBV5; argp_parse(&argp, argc, argv, ARGP_NO_HELP | ARGP_NO_EXIT, &idx, &args); if (idx < argc) channel = argv[idx]; if (!channel) { argp_help(&argp, stderr, ARGP_HELP_STD_HELP, PROGRAM_NAME); return -1; } if (args.input_format == FILE_UNKNOWN) { fprintf(stderr, _("ERROR: Please specify a valid format\n")); argp_help(&argp, stderr, ARGP_HELP_STD_HELP, PROGRAM_NAME); return -1; } if (!args.traffic_monitor && args.search) { fprintf(stderr, _("ERROR: search string can be used only on monitor mode\n")); argp_help(&argp, stderr, ARGP_HELP_STD_HELP, PROGRAM_NAME); return -1; } if (args.lnb_name) { lnb = dvb_sat_search_lnb(args.lnb_name); if (lnb < 0) { printf(_("Please select one of the LNBf's below:\n")); dvb_print_all_lnb(); exit(1); } else { printf(_("Using LNBf ")); dvb_print_lnb(lnb); } } r = asprintf(&args.demux_dev, "/dev/dvb/adapter%i/demux%i", args.adapter, args.demux); if (r < 0) { fprintf(stderr, _("asprintf error\n")); return -1; } r = asprintf(&args.dvr_dev, "/dev/dvb/adapter%i/dvr%i", args.adapter, args.demux); if (r < 0) { fprintf(stderr, _("asprintf error\n")); return -1; } if (args.silent < 2) fprintf(stderr, _("using demux '%s'\n"), args.demux_dev); if (!args.confname) { if (!homedir) ERROR(_("$HOME not set")); r = asprintf(&args.confname, "%s/.tzap/%i/%s", homedir, args.adapter, CHANNEL_FILE); if (access(args.confname, R_OK)) { free(args.confname); r = asprintf(&args.confname, "%s/.tzap/%s", homedir, CHANNEL_FILE); } } fprintf(stderr, _("reading channels from file '%s'\n"), args.confname); parms = dvb_fe_open(args.adapter, args.frontend, args.verbose, args.force_dvbv3); if (!parms) goto err; if (lnb >= 0) parms->lnb = dvb_sat_get_lnb(lnb); if (args.sat_number > 0) parms->sat_number = args.sat_number % 3; parms->diseqc_wait = args.diseqc_wait; parms->freq_bpf = args.freq_bpf; parms->lna = args.lna; r = dvb_fe_set_default_country(parms, args.cc); if (r < 0) fprintf(stderr, _("Failed to set the country code:%s\n"), args.cc); if (parse(&args, parms, channel, &vpid, &apid, &sid)) goto err; if (setup_frontend(&args, parms) < 0) goto err; if (args.exit_after_tuning) { err = 0; check_frontend(&args, parms); goto err; } if (args.traffic_monitor) { signal(SIGTERM, do_timeout); signal(SIGINT, do_timeout); if (args.timeout > 0) { signal(SIGINT, do_timeout); alarm(args.timeout); } err = do_traffic_monitor(&args, parms); goto err; } if (args.rec_psi) { if (sid < 0) { fprintf(stderr, _("Service id 0x%04x was not specified at the file\n"), sid); goto err; } sid_fd = dvb_dmx_open(args.adapter, args.demux); if (sid_fd < 0) { perror(_("opening pat demux failed")); return -1; } pmtpid = dvb_get_pmt_pid(sid_fd, sid); dvb_dmx_close(sid_fd); if (pmtpid <= 0) { fprintf(stderr, _("couldn't find pmt-pid for sid %04x\n"), sid); goto err; } if ((pat_fd = open(args.demux_dev, O_RDWR)) < 0) { perror(_("opening pat demux failed")); goto err; } if (dvb_set_pesfilter(pat_fd, 0, DMX_PES_OTHER, args.dvr ? DMX_OUT_TS_TAP : DMX_OUT_DECODER, args.dvr ? 64 * 1024 : 0) < 0) goto err; if ((pmt_fd = open(args.demux_dev, O_RDWR)) < 0) { perror(_("opening pmt demux failed")); goto err; } if (dvb_set_pesfilter(pmt_fd, pmtpid, DMX_PES_OTHER, args.dvr ? DMX_OUT_TS_TAP : DMX_OUT_DECODER, args.dvr ? 64 * 1024 : 0) < 0) goto err; } if (args.all_pids++) { vpid = 0x2000; apid = 0; } if (vpid >= 0) { if (args.silent < 2) { if (vpid == 0x2000) fprintf(stderr, _("pass all PID's to TS\n")); else fprintf(stderr, _("video pid %d\n"), vpid); } if ((video_fd = open(args.demux_dev, O_RDWR)) < 0) { PERROR(_("failed opening '%s'"), args.demux_dev); goto err; } if (args.silent < 2) fprintf(stderr, _(" dvb_set_pesfilter %d\n"), vpid); if (vpid == 0x2000) { if (ioctl(video_fd, DMX_SET_BUFFER_SIZE, 1024 * 1024) == -1) perror(_("DMX_SET_BUFFER_SIZE failed")); if (dvb_set_pesfilter(video_fd, vpid, DMX_PES_OTHER, DMX_OUT_TS_TAP, 0) < 0) goto err; } else { if (dvb_set_pesfilter(video_fd, vpid, DMX_PES_VIDEO, args.dvr ? DMX_OUT_TS_TAP : DMX_OUT_DECODER, args.dvr ? 64 * 1024 : 0) < 0) goto err; } } if (apid > 0) { if (args.silent < 2) fprintf(stderr, _("audio pid %d\n"), apid); if ((audio_fd = open(args.demux_dev, O_RDWR)) < 0) { PERROR(_("failed opening '%s'"), args.demux_dev); goto err; } if (args.silent < 2) fprintf(stderr, _(" dvb_set_pesfilter %d\n"), apid); if (dvb_set_pesfilter(audio_fd, apid, DMX_PES_AUDIO, args.dvr ? DMX_OUT_TS_TAP : DMX_OUT_DECODER, args.dvr ? 64 * 1024 : 0) < 0) goto err; } signal(SIGALRM, do_timeout); signal(SIGTERM, do_timeout); if (args.timeout > 0) { signal(SIGINT, do_timeout); alarm(args.timeout); } if (!check_frontend(&args, parms)) { err = 1; fprintf(stderr, _("frontend doesn't lock\n")); goto err; } if (args.dvr) { if (args.filename) { file_fd = STDOUT_FILENO; if (strcmp(args.filename, "-") != 0) { file_fd = open(args.filename, #ifdef O_LARGEFILE O_LARGEFILE | #endif O_WRONLY | O_CREAT, 0644); if (file_fd < 0) { PERROR(_("open of '%s' failed"), args.filename); return -1; } } } if (args.silent < 2) get_show_stats(&args, parms, 0); if (file_fd >= 0) { if ((dvr_fd = open(args.dvr_dev, O_RDONLY)) < 0) { PERROR(_("failed opening '%s'"), args.dvr_dev); goto err; } if (!timeout_flag) fprintf(stderr, _("Record to file '%s' started\n"), args.filename); copy_to_file(dvr_fd, file_fd, args.timeout, args.silent); } else { if (!timeout_flag) fprintf(stderr, _("DVR interface '%s' can now be opened\n"), args.dvr_dev); get_show_stats(&args, parms, 1); } if (args.silent < 2) get_show_stats(&args, parms, 0); } err = 0; err: if (file_fd > 0) close(file_fd); if (dvr_fd > 0) close(dvr_fd); if (pat_fd > 0) close(pat_fd); if (pmt_fd > 0) close(pmt_fd); if (audio_fd > 0) close(audio_fd); if (video_fd > 0) close(video_fd); if (parms) dvb_fe_close(parms); if (args.confname) free(args.confname); if (args.demux_dev) free(args.demux_dev); if (args.dvr_dev) free(args.dvr_dev); return err; }