Merge remote-tracking branch 'origin/obi/master-20110412'
[enigma2.git] / lib / dvb / frontend.cpp
index ea9e73854e38d51deb14c519e389fb906102ee77..57188963cebd10f175d8425517f0b663b2ad26b9 100644 (file)
@@ -453,8 +453,8 @@ DEFINE_REF(eDVBFrontend);
 
 int eDVBFrontend::PriorityOrder=0;
 
-eDVBFrontend::eDVBFrontend(int adap, int fe, int &ok, bool simulate)
-       :m_simulate(simulate), m_enabled(false), m_type(-1), m_dvbid(fe), m_slotid(fe)
+eDVBFrontend::eDVBFrontend(int adap, int fe, int &ok, bool simulate, eDVBFrontend *simulate_fe)
+       :m_simulate(simulate), m_enabled(false), m_type(-1), m_simulate_fe(simulate_fe), m_dvbid(fe), m_slotid(fe)
        ,m_fd(-1), m_rotor_mode(false), m_need_rotor_workaround(false), m_can_handle_dvbs2(false)
        ,m_state(stateClosed), m_timeout(0), m_tuneTimer(0)
 #if HAVE_DVB_API_VERSION < 3
@@ -503,10 +503,10 @@ int eDVBFrontend::openFrontend()
 #else
        dvb_frontend_info fe_info;
 #endif
-       eDebugNoSimulate("opening frontend %d", m_dvbid);
-       if (m_fd < 0)
+       if (!m_simulate)
        {
-               if (!m_simulate || m_type == -1)
+               eDebug("opening frontend %d", m_dvbid);
+               if (m_fd < 0)
                {
                        m_fd = ::open(m_filename, O_RDWR|O_NONBLOCK);
                        if (m_fd < 0)
@@ -515,70 +515,69 @@ int eDVBFrontend::openFrontend()
                                return -1;
                        }
                }
-       }
-       else
-               eWarning("frontend %d already opened", m_dvbid);
-       if (m_type == -1)
-       {
-               if (::ioctl(m_fd, FE_GET_INFO, &fe_info) < 0)
+               else
+                       eWarning("frontend %d already opened", m_dvbid);
+               if (m_type == -1)
                {
-                       eWarning("ioctl FE_GET_INFO failed");
-                       ::close(m_fd);
-                       m_fd = -1;
-                       return -1;
-               }
+                       if (::ioctl(m_fd, FE_GET_INFO, &fe_info) < 0)
+                       {
+                               eWarning("ioctl FE_GET_INFO failed");
+                               ::close(m_fd);
+                               m_fd = -1;
+                               return -1;
+                       }
 
-               switch (fe_info.type)
-               {
-               case FE_QPSK:
-                       m_type = iDVBFrontend::feSatellite;
-                       break;
-               case FE_QAM:
-                       m_type = iDVBFrontend::feCable;
-                       break;
-               case FE_OFDM:
-                       m_type = iDVBFrontend::feTerrestrial;
-                       break;
-               default:
-                       eWarning("unknown frontend type.");
-                       ::close(m_fd);
-                       m_fd = -1;
-                       return -1;
+                       switch (fe_info.type)
+                       {
+                       case FE_QPSK:
+                               m_type = iDVBFrontend::feSatellite;
+                               break;
+                       case FE_QAM:
+                               m_type = iDVBFrontend::feCable;
+                               break;
+                       case FE_OFDM:
+                               m_type = iDVBFrontend::feTerrestrial;
+                               break;
+                       default:
+                               eWarning("unknown frontend type.");
+                               ::close(m_fd);
+                               m_fd = -1;
+                               return -1;
+                       }
+                       if (m_simulate_fe)
+                               m_simulate_fe->m_type = m_type;
+                       eDebugNoSimulate("detected %s frontend", "satellite\0cable\0    terrestrial"+fe_info.type*10);
                }
-               eDebugNoSimulate("detected %s frontend", "satellite\0cable\0    terrestrial"+fe_info.type*10);
-       }
 
 #if HAVE_DVB_API_VERSION < 3
-       if (m_type == iDVBFrontend::feSatellite)
-       {
-                       if (m_secfd < 0)
-                       {
-                               if (!m_simulate)
+               if (m_type == iDVBFrontend::feSatellite)
+               {
+                               if (m_secfd < 0)
                                {
-                                       m_secfd = ::open(m_sec_filename, O_RDWR);
-                                       if (m_secfd < 0)
+                                       if (!m_simulate)
                                        {
-                                               eWarning("failed! (%s) %m", m_sec_filename);
-                                               ::close(m_fd);
-                                               m_fd=-1;
-                                               return -1;
+                                               m_secfd = ::open(m_sec_filename, O_RDWR);
+                                               if (m_secfd < 0)
+                                               {
+                                                       eWarning("failed! (%s) %m", m_sec_filename);
+                                                       ::close(m_fd);
+                                                       m_fd=-1;
+                                                       return -1;
+                                               }
                                        }
                                }
-                       }
-                       else
-                               eWarning("sec %d already opened", m_dvbid);
-       }
+                               else
+                                       eWarning("sec %d already opened", m_dvbid);
+               }
 #endif
 
-       setTone(iDVBFrontend::toneOff);
-       setVoltage(iDVBFrontend::voltageOff);
-
-       if (!m_simulate)
-       {
                m_sn = eSocketNotifier::create(eApp, m_fd, eSocketNotifier::Read, false);
                CONNECT(m_sn->activated, eDVBFrontend::feEvent);
        }
 
+       setTone(iDVBFrontend::toneOff);
+       setVoltage(iDVBFrontend::voltageOff);
+
        return 0;
 }
 
@@ -1860,11 +1859,11 @@ int eDVBFrontend::tuneLoopInt()  // called by m_tuneTimer
                                                int slotid = sec_fe->m_slotid;
                                                // FIXMEEEEEE hardcoded i2c devices for dm7025 and dm8000
                                                if (slotid < 2)
-                                                       sprintf(dev, "/dev/i2c/%d", slotid);
+                                                       sprintf(dev, "/dev/i2c-%d", slotid);
                                                else if (slotid == 2)
-                                                       sprintf(dev, "/dev/i2c/2"); // first nim socket on DM8000 use /dev/i2c/2
+                                                       sprintf(dev, "/dev/i2c-2"); // first nim socket on DM8000 use /dev/i2c-2
                                                else if (slotid == 3)
-                                                       sprintf(dev, "/dev/i2c/4"); // second nim socket on DM8000 use /dev/i2c/4
+                                                       sprintf(dev, "/dev/i2c-4"); // second nim socket on DM8000 use /dev/i2c-4
                                                int fd = ::open(dev, O_RDWR);
 
                                                unsigned char data[2];