Lines Matching +full:gnss +full:- +full:receiver
2 * ntp_calgps.c - calendar for GPS/GNSS based clocks
7 * --------------------------------------------------------------------
9 * This module implements stuff often used with GPS/GNSS receivers
26 * misc. helpers -- might go elsewhere sometime?
37 /* calculate 'lfp - ofs' as '(l_fp)(-ofs) + lfp': negating a in ntpfp_with_fudge()
40 ofs = -ofs; in ntpfp_with_fudge()
52 /* --------------------------------------------------------------------
55 * alike) it does not really pay off to do a floor-corrected division
57 * --------------------------------------------------------------------
66 if (datum->secs >= limit) { in _norm_ntp_datum()
68 ++datum->days; in _norm_ntp_datum()
69 while ((datum->secs -= limit) >= limit); in _norm_ntp_datum()
70 } else if (datum->secs < 0) { in _norm_ntp_datum()
72 --datum->days; in _norm_ntp_datum()
73 while ((datum->secs += limit) < 0); in _norm_ntp_datum()
84 if (datum->wsecs >= limit) { in _norm_gps_datum()
86 ++datum->weeks; in _norm_gps_datum()
87 while ((datum->wsecs -= limit) >= limit); in _norm_gps_datum()
88 } else if (datum->wsecs < 0) { in _norm_gps_datum()
90 --datum->weeks; in _norm_gps_datum()
91 while ((datum->wsecs += limit) < 0); in _norm_gps_datum()
95 /* --------------------------------------------------------------------
100 * --------------------------------------------------------------------
109 datum->frac += offset.l_uf; in gpsntp_add_offset()
110 datum->secs += (datum->frac < offset.l_uf); in gpsntp_add_offset()
114 datum->secs -= (int32_t)~offset.l_ui + 1; in gpsntp_add_offset()
116 datum->secs += (int32_t)offset.l_ui; in gpsntp_add_offset()
127 datum->frac += offset.l_uf; in gpscal_add_offset()
128 datum->wsecs += (datum->frac < offset.l_uf); in gpscal_add_offset()
133 datum->wsecs -= (int32_t)~offset.l_ui + 1; in gpscal_add_offset()
135 datum->wsecs += (int32_t)offset.l_ui; in gpscal_add_offset()
139 /* -------------------------------------------------------------------
141 * -------------------------------------------------------------------
164 - GPSNTP_DSHIFT; in _gpsntp_fix_gps_era()
167 sign = (uint32_t)-(days < base); in _gpsntp_fix_gps_era()
168 days = sign ^ (days - base); in _gpsntp_fix_gps_era()
186 /* ----------------------------------------------------------------- */
199 /* set result based on pivot -- ops order is important here */ in _gpsntp_from_daytime()
203 retv.days = pivot->days; in _gpsntp_from_daytime()
206 if (pivot->secs < shift) { in _gpsntp_from_daytime()
207 int32_t lim = pivot->secs + shift; in _gpsntp_from_daytime()
208 retv.days -= (retv.secs > lim || in _gpsntp_from_daytime()
209 (retv.secs == lim && retv.frac >= pivot->frac)); in _gpsntp_from_daytime()
211 int32_t lim = pivot->secs - shift; in _gpsntp_from_daytime()
213 (retv.secs == lim && retv.frac < pivot->frac)); in _gpsntp_from_daytime()
218 /* -----------------------------------------------------------------
219 * Given the time-of-day part of a civil datum and an additional
237 /* -----------------------------------------------------------------
264 /* -----------------------------------------------------------------
280 /* -----------------------------------------------------------------
292 nd->days + DAY_NTP_STARTS + ntpcal_daysec_to_date( in gpsntp_to_calendar()
293 cd, nd->secs)); in gpsntp_to_calendar()
296 /* -----------------------------------------------------------------
313 date.weeks = ((date.weeks - base) & 1023u) + base; in gpsntp_from_gpscal_ex()
320 retv.frac = gd->frac; in gpsntp_from_gpscal_ex()
326 /* -----------------------------------------------------------------
336 retv.l_uf = nd->frac; in ntpfp_from_ntpdatum()
337 retv.l_ui = nd->days * (uint32_t)SECSPERDAY in ntpfp_from_ntpdatum()
338 + nd->secs; in ntpfp_from_ntpdatum()
342 /* -------------------------------------------------------------------
345 * Here we use a calendar base of 1899-12-31, so the NTP epoch has
347 * -------------------------------------------------------------------
366 week = base + ((week - base) & (GPSWEEKS - 1)); in _gpscal_fix_gps_era()
381 /* -----------------------------------------------------------------
386 * This function also augments the century if just a 2-digit year
389 * This is a fail-safe against GPS receivers with an unknown starting
394 * trusting the era mapping of the receiver and doing the era assignment
404 /* (-DAY_GPS_STARTS) (mod 7*1024) -- complement of cycle shift */ in gpscal_from_calendar_ex()
406 (7 * 1024) - DAY_GPS_STARTS % (7 * 1024); in gpscal_from_calendar_ex()
412 /* if needed, convert from 2-digit year to full year in gpscal_from_calendar_ex()
427 - 1; /* both RDN and yearday start with '1'. */ in gpscal_from_calendar_ex()
439 days -= DAY_GPS_STARTS; in gpscal_from_calendar_ex()
440 } else if (jd->year < 100) { in gpscal_from_calendar_ex()
441 /* Two-digit year on input: add another century and in gpscal_from_calendar_ex()
443 * yielded a date between 1980-01-01 and 1980-01-05, in gpscal_from_calendar_ex()
463 days -= week * 7; in gpscal_from_calendar_ex()
465 /* re-base on start of NTP with weeks mapped to 1024 weeks in gpscal_from_calendar_ex()
475 /* -----------------------------------------------------------------
491 /* -----------------------------------------------------------------
499 * (1980-01-06) on input. The output weeks will be aligned to NTPD's
500 * week calendar start (1899-12-31)!
518 /* -----------------------------------------------------------------
519 * internal work horse for time-of-week expansion
532 /* set result based on pivot -- ops order is important here */ in _gpscal_from_weektime()
536 retv.weeks = pivot->weeks; in _gpscal_from_weektime()
539 if (pivot->wsecs < shift) { in _gpscal_from_weektime()
540 int32_t lim = pivot->wsecs + shift; in _gpscal_from_weektime()
541 retv.weeks -= (retv.wsecs > lim || in _gpscal_from_weektime()
542 (retv.wsecs == lim && retv.frac >= pivot->frac)); in _gpscal_from_weektime()
544 int32_t lim = pivot->wsecs - shift; in _gpscal_from_weektime()
546 (retv.wsecs == lim && retv.frac < pivot->frac)); in _gpscal_from_weektime()
551 /* -----------------------------------------------------------------
552 * expand a time-of-week around a pivot given as week datum
566 /* -----------------------------------------------------------------
567 * epand a time-of-week around an pivot given as LFP, which in turn
582 /* get 64-bit pivot in NTP epoch */ in gpscal_from_weektime1()
585 /* convert to weeks since 1899-12-31 and seconds in week */ in gpscal_from_weektime1()
595 /* -----------------------------------------------------------------
607 ts64 = ntpcal_dayjoin(gd->days, gd->secs); in gpscal_from_gpsntp()
611 retv.frac = gd->frac; in gpscal_from_gpsntp()
617 /* -----------------------------------------------------------------
627 retv.l_uf = gd->frac; in ntpfp_from_gpsdatum()
628 retv.l_ui = gd->weeks * (uint32_t)SECSPERWEEK in ntpfp_from_gpsdatum()
629 + (uint32_t)gd->wsecs in ntpfp_from_gpsdatum()
630 - (uint32_t)SECSPERDAY * GPSNTP_DSHIFT; in ntpfp_from_gpsdatum()
634 /* -*-EOF-*- */