gpstime.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2013 Swift Navigation Inc.
00003  * Contact: Fergus Noble <fergus@swift-nav.com>
00004  *
00005  * This source is subject to the license found in the file 'LICENSE' which must
00006  * be be distributed together with this source. All other rights reserved.
00007  *
00008  * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
00009  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
00010  * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
00011  */
00012 
00013 #include <math.h>
00014 
00015 #include "gpstime.h"
00016 
00024 /* TODO: Either normalise in place or rename to normalised. */
00025 gps_time_t normalize_gps_time(gps_time_t t)
00026 {
00027   while(t.tow < 0) {
00028     t.tow += 3600*24*7;
00029     t.wn += 1;
00030   }
00031 
00032   while(t.tow > 3600*24*7) {
00033     t.tow -= 3600*24*7;
00034     t.wn -= 1;
00035   }
00036 
00037   return t;
00038 }
00039 
00046 time_t gps2time(gps_time_t gps_t)
00047 {
00048   time_t t = GPS_EPOCH - GPS_MINUS_UTC_SECS;
00049 
00050   t += 7*24*3600*gps_t.wn;
00051   t += (s32)gps_t.tow;
00052 
00053   return t;
00054 }
00055 
00063 double gpsdifftime(gps_time_t end, gps_time_t beginning)
00064 {
00065   return (end.wn - beginning.wn)*7*24*3600 + \
00066          end.tow - beginning.tow;
00067 }
00068 
00069 


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:50