|
From: <lin...@us...> - 2002-06-27 19:29:42
|
Update of /cvsroot/dvbtools/dvbstream In directory usw-pr-cvs1:/tmp/cvs-serv17263 Modified Files: tune.c Added Files: dvb_defaults.h Log Message: copied tune.c from dvbtune --- NEW FILE: dvb_defaults.h --- /* dvb_defaults.h Idea provided by Tomi Ollila, implemented by Dave Chapman. Copyright (C) Dave Chapman 2002 This program 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 2 of the License, or (at your option) any later version. This program 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 this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Or, point your browser to http://www.gnu.org/copyleft/gpl.html */ #ifndef _DVB_DEFAULTS_H #define _DVB_DEFAULTS_H /* Either uncomment one of the following lines, or add it to your "make" command. e.g. make FINLAND=1 */ //#define UK //#define FINLAND //#define FINLAND2 /* Firstly, lets define some world-wide defaults */ #define BANDWIDTH_DEFAULT BANDWIDTH_8_MHZ #define CONSTELLATION_DEFAULT QAM_64 #define HIERARCHY_DEFAULT HIERARCHY_NONE #define LP_CODERATE_DEFAULT FEC_1_2 /* DVB-T */ #ifdef UK /* UNITED KINGDOM settings */ #define HP_CODERATE_DEFAULT FEC_2_3 #define TRANSMISSION_MODE_DEFAULT TRANSMISSION_MODE_2K #define GUARD_INTERVAL_DEFAULT GUARD_INTERVAL_1_32 #endif #ifdef FINLAND /* FINLAND settings 1 */ #define HP_CODERATE_DEFAULT FEC_2_3 #define TRANSMISSION_MODE_DEFAULT TRANSMISSION_MODE_8K #define GUARD_INTERVAL_DEFAULT GUARD_INTERVAL_1_8 #endif #ifdef FINLAND2 /* FINLAND settings 2 */ #define HP_CODERATE_DEFAULT FEC_1_2 #define TRANSMISSION_MODE_DEFAULT TRANSMISSION_MODE_2K #define GUARD_INTERVAL_DEFAULT GUARD_INTERVAL_1_8 #endif #ifndef HP_CODERATE_DEFAULT #warning No DVB-T country defined in dvb_defaults.h #warning defaulting to UK #warning Ignore this if using Satellite or Cable /* Default to the UK */ #define HP_CODERATE_DEFAULT FEC_2_3 #define TRANSMISSION_MODE_DEFAULT TRANSMISSION_MODE_2K #define GUARD_INTERVAL_DEFAULT GUARD_INTERVAL_1_32 #endif #endif Index: tune.c =================================================================== RCS file: /cvsroot/dvbtools/dvbstream/tune.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** tune.c 17 May 2002 16:25:12 -0000 1.2 --- tune.c 27 Jun 2002 19:29:36 -0000 1.3 *************** *** 1,2 **** --- 1,23 ---- + /* dvbtune - tune.c + + Copyright (C) Dave Chapman 2001,2002 + + This program 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 2 + of the License, or (at your option) any later version. + + This program 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + Or, point your browser to http://www.gnu.org/copyleft/gpl.html + + */ + #include <stdio.h> #include <stdlib.h> *************** *** 4,12 **** #include <sys/ioctl.h> #include <sys/poll.h> ! #include <fcntl.h> #include <ost/dmx.h> #include <ost/sec.h> #include <ost/frontend.h> #define slof (11700*1000UL) --- 25,36 ---- #include <sys/ioctl.h> #include <sys/poll.h> ! #include <unistd.h> #include <ost/dmx.h> #include <ost/sec.h> #include <ost/frontend.h> + #include <ost/frontend.h> + + #include "dvb_defaults.h" #define slof (11700*1000UL) *************** *** 14,19 **** #define lof2 (10600*1000UL) ! int tune_it(int fd_frontend, int fd_sec, unsigned long freq, unsigned long srate, char pol) { int i,res; int32_t strength; --- 38,151 ---- #define lof2 (10600*1000UL) ! int OSTSelftest(int fd) ! { ! int ans; ! ! if ( (ans = ioctl(fd,FE_SELFTEST,0) < 0)){ ! perror("FE SELF TEST: "); ! return -1; ! } ! ! return 0; ! } ! ! int OSTSetPowerState(int fd, uint32_t state) ! { ! int ans; ! ! if ( (ans = ioctl(fd,FE_SET_POWER_STATE,state) < 0)){ ! perror("OST SET POWER STATE: "); ! return -1; ! } ! ! return 0; ! } ! ! int OSTGetPowerState(int fd, uint32_t *state) ! { ! int ans; ! ! if ( (ans = ioctl(fd,FE_GET_POWER_STATE,state) < 0)){ ! perror("OST GET POWER STATE: "); ! return -1; ! } ! ! switch(*state){ ! case FE_POWER_ON: ! fprintf(stderr,"POWER ON (%d)\n",*state); ! break; ! case FE_POWER_STANDBY: ! fprintf(stderr,"POWER STANDBY (%d)\n",*state); ! break; ! case FE_POWER_SUSPEND: ! fprintf(stderr,"POWER SUSPEND (%d)\n",*state); ! break; ! case FE_POWER_OFF: ! fprintf(stderr,"POWER OFF (%d)\n",*state); ! break; ! default: ! fprintf(stderr,"unknown (%d)\n",*state); ! break; ! } ! ! return 0; ! } ! ! int SecGetStatus (int fd, struct secStatus *state) ! { ! int ans; ! ! if ( (ans = ioctl(fd,SEC_GET_STATUS, state) < 0)){ ! perror("SEC GET STATUS: "); ! return -1; ! } ! ! switch (state->busMode){ ! case SEC_BUS_IDLE: ! fprintf(stderr,"SEC BUS MODE: IDLE (%d)\n",state->busMode); ! break; ! case SEC_BUS_BUSY: ! fprintf(stderr,"SEC BUS MODE: BUSY (%d)\n",state->busMode); ! break; ! case SEC_BUS_OFF: ! fprintf(stderr,"SEC BUS MODE: OFF (%d)\n",state->busMode); ! break; ! case SEC_BUS_OVERLOAD: ! fprintf(stderr,"SEC BUS MODE: OVERLOAD (%d)\n",state->busMode); ! break; ! default: ! fprintf(stderr,"SEC BUS MODE: unknown (%d)\n",state->busMode); ! break; ! } + switch (state->selVolt){ + case SEC_VOLTAGE_OFF: + fprintf(stderr,"SEC VOLTAGE: OFF (%d)\n",state->selVolt); + break; + case SEC_VOLTAGE_LT: + fprintf(stderr,"SEC VOLTAGE: LT (%d)\n",state->selVolt); + break; + case SEC_VOLTAGE_13: + fprintf(stderr,"SEC VOLTAGE: 13 (%d)\n",state->selVolt); + break; + case SEC_VOLTAGE_13_5: + fprintf(stderr,"SEC VOLTAGE: 13.5 (%d)\n",state->selVolt); + break; + case SEC_VOLTAGE_18: + fprintf(stderr,"SEC VOLTAGE: 18 (%d)\n",state->selVolt); + break; + case SEC_VOLTAGE_18_5: + fprintf(stderr,"SEC VOLTAGE: 18.5 (%d)\n",state->selVolt); + break; + default: + fprintf(stderr,"SEC VOLTAGE: unknown (%d)\n",state->selVolt); + break; + } + + fprintf(stderr,"SEC CONT TONE: %s\n", (state->contTone == SEC_TONE_ON ? "ON" : "OFF")); + return 0; + } + + int tune_it(int fd_frontend, int fd_sec, unsigned int freq, unsigned int srate, char pol, int tone, SpectralInversion specInv, unsigned int diseqc) { int i,res; int32_t strength; *************** *** 21,85 **** FrontendEvent event; FrontendParameters feparams; - secToneMode tone; secVoltage voltage; ! if (freq > 100000000) { ! fprintf(stderr,"tuning DVB-T to %u\n",freq); ! feparams.Frequency=freq; ! feparams.u.ofdm.bandWidth=BANDWIDTH_8_MHZ; // WAS: 8 ! feparams.u.ofdm.HP_CodeRate=FEC_2_3; ! feparams.u.ofdm.LP_CodeRate=FEC_1_2; ! feparams.u.ofdm.Constellation=QAM_64; // WAS: 16 ! feparams.u.ofdm.TransmissionMode=TRANSMISSION_MODE_2K; ! feparams.u.ofdm.guardInterval=GUARD_INTERVAL_1_32; ! feparams.u.ofdm.HierarchyInformation=HIERARCHY_NONE; ! } else { ! fprintf(stderr,"tuning DVB-S to %d%c %d\n",freq,pol,srate); ! if (freq < slof) { ! feparams.Frequency=(freq-lof1); ! tone = SEC_TONE_OFF; ! } else { ! feparams.Frequency=(freq-lof2); ! tone = SEC_TONE_ON; ! } ! feparams.Inversion=INVERSION_AUTO; ! if ((pol=='h') || (pol=='H')) { ! voltage = SEC_VOLTAGE_18; ! } else { ! voltage = SEC_VOLTAGE_13; ! } ! feparams.u.qpsk.SymbolRate=srate; ! feparams.u.qpsk.FEC_inner=FEC_AUTO; ! if (ioctl(fd_sec,SEC_SET_TONE,tone) < 0) { ! perror("ERROR setting tone\n"); ! } ! ! if (ioctl(fd_sec,SEC_SET_VOLTAGE,voltage) < 0) { ! perror("ERROR setting voltage\n"); ! } ! usleep(200000); ! } ! if (ioctl(fd_frontend,FE_SET_FRONTEND,&feparams) < 0) { ! perror("ERROR tuning channel\n"); ! } else { ! fprintf(stderr,"Channel tuned\n"); } ! // usleep(5000000); ! i=10; ! res = ioctl(fd_frontend, FE_GET_EVENT, &event); ! while ((i<10) && (res < 0)) { ! res = ioctl(fd_frontend, FE_GET_EVENT, &event); ! i--; } ! if (res < 0) ! perror("qpsk get event"); ! else switch (event.type) { case FE_UNEXPECTED_EV: fprintf(stderr,"FE_UNEXPECTED_EV\n"); --- 153,297 ---- FrontendEvent event; FrontendParameters feparams; secVoltage voltage; + struct pollfd pfd[1]; + struct secStatus sec_state; + FrontendInfo fe_info; ! if ( (res = ioctl(fd_frontend,FE_GET_INFO, &fe_info) < 0)){ ! perror("FE_GET_INFO: "); ! return -1; ! } ! ! // OSTSelftest(fd_frontend); ! // OSTSetPowerState(fd_frontend, FE_POWER_ON); ! // OSTGetPowerState(fd_frontend, &festatus); ! switch(fe_info.type) { ! case FE_OFDM: ! fprintf(stderr,"tuning DVB-T to %d\n",freq); ! feparams.Frequency=freq; ! feparams.Inversion=INVERSION_OFF; ! feparams.u.ofdm.bandWidth=BANDWIDTH_DEFAULT; ! feparams.u.ofdm.HP_CodeRate=HP_CODERATE_DEFAULT; ! feparams.u.ofdm.LP_CodeRate=LP_CODERATE_DEFAULT; ! feparams.u.ofdm.Constellation=CONSTELLATION_DEFAULT; ! feparams.u.ofdm.TransmissionMode=TRANSMISSION_MODE_DEFAULT; ! feparams.u.ofdm.guardInterval=GUARD_INTERVAL_DEFAULT; ! feparams.u.ofdm.HierarchyInformation=HIERARCHY_DEFAULT; ! break; ! case FE_QPSK: ! fprintf(stderr,"tuning DVB-S to L-Band:%d, Pol:%c Srate=%d, 22kHz=%s\n",feparams.Frequency,pol,srate,tone == SEC_TONE_ON ? "on" : "off"); ! if ((pol=='h') || (pol=='H')) { ! voltage = SEC_VOLTAGE_18; ! } else { ! voltage = SEC_VOLTAGE_13; ! } ! if (ioctl(fd_sec,SEC_SET_VOLTAGE,voltage) < 0) { ! perror("ERROR setting voltage\n"); ! } ! if (freq > 2200000) { ! // this must be an absolute frequency ! if (freq < slof) { ! feparams.Frequency=(freq-lof1); ! if (tone < 0) tone = SEC_TONE_OFF; ! } else { ! feparams.Frequency=(freq-lof2); ! if (tone < 0) tone = SEC_TONE_ON; ! } ! } else { ! // this is an L-Band frequency ! feparams.Frequency=freq; ! } ! ! feparams.Inversion=specInv; ! feparams.u.qpsk.SymbolRate=srate; ! feparams.u.qpsk.FEC_inner=FEC_AUTO; ! if (ioctl(fd_sec,SEC_SET_TONE,tone) < 0) { ! perror("ERROR setting tone\n"); ! } ! if (diseqc > 0) { ! struct secCommand scmd; ! struct secCmdSequence scmds; ! ! scmds.continuousTone = tone; ! scmds.voltage = voltage; ! /* ! scmds.miniCommand = toneBurst ? SEC_MINI_B : SEC_MINI_A; ! */ ! scmds.miniCommand = SEC_MINI_NONE; ! ! scmd.type = 0; ! scmds.numCommands = 1; ! scmds.commands = &scmd; ! ! scmd.u.diseqc.addr = 0x10; ! scmd.u.diseqc.cmd = 0x38; ! scmd.u.diseqc.numParams = 1; ! scmd.u.diseqc.params[0] = 0xf0 | ! (((diseqc - 1) << 2) & 0x0c) | ! (voltage==SEC_VOLTAGE_18 ? 0x02 : 0) | ! (tone==SEC_TONE_ON ? 0x01 : 0); ! ! if (ioctl(fd_sec,SEC_SEND_SEQUENCE,&scmds) < 0) { ! perror("Error sending DisEqC"); ! return -1; ! } ! } ! break; ! case FE_QAM: ! feparams.Frequency=freq; ! feparams.Inversion=INVERSION_OFF; ! feparams.u.qam.SymbolRate = srate; ! feparams.u.qam.FEC_inner = FEC_AUTO; ! feparams.u.qam.QAM = QAM_64; break; ! default: ! fprintf(stderr,"Unknown FE type. Aborting\n"); ! exit(-1); } + usleep(100000); + + if (fd_sec) SecGetStatus(fd_sec, &sec_state); + + i = 0; res = -1; + while ((i < 3) && (res < 0)) { + if (ioctl(fd_frontend,FE_SET_FRONTEND,&feparams) < 0) { + perror("ERROR tuning channel\n"); + return -1; + } ! pfd[0].fd = fd_frontend; ! pfd[0].events = POLLIN; ! if (poll(pfd,1,10000)){ ! if (pfd[0].revents & POLLIN){ ! fprintf(stderr,"Getting frontend event\n"); ! if ( ioctl(fd_frontend, FE_GET_EVENT, &event) == -EBUFFEROVERFLOW){ ! perror("FE_GET_EVENT"); ! return -1; ! } ! fprintf(stderr,"Received "); ! switch(event.type){ ! case FE_UNEXPECTED_EV: ! fprintf(stderr,"unexpected event\n"); ! res = -1; ! break; ! case FE_FAILURE_EV: ! fprintf(stderr,"failure event\n"); ! res = -1; ! break; ! case FE_COMPLETION_EV: ! fprintf(stderr,"completion event\n"); ! res = 0; ! break; ! } ! } ! i++; ! } } ! if (res > 0) switch (event.type) { case FE_UNEXPECTED_EV: fprintf(stderr,"FE_UNEXPECTED_EV\n"); *************** *** 89,128 **** case FE_FAILURE_EV: fprintf(stderr,"FE_FAILURE_EV\n"); break; ! } ! if (freq > 100000000) { ! fprintf(stderr,"Event: iFrequency: %ld\n",event.u.completionEvent.Frequency); ! } else { ! fprintf(stderr,"Event: iFrequency: %ld\n",(event.u.completionEvent.Frequency)+(tone==SEC_TONE_OFF ? lof1 : lof2)); ! fprintf(stderr," SymbolRate: %ld\n",event.u.completionEvent.u.qpsk.SymbolRate); ! fprintf(stderr," FEC_inner: %d\n",event.u.completionEvent.u.qpsk.FEC_inner); ! fprintf(stderr,"\n"); ! } ! strength=0; ! ioctl(fd_frontend,FE_READ_BER,&strength); ! fprintf(stderr,"Bit error rate: %ld\n",strength); ! strength=0; ! ioctl(fd_frontend,FE_READ_SIGNAL_STRENGTH,&strength); ! fprintf(stderr,"Signal strength: %ld\n",strength); ! strength=0; ! ioctl(fd_frontend,FE_READ_SNR,&strength); ! fprintf(stderr,"SNR: %ld\n",strength); ! festatus=0; ! ioctl(fd_frontend,FE_READ_STATUS,&festatus); ! fprintf(stderr,"FE_STATUS:"); ! if (festatus & FE_HAS_POWER) fprintf(stderr," FE_HAS_POWER"); ! if (festatus & FE_HAS_SIGNAL) fprintf(stderr," FE_HAS_SIGNAL"); ! if (festatus & FE_SPECTRUM_INV) fprintf(stderr," FE_SPECTRUM_INV"); ! if (festatus & FE_HAS_LOCK) fprintf(stderr," FE_HAS_LOCK"); ! if (festatus & FE_HAS_CARRIER) fprintf(stderr," FE_HAS_CARRIER"); ! if (festatus & FE_HAS_VITERBI) fprintf(stderr," FE_HAS_VITERBI"); ! if (festatus & FE_HAS_SYNC) fprintf(stderr," FE_HAS_SYNC"); ! if (festatus & FE_TUNER_HAS_LOCK) fprintf(stderr," FE_TUNER_HAS_LOCK"); ! fprintf(stderr,"\n"); ! } --- 301,369 ---- case FE_FAILURE_EV: fprintf(stderr,"FE_FAILURE_EV\n"); break; ! } ! if (event.type == FE_COMPLETION_EV) { ! switch(fe_info.type) { ! case FE_OFDM: ! fprintf(stderr,"Event: Frequency: %d\n",event.u.completionEvent.Frequency); ! break; ! case FE_QPSK: ! fprintf(stderr,"Event: Frequency: %d\n",(unsigned int)((event.u.completionEvent.Frequency)+(tone==SEC_TONE_OFF ? lof1 : lof2))); ! fprintf(stderr," SymbolRate: %d\n",event.u.completionEvent.u.qpsk.SymbolRate); ! fprintf(stderr," FEC_inner: %d\n",event.u.completionEvent.u.qpsk.FEC_inner); ! fprintf(stderr,"\n"); ! break; ! case FE_QAM: ! fprintf(stderr,"Event: Frequency: %d\n",event.u.completionEvent.Frequency); ! fprintf(stderr," SymbolRate: %d\n",event.u.completionEvent.u.qpsk.SymbolRate); ! fprintf(stderr," FEC_inner: %d\n",event.u.completionEvent.u.qpsk.FEC_inner); ! break; ! default: ! break; ! } ! strength=0; ! ioctl(fd_frontend,FE_READ_BER,&strength); ! fprintf(stderr,"Bit error rate: %d\n",strength); ! strength=0; ! ioctl(fd_frontend,FE_READ_SIGNAL_STRENGTH,&strength); ! fprintf(stderr,"Signal strength: %d\n",strength); ! strength=0; ! ioctl(fd_frontend,FE_READ_SNR,&strength); ! fprintf(stderr,"SNR: %d\n",strength); ! festatus=0; ! ioctl(fd_frontend,FE_READ_STATUS,&festatus); ! fprintf(stderr,"FE_STATUS:"); ! if (festatus & FE_HAS_POWER) fprintf(stderr," FE_HAS_POWER"); ! if (festatus & FE_HAS_SIGNAL) fprintf(stderr," FE_HAS_SIGNAL"); ! if (festatus & FE_SPECTRUM_INV) fprintf(stderr," FE_SPECTRUM_INV"); ! if (festatus & FE_HAS_LOCK) fprintf(stderr," FE_HAS_LOCK"); ! if (festatus & FE_HAS_CARRIER) fprintf(stderr," FE_HAS_CARRIER"); ! if (festatus & FE_HAS_VITERBI) fprintf(stderr," FE_HAS_VITERBI"); ! if (festatus & FE_HAS_SYNC) fprintf(stderr," FE_HAS_SYNC"); ! if (festatus & FE_TUNER_HAS_LOCK) fprintf(stderr," FE_TUNER_HAS_LOCK"); ! fprintf(stderr,"\n"); ! } else { ! #if 0 ! FrontendInfo info; ! if ( (res = ioctl(fd_frontend,FE_GET_INFO, &info) < 0)){ ! perror("FE_GET_INFO: "); ! return -1; ! } + fprintf(stderr,"min Frequency : %d\n", info.minFrequency); + fprintf(stderr,"max Frequency : %d\n", info.maxFrequency); + fprintf(stderr,"min Symbol Rate : %d\n", info.minSymbolRate); + fprintf(stderr,"max Symbol Rate : %d\n", info.maxSymbolRate); + fprintf(stderr,"Hardware Type : %d\n", info.hwType); + fprintf(stderr,"Hardware Version: %d\n", info.hwVersion); + #endif + fprintf(stderr,"Not able to lock to the signal on the given frequency\n"); + return -1; + } + return 0; + } |