From: atx23 Date: Thu, 18 Dec 2008 10:59:06 +0000 (+0000) Subject: minor cleanup X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=92fd389adc2b26e84344d34d5528c0eb55e145cc;p=senf.git minor cleanup removed bug by parsing configfile git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1023 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Socket/Protocols/DVB/DVBConfigParser.cc b/Socket/Protocols/DVB/DVBConfigParser.cc index aa45acb..2fc87ae 100644 --- a/Socket/Protocols/DVB/DVBConfigParser.cc +++ b/Socket/Protocols/DVB/DVBConfigParser.cc @@ -1,7 +1,7 @@ #include "DVBConfigParser.hh" #include -#include "../../../Utils/Exception.hh" - +#include "senf/Utils/Exception.hh" +#include "senf/Utils/Logger.hh" using namespace std; #define prefix_ @@ -93,8 +93,10 @@ prefix_ string senf::DVBConfigParser::getConfigLine(string channel) transform(channel.begin(), channel.end(), channel.begin(), ::toupper); if(configFile.bad()) SENF_THROW_SYSTEM_EXCEPTION("Could not read file."); + configFile.seekg(0); while (configFile.good()){ getline( configFile, configLine ); + SENF_LOG((senf::log::NOTICE) ("configLine: " << configLine )); transform(configLine.begin(), configLine.end(), configLine.begin(), ::toupper); pos = configLine.find(channel); diff --git a/Socket/Protocols/DVB/DVBConfigParser.hh b/Socket/Protocols/DVB/DVBConfigParser.hh index 1fa99f6..9a1f684 100644 --- a/Socket/Protocols/DVB/DVBConfigParser.hh +++ b/Socket/Protocols/DVB/DVBConfigParser.hh @@ -48,14 +48,14 @@ class DVBConfigParser DVBParams(); }; static const DVBParams params; typedef boost::tokenizer > tokenizer; - + + public: DVBConfigParser(fe_type_t type_, const std::string & configFilePath = ""); ~DVBConfigParser(); std::string getConfigLine(std::string channel); - dvb_frontend_parameters parseCMDInput(std::string input); dvb_frontend_parameters getFrontendParam(std::string configLine); private: diff --git a/Socket/Protocols/DVB/DVBDemuxHandles.cc b/Socket/Protocols/DVB/DVBDemuxHandles.cc index da8a189..fca478a 100644 --- a/Socket/Protocols/DVB/DVBDemuxHandles.cc +++ b/Socket/Protocols/DVB/DVBDemuxHandles.cc @@ -32,8 +32,7 @@ #include #include #include "../../../Utils/Exception.hh" -// TODO REMOVE V -#include + //#include "DVBDemuxHandles.mpp" #define prefix_ @@ -45,8 +44,7 @@ prefix_ void senf::DVBDemuxSectionSocketProtocol::init_client(unsigned short adapter, unsigned short device) const { - std::string devDemux = str( boost::format( - "/dev/dvb/adapter%d/demux%d") % adapter % device); + std::string devDemux = str( boost::format("/dev/dvb/adapter%d/demux%d") % adapter % device); int f = open(devDemux.c_str(), O_RDONLY | O_NONBLOCK); if (f < 0){ SENF_THROW_SYSTEM_EXCEPTION("Could not open demux device of DVB adapter ") << devDemux << "."; diff --git a/Socket/Protocols/DVB/DVBFrontendHandle.cc b/Socket/Protocols/DVB/DVBFrontendHandle.cc index 3b01f22..55c48d0 100644 --- a/Socket/Protocols/DVB/DVBFrontendHandle.cc +++ b/Socket/Protocols/DVB/DVBFrontendHandle.cc @@ -29,7 +29,7 @@ // Custom includes #include #include -#include "../../../Utils/Exception.hh" +#include "senf/Utils/Exception.hh" #include @@ -151,7 +151,9 @@ const tune(frontend); } -prefix_ void senf::DVBFrontendSocketProtocol::setNonBlock(bool on) const{ +prefix_ void senf::DVBFrontendSocketProtocol::setNonBlock(bool on) + const +{ if(on) ::fcntl(fd(), F_SETFL, ::fcntl(fd(), F_GETFL) | O_NONBLOCK); else @@ -223,7 +225,7 @@ prefix_ int16_t senf::DVBFrontendSocketProtocol::signalStrength() } prefix_ int16_t senf::DVBFrontendSocketProtocol::signalNoiseRatio() - const + const { int16_t snr; if (::ioctl(fd(), FE_READ_SNR, &snr) < 0) diff --git a/Socket/Protocols/DVB/DVBSocketController.cc b/Socket/Protocols/DVB/DVBSocketController.cc index a53ea11..03981a0 100644 --- a/Socket/Protocols/DVB/DVBSocketController.cc +++ b/Socket/Protocols/DVB/DVBSocketController.cc @@ -1,6 +1,6 @@ -#include "../../../Utils/Exception.hh" -#include "../../../Utils/Logger/Logger.hh" -#include <../../../Utils/membind.hh> +#include "senf/Utils/Exception.hh" +#include "senf/Utils/Logger/Logger.hh" +#include "senf/Utils/membind.hh" #include "DVBSocketController.hh" #include @@ -24,21 +24,17 @@ senf::DVBSocketController::DVBSocketController(DVBFrontendHandle frontendHandle_ prefix_ senf::DVBSocketController::~DVBSocketController() { } -prefix_ string senf::DVBSocketController::tuneToCMD(const string & configLine, const string & mode){ +prefix_ void senf::DVBSocketController::tuneToCMD(const string & configLine, const string & mode){ struct dvb_frontend_parameters frontend; // no valid configline, so it will be treaten like a channel name if (configLine.find(":")==string::npos){ - if (mode.c_str()[0]=='a'){ + if (mode.c_str()[0]=='a') tuneTo(configLine); - return "async readConfFile"; - } - else{ + else tuneTo_sync(configLine); - return "sync readConfFile"; - } - + return; } // add psydo name to complete configline syntax frontend = parser.getFrontendParam("foo:"+configLine); @@ -57,7 +53,6 @@ prefix_ string senf::DVBSocketController::tuneToCMD(const string & configLine, c default: SENF_THROW_SYSTEM_EXCEPTION("Could not determine type of card."); } - return "async get directly"; } else { switch (type) { @@ -73,7 +68,6 @@ prefix_ string senf::DVBSocketController::tuneToCMD(const string & configLine, c default: SENF_THROW_SYSTEM_EXCEPTION("Could not determine type of card."); } - return "sync get directly"; } } @@ -112,7 +106,9 @@ prefix_ void senf::DVBSocketController::tuneDVB_T(unsigned int frequency, { if(type != FE_OFDM) SENF_THROW_SYSTEM_EXCEPTION("Type of card is: ") << getTypeString() << " for this operation you need a DVB-T Card!"; + event.enable(); + frontendHandle.protocol().setNonBlock(); frontendHandle.protocol().tuneDVB_T(frequency, inversion, @@ -128,7 +124,9 @@ prefix_ void senf::DVBSocketController::tuneDVB_T(unsigned int frequency, prefix_ void senf::DVBSocketController::tuneDVB_S(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate){ if(type != FE_QPSK) SENF_THROW_SYSTEM_EXCEPTION("Type of card is: ") << getTypeString() << " for this operation you need a DVB-S Card!"; + event.enable(); + frontendHandle.protocol().setNonBlock(); frontendHandle.protocol().tuneDVB_S(frequency, inversion, symbole_rate, code_rate); } @@ -144,6 +142,7 @@ prefix_ void senf::DVBSocketController::tuneDVB_C(unsigned int frequency, SENF_THROW_SYSTEM_EXCEPTION("Type of card is: ") << getTypeString() << " for this operation you need a DVB-C Card!"; event.enable(); + frontendHandle.protocol().setNonBlock(); frontendHandle.protocol().tuneDVB_C(frequency, inversion, symbol_rate, fec_inner, modulation); @@ -185,7 +184,9 @@ prefix_ dvb_frontend_event senf::DVBSocketController::tuneDVB_T_sync(unsigned in { if(type != FE_OFDM) SENF_THROW_SYSTEM_EXCEPTION("Type of card is: ") << getTypeString() << " for this operation you need a DVB-T Card!"; + event.disable(); + frontendHandle.protocol().setNonBlock(false); frontendHandle.protocol().tuneDVB_T(frequency, @@ -207,8 +208,11 @@ prefix_ dvb_frontend_event senf::DVBSocketController::tuneDVB_T_sync(unsigned in prefix_ dvb_frontend_event senf::DVBSocketController::tuneDVB_S_sync(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate){ if(type != FE_QPSK) SENF_THROW_SYSTEM_EXCEPTION("Type of card is: ") << getTypeString() << " for this operation you need a DVB-S Card!"; + event.disable(); + frontendHandle.protocol().setNonBlock(false); + frontendHandle.protocol().tuneDVB_S(frequency, inversion, symbole_rate, code_rate); if(!frontendHandle.waitOOBReadable(senf::ClockService::seconds(2))) @@ -227,7 +231,9 @@ prefix_ dvb_frontend_event senf::DVBSocketController::tuneDVB_C_sync(unsigned in SENF_THROW_SYSTEM_EXCEPTION("Type of card is: ") << getTypeString() << " for this operation you need a DVB-C Card!"; event.disable(); + frontendHandle.protocol().setNonBlock(false); + frontendHandle.protocol().tuneDVB_C(frequency, inversion, symbol_rate, fec_inner, modulation); if(!frontendHandle.waitOOBReadable(senf::ClockService::seconds(2))) SENF_THROW_SYSTEM_EXCEPTION("Could not tune to channel!"); @@ -266,6 +272,7 @@ prefix_ string senf::DVBSocketController::getTuneInfo(const string & conf){ stringstream info; fe_status_t status; + frontendHandle.protocol().setNonBlock(false); uint16_t snr, signal; uint32_t ber, uncorrected_blocks; status = frontendHandle.protocol().status(); @@ -277,21 +284,23 @@ prefix_ string senf::DVBSocketController::getTuneInfo(const string & conf){ info << hex; for(unsigned int i = 0; i < conf.size(); ++i){ + if(i>0) + info << " | "; switch(cConf[i]){ case 'S' : - info << " | signal " << signal; + info << "signal " << signal; break; case 's' : - info << " | snr " << snr; + info << "snr " << snr; break; case 'b' : - info << " | ber " << ber; + info << "ber " << ber; break; case 'u' : - info << " | unc " << uncorrected_blocks; + info << "unc " << uncorrected_blocks; break; case 'f' : - info << " | status: " << status2String(status); + info << "status: " << status2String(status); break; default: break; @@ -302,28 +311,28 @@ prefix_ string senf::DVBSocketController::getTuneInfo(const string & conf){ prefix_ string senf::DVBSocketController::status2String(fe_status_t status){ string s(""); if (status & FE_HAS_LOCK) - return s += "|HAS LOCK"; + return s += "HAS LOCK"; if (status & FE_HAS_CARRIER) - s += "|HAS CARRIER"; + s += "HAS CARRIER"; if (status & FE_HAS_VITERBI) - s += "|HAS VITERBI"; + s += "HAS VITERBI"; if (status & FE_HAS_SYNC) - s += "|HAS SYNC"; + s += "HAS SYNC"; if (status & FE_HAS_SIGNAL) - s += "|HAS SIGNAL"; + s += "HAS SIGNAL"; if (status & FE_TIMEDOUT) - s += "|TIMED OUT"; + s += "TIMED OUT"; if (status & FE_REINIT) - s += "|REINIT"; + s += "REINIT"; return s; } prefix_ void senf::DVBSocketController::setSectionFilter(unsigned short int pid, - unsigned char filter, + u_int8_t filter, unsigned int flags, - unsigned char mask, - unsigned char mode, + u_int8_t mask, + u_int8_t mode, unsigned int timeout) { sectionHandle.protocol().setSectionFilter(pid, timeout, flags, filter, mask, mode); @@ -345,13 +354,13 @@ prefix_ void senf::DVBSocketController::stopFiltering() sectionHandle.protocol().stopFiltering(); } - prefix_ fe_type_t senf::DVBSocketController::getType(){ return type; } prefix_ void senf::DVBSocketController::readEvent(int event){ - cb(frontendHandle.protocol().getEvent()); + if(cb) + cb(frontendHandle.protocol().getEvent()); } prefix_ void senf::DVBSocketController::initConsole(){ @@ -374,7 +383,7 @@ prefix_ void senf::DVBSocketController::initConsole(){ and could end in throwing an exception!") .arg("conf", "Ssbuf", kw::default_value = "Ssbuf"); - dir.add("tuneTo", &DVBSocketController::tuneToCMD) + dir.add("tune", &DVBSocketController::tuneToCMD) .doc("tunes to channel listet in the configfile.") .arg("channel", "channel to tune") .arg("mode", "mode \"sync\" or \"async\"", kw::default_value = "async"); diff --git a/Socket/Protocols/DVB/DVBSocketController.hh b/Socket/Protocols/DVB/DVBSocketController.hh index 9d21440..d37dbac 100644 --- a/Socket/Protocols/DVB/DVBSocketController.hh +++ b/Socket/Protocols/DVB/DVBSocketController.hh @@ -6,9 +6,9 @@ // Custom includes #include #include -#include +#include "senf/Scheduler/Scheduler.hh" #include "DVBConfigParser.hh" -#include +#include "senf/Console.hh" #define MPE_TABLEID 62 @@ -24,7 +24,7 @@ public: DVBSocketController(DVBFrontendHandle frontendHandle_ = DVBFrontendHandle(0,0), DVBDemuxSectionHandle sectionHandle_ = DVBDemuxSectionHandle(0,0), const Callback & cb = NULL); ~DVBSocketController(); - std::string tuneToCMD( const std::string & channel, const std::string & mode = "async"); + void tuneToCMD( const std::string & channel, const std::string & mode = "async"); void tuneTo(const std::string & channel); @@ -72,10 +72,10 @@ public: unsigned int signalStrength(); void setSectionFilter(unsigned short int pid, - unsigned char filter = MPE_TABLEID, + u_int8_t filter = MPE_TABLEID, unsigned int flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC, - unsigned char mask = 0xff, - unsigned char mode = 0, + u_int8_t mask = 0xff, + u_int8_t mode = 0, unsigned int timeout = 0); void setBufferSize(unsigned long size);