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

Commit 9e27059

Browse files
committed
Merge pull request #235 from jacobmcnamee/prn_generalize
remove indexing by PRN
2 parents b3b8814 + 60ec2d7 commit 9e27059

File tree

4 files changed

+39
-56
lines changed

4 files changed

+39
-56
lines changed

include/libswiftnav/observation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ u8 make_propagated_sdiffs_wip(u8 n_local, navigation_measurement_t *m_local,
4848
u8 make_propagated_sdiffs(u8 n_local, navigation_measurement_t *m_local,
4949
u8 n_remote, navigation_measurement_t *m_remote,
5050
double *remote_dists, double remote_pos_ecef[3],
51-
ephemeris_t *es, gps_time_t t,
51+
const ephemeris_t *e[], gps_time_t t,
5252
sdiff_t *sds);
5353

5454
s8 make_dd_measurements_and_sdiffs(gnss_signal_t ref_sid, const gnss_signal_t *non_ref_sids, u8 num_dds,
5555
u8 num_sdiffs, const sdiff_t *sdiffs_in,
5656
double *dd_meas, sdiff_t *sdiffs_out);
5757

58-
u8 check_lock_counters(u8 n_sds, const sdiff_t *sds, u16 *lock_counters,
58+
u8 check_lock_counters(u8 n_sds, const sdiff_t *sds, u16 *lock_counters[],
5959
gnss_signal_t *sats_to_drop);
6060

6161
s8 copy_sdiffs_put_ref_first(const gnss_signal_t ref_sid, const u8 num_sdiffs,

include/libswiftnav/track.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,7 @@ float cn0_est(cn0_est_state_t *s, float I, float Q);
233233

234234
void calc_navigation_measurement(u8 n_channels, channel_measurement_t meas[],
235235
navigation_measurement_t nav_meas[],
236-
double nav_time, ephemeris_t ephemerides[]);
237-
void calc_navigation_measurement_(u8 n_channels, channel_measurement_t* meas[],
238-
navigation_measurement_t* nav_meas[],
239-
double nav_time, ephemeris_t* ephemerides[]);
236+
double nav_time, const ephemeris_t* e[]);
240237

241238
int nav_meas_cmp(const void *a, const void *b);
242239
u8 tdcp_doppler(u8 n_new, navigation_measurement_t *m_new,

src/observation.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void single_diff_(void *context, u32 n, const void *a, const void *b)
5858
const navigation_measurement_t *m_b = (const navigation_measurement_t *)b;
5959
sdiff_t *sds = (sdiff_t *)context;
6060

61-
sds[n].sid.sat = m_a->sid.sat;
61+
sds[n].sid = m_a->sid;
6262
sds[n].pseudorange = m_a->raw_pseudorange - m_b->raw_pseudorange;
6363
sds[n].carrier_phase = m_a->carrier_phase - m_b->carrier_phase;
6464
sds[n].doppler = m_a->raw_doppler - m_b->raw_doppler;
@@ -168,15 +168,16 @@ int cmp_sid_sdiff(const void *a, const void *b)
168168
* correspond to the i-th element of m_remote).
169169
* \param remote_pos_ecef The position of the remote receiver (presumed
170170
* constant in ecef).
171-
* \param es
171+
* \param e Array of pointers to ephemerides corresponding
172+
* to the signals in m_local
172173
* \param t
173174
* \param sds The single differenced propagated measurements.
174175
* \return The number of sats common in both local and remote sdiffs.
175176
*/
176177
u8 make_propagated_sdiffs(u8 n_local, navigation_measurement_t *m_local,
177178
u8 n_remote, navigation_measurement_t *m_remote,
178179
double *remote_dists, double remote_pos_ecef[3],
179-
ephemeris_t *es, gps_time_t t,
180+
const ephemeris_t *e[], gps_time_t t,
180181
sdiff_t *sds)
181182
{
182183
u8 i, j, n = 0;
@@ -187,12 +188,12 @@ u8 make_propagated_sdiffs(u8 n_local, navigation_measurement_t *m_local,
187188
j--;
188189
else if (sid_compare(m_local[i].sid, m_remote[j].sid) > 0)
189190
i--;
190-
else if (ephemeris_good(&es[m_local[i].sid.sat], t)) {
191+
else if (ephemeris_good(e[i], t)) {
191192
double clock_err;
192193
double clock_rate_err;
193194
double local_sat_pos[3];
194195
double local_sat_vel[3];
195-
calc_sat_state(&es[m_local[i].sid.sat], t, local_sat_pos, local_sat_vel,
196+
calc_sat_state(e[i], t, local_sat_pos, local_sat_vel,
196197
&clock_err, &clock_rate_err);
197198
sds[n].sid = m_local[i].sid;
198199
double dx = local_sat_pos[0] - remote_pos_ecef[0];
@@ -245,14 +246,15 @@ u8 make_propagated_sdiffs(u8 n_local, navigation_measurement_t *m_local,
245246
*
246247
* The lock counter values are then updated to reflect their changed values.
247248
*
248-
* \param n_sds Number of single difference observations passed in
249-
* \param sds Array of single difference observations
250-
* \param lock_counter Array of lock counter values, indexed by PRN
251-
* \param sats_to_drop Output array of PRNs for which the lock counter value
252-
* has changed
249+
* \param n_sds Number of single difference observations passed in
250+
* \param sds Array of single difference observations
251+
* \param lock_counters Array of lock counter values corresponding to signals
252+
* in sds
253+
* \param sats_to_drop Output array of signals for which the lock counter value
254+
* has changed
253255
* \return Number of sats with changed lock counter
254256
*/
255-
u8 check_lock_counters(u8 n_sds, const sdiff_t *sds, u16 *lock_counters,
257+
u8 check_lock_counters(u8 n_sds, const sdiff_t *sds, u16 *lock_counters[],
256258
gnss_signal_t *sats_to_drop)
257259
{
258260
assert(sds != NULL);
@@ -261,11 +263,10 @@ u8 check_lock_counters(u8 n_sds, const sdiff_t *sds, u16 *lock_counters,
261263

262264
u8 num_sats_to_drop = 0;
263265
for (u8 i = 0; i<n_sds; i++) {
264-
gnss_signal_t sid = sds[i].sid;
265266
u16 new_count = sds[i].lock_counter;
266-
if (new_count != lock_counters[sid.sat]) {
267-
sats_to_drop[num_sats_to_drop++] = sid;
268-
lock_counters[sid.sat] = new_count;
267+
if (new_count != *lock_counters[i]) {
268+
sats_to_drop[num_sats_to_drop++] = sds[i].sid;
269+
*lock_counters[i] = new_count;
269270
}
270271
}
271272
return num_sats_to_drop;

src/track.c

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -746,50 +746,35 @@ float cn0_est(cn0_est_state_t *s, float I, float Q)
746746
}
747747

748748
void calc_navigation_measurement(u8 n_channels, channel_measurement_t meas[],
749-
navigation_measurement_t nav_meas[], double nav_time,
750-
ephemeris_t ephemerides[])
751-
{
752-
channel_measurement_t* meas_ptrs[n_channels];
753-
navigation_measurement_t* nav_meas_ptrs[n_channels];
754-
ephemeris_t* ephemerides_ptrs[n_channels];
755-
756-
for (u8 i=0; i<n_channels; i++) {
757-
meas_ptrs[i] = &meas[i];
758-
nav_meas_ptrs[i] = &nav_meas[i];
759-
ephemerides_ptrs[i] = &ephemerides[meas[i].sid.sat];
760-
}
761-
762-
calc_navigation_measurement_(n_channels, meas_ptrs, nav_meas_ptrs, nav_time, ephemerides_ptrs);
763-
}
764-
765-
void calc_navigation_measurement_(u8 n_channels, channel_measurement_t* meas[], navigation_measurement_t* nav_meas[], double nav_time, ephemeris_t* ephemerides[])
749+
navigation_measurement_t nav_meas[],
750+
double nav_time, const ephemeris_t* e[])
766751
{
767752
double TOTs[n_channels];
768753
double min_TOF = -DBL_MAX;
769754
double clock_err[n_channels], clock_rate_err[n_channels];
770755

771756
for (u8 i=0; i<n_channels; i++) {
772-
TOTs[i] = 1e-3 * meas[i]->time_of_week_ms;
773-
TOTs[i] += meas[i]->code_phase_chips / 1.023e6;
774-
TOTs[i] += (nav_time - meas[i]->receiver_time) * meas[i]->code_phase_rate / 1.023e6;
757+
TOTs[i] = 1e-3 * meas[i].time_of_week_ms;
758+
TOTs[i] += meas[i].code_phase_chips / 1.023e6;
759+
TOTs[i] += (nav_time - meas[i].receiver_time) * meas[i].code_phase_rate / 1.023e6;
775760

776761
/** \todo Maybe keep track of week number in tracking channel
777762
state or derive it from system time. */
778-
nav_meas[i]->tot.tow = TOTs[i];
779-
gps_time_match_weeks(&nav_meas[i]->tot, &ephemerides[i]->toe);
763+
nav_meas[i].tot.tow = TOTs[i];
764+
gps_time_match_weeks(&nav_meas[i].tot, &e[i]->toe);
780765

781-
nav_meas[i]->raw_doppler = meas[i]->carrier_freq;
782-
nav_meas[i]->snr = meas[i]->snr;
783-
nav_meas[i]->sid.sat = meas[i]->sid.sat;
766+
nav_meas[i].raw_doppler = meas[i].carrier_freq;
767+
nav_meas[i].snr = meas[i].snr;
768+
nav_meas[i].sid = meas[i].sid;
784769

785-
nav_meas[i]->carrier_phase = meas[i]->carrier_phase;
786-
nav_meas[i]->carrier_phase += (nav_time - meas[i]->receiver_time) * meas[i]->carrier_freq;
770+
nav_meas[i].carrier_phase = meas[i].carrier_phase;
771+
nav_meas[i].carrier_phase += (nav_time - meas[i].receiver_time) * meas[i].carrier_freq;
787772

788-
nav_meas[i]->lock_counter = meas[i]->lock_counter;
773+
nav_meas[i].lock_counter = meas[i].lock_counter;
789774

790775
/* calc sat clock error */
791-
calc_sat_state(ephemerides[i], nav_meas[i]->tot,
792-
nav_meas[i]->sat_pos, nav_meas[i]->sat_vel,
776+
calc_sat_state(e[i], nav_meas[i].tot,
777+
nav_meas[i].sat_pos, nav_meas[i].sat_vel,
793778
&clock_err[i], &clock_rate_err[i]);
794779

795780
/* remove clock error to put all tots within the same time window */
@@ -798,14 +783,14 @@ void calc_navigation_measurement_(u8 n_channels, channel_measurement_t* meas[],
798783
}
799784

800785
for (u8 i=0; i<n_channels; i++) {
801-
nav_meas[i]->raw_pseudorange = (min_TOF - TOTs[i])*GPS_C + GPS_NOMINAL_RANGE;
786+
nav_meas[i].raw_pseudorange = (min_TOF - TOTs[i])*GPS_C + GPS_NOMINAL_RANGE;
802787

803-
nav_meas[i]->pseudorange = nav_meas[i]->raw_pseudorange \
788+
nav_meas[i].pseudorange = nav_meas[i].raw_pseudorange \
804789
+ clock_err[i]*GPS_C;
805-
nav_meas[i]->doppler = nav_meas[i]->raw_doppler + clock_rate_err[i]*GPS_L1_HZ;
790+
nav_meas[i].doppler = nav_meas[i].raw_doppler + clock_rate_err[i]*GPS_L1_HZ;
806791

807-
nav_meas[i]->tot.tow -= clock_err[i];
808-
nav_meas[i]->tot = normalize_gps_time(nav_meas[i]->tot);
792+
nav_meas[i].tot.tow -= clock_err[i];
793+
nav_meas[i].tot = normalize_gps_time(nav_meas[i].tot);
809794
}
810795
}
811796

0 commit comments

Comments
 (0)