浏览代码

Adjusted versions of WebNetworkTimeProtocol for better diffs

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@8026 8c9fc860-2736-0410-a75d-ab315db34111
negelef 7 年之前
父节点
当前提交
a7b6112824
共有 2 个文件被更改,包括 10 次插入63 次删除
  1. 6 37
      source/BIOS.WebNetworkTimeProtocol.Mod
  2. 4 26
      source/Windows.WebNetworkTimeProtocol.Mod

+ 6 - 37
source/WebNetworkTimeProtocol.Mod → source/BIOS.WebNetworkTimeProtocol.Mod

@@ -21,7 +21,7 @@ ToDo: full NTP synchronization algorithm.
 Note the comments on leap seconds: http://www.eecis.udel.edu/~mills/leap.html
 Note the comments on leap seconds: http://www.eecis.udel.edu/~mills/leap.html
 *)
 *)
 
 
-IMPORT IP,UDP, Streams, Commands, Configuration, DNS, Machine, Kernel32, Dates;
+IMPORT IP,UDP, Streams, Commands, Configuration, DNS, Machine, Dates;
 
 
 CONST NTPPort*=123;
 CONST NTPPort*=123;
 
 
@@ -89,38 +89,8 @@ BEGIN
 	END;
 	END;
 END Get;
 END Get;
 
 
-(*Windows Version*)
-(*
-(* timeZone and daylightSaving is difference to UTC in minutes*)
-PROCEDURE SetSystemTime*(time:HUGEINT; timeZone, daylightSaving:LONGINT); 
-VAR st: Kernel32.SystemTime;retBOOL: Kernel32.BOOL;					
-	dt: Dates.DateTime; frac: HUGEINT;
-BEGIN {EXCLUSIVE}
-	
-	frac:=time MOD 100000000H; 
-	time:=time DIV 100000000H MOD 100000000H; 
-	dt:=Dates.ZeroDateNTP;
-	
-	Dates.AddSeconds(dt, LONGINT(time MOD (LONGINT(60)*60*24)));
-	Dates.AddMinutes(dt, timeZone+daylightSaving);
-	Dates.AddDays(dt, LONGINT(time DIV (LONGINT(60)*60*24)));
-	(*
-	Dates.AddSeconds(dt, LONGINT(time)); (* would need unsigned addition of time, the latter possibly being negative*)
-	*)
-	st.wDay := SHORT(dt.day);
-	st.wMonth := SHORT(dt.month);
-	st.wYear := SHORT(dt.year);
-	st.wMilliseconds := 0; (*!TBD: use frac here*)
-	st.wSecond := SHORT(dt.second);
-	st.wMinute := SHORT(dt.minute);
-	st.wHour := SHORT(dt.hour);
-	retBOOL := Kernel32.SetLocalTime(st)
-END SetSystemTime;
-*)
-
-(*native *)
-(* timeZone and daylightSaving in minutes offset to universal time *)
-PROCEDURE SetSystemTime(time: HUGEINT; timeZone, daylightSaving: LONGINT);
+(* timeZone and daylightSaving in minutes is difference to UTC in minutes *)
+PROCEDURE SetSystemTime* (time: HUGEINT; timeZone, daylightSaving: LONGINT);
 VAR dt: Dates.DateTime; frac:HUGEINT;
 VAR dt: Dates.DateTime; frac:HUGEINT;
 BEGIN {EXCLUSIVE}
 BEGIN {EXCLUSIVE}
 		frac:=time MOD 100000000H; 
 		frac:=time MOD 100000000H; 
@@ -141,15 +111,14 @@ BEGIN {EXCLUSIVE}
 	Machine.PutNVByte(0BH, 12X)	(* 24 hour mode & 1 second interrupt *)
 	Machine.PutNVByte(0BH, 12X)	(* 24 hour mode & 1 second interrupt *)
 END SetSystemTime;
 END SetSystemTime;
 
 
-
 (* to be done: full NTP synchronization algorithm from RFC5905 to set machine clock *)
 (* to be done: full NTP synchronization algorithm from RFC5905 to set machine clock *)
 PROCEDURE SynchronizeNTP;
 PROCEDURE SynchronizeNTP;
 END SynchronizeNTP;
 END SynchronizeNTP;
 
 
-(* to be done: simple NTP synchronization algo from RFC 4330; parametrization of timeZone and daylightSaving*)
+(* to be done: SNTP synchronization algo from RFC 4330; parametrization of timeZone and daylightSaving*)
 PROCEDURE SynchronizeSNTP*(context:Commands.Context);
 PROCEDURE SynchronizeSNTP*(context:Commands.Context);
 VAR fip: IP.Adr; port, res:LONGINT; packet:Packet;
 VAR fip: IP.Adr; port, res:LONGINT; packet:Packet;
-(*
+(* SNTP algorithm:
  The roundtrip delay d and system clock offset t are defined as:
  The roundtrip delay d and system clock offset t are defined as:
       d = (T4 - T1) - (T3 - T2)     t = ((T2 - T1) + (T3 - T4)) / 2.
       d = (T4 - T1) - (T3 - T2)     t = ((T2 - T1) + (T3 - T4)) / 2.
 This can be used to set the system clock, if a high accuracy clock is retrievable & settable on this hardware/OS
 This can be used to set the system clock, if a high accuracy clock is retrievable & settable on this hardware/OS
@@ -205,4 +174,4 @@ WebNetworkTimeProtocol.GetSimpleTime~
 WebNetworkTimeProtocol.SynchronizeSNTP ~
 WebNetworkTimeProtocol.SynchronizeSNTP ~
 
 
 SystemTools.Free WebNetworkTimeProtocol~
 SystemTools.Free WebNetworkTimeProtocol~
-SystemTools.Free Dates ~
+SystemTools.Free Dates ~

+ 4 - 26
source/Windows.WebNetworkTimeProtocol.Mod

@@ -21,7 +21,7 @@ ToDo: full NTP synchronization algorithm.
 Note the comments on leap seconds: http://www.eecis.udel.edu/~mills/leap.html
 Note the comments on leap seconds: http://www.eecis.udel.edu/~mills/leap.html
 *)
 *)
 
 
-IMPORT IP,UDP, Streams, Commands, Configuration, DNS, Machine, Kernel32, Dates;
+IMPORT IP,UDP, Streams, Commands, Configuration, DNS, Kernel32, Dates;
 
 
 CONST NTPPort*=123;
 CONST NTPPort*=123;
 
 
@@ -89,9 +89,8 @@ BEGIN
 	END;
 	END;
 END Get;
 END Get;
 
 
-(*Windows Version*)
 (* timeZone and daylightSaving is difference to UTC in minutes*)
 (* timeZone and daylightSaving is difference to UTC in minutes*)
-PROCEDURE SetSystemTime*(time:HUGEINT; timeZone, daylightSaving:LONGINT); 
+PROCEDURE SetSystemTime*(time: HUGEINT; timeZone, daylightSaving:LONGINT); 
 VAR st: Kernel32.SystemTime;retBOOL: Kernel32.BOOL;					
 VAR st: Kernel32.SystemTime;retBOOL: Kernel32.BOOL;					
 	dt: Dates.DateTime; frac: HUGEINT;
 	dt: Dates.DateTime; frac: HUGEINT;
 BEGIN {EXCLUSIVE}
 BEGIN {EXCLUSIVE}
@@ -114,28 +113,6 @@ BEGIN {EXCLUSIVE}
 	retBOOL := Kernel32.SetLocalTime(st)
 	retBOOL := Kernel32.SetLocalTime(st)
 END SetSystemTime;
 END SetSystemTime;
 
 
-(* (*native *)
-PROCEDURE SetSystemTime(time: HUGEINT);
-VAR dt: Dates.DateTime; frac:HUGEINT;
-BEGIN {EXCLUSIVE}
-		frac:=time MOD 100000000H; 
-	time:=time DIV 100000000H MOD 100000000H; 
-	dt:=Dates.ZeroDateNTP;
-	Dates.AddSeconds(dt, LONGINT(time MOD (60*60*24)));
-	time:=time DIV (60*60*24);
-	Dates.AddDays(dt, LONGINT(time));
-	
-	Machine.PutNVByte(0BH, 82X);	(* disable clock & interrupt *)
-	Machine.PutNVByte(0, CHR(dt.seconds0)); 
-	Machine.PutNVByte(2, CHR(dt.minutes)); 
-	Machine.PutNVByte(4, CHR(dt.hours)); 
-	Machine.PutNVByte(7, CHR(dt.day));
-	Machine.PutNVByte(8, CHR(dt.month));
-	Machine.PutNVByte(9, CHR(dt.year));
-	Machine.PutNVByte(0BH, 12X)	(* 24 hour mode & 1 second interrupt *)
-END SetSystemTime;
-*)
-
 (* to be done: full NTP synchronization algorithm from RFC5905 to set machine clock *)
 (* to be done: full NTP synchronization algorithm from RFC5905 to set machine clock *)
 PROCEDURE SynchronizeNTP;
 PROCEDURE SynchronizeNTP;
 END SynchronizeNTP;
 END SynchronizeNTP;
@@ -179,6 +156,7 @@ BEGIN
 	
 	
 	context.out.String("checking server "); context.out.String(ipstr);context.out.Char(":"); context.out.Int(port,0);  context.out.Ln; context.out.Update;
 	context.out.String("checking server "); context.out.String(ipstr);context.out.Char(":"); context.out.Int(port,0);  context.out.Ln; context.out.Update;
 	context.out.String("SNTP result, transmit time [seconds.fraction]: "); context.out.Ln;
 	context.out.String("SNTP result, transmit time [seconds.fraction]: "); context.out.Ln;
+
 	context.out.Int(res,5); context.out.Char(":");
 	context.out.Int(res,5); context.out.Char(":");
 	context.out.Int(packet.TransmitTimestamp DIV 100000000H MOD 100000000H,0);
 	context.out.Int(packet.TransmitTimestamp DIV 100000000H MOD 100000000H,0);
 	context.out.Char(".");
 	context.out.Char(".");
@@ -200,4 +178,4 @@ WebNetworkTimeProtocol.GetSimpleTime~
 WebNetworkTimeProtocol.SynchronizeSNTP ~
 WebNetworkTimeProtocol.SynchronizeSNTP ~
 
 
 SystemTools.Free WebNetworkTimeProtocol~
 SystemTools.Free WebNetworkTimeProtocol~
-SystemTools.Free Dates ~
+SystemTools.Free Dates ~