diff --git a/src/driver/rcinput.cpp b/src/driver/rcinput.cpp index 42ffec941..a267662ef 100644 --- a/src/driver/rcinput.cpp +++ b/src/driver/rcinput.cpp @@ -827,35 +827,48 @@ void CRCInput::getMsg_us(neutrino_msg_t * msg, neutrino_msg_data_t * data, uint6 switch(emsg.eventID) { case CSectionsdClient::EVT_TIMESET: - { - struct timeval ltv; - gettimeofday( <v, NULL ); - int64_t timeOld = (int64_t) ltv.tv_usec + (int64_t)((int64_t) ltv.tv_sec * (int64_t) 1000000); - - //printf("[neutrino] event TIMESET from SECTIONSD %x %x\n", emsg.eventID, *(unsigned*) p); - //g_Sectionsd->registerEvent(CSectionsdClient::EVT_TIMESET, 222, NEUTRINO_UDS_NAME); - stime((time_t*) p); - - gettimeofday( <v, NULL ); - int64_t timeNew = (int64_t) ltv.tv_usec + (int64_t)((int64_t) ltv.tv_sec * (int64_t) 1000000); - - delete[] p;//new [] delete [] - p= new unsigned char[ sizeof(int64_t) ]; - *(int64_t*) p = timeNew - timeOld; - - if ((int64_t)last_keypress > *(int64_t*)p) - last_keypress += *(int64_t *)p; - - // Timer anpassen - for(std::vector::iterator e = timers.begin(); e != timers.end(); ++e) - if (e->correct_time) - e->times_out+= *(int64_t*) p; - - *msg = NeutrinoMessages::EVT_TIMESET; - *data = (neutrino_msg_data_t) p; - dont_delete_p = true; + { + struct timeval ltv; + gettimeofday(<v, NULL); + int64_t timeOld = ltv.tv_usec + ltv.tv_sec * (int64_t)1000000; + time_t dvbtime = *((time_t*)p); + if (dvbtime) { + printf("[neutrino] timeset event. "); + time_t difftime = dvbtime - ltv.tv_sec; + if (abs(difftime) > 120) { + printf("difference is %ld s, stepping...\n", difftime); + if (stime(&dvbtime)) + perror("stime"); + } else if (difftime != 0) { + struct timeval oldd; + ltv.tv_sec = difftime; + ltv.tv_usec = 0; + if (adjtime(<v, &oldd)) + perror("adjtime"); + int64_t t = oldd.tv_sec * 1000000LL + oldd.tv_usec; + printf("difference is %ld s, using adjtime(). oldd: %lld us\n", difftime, t); + } else + printf("difference is 0 s, nothing to do...\n"); } + gettimeofday( <v, NULL ); + int64_t timeNew = ltv.tv_usec + ltv.tv_sec * (int64_t)1000000; + + delete[] p;//new [] delete [] + p = new unsigned char[sizeof(int64_t)]; + *(int64_t*) p = timeNew - timeOld; + + if ((int64_t)last_keypress > *(int64_t*)p) + last_keypress += *(int64_t *)p; + + // Timer anpassen + for(std::vector::iterator e = timers.begin(); e != timers.end(); ++e) + if (e->correct_time) + e->times_out+= *(int64_t*) p; + *msg = NeutrinoMessages::EVT_TIMESET; + *data = (neutrino_msg_data_t) p; + dont_delete_p = true; break; + } case CSectionsdClient::EVT_GOT_CN_EPG: printf("[neutrino] CSectionsdClient::EVT_GOT_CN_EPG\n"); *msg = NeutrinoMessages::EVT_CURRENTNEXT_EPG;