/************************************************************************* * Copyright 2009 Ralph Spitzner (rasp@spitzner.org) * * This file is part of Yahdr. * * Yahdr is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Yahdr is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Yahdr. If not, see . **************************************************************************/ #include "dvbtcontrol.h" /******* Start frequencies case 0 ... 12: return 73000000; case 22 ... 90: return 138000000; step 8000000; always 8MhZ ********/ #define LCHANS 73000000 #define LNUM 13 #define UCHANS 138000000 #define UNUM 68 extern sql::mysql::MySQL_Driver *driver; extern sql::Connection *con; extern sql::Statement *stmt; DVBccontrol::DVBccontrol() { frontend_fd = demux_fd = dvr_fd = video_fd = audio_fd = nit_fd = 0; first_sdt = sdp = 0; intchan = 1; //ctor } //bool DVBccontrol::tuneto(uint32_t freq,uint8_t bw, uint16_t vpid, uint16_t apid,uint16_t textpid, fe_modulation_t QAM) bool DVBccontrol::tuneto(uint32_t freq,uint8_t bw, CPIDS *pids, fe_modulation_t QAM) { char buffer[256]; int i = 0; clearfds(); // printf("tune %d,%d\n",vpid,apid); memset(&frontend_param, 0, sizeof(struct dvb_frontend_parameters)); frontend_param.frequency = freq; frontend_param.inversion = INVERSION_AUTO; frontend_param.u.qam.symbol_rate = 6900000; frontend_param.u.qam.fec_inner = FEC_NONE; frontend_param.u.qam.modulation = QAM; if (frontend_fd == 0) { sprintf(buffer,"/dev/dvb/adapter%d/frontend%d",adapter,0); if ((frontend_fd = open(buffer, O_RDWR)) < 0) { printf ("failed opening '%s'", buffer); return false; } } if (setup_frontend (frontend_fd, &frontend_param) < 0) return false; if(0 == check_frontend(frontend_fd)) { cout << endl << "Frontend has _NO_ LOCK !!!" << endl; return false; } sprintf(buffer,"/dev/dvb/adapter%d/demux%d",adapter,0); if(pids != NULL) do { if ((pidfds[i] = open(buffer, O_RDWR)) < 0) { printf ("failed opening (fd #%d)\n", i); return false; } pesfilter.pid = pids->pid; //vpid; pesfilter.input = DMX_IN_FRONTEND; pesfilter.output = DMX_OUT_TS_TAP;// : */DMX_OUT_DECODER; pesfilter.flags = DMX_IMMEDIATE_START; printf("pid %d -- type %d\n",pids->pid,pids->type); pesfilter.pes_type = DMX_PES_OTHER; if (ioctl(pidfds[i], DMX_SET_PES_FILTER, &pesfilter) < 0) { printf("ioctl(DMX_SET_PES_FILTER) for PID #%d failed\n",i); //return false; } i++; } while(pids = pids->next); return true; } bool DVBccontrol::setup_frontend (int fe_fd, struct dvb_frontend_parameters *frontend) { struct dvb_frontend_info fe_info; if (ioctl(fe_fd, FE_GET_INFO, &fe_info) < 0) { printf("ioctl FE_GET_INFO failed\n"); return false; } //printf("CAPS: %x\n",fe_info.caps); if (fe_info.type != FE_QAM) { printf("frontend device is not a (DVB-C) device\n"); return false; } printf ("tuning to %i Hz\n", frontend->frequency); if (ioctl(fe_fd, FE_SET_FRONTEND, frontend) < 0) { printf("ioctl FE_SET_FRONTEND failed\n"); return false; } return true; } #warning get rid of init (useless by now anyway) bool DVBccontrol::init(uint16_t adapter,uint16_t device,char *ch_fname) { char buffer[256]; intchan = 1; ch_dbname = ch_fname; adapnum = adapter; devnum = device; memset(&frontend_param, 0, sizeof(struct dvb_frontend_parameters)); frontend_param.frequency = 73000000;//50500000; frontend_param.inversion = INVERSION_AUTO; frontend_param.u.qam.symbol_rate = 6900000; frontend_param.u.qam.fec_inner = FEC_NONE; frontend_param.u.qam.modulation = QAM_64; //frontend_param.u.ofdm.hierarchy_information = HIERARCHY_NONE; #warning put device # in config sprintf(buffer,"/dev/dvb/adapter%d/frontend%d",adapter,0); printf("DVBinit device %s\n",buffer); if ((frontend_fd = open(buffer, O_RDWR)) < 0) { printf ("failed opening '%s'", buffer); return false; } if (setup_frontend (frontend_fd, &frontend_param) < 0) return false; sprintf(buffer,"/dev/dvb/adapter%d/demux%d",demux_adapter,0); if ((demux_fd = open(buffer, O_RDWR)) < 0) { printf ("failed opening '%s'", buffer); return false; } if ((video_fd = open(buffer, O_RDWR)) < 0) { printf ("failed opening '%s'", buffer); return false; } if ((audio_fd = open(buffer, O_RDWR)) < 0) { printf ("failed opening '%s'", buffer); return false; } if ((nit_fd = open(buffer, O_RDWR)) < 0) { printf ("failed opening '%s'", buffer); return false; } return true; } bool DVBccontrol::scan() { int i,hadlock; uint32_t freq; CH chp; int tpnum; char buffer[256]; intchan = 0; tpnum = 1; if(frontend_fd == 0) { sprintf(buffer,"/dev/dvb/adapter%d/frontend0",adapter); if((frontend_fd = open(buffer,O_RDWR)) < 0) { printf("cannot open frontend\n"); exit(666); } } if(demux_fd == 0) { sprintf(buffer,"/dev/dvb/adapter%d/demux0",demux_adapter); if((demux_fd = open(buffer,O_RDWR)) < 0) { printf("cannot open demux\n"); exit(666); } } // stmt->execute("delete from channels;"); // stmt->execute("delete from pids;"); /// double (as in 2 times) for is not very lean..... for (i = 0 ; i != LNUM ; i++) { hadlock = 0; freq = LCHANS + (i * 8000000); frontend_param.frequency = freq; frontend_param.u.qam.symbol_rate = 6900000; frontend_param.u.qam.fec_inner = FEC_NONE; frontend_param.u.qam.modulation = QAM_64; chp.freq = freq; chp.bw = 8; if (setup_frontend (frontend_fd, &frontend_param) == false) { printf("setup frontend failed !!\n"); return false; } if (check_frontend (frontend_fd)) { printf("##### LOCK on freq %d QAM_64\n",freq); qam = QAM_64; read_tpinfo(&chp,tpnum++); /// read info and put into db hadlock = 1; } else printf("!!!! no LOCK on freq %d QAM_64\n",freq); if (hadlock == 0) { frontend_param.u.qam.modulation = QAM_256; if (setup_frontend (frontend_fd, &frontend_param) < 0) return false; if (check_frontend (frontend_fd)) { printf("##### LOCK on freq %d QAM_256\n",freq); qam = QAM_256; read_tpinfo(&chp,tpnum++); /// read info and put into db } else printf("!!!! no LOCK on freq %d QAM_256\n",freq); } } printf("############ Switching to UPPER band\n"); for (i = 0 ; i != UNUM ; i++) { hadlock = 0; freq = UCHANS + (i * 8000000); frontend_param.frequency = freq; frontend_param.u.qam.symbol_rate = 6900000; frontend_param.u.qam.fec_inner = FEC_NONE; frontend_param.u.qam.modulation = QAM_256; chp.freq = freq; chp.bw = 8; if (setup_frontend (frontend_fd, &frontend_param) < 0) return false; if (check_frontend (frontend_fd)) { printf("##### LOCK on freq %d QAM_256\n",freq); qam = QAM_256; read_tpinfo(&chp,tpnum++); /// read info and put into db hadlock = 1; } else printf("!!!! no LOCK on freq %d QAM_256\n",freq); if (hadlock == 0) { frontend_param.u.qam.modulation = QAM_64; if (setup_frontend (frontend_fd, &frontend_param) < 0) return false; if (check_frontend (frontend_fd)) { printf("##### LOCK on freq %d QAM_64\n",freq); qam = QAM_64; read_tpinfo(&chp,tpnum++); /// read info and put into db } else printf("!!!! no LOCK on freq %d QAM_64\n",freq); } } return true; } DVBccontrol::~DVBccontrol() { //dtor }