Plugin timesync.spf

File: timesync.spf
Author: Nicholas Nemtsev
Description: Provides a capability to synchronize system clock with a specified precise time server using NTP protocol. A list of NTP servers is provided here.

New words:


TP-SYNC: <server_name>

This command starts the process of time synching. Use a name of an NTP server as a parameter.

Example:

#( time_adjust
\ a simple example of time synchronization
OnceADay
Rule: ONLINE?
Action:
    TP-SYNC: time.nist.gov
    TP-SYNC-RESULT 0<>
    IF 
        CLEAR-ONCE 
        MSG: "Can't synchronize time"
    ELSE
        TMSG: "Time was synchronized. Server response delay: %TP-SYNC-DELAY%" 10
    THEN
)#

#( time_adjust1
\ an advanced example of time synchronization
0 VALUE hh0
0 VALUE mm0
0 VALUE ss0
0 VALUE s_hh
0 VALUE s_mm
0 VALUE s_ss
OnceADay
Rule: ONLINE?
Action:
GET-CUR-TIME
Hour@ TO hh0 Min@ TO mm0 Sec@ TO ss0
TP-SYNC: time.nist.gov
<time> @ UT>TIME 2DROP DROP TO s_hh TO s_mm TO s_ss
TP-SYNC-RESULT 0<>
IF
    LOG: timesync.log "*** %YYYY%-%MMM%-%DD%  %hh0%:%mm0%:%ss0% %TP-SYNC-DELAY% (%s_hh%:%s_mm%:%s_ss%)"
    TQUERY: "Can't synchronize time.%crlf%Continue synchronization?" 10 Yes
    IF CLEAR-ONCE THEN
ELSE
    GET-CUR-TIME
    LOG: timesync.log "%YYYY%-%MMM%-%DD%  %hh0%:%mm0%:%ss0% -> %hh%:%mm%:%ss%  %TP-SYNC-DELAY%"
    TMSG: "Time is synchronized%crlf%%YYYY%-%MMM%-%DD% %hh0%:%mm0%:%ss0% -> %hh%:%mm%:%Ss% (server time %s_hh%:%s_mm%:%s_ss%)" 5
THEN
)#


TP-SYNC-RESULT

Variable TP-SYNC-RESULT allows to check if the time sinchronization was successfull. It countains 0 if sinchronization was successful, and it contains winsock error code if there was an error while trying to connect to the NTP server.
Use it after word TP-SYNC:.


TP-SYNC-DELAY

Variable TP-SYNC-DELAY contains response time of the NTP server (in milliseconds).
Use it after TP-SYNC:.


List of available NTP servers:

time.nist.gov
clock.psu.edu
finch.cc.ukans.edu
ntp.css.gov
ntp.lth.se
ntp.maths.tcd.ie
ntp0.cornell.edu
ntp-1.ece.cmu.edu
ntp-2.ece.cmu.edu
ntp2a.mcc.ac.uk
Rolex.PeachNet.EDU
salmon.maths.tcd.ie
sundial.columbia.edu
time.nrc.ca
timelord.uregina.ca
timex.cs.columbia.edu
Timex.PeachNet.EDU