I'm also trying to do the reverse - set a flag if the transponder time has been set (just so that any forever-backgrounded NTP-trier can give up).
I was considering a slightly different approach:
In order to solve the possible interfering of DVB and NTP time syncs, one could create an dvbdate-sync app, the source code already exists:
https://github.com/linuxstb/dvbtools/tree/master/dvbdate
That way all the time syncing could be offloaded to the OS (yocto, Linux) and E2 wouldn't need to care about it at all (Except to allow the user to configure its preferences and checking for success).
The options should be
- NTP first, DVB fallback
- NTP only
- DVB first, NTP fallback
- DVB only
plus:
- Fall back after n failed attempts: >=3
ntpdate should only give up if DVB fallback is set and only temporarily.
This is due to NTP being much more accurate than DVB and if the user decides to use NTP only, DVB sync is no option at all.
One actually needs at least two different flagfiles:
- If a sync succeeded within the current "session" at all
- A counter for the failed attempts
As long as NTP succeeded once (e.g. at boot), there shouldn't be an immedeate fall-back to DVB sync just because a later NTP sync failed once.
If NTP succeeds only once per hour, that time is most likely still better than that from transponders (Where I can easily find transponders that are off by ~ 5min).
Once the sync fell back, it should also revert to the preferred method as soon as it succeeds again, for the same reason as above.
My idea so far was to write the time of the last successful sync (after sync of course) into a flag file
/var/tmp/ntp-synced
and the amount of failed attempts into
/var/tmp/ntp-fails
So if /var/tmp/ntp-synced exists, we had a successful sync at least once within the current session (As /var/tmp is volatile and its content is lost on reboot), by reading it, we can learn
when it succeeded the last time.
On successful sync, "0" gets written into /var/tmp/ntp-fails, so if /var/tmp/ntp-synced exists
and /var/tmp/ntp-fails contains "0", then we know it was the latest sync that succeeded -> Everything ok.
If /var/tmp/ntp-synced does
not exist, we have to fall back to DVB until NTP succeeds.
If /var/tmp/ntp-synced exists but /var/tmp/ntp-fails contains "n" with "n > failed attempts before fallback", we also have to fall-back to DVB until NTP succeeds again (= /var/tmp/ntp-fails contains "0" again).
The code seems to assume that if you have a transponder then the time can be obtained from it "immediately". Does anyone know whether that is true (not that the time is correct, but that " a time" can be gotten)?
For DVB sync, m_time_ready gets set to true when the time is already retrieved:
https://github.com/OpenViX/enigma2/blob/master/lib/dvb/dvbtime.cpp#L515
It becomes true a few (milli)seconds before the system time gets actually written though.
That's due to later return statements inside the code that would prevent m_time_ready becoming true if transponder time was retrieved but has no difference to current time.
Ugly spaghetti code ...