News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Synchronizate PC time

Started by six_L, February 20, 2006, 01:13:54 PM

Previous topic - Next topic

six_L

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]
regards

skywalker

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.

six_L

#2
GMT: standard the world time(London)
TimeZone=0

update:
adjust the west world time

23=-1
22=-2
...

/bug fixed
regards

dsouza123

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]

dsouza123

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]

GregL

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.







dsouza123

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]

GregL

dsouza123,

You can also determine the current offset from GMT (in minutes) by calling GetTimeZoneInformation.


dsouza123

Thought about the fractional hours, so I added a spot for minutes.

I'll check out the GetTimeZoneInformation.

[attachment deleted by admin]

GregL

#9
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.


Merrick

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.

six_L

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.
regards

dsouza123

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]

six_L

Hey,dsouza123
:U good work.

httpSync7 works fine for me.
regards

GregL