Rick,
I do have an event scheduler that is tick based at a one second interval. I will integrate the DS1307 into that.
My SNTP routine accounts for DST. My testing showed in was functional, YMMV. :) Let me know if you do find anything wrong.
In this code, I haven't yet integrated the hardware RTC. That is how I got to this thread....
Basically the first code block is a UTC offset read from a SD card, there are many paramaters in this file but only included what is relevant here. The second code block is the SNTP getting the time, the UTC offset is added, in my case I am CST so I am -6hrs. that is read from the server.cfg file. If the Server_InDST is true then an hour(60^2 or 3600 ticks) are added back. The third block is the actual DST function.
The hour offset is converted to seconds as that is my tick resolution.
[code:1:cba931ae8e]
dwrdSNTP_UTCoffset = -6 ' value read from SD card in hours
dwrdSNTP_UTCoffset = dwrdSNTP_UTCoffset * TickValue_OneHour ' CST to UTC offset in seconds
[/code:1:cba931ae8e]
[code:1:cba931ae8e]
if socketnum <> 255 then ' 255 = no socket
SNTPtime = Sntp(socketnum , IPcon) ' get time, NTP uses port 37, fixed in the tcp asm code
#if debugflag
Print #Debugchannel, "Server_SNTPtime, ";time$;" Non Adjusted - ";Date(SNTPtime) ; Spc(3) ; Time(SNTPtime); " Soft Time = ";time$
#endif
if SNTPtime <> 0 then ' 0 indicates no connection / data from SNTP server
b = 1 ' set flag to remember successful time connection
SNTPtime = SNTPtime + dwrdSNTP_UTCoffset ' read UTC offset that was from SD Card
if Server_InDST() = true then ' is current date / time in DST window?
SNTPtime = SNTPtime + TickValue_OneHour ' yes, add an hour back
endif
#if debugflag
Print #Debugchannel, "Server_SNTPtime, ";time$;" Adjusted - ";Date(SNTPtime) ; Spc(3) ; Time(SNTPtime)
#endif
if date$ <> Date(SNTPtime) or time$ <> Time(SNTPtime) then 'set soft RTC only at reset, to watch %error
date$ = Date(SNTPtime)
time$ = Time(SNTPtime)
#if debugflag
Print #Debugchannel, "Server_SNTPtime, "; time$;" Soft RTC SET - "; date$;" ";time$
#endif
endif
endif
[/code:1:cba931ae8e]
[code:1:cba931ae8e]
Function Server_InDST() as Byte
'
' This funtion will determine if the current date and time is within
' the parameters defined as Daylight Savings Time(DST) as defined on
' the day this function was created.
'
' DST VB6 example:
' http://www.freevbcode.com/ShowCode.asp?ID=7496
'
' DST Wiki rules: 2007 rule change...Starting in 2007, most of the United States and
' Canada observe DST from the second Sunday in March 2AM to the first Sunday in November 2AM.
' http://en.wikipedia.org/wiki/Daylight_saving_time#Procedure
'
' Mark L. Marlette 12/12/2013
local Temp as Byte
local Start_Sec as byte ' byte array MUST remain in SEC MIN HOUR DAY MONTH YEAR format per function weekday/sysec
local Start_Min as byte
local Start_Hour as byte
local Start_Day as byte
local Start_Month as byte
local Start_Year as byte ' end of Start Time byte array block
local End_Sec as byte ' byte array MUST remain in SEC MIN HOUR DAY MONTH YEAR format per function weekday/syssec
local End_Min as byte
local End_Hour as byte
local End_Day as byte
local End_Month as byte
local End_Year as byte ' end of End Time byte array block
local StartDT as long
local EndDT as long
local CurrentDT as long
Start_Month = 3 ' Define March 1 of current year as starting date
Start_Day = 1
Start_Year = _year
Start_Hour = 2 ' 2AM
Start_Min = 0
Start_Sec = 0
End_Month = 11 ' Define Nov 1 of current year as ending date
End_Day = 1
End_Year = _year
End_Hour = 2 ' 2AM
End_Min = 0
End_Sec = 0
'
' Compute date for second Sunday in March
'
Start_Day = Start_Day + 14 ' Next add 14 days to the starting days, for second week of March
Temp = Dayofweek(Start_Day) ' find the starting day we are at currently at.
incr TEMP ' DayOfWeek function is based 0 so we need to add one
Start_Day = Start_Day - Temp ' Take day back to Sunday of second week in March
StartDT = syssec(Start_Sec)
#if debugflag
print "Server_InDST, Start of DST for year 20"; _year ; " is = "; Start_Month ; "/" ; Start_Day ; "/20" ; _year ; " @ 2:00AM, system time = "; StartDT
#endif
'
' Compute date for first Sunday in November
'
End_Day = End_Day + 7 ' Next add 14 days to the starting days, for second week of March
Temp = Dayofweek(End_Day) ' find the starting day we are at currently at.
incr TEMP ' DayOfWeek function is based 0 so we need to add one
End_Day = End_Day - Temp ' Take day back to Sunday of second week in March
EndDT = syssec(End_Sec)
#if debugflag
print "Server_InDST, End of DST for year 20"; _year ; " is = "; End_Month ; "/" ; End_Day ; "/20" ; _year ; " @ 2:00AM, system time = "; EndDT
#endif
CurrentDT = syssec()
#if debugflag
print "Server_InDST, Current date = "; date$ ; ", time = "; time$ ; ", system time = "; CurrentDT
#endif
'
' Compare current date to see if between DST period
'
if CurrentDT >= StartDT and CurrentDT < EndDT then ' is current date/time within DST window?
Temp = 1 ' yes, set to true
else
Temp = 0 ' no, set to false
endif
#if debugflag
Print "Server_InDST, Current DST status is...0=false, 1=true, = ";Temp
#endif
Server_InDST = Temp
End Function
[/code:1:cba931ae8e]
Thanks for your help..... Enjoy. :)
Mark
↧