conversion between UTC and GPS time of week

This commit is contained in:
Pascal Brisset
2007-12-29 17:59:57 +00:00
parent cac2fb471e
commit f940e047b9
2 changed files with 28 additions and 0 deletions
+19
View File
@@ -443,3 +443,22 @@ let bearing = fun geo1 geo2 ->
and utm2 = utm_of WGS84 geo2 in
let (dx, dy) = utm_sub utm2 utm1 in
((Rad>>Deg)(atan2 dx dy), sqrt(dx*.dx+.dy*.dy))
let leap_seconds = 14 (* http://www.leapsecond.com/java/gpsclock.htm *)
let gps_tow_of_utc = fun ?wday hour min sec ->
let wday =
match wday with
Some w -> w
| None -> (Unix.gmtime (Unix.gettimeofday ())).Unix.tm_wday in
((wday*24 + hour)*60+min)*60+sec + leap_seconds
let get_gps_tow = fun () ->
let utc = Unix.gmtime (Unix.gettimeofday ()) in
gps_tow_of_utc ~wday:utc.Unix.tm_wday utc.Unix.tm_hour utc.Unix.tm_min utc.Unix.tm_sec
let unix_time_of_tow = fun tow ->
let host_tow = get_gps_tow () in
Unix.gettimeofday () +. float (tow - host_tow)
+9
View File
@@ -146,3 +146,12 @@ val inv_mercator_lat : float -> float
val bearing : geographic -> geographic -> float * float
(** [bearing from to] returns (degrees CW/north, m) *)
val gps_tow_of_utc : ?wday:int -> int -> int -> int -> int
(** [gps_tow_of_utc ?wday hour min sec] Returns the GPS time of week
in seconds, taking into acount the leap seconds. Default [wday] (week
day) is the current day (Sunday is 0). *)
val get_gps_tow : unit -> int
(** Returns the current GPS time of week in seconds *)
val unix_time_of_tow : int -> float