Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

Commit

Permalink
TRACK: Correctly match week number of measurement to ephemeris
Browse files Browse the repository at this point in the history
  • Loading branch information
henryhallam committed Jul 21, 2015
1 parent 69ec6de commit e947cd7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/libswiftnav/gpstime.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ gps_time_t normalize_gps_time(gps_time_t);
time_t gps2time(gps_time_t t);

double gpsdifftime(gps_time_t end, gps_time_t beginning);
void gps_time_match_weeks(gps_time_t *t, const gps_time_t *ref);

#endif /* LIBSWIFTNAV_TIME_H */

Expand Down
16 changes: 16 additions & 0 deletions src/gpstime.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,19 @@ double gpsdifftime(gps_time_t end, gps_time_t beginning)
}
return dt;
}

/** Set the week number of t so as to minimize the magnitude of the
* time difference between t and ref.
*
* \param t Pointer to GPS time whose week number will be set
* \param ref Reference GPS time
*/
void gps_time_match_weeks(gps_time_t *t, const gps_time_t *ref)
{
t->wn = ref->wn;
double dt = t->tow - ref->tow;
if (dt > WEEK_SECS / 2)
t->wn--;
else if (dt < -WEEK_SECS / 2)
t->wn++;
}
8 changes: 3 additions & 5 deletions src/track.c
Original file line number Diff line number Diff line change
Expand Up @@ -767,12 +767,10 @@ void calc_navigation_measurement_(u8 n_channels, channel_measurement_t* meas[],
TOTs[i] += meas[i]->code_phase_chips / 1.023e6;
TOTs[i] += (nav_time - meas[i]->receiver_time) * meas[i]->code_phase_rate / 1.023e6;

/** \todo Handle GPS time properly here, e.g. week rollover */
nav_meas[i]->tot.wn = ephemerides[i]->toe.wn;
/** \todo Maybe keep track of week number in tracking channel
state or derive it from system time. */
nav_meas[i]->tot.tow = TOTs[i];

if (gpsdifftime(nav_meas[i]->tot, ephemerides[i]->toe) > 3*24*3600)
nav_meas[i]->tot.wn -= 1;
gps_time_match_weeks(&nav_meas[i]->tot, &ephemerides[i]->toe);

nav_meas[i]->raw_doppler = meas[i]->carrier_freq;
nav_meas[i]->snr = meas[i]->snr;
Expand Down

0 comments on commit e947cd7

Please sign in to comment.