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

Commit 0aef497

Browse files
committed
Merge pull request #299 from ljbade/improve-calc-sat-state-error
Improve calc_sat_state error checking
2 parents 9fae95a + 565afe7 commit 0aef497

File tree

5 files changed

+62
-28
lines changed

5 files changed

+62
-28
lines changed

DEVELOPMENT.rst renamed to DEVELOPMENT.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Tools needed:
1212

1313
To get started, run::
1414

15-
./checks/setup-hooks.sh [DIR]
15+
./checks/setup-hooks.sh [DIR]
1616

1717
from within the libswiftnav root directory. The default build-dir will be `build`.
1818

@@ -22,6 +22,23 @@ in this build directory. These checks require doxygen, gcovr, and diff-cover
2222

2323
To manually run the coverage task, use `make check-coverage`. For syntax, use `make check-style`.
2424

25+
Building/Testing Python
26+
=======================
27+
28+
To build and test the python bindings use these commands:
29+
30+
First build and locally install libswiftnav:
31+
32+
cd build
33+
make
34+
make DESTDIR="./install" install
35+
36+
Then build the python bindings:
37+
38+
cd ../python
39+
export LD_LIBRARY_PATH=../build/install/usr/local/lib
40+
tox
41+
2542
Issues
2643
======
2744

@@ -31,7 +48,7 @@ You may see this in the output from diff-cover.
3148

3249
Did you set up your build with::
3350

34-
cmake -DCMAKE_BUILD_TYPE=Coverage ..
51+
cmake -DCMAKE_BUILD_TYPE=Coverage ..
3552

3653
or with the :code:`setup-hooks.sh` script? The :code:`Coverage` flag is
3754
required. If you are manually running the coverage script, make sure you run

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ For Doxygen documentation, see [docs.swift-nav.com.](http://docs.swift-nav.com/l
1717

1818
For installation, see [docs/install.dox.](http://docs.swift-nav.com/libswiftnav/install.html)
1919

20-
For development help, see [DEVELOPMENT.rst](https://github.com/swift-nav/libswiftnav/blob/master/DEVELOPMENT.rst)
20+
For development help, see [DEVELOPMENT.md](https://github.com/swift-nav/libswiftnav/blob/master/DEVELOPMENT.md)
2121

2222
[1]: https://travis-ci.org/swift-nav/libswiftnav.svg?branch=master
2323
[2]: https://travis-ci.org/swift-nav/libswiftnav

python/tests/test_ephemeris.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ def test_sat_state():
5454
assert clock_err - 0.00336435649383 < tol
5555
assert clock_rate_err - 3.63797880709e-12 < tol
5656
assert not eph.is_valid(t.GpsTime(**{ 'wn': 1866, 'tow': 518400.0,}))
57-
assert not eph.is_valid(t.GpsTime(**{ 'wn': 1867, 'tow': 518400.0 + 3600.*4}))
58-
assert eph.is_valid(t.GpsTime(**{ 'wn': 1867, 'tow': 518400.0 + 3600.*2}))
57+
assert not eph.is_valid(t.GpsTime(**{ 'wn': 1867, 'tow': 518400.0 + 3600.*2 + 1}))
58+
assert not eph.is_valid(t.GpsTime(**{ 'wn': 1867, 'tow': 518400.0 - 3600.*2 - 1}))
59+
assert eph.is_valid(t.GpsTime(**{ 'wn': 1867, 'tow': 518400.0 + 3600.*1}))
60+
assert eph.is_valid(t.GpsTime(**{ 'wn': 1867, 'tow': 518400.0 - 3600.*1}))
5961
assert not eph.is_valid(t.GpsTime(**{ 'wn': 1868, 'tow': 518400.0,}))
6062
assert len(eph.to_dict()) == 8
6163
assert repr(eph)
@@ -150,6 +152,6 @@ def test_sat_state():
150152
'af0': 0.0004458986222743988,
151153
'af1': 3.637978807091713e-12,
152154
'af2': 0.0}})
153-
assert eph.is_valid(t.GpsTime(**{ 'wn': 1867, 'tow': 518400.0 + 3600.*4}))
154-
assert not eph.is_valid(t.GpsTime(**{ 'wn': 1867, 'tow': 518400.0 + 3600.*6}))
155+
assert eph.is_valid(t.GpsTime(**{ 'wn': 1867, 'tow': 518400.0 + 3600.*2}))
156+
assert not eph.is_valid(t.GpsTime(**{ 'wn': 1867, 'tow': 518400.0 + 3600.*3 + 1}))
155157
assert eph.is_healthy()

src/bits.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void setbits(u8 *buff, u32 pos, u32 len, s32 data)
124124
* The method performs in-place shift operation.
125125
*
126126
* \param[in,out] buf Pointer to buffer head.
127-
* \param[in] bits Number of bytes in the buffer.
127+
* \param[in] size Number of bytes in the buffer.
128128
* \param[in] shift Number of bits for left shift operation.
129129
*
130130
* \return None
@@ -133,7 +133,7 @@ void bitshl(void *buf, u32 size, u32 shift)
133133
{
134134
if (shift > size * CHAR_BIT) {
135135
/* Quick check: if the shift is larger, than the buffer, zero the data */
136-
memset(buf, size, 0);
136+
memset(buf, 0, size);
137137
return;
138138
}
139139

src/ephemeris.c

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,6 @@ static s8 calc_sat_state_xyz(const ephemeris_t *e, const gps_time_t *t,
4141
double pos[3], double vel[3],
4242
double *clock_err, double *clock_rate_err)
4343
{
44-
/*
45-
*Ephemeris did not get time-stammped when it was received.
46-
*/
47-
if (e->toe.wn == 0)
48-
return -1;
49-
50-
if (!e->valid || !e->healthy)
51-
return -1;
52-
5344
const ephemeris_xyz_t *ex = &e->xyz;
5445
u8 ndays = t->tow / DAY_SECS;
5546
double tod = t->tow - DAY_SECS * ndays;
@@ -111,12 +102,6 @@ static s8 calc_sat_state_kepler(const ephemeris_t *e,
111102
/* Seconds from the time from ephemeris reference epoch (toe) */
112103
dt = gpsdifftime(t, &e->toe);
113104

114-
/* If dt is greater than fit_interval hours our ephemeris isn't valid. */
115-
if (fabs(dt) > ((u32)e->fit_interval)*60*60) {
116-
log_error("Using ephemeris outside validity period, dt = %+.0f", dt);
117-
return -1;
118-
}
119-
120105
/* Calculate position per IS-GPS-200D p 97 Table 20-IV */
121106

122107
/* Semi-major axis in meters. */
@@ -217,7 +202,7 @@ static s8 calc_sat_state_kepler(const ephemeris_t *e,
217202
* clock error [s/s]
218203
*
219204
* \return 0 on success,
220-
* -1 if ephemeris is older (or newer) than 4 hours
205+
* -1 if ephemeris is invalid
221206
*/
222207
s8 calc_sat_state(const ephemeris_t *e, const gps_time_t *t,
223208
double pos[3], double vel[3],
@@ -228,15 +213,21 @@ s8 calc_sat_state(const ephemeris_t *e, const gps_time_t *t,
228213
assert(clock_err != NULL);
229214
assert(clock_rate_err != NULL);
230215
assert(e != NULL);
231-
assert(ephemeris_valid(e, t));
216+
217+
if (!ephemeris_valid(e, t)) {
218+
char buf[SID_STR_LEN_MAX];
219+
sid_to_string(buf, sizeof(buf), e->sid);
220+
log_error("Using invalid or too old ephemeris in calc_sat_state for %s", buf);
221+
return -1;
222+
}
232223

233224
switch (e->sid.constellation) {
234225
case CONSTELLATION_GPS:
235226
return calc_sat_state_kepler(e, t, pos, vel, clock_err, clock_rate_err);
236227
case CONSTELLATION_SBAS:
237228
return calc_sat_state_xyz(e, t, pos, vel, clock_err, clock_rate_err);
238229
default:
239-
assert("unsupported constellation");
230+
assert("Unsupported constellation");
240231
return -1;
241232
}
242233
}
@@ -250,12 +241,36 @@ s8 calc_sat_state(const ephemeris_t *e, const gps_time_t *t,
250241
*/
251242
u8 ephemeris_valid(const ephemeris_t *eph, const gps_time_t *t)
252243
{
244+
assert(eph != NULL);
245+
assert(t != NULL);
246+
247+
if (!eph->valid) {
248+
return 0;
249+
}
250+
251+
if (eph->fit_interval <= 0) {
252+
log_warn("ephemeris_valid used with 0 eph->fit_interval");
253+
return 0;
254+
}
255+
256+
/*
257+
*Ephemeris did not get time-stammped when it was received.
258+
*/
259+
if (eph->toe.wn == 0) {
260+
return 0;
261+
}
262+
253263
/* Seconds from the time from ephemeris reference epoch (toe) */
254264
double dt = gpsdifftime(t, &eph->toe);
255265

256266
/* TODO: this doesn't exclude ephemerides older than a week so could be made
257267
* better. */
258-
return (eph->valid && fabs(dt) < ((u32)eph->fit_interval)*60*60);
268+
/* If dt is greater than fit_interval / 2 hours our ephemeris isn't valid. */
269+
if (fabs(dt) > ((u32)eph->fit_interval / 2) * 60 * 60) {
270+
return 0;
271+
}
272+
273+
return 1;
259274
}
260275

261276
/** Is this satellite healthy? Note this function only checks flags in the

0 commit comments

Comments
 (0)