Hoping to get some advice from experts on C/C++ time functions
I want to set the time of my DS1307 Real Time Clock accurately (+/- 1 sec or better). Using the example TimeRTCset in the IDE I am able to do this, but it is limited to receiving the input time in time_t form (seconds since noon 1 Jan 1970). (e.g. 1326758400 which equals 00:00 17 Jan 2012). My goal is to set the time from GPS time which is provided in the form sec, min, hr, day, mon, yr.
So I dived into Time.cpp and DS1307RTC.cpp to figure out what’s possible. One big question I have, there are many mentions of “system time”as distinct from RTC time, but what IS this mythical “system time”??? for example the following code appears in timeRTCset, and both must be executed or it doesn’t work:
RTC.set(t); // set the RTC and the system time to the received value
setTime(t);
But here’s the rub. The following code will work:
RTC.set(1294911050);
setTime(1294911050);
and so will this:
(note this code alone only sets time temporarily, i.e. doesn't survive reset)
setTime(9,30,50,13,1,2012); // sec, min, hr, day, mon, yr
but this won’t because the “set” routine in DS1307RTC doesn’t support the time elements form (whereas Time.cpp does):
RTC.set(9,30,50,13,1,2012); // sec, min, hr, day, mon, yr
setTime(9,30,50,13,1,2012); // sec, min, hr, day, mon, yr
I found the “maketime” routine in Time.cpp which takes time elements as input and outputs time_t. If I could access this my problem would be resolved, but I haven’t figured this out (my limited C/C++ skills are being tested!). Here’s the beginning of maketime in Time.cpp:
time_t makeTime(tmElements_t &tm){
How can I use this routine from my sketch? Or perhaps better still – how would I add this to DS1307RTC.cpp?
TIA