static void process_pps( peerT * const peer , json_ctx * const jctx , const l_fp * const rtime) { clockprocT * const pp = peer->procptr; gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; struct timespec ts; errno = 0; ts.tv_sec = (time_t)json_object_lookup_int( jctx, 0, "clock_sec"); if (up->fl_nsec) ts.tv_nsec = json_object_lookup_int( jctx, 0, "clock_nsec"); else ts.tv_nsec = json_object_lookup_int( jctx, 0, "clock_musec") * 1000; if (0 != errno) goto fail; up->pps_local = *rtime; /* get fudged receive time */ up->pps_recvt = tspec_stamp_to_lfp(ts); L_SUB(&up->pps_recvt, &up->pps_fudge); /* map to next full second as reference time stamp */ up->pps_stamp = up->pps_recvt; L_ADDUF(&up->pps_stamp, 0x80000000u); up->pps_stamp.l_uf = 0; pp->lastrec = up->pps_stamp; DPRINTF(2, ("GPSD_JSON(%d): process_pps, stamp='%s', recvt='%s'\n", up->unit, gmprettydate(&up->pps_stamp), gmprettydate(&up->pps_recvt))); /* When we have a time pulse, clear the TPV flag: the * PPS is only valid for the >NEXT< TPV value! */ up->fl_pps = -1; up->fl_tpv = 0; return; fail: DPRINTF(2, ("GPSD_JSON(%d): process_pps FAILED, nsec=%d stamp='%s', recvt='%s'\n", up->unit, up->fl_nsec, gmprettydate(&up->pps_stamp), gmprettydate(&up->pps_recvt))); up->tc_breply += 1; }
void test_ConstantDate(void) { const u_int32 HALF = 2147483648UL; l_fp e_time = {{3485080800UL}, HALF}; /* 2010-06-09 14:00:00.5 */ TEST_ASSERT_EQUAL_STRING("cfba1ce0.80000000 Wed, Jun 9 2010 14:00:00.500", gmprettydate(&e_time)); return; }
TEST_F(prettydateTest, ConstantDate) { l_fp time = {3485080800UL, HALF}; // 2010-06-09 14:00:00.5 ASSERT_STREQ("cfba1ce0.80000000 Wed, Jun 9 2010 14:00:00.500", gmprettydate(&time)); }
static void process_tpv( peerT * const peer , json_ctx * const jctx , const l_fp * const rtime) { clockprocT * const pp = peer->procptr; gpsd_unitT * const up = (gpsd_unitT *)pp->unitptr; const char * gps_time; int gps_mode; double ept, epp, epx, epy, epv; int xlog2; gps_mode = (int)json_object_lookup_int_default( jctx, 0, "mode", 0); gps_time = json_object_lookup_string_default( jctx, 0, "time", NULL); if (gps_mode < 1 || NULL == gps_time) { /* receiver has no fix; tell about and avoid stale data */ up->tc_breply += 1; up->fl_tpv = 0; up->fl_pps = 0; return; } /* save last time code to clock data */ save_ltc(pp, gps_time); /* convert clock and set resulting ref time */ if (convert_ascii_time(&up->tpv_stamp, gps_time)) { DPRINTF(2, ("GPSD_JSON(%d): process_tpv, stamp='%s', recvt='%s' mode=%u\n", up->unit, gmprettydate(&up->tpv_stamp), gmprettydate(&up->tpv_recvt), gps_mode)); up->tpv_local = *rtime; up->tpv_recvt = *rtime;/*TODO: hack until we get it remote from GPSD */ L_SUB(&up->tpv_recvt, &up->tpv_fudge); up->fl_tpv = -1; } else { up->tc_btime += 1; up->fl_tpv = 0; } /* Set the precision from the GPSD data * * Since EPT has some issues, we use EPT and a home-brewed error * estimation base on a sphere derived from EPX/Y/V and the * speed of light. Use the better one of those two. */ ept = json_object_lookup_float_default(jctx, 0, "ept", 1.0); epx = json_object_lookup_float_default(jctx, 0, "epx", 1000.0); epy = json_object_lookup_float_default(jctx, 0, "epy", 1000.0); if (1 == gps_mode) { /* 2d-fix: extend bounding rectangle to cuboid */ epv = max(epx, epy); } else { /* 3d-fix: get bounding cuboid */ epv = json_object_lookup_float_default( jctx, 0, "epv", 1000.0); } /* get diameter of enclosing sphere of bounding cuboid as spatial * error, then divide spatial error by speed of light to get * another time error estimate. Add extra 100 meters as * optimistic lower bound. Then use the better one of the two * estimations. */ epp = 2.0 * sqrt(epx*epx + epy*epy + epv*epv); epp = (epp + 100.0) / 299792458.0; ept = min(ept, epp ); ept = min(ept, 0.5 ); ept = max(ept, 1.0-9); ept = frexp(ept, &xlog2); peer->precision = xlog2; }