📄 scan.c
字号:
s->table_id = tid; s->run_once = run_once; s->segmented = segmented; if (long_timeout) s->timeout = 5 * timeout; else s->timeout = timeout; s->table_id_ext = -1; s->section_version_number = -1; INIT_LIST_HEAD (&s->list);}static void update_poll_fds(void){ struct list_head *p; struct section_buf* s; int i; memset(poll_section_bufs, 0, sizeof(poll_section_bufs)); for (i = 0; i < MAX_RUNNING; i++) poll_fds[i].fd = -1; i = 0; list_for_each (p, &running_filters) { if (i >= MAX_RUNNING) fatal("too many poll_fds\n"); s = list_entry (p, struct section_buf, list); if (s->fd == -1) fatal("s->fd == -1 on running_filters\n"); verbosedebug("poll fd %d\n", s->fd); poll_fds[i].fd = s->fd; poll_fds[i].events = POLLIN; poll_fds[i].revents = 0; poll_section_bufs[i] = s; i++; } if (i != n_running) fatal("n_running is hosed\n");}static int start_filter (struct section_buf* s){ struct dmx_sct_filter_params f; if (n_running >= MAX_RUNNING) goto err0; if ((s->fd = open (s->dmx_devname, O_RDWR)) < 0) goto err0; verbosedebug("start filter pid 0x%04x table_id 0x%02x\n", s->pid, s->table_id); memset(&f, 0, sizeof(f)); f.pid = (uint16_t) s->pid; if (s->table_id < 0x100 && s->table_id > 0) { f.filter.filter[0] = (uint8_t) s->table_id; f.filter.mask[0] = 0xff; } f.timeout = 0; f.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC; if (ioctl(s->fd, DMX_SET_FILTER, &f) == -1) { errorn ("ioctl DMX_SET_FILTER failed"); goto err1; } s->sectionfilter_done = 0; time(&s->start_time); list_del_init (&s->list); /* might be in waiting filter list */ list_add (&s->list, &running_filters); n_running++; update_poll_fds(); return 0;err1: ioctl (s->fd, DMX_STOP); close (s->fd);err0: return -1;}static void stop_filter (struct section_buf *s){ verbosedebug("stop filter pid 0x%04x\n", s->pid); ioctl (s->fd, DMX_STOP); close (s->fd); s->fd = -1; list_del (&s->list); s->running_time += time(NULL) - s->start_time; n_running--; update_poll_fds();}static void add_filter (struct section_buf *s){ verbosedebug("add filter pid 0x%04x\n", s->pid); if (start_filter (s)) list_add_tail (&s->list, &waiting_filters);}static void remove_filter (struct section_buf *s){ verbosedebug("remove filter pid 0x%04x\n", s->pid); stop_filter (s); while (!list_empty(&waiting_filters)) { struct list_head *next = waiting_filters.next; s = list_entry (next, struct section_buf, list); if (start_filter (s)) break; };}static void read_filters (void){ struct section_buf *s; int i, n, done; n = poll(poll_fds, n_running, 1000); if (n == -1) errorn("poll"); for (i = 0; i < n_running; i++) { s = poll_section_bufs[i]; if (!s) fatal("poll_section_bufs[%d] is NULL\n", i); if (poll_fds[i].revents) done = read_sections (s) == 1; else done = 0; /* timeout */ if (done || time(NULL) > s->start_time + s->timeout) { if (s->run_once) { if (done) verbosedebug("filter done pid 0x%04x\n", s->pid); else info("Info: filter timeout pid 0x%04x\n", s->pid); remove_filter (s); } } }}static int mem_is_zero (const void *mem, int size){ const char *p = mem; unsigned long i; for (i=0; i<size; i++) { if (p[i] != 0x00) return 0; } return 1;}static int __tune_to_transponder (int frontend_fd, struct transponder *t, int v){ struct dvb_frontend_parameters p; fe_status_t s; int i; current_tp = t; if (mem_is_zero (&t->param, sizeof(struct dvb_frontend_parameters))) return -1; memcpy (&p, &t->param, sizeof(struct dvb_frontend_parameters)); if ((verbosity >= 1) && (v > 0)) { dprintf(1, "tune to: "); dump_dvb_parameters (stderr, t); if (t->last_tuning_failed) dprintf(1, " (no signal)"); dprintf(1, "\n"); } if (ioctl(frontend_fd, FE_SET_FRONTEND, &p) == -1) { errorn("Setting frontend parameters failed"); return -1; } for (i = 0; i < 5*tuning_speed; i++) { usleep (200000); if (ioctl(frontend_fd, FE_READ_STATUS, &s) == -1) { errorn("FE_READ_STATUS failed"); return -1; } if (v > 0) verbose(">>> tuning status == 0x%02x\n", s); if (s & FE_HAS_LOCK) { t->last_tuning_failed = 0; return 0; } } if (v > 0) info("----------no signal----------\n"); else info("no signal(0x%02x)\n", s); t->last_tuning_failed = 1; return -1;}static int tune_to_transponder (int frontend_fd, struct transponder *t){ /* move TP from "new" to "scanned" list */ list_del_init(&t->list); list_add_tail(&t->list, &scanned_transponders); t->scan_done = 1; if (t->type != fe_info.type) { /* ignore cable descriptors in sat NIT and vice versa */ t->last_tuning_failed = 1; return -1; } if (__tune_to_transponder (frontend_fd, t, 1) == 0) return 0; return __tune_to_transponder (frontend_fd, t, 1);}static int tune_to_next_transponder (int frontend_fd){ struct list_head *pos, *tmp; struct transponder *t; list_for_each_safe(pos, tmp, &new_transponders) { t = list_entry (pos, struct transponder, list);retry: if (tune_to_transponder (frontend_fd, t) == 0) return 0; if (t->other_frequency_flag && t->other_f && t->n_other_f) { t->param.frequency = t->other_f[t->n_other_f - 1]; t->n_other_f--; info("retrying with f=%d\n", t->param.frequency); goto retry; } } return -1;}struct strtab { const char *str; int val;};static int check_frontend (int fd, int verbose) { fe_status_t status; uint16_t snr, signal; uint32_t ber, uncorrected_blocks; ioctl(fd, FE_READ_STATUS, &status); ioctl(fd, FE_READ_SIGNAL_STRENGTH, &signal); ioctl(fd, FE_READ_SNR, &snr); ioctl(fd, FE_READ_BER, &ber); ioctl(fd, FE_READ_UNCORRECTED_BLOCKS, &uncorrected_blocks); if (verbose) { info("signal %04x | snr %04x | ber %08x | unc %08x | ", \ signal, snr, ber, uncorrected_blocks); if (status & FE_HAS_LOCK) info("FE_HAS_LOCK"); info("\n"); } return (status & FE_HAS_LOCK);}static int initial_tune (int frontend_fd){unsigned int f, channel, cnt, ret, qam_parm;struct transponder *t, *ptest;struct transponder test;struct dvb_frontend_parameters frontend_parameters;test.type = FE_OFDM;test.param.inversion = caps_inversion;test.param.u.ofdm.bandwidth = BANDWIDTH_7_MHZ;test.param.u.ofdm.code_rate_HP = caps_fec;test.param.u.ofdm.code_rate_LP = caps_fec;test.param.u.ofdm.constellation = caps_qam;test.param.u.ofdm.transmission_mode = caps_transmission_mode;test.param.u.ofdm.guard_interval = caps_guard_interval;test.param.u.ofdm.hierarchy_information = caps_hierarchy;test.param.frequency = 177500000;ptest=&test;memcpy (&frontend_parameters, &ptest->param, sizeof(struct dvb_frontend_parameters));if (fe_info.type == FE_OFDM) { // DVB-T// for (channel=5; channel <= 12; channel++) {for (channel=5; channel <= 12; channel++) { f=142500000 + channel*7000000; test.type = FE_OFDM; test.param.inversion = caps_inversion; test.param.u.ofdm.bandwidth = BANDWIDTH_7_MHZ; test.param.u.ofdm.code_rate_HP = caps_fec; test.param.u.ofdm.code_rate_LP = caps_fec; test.param.u.ofdm.constellation = caps_qam; test.param.u.ofdm.transmission_mode = caps_transmission_mode; test.param.u.ofdm.guard_interval = caps_guard_interval; test.param.u.ofdm.hierarchy_information = caps_hierarchy; test.param.frequency = f; memcpy (&frontend_parameters, &ptest->param, \ sizeof(struct dvb_frontend_parameters)); if (ioctl(frontend_fd, FE_SET_FRONTEND, &frontend_parameters) < 0) { dprintf(1, "%s:%d: Setting frontend parameters failed f%d bw%d", __FUNCTION__,__LINE__,f,7); continue; } usleep (1500000); info("%d: ", frontend_parameters.frequency/1000); for (cnt=0;cnt<5;cnt++) { ret = check_frontend(frontend_fd,0); if (ret == 1) break; usleep(200000); } if (ret == 0) { info("\n"); continue; } if (__tune_to_transponder (frontend_fd, ptest,0) < 0) continue; t = alloc_transponder(f); t->type = ptest->type; t->param.inversion = ptest->param.inversion; t->param.u.ofdm.bandwidth = ptest->param.u.ofdm.bandwidth; t->param.u.ofdm.code_rate_HP = ptest->param.u.ofdm.code_rate_HP; t->param.u.ofdm.code_rate_LP = ptest->param.u.ofdm.code_rate_LP; t->param.u.ofdm.constellation = ptest->param.u.ofdm.constellation; t->param.u.ofdm.transmission_mode = ptest->param.u.ofdm.transmission_mode; t->param.u.ofdm.guard_interval = ptest->param.u.ofdm.guard_interval; t->param.u.ofdm.hierarchy_information = ptest->param.u.ofdm.hierarchy_information; info("signal ok (I%sB%sC%sD%sM%sT%sG%sY%s)\n", inv_name[t->param.inversion], bw_name[t->param.u.ofdm.bandwidth], fec_name[t->param.u.ofdm.code_rate_HP], fec_name[t->param.u.ofdm.code_rate_LP], qam_name[t->param.u.ofdm.constellation], mode_name[t->param.u.ofdm.transmission_mode], guard_name[t->param.u.ofdm.guard_interval], hierarchy_name[t->param.u.ofdm.hierarchy_information]); } for (channel=21; channel<= 69; channel++) { f=306000000 + channel*8000000; test.type = FE_OFDM; test.param.inversion = caps_inversion; test.param.u.ofdm.bandwidth = BANDWIDTH_8_MHZ; test.param.u.ofdm.code_rate_HP = caps_fec; test.param.u.ofdm.code_rate_LP = caps_fec; test.param.u.ofdm.constellation = caps_qam; test.param.u.ofdm.transmission_mode = caps_transmission_mode; test.param.u.ofdm.guard_interval = caps_guard_interval; test.param.u.ofdm.hierarchy_information = caps_hierarchy; test.param.frequency = f; memcpy (&frontend_parameters, &ptest->param, \ sizeof(struct dvb_frontend_parameters)); if (ioctl(frontend_fd, FE_SET_FRONTEND, &frontend_parameters) < 0) { dprintf(1, "%s:%d: Setting frontend parameters failed f%d bw%d", __FUNCTION__,__LINE__,f,8); continue; } usleep (1500000); info("%d: ", frontend_parameters.frequency/1000); for (cnt=0;cnt<5;cnt++) { ret = check_frontend(frontend_fd,0); if (ret == 1) break; usleep(200000); } if (ret == 0) { info("\n"); continue; } if (__tune_to_transponder (frontend_fd, ptest,0) < 0) continue; t = alloc_transponder(f); t->type = ptest->type; t->param.inversion = ptest->param.inversion; t->param.u.ofdm.bandwidth = ptest->param.u.ofdm.bandwidth; t->param.u.ofdm.code_rate_HP = ptest->param.u.ofdm.code_rate_HP; t->param.u.ofdm.code_rate_LP = ptest->param.u.ofdm.code_rate_LP; t->param.u.ofdm.constellation = ptest->param.u.ofdm.constellation; t->param.u.ofdm.transmission_mode = ptest->param.u.ofdm.transmission_mode; t->param.u.ofdm.guard_interval = ptest->param.u.ofdm.guard_interval; t->param.u.ofdm.hierarchy_information = ptest->param.u.ofdm.hierarchy_information; info("signal ok (I%sB%sC%sD%sM%sT%sG%sY%s)\n", inv_name[t->param.inversion], bw_name[t->param.u.ofdm.bandwidth], fec_name[t->param.u.ofdm.code_rate_HP], fec_name[t->param.u.ofdm.code_rate_LP], qam_name[t->param.u.ofdm.constellation], mode_name[t->param.u.ofdm.transmission_mode], guard_name[t->param.u.ofdm.guard_interval], hierarchy_name[t->param.u.ofdm.hierarchy_information]); } }if (fe_info.type == FE_QAM) { // DVB-C // 20060705 for (qam_parm=0; qam_parm<6; qam_parm++) { //info ("qam_parm=M%s\n", qam_name[qam_parm]); this_qam=caps_qam; if (qam_no_auto) switch(qam_parm) { case 0: continue; case 1: continue; case 2: continue; case 4: continue; default: this_qam=qam_tab[qam_parm];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -