dvbtime.h/cpp: add possibility to build a 16bit hash with event start time and month day
[enigma2.git] / lib / dvb / dvbtime.cpp
index d879cface8b8c73204c03fb341fbadd4f458c327..bb6b94b0d9e7207a9a77ed4ddaedf855dd59f1d8 100644 (file)
@@ -20,7 +20,7 @@ void setRTC(time_t time)
        FILE *f = fopen("/proc/stb/fp/rtc", "w");
        if (f)
        {
-               if (fprintf(f, "%u", time))
+               if (fprintf(f, "%u", (unsigned int)time))
                        prev_time = time;
                else
                        eDebug("write /proc/stb/fp/rtc failed (%m)");
@@ -47,8 +47,11 @@ time_t getRTC()
        if (f)
        {
                // sanity check to detect corrupt atmel firmware
-               if (fscanf(f, "%u", &rtc_time) != 1)
+               unsigned int tmp;
+               if (fscanf(f, "%u", &tmp) != 1)
                        eDebug("read /proc/stb/fp/rtc failed (%m)");
+               else
+                       rtc_time=tmp;
                fclose(f);
        }
        else
@@ -64,7 +67,7 @@ time_t getRTC()
        return rtc_time != prev_time ? rtc_time : 0;
 }
 
-time_t parseDVBtime(__u8 t1, __u8 t2, __u8 t3, __u8 t4, __u8 t5)
+time_t parseDVBtime(__u8 t1, __u8 t2, __u8 t3, __u8 t4, __u8 t5, __u16 *hash)
 {
        tm t;
        t.tm_sec=fromBCD(t5);
@@ -84,6 +87,11 @@ time_t parseDVBtime(__u8 t1, __u8 t2, __u8 t3, __u8 t4, __u8 t5)
        t.tm_isdst =  0;
        t.tm_gmtoff = 0;
 
+       if (hash) {
+               *hash = t.tm_hour * 60 + t.tm_min;
+               *hash |= t.tm_mday << 11;
+       }
+
        return timegm(&t);
 }
 
@@ -145,7 +153,7 @@ eDVBLocalTimeHandler *eDVBLocalTimeHandler::instance;
 DEFINE_REF(eDVBLocalTimeHandler);
 
 eDVBLocalTimeHandler::eDVBLocalTimeHandler()
-       :m_time_ready(false), m_updateNonTunedTimer(eTimer::create(eApp))
+       :m_use_dvb_time(false), m_updateNonTunedTimer(eTimer::create(eApp)), m_time_ready(false)
 {
        if ( !instance )
                instance=this;
@@ -214,6 +222,33 @@ void eDVBLocalTimeHandler::writeTimeOffsetData( const char* filename )
        }
 }
 
+void eDVBLocalTimeHandler::setUseDVBTime(bool b)
+{
+       if (m_use_dvb_time != b) {
+               if (m_use_dvb_time) {
+                       eDebug("[eDVBLocalTimeHandler] disable sync local time with transponder time!");
+                       std::map<iDVBChannel*, channel_data>::iterator it =
+                               m_knownChannels.begin();
+                       for (; it != m_knownChannels.end(); ++it) {
+                               if (it->second.m_prevChannelState == iDVBChannel::state_ok)
+                                       it->second.tdt = 0;
+                       }
+               }
+               else {
+                       eDebug("[eDVBLocalTimeHandler] enable sync local time with transponder time!");
+                       std::map<iDVBChannel*, channel_data>::iterator it =
+                               m_knownChannels.begin();
+                       for (; it != m_knownChannels.end(); ++it) {
+                               if (it->second.m_prevChannelState == iDVBChannel::state_ok) {
+                                       it->second.tdt = new TDT(it->second.channel);
+                                       it->second.tdt->start();
+                               }
+                       }
+               }
+               m_use_dvb_time = b;
+       }
+}
+
 void eDVBLocalTimeHandler::updateNonTuned()
 {
        updateTime(-1, 0, 0);
@@ -440,8 +475,10 @@ void eDVBLocalTimeHandler::DVBChannelStateChanged(iDVBChannel *chan)
                                case iDVBChannel::state_ok:
                                        eDebug("[eDVBLocalTimerHandler] channel %p running", chan);
                                        m_updateNonTunedTimer->stop();
-                                       it->second.tdt = new TDT(it->second.channel);
-                                       it->second.tdt->start();
+                                       if (m_use_dvb_time) {
+                                               it->second.tdt = new TDT(it->second.channel);
+                                               it->second.tdt->start();
+                                       }
                                        break;
                                case iDVBChannel::state_release:
                                        eDebug("[eDVBLocalTimerHandler] remove channel %p", chan);