Hey,all
here a code about time of Synchronizatation.
i think it is difficult to Synchronizate time with 1mm precision.
|
t1 |
start read-> |----------------|
|
|
|<-timerServer send
t2 |
end read -> |---------------|
|
|
t3 |
write time ->|
deltaT1=t2-t1
deltaT2=t3-t2
Milliseconds =Milliseconds + deltaT2 + deltaT1/2
any suggestion,optimization,simpleness... will be welcomed.
regards
[attachment deleted by admin]
Quote from: six_L on February 20, 2006, 01:13:54 PM
Hey,all
here a code about time of Synchronizatation.
i think it is difficult to Synchronizate time with 1mm precision.
|
t1 |
start read-> |-----------------|
|
|
|<-timerServer send
t2 |
end read -> |----------------|
|
|
t3 |
write time ->|
deltaT1=t2-t1
deltaT2=t3-t2
Milliseconds =Milliseconds + deltaT2 + deltaT1/2
any suggestion,optimization,simpleness... will be welcomed.
regards
I need to know what number to use for the Central Time Zone.
It set my clock 2 hours ahead.
Thanks.
GMT: standard the world time(London)
TimeZone=0
update:
adjust the west world time
23=-1
22=-2
...
/bug fixed
Sync_3 works well if TCP port 13 (DayTime) traffic is allowed,
but if the only remote port allowed is port 80 (HTTP) then it can't work.
When only web access is allowed...
I've combined TCPTest.asm -- Jay Sullivan and routines from sync_3.asm -- six_L
and added new code to extract the date time stamp
from the HEAD response from a webpage,
as the source for time syncronization.
This lets virtually any web site act as the time server,
it currently uses time.gov but any site that returns
pages quickly and accurately maintains their server's time
will serve well as a virtual time server.
[attachment deleted by admin]
Made it easier to change the GMT offset,
it is the dword GMToffset now,
the current value is -4,
if the location is ahead of GMT it would be a positive value.
Example
GMToffset dd 2 ; for Athens Greece.
Made the GMT info parsing flexible,
now will search for GMT ( using "TMG ")
to create the offset into the HEAD string.
It was needed for other sites
or in case the GMT line in the HEAD string is shifted.
[attachment deleted by admin]
dsouza123,
Works fine if your GMT offset is an even hour, but for say New Delhi, India the offset is 5 hours 30 minutes. You should work with minutes instead of hours for the GMT offset.
Six_L,
I am unable to enter a negative GMT offset. Also same comment as above.
I'll have to think about dealing with hour(s) and a fraction offsets.
Added an entry spot for the GMT offset, also handles positive and negative hour offsets.
[attachment deleted by admin]
dsouza123,
You can also determine the current offset from GMT (in minutes) by calling GetTimeZoneInformation (http://msdn2.microsoft.com/en-us/library/ms724421.aspx).
Thought about the fractional hours, so I added a spot for minutes.
I'll check out the GetTimeZoneInformation.
[attachment deleted by admin]
dsouza123,
Works fine. :thumbu
Here's a procedure I wrote to get the current offset from UTC in minutes. It seems to work correctly.
CurrentUtcOffsetInMinutes PROC psdwOffset:PTR SDWORD
; Returns eax = -1 on error, 0 otherwise
; Example: sdwOffset = -480 for Pacific Standard Time
; sdwOffset = -420 for Pacific Daylight Time
LOCAL tzi:TIME_ZONE_INFORMATION
LOCAL dwTimeZoneMode:DWORD
LOCAL sdwRv:SDWORD
INVOKE GetTimeZoneInformation, ADDR tzi
mov dwTimeZoneMode, eax
mov eax, tzi.Bias
.IF (dwTimeZoneMode == TIME_ZONE_ID_STANDARD) || (dwTimeZoneMode == TIME_ZONE_ID_UNKNOWN)
add eax, tzi.StandardBias
mov edx, psdwOffset
mov SDWORD PTR [edx], eax
neg SDWORD PTR [edx]
mov sdwRv, 0
.ELSEIF dwTimeZoneMode == TIME_ZONE_ID_DAYLIGHT
add eax, tzi.DaylightBias
mov edx, psdwOffset
mov SDWORD PTR [edx], eax
neg SDWORD PTR [edx]
mov sdwRv, 0
.ELSE ; dwTimeZoneMode == TIME_ZONE_ID_INVALID
mov sdwRv, -1
.ENDIF
mov eax, sdwRv
ret
CurrentUtcOffsetInMinutes ENDP
Edit: I cleaned up the code a bit.
You have to do it as minutes (or at least allow fractional hours) because not all time zones are offset from GMT by integer multiples of an hour.
hey,Greg
QuoteSix_L,
I am unable to enter a negative GMT offset. Also same comment as above.
Thanks for interestint it.
the west world: GMT+13~23
the east world: GMT+1~11
the rule stipulates that the date of east world is bigger one day than the date of west world.
so, if you locate the timezone of "-1" , your local time=GMT -1=(GMT+23)-24;
-2____,your local time=GMT -2=(GMT+22)-24
...
-9____,your local time=GMT -9=(GMT+13)-24
so on.
Now at program startup the hour and minute GMT offset dwords and strings
are updated with the system's offset using the timezone info.
thanks Greg for the illuminating timezone code.
thanks six_L for the important time updating routines
thanks Jay Sullivan for the http info retrieval code
[attachment deleted by admin]
Hey,dsouza123
:U good work.
httpSync7 works fine for me.
dsouza123,
Works great.
Here is another way to get the current offset from UTC (in minutes):
CurrentUtcOffsetInMinutes PROC
; Returns: eax = the current offset from UTC in minutes
; Example: returns -480 for Pacific Standard Time
; returns -420 for Pacific Daylight Time
; Gets the value from the Windows Registry at
; HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias
LOCAL hKey:DWORD
LOCAL dwType:DWORD
LOCAL sdwData:SDWORD
LOCAL cbData:DWORD
mov cbData, SIZEOF sdwData
INVOKE RegOpenKeyEx, HKEY_LOCAL_MACHINE, SADD("SYSTEM\CurrentControlSet\Control\TimeZoneInformation"), 0, KEY_QUERY_VALUE, ADDR hKey
INVOKE RegQueryValueEx, hKey, SADD("ActiveTimeBias"), NULL, ADDR dwType, ADDR sdwData, ADDR cbData
INVOKE RegCloseKey, hKey
mov eax, sdwData
neg eax
ret
CurrentUtcOffsetInMinutes ENDP
Hi dsouza123:
It does work, but it is adjusting the time to Greenwich[London] [GMT] [UTC] which
is four hours ahead. I used the httpsync7.zip
The program works by combining the GMT offset setting in the computer
(which it gets using GetTimeZoneInformation
and displays both the hour and minutes in editable fields
so you can change them, maybe you like to set your clock ahead),
along with the values converted from the text from the HEAD reply
example
GMT offset -4 00
Date: Tue, 03 Jul 2007 23:42:44 GMT
will combine for 19:42:44 or 7:42:44 PM