|
|
@ -1,6 +1,8 @@ |
|
|
|
#!/usr/bin/env python3 |
|
|
|
#!/usr/bin/env python3 |
|
|
|
import unittest |
|
|
|
import unittest |
|
|
|
from datetime import datetime |
|
|
|
from datetime import datetime |
|
|
|
|
|
|
|
from unittest import mock |
|
|
|
|
|
|
|
from unittest.mock import Mock |
|
|
|
|
|
|
|
|
|
|
|
from laika.ephemeris import EphemerisType |
|
|
|
from laika.ephemeris import EphemerisType |
|
|
|
from laika.gps_time import GPSTime |
|
|
|
from laika.gps_time import GPSTime |
|
|
@ -21,7 +23,7 @@ def get_log(segs=range(0)): |
|
|
|
def verify_messages(lr, laikad): |
|
|
|
def verify_messages(lr, laikad): |
|
|
|
good_msgs = [] |
|
|
|
good_msgs = [] |
|
|
|
for m in lr: |
|
|
|
for m in lr: |
|
|
|
msg = laikad.process_ublox_msg(m.ubloxGnss, m.logMonoTime) |
|
|
|
msg = laikad.process_ublox_msg(m.ubloxGnss, m.logMonoTime, block=True) |
|
|
|
if msg is not None and len(msg.gnssMeasurements.correctedMeasurements) > 0: |
|
|
|
if msg is not None and len(msg.gnssMeasurements.correctedMeasurements) > 0: |
|
|
|
good_msgs.append(msg) |
|
|
|
good_msgs.append(msg) |
|
|
|
return good_msgs |
|
|
|
return good_msgs |
|
|
@ -52,28 +54,21 @@ class TestLaikad(unittest.TestCase): |
|
|
|
|
|
|
|
|
|
|
|
def test_laika_online_nav_only(self): |
|
|
|
def test_laika_online_nav_only(self): |
|
|
|
laikad = Laikad(auto_update=True, valid_ephem_types=EphemerisType.NAV) |
|
|
|
laikad = Laikad(auto_update=True, valid_ephem_types=EphemerisType.NAV) |
|
|
|
|
|
|
|
# Disable fetch_orbits to test NAV only |
|
|
|
|
|
|
|
laikad.fetch_orbits = Mock() |
|
|
|
correct_msgs = verify_messages(self.logs, laikad) |
|
|
|
correct_msgs = verify_messages(self.logs, laikad) |
|
|
|
correct_msgs_expected = 560 |
|
|
|
correct_msgs_expected = 560 |
|
|
|
self.assertEqual(correct_msgs_expected, len(correct_msgs)) |
|
|
|
self.assertEqual(correct_msgs_expected, len(correct_msgs)) |
|
|
|
self.assertEqual(correct_msgs_expected, len([m for m in correct_msgs if m.gnssMeasurements.positionECEF.valid])) |
|
|
|
self.assertEqual(correct_msgs_expected, len([m for m in correct_msgs if m.gnssMeasurements.positionECEF.valid])) |
|
|
|
|
|
|
|
|
|
|
|
def test_laika_offline(self): |
|
|
|
@mock.patch('laika.downloader.download_and_cache_file') |
|
|
|
# Set auto_update to false forces to use ephemeris messages |
|
|
|
def test_laika_offline(self, downloader_mock): |
|
|
|
|
|
|
|
downloader_mock.side_effect = IOError |
|
|
|
laikad = Laikad(auto_update=False) |
|
|
|
laikad = Laikad(auto_update=False) |
|
|
|
correct_msgs = verify_messages(self.logs, laikad) |
|
|
|
correct_msgs = verify_messages(self.logs, laikad) |
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(256, len(correct_msgs)) |
|
|
|
self.assertEqual(256, len(correct_msgs)) |
|
|
|
self.assertEqual(256, len([m for m in correct_msgs if m.gnssMeasurements.positionECEF.valid])) |
|
|
|
self.assertEqual(256, len([m for m in correct_msgs if m.gnssMeasurements.positionECEF.valid])) |
|
|
|
|
|
|
|
|
|
|
|
def test_laika_offline_ephem_at_start(self): |
|
|
|
|
|
|
|
# Test offline but process ephemeris msgs of segment first |
|
|
|
|
|
|
|
laikad = Laikad(auto_update=False, valid_ephem_types=EphemerisType.NAV) |
|
|
|
|
|
|
|
ephemeris_logs = [m for m in self.logs if m.ubloxGnss.which() == 'ephemeris'] |
|
|
|
|
|
|
|
correct_msgs = verify_messages(ephemeris_logs+self.logs, laikad) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(554, len(correct_msgs)) |
|
|
|
|
|
|
|
self.assertGreaterEqual(554, len([m for m in correct_msgs if m.gnssMeasurements.positionECEF.valid])) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_laika_get_orbits(self): |
|
|
|
def test_laika_get_orbits(self): |
|
|
|
laikad = Laikad(auto_update=False) |
|
|
|
laikad = Laikad(auto_update=False) |
|
|
|
first_gps_time = None |
|
|
|
first_gps_time = None |
|
|
@ -97,5 +92,6 @@ class TestLaikad(unittest.TestCase): |
|
|
|
self.assertLess(0, len(laikad.astro_dog.orbits[prn])) |
|
|
|
self.assertLess(0, len(laikad.astro_dog.orbits[prn])) |
|
|
|
print(min(laikad.astro_dog.orbits[prn], key=lambda e: e.epoch).epoch.as_datetime()) |
|
|
|
print(min(laikad.astro_dog.orbits[prn], key=lambda e: e.epoch).epoch.as_datetime()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
if __name__ == "__main__": |
|
|
|
unittest.main() |
|
|
|
unittest.main() |
|
|
|