Laikad: more sensible ephemeris management (#28721)

* Laikad: more sensible ephemeris management

* Tow

* fix test

* Also publish qcom

* Update

* Update laikad.py
old-commit-hash: 5c6efd2aab
beeps
Harald Schäfer 2 years ago committed by GitHub
parent a5080e07d6
commit c89a9b1b73
  1. 33
      selfdrive/locationd/laikad.py
  2. 5
      selfdrive/locationd/test/test_laikad.py
  3. 2
      selfdrive/test/process_replay/ref_commit

@ -130,26 +130,27 @@ class Laikad:
if self.save_ephemeris and (self.last_report_time - self.last_cached_t > SECS_IN_MIN): if self.save_ephemeris and (self.last_report_time - self.last_cached_t > SECS_IN_MIN):
nav_list: List = sum([v for k,v in self.astro_dog.navs.items()], []) nav_list: List = sum([v for k,v in self.astro_dog.navs.items()], [])
ephem_cache = ephemeris_structs.EphemerisCache(**{'glonassEphemerides': [e.data for e in nav_list if e.prn[0]=='R'], #TODO this only saves currently valid ephems, when we download future ephems we should save them too
'gpsEphemerides': [e.data for e in nav_list if e.prn[0]=='G']}) valid_navs = [e for e in nav_list if e.valid(self.last_report_time)]
if len(valid_navs) > 0:
put_nonblocking(EPHEMERIS_CACHE, ephem_cache.to_bytes()) ephem_cache = ephemeris_structs.EphemerisCache(**{'glonassEphemerides': [e.data for e in valid_navs if e.prn[0]=='R'],
cloudlog.debug("Cache saved") 'gpsEphemerides': [e.data for e in valid_navs if e.prn[0]=='G']})
put_nonblocking(EPHEMERIS_CACHE, ephem_cache.to_bytes())
cloudlog.debug("Cache saved")
self.last_cached_t = self.last_report_time self.last_cached_t = self.last_report_time
def create_ephem_statuses(self): def create_ephem_statuses(self):
ephemeris_statuses = [] ephemeris_statuses = []
prns_to_check = list(self.astro_dog.get_all_ephem_prns()) eph_list: List = sum([v for k,v in self.astro_dog.navs.items()], []) + sum([v for k,v in self.astro_dog.qcom_polys.items()], [])
prns_to_check.sort() for eph in eph_list:
for prn in prns_to_check: status = log.GnssMeasurements.EphemerisStatus.new_message()
eph = self.astro_dog.get_eph(prn, self.last_report_time) status.constellationId = ConstellationId.from_rinex_char(eph.prn[0]).value
if eph is not None: status.svId = get_sv_id(eph.prn)
status = log.GnssMeasurements.EphemerisStatus.new_message() status.type = get_log_eph_type(eph).value
status.constellationId = ConstellationId.from_rinex_char(prn[0]).value status.source = get_log_eph_source(eph).value
status.svId = get_sv_id(prn) status.tow = eph.epoch.tow
status.type = get_log_eph_type(eph).value status.gpsWeek = eph.epoch.week
status.source = get_log_eph_source(eph).value ephemeris_statuses.append(status)
ephemeris_statuses.append(status)
return ephemeris_statuses return ephemeris_statuses

@ -251,6 +251,7 @@ class TestLaikad(unittest.TestCase):
def test_cache(self): def test_cache(self):
use_qcom = True use_qcom = True
for use_qcom, logs in zip([True, False], [self.logs_qcom, self.logs]): for use_qcom, logs in zip([True, False], [self.logs_qcom, self.logs]):
Params().remove(EPHEMERIS_CACHE)
laikad = Laikad(auto_update=True, save_ephemeris=True, use_qcom=use_qcom) laikad = Laikad(auto_update=True, save_ephemeris=True, use_qcom=use_qcom)
def wait_for_cache(): def wait_for_cache():
max_time = 2 max_time = 2
@ -263,8 +264,8 @@ class TestLaikad(unittest.TestCase):
# Test cache with no ephemeris # Test cache with no ephemeris
laikad.last_report_time = GPSTime(1,0) laikad.last_report_time = GPSTime(1,0)
laikad.cache_ephemeris() laikad.cache_ephemeris()
wait_for_cache() if Params().get(EPHEMERIS_CACHE) is not None:
Params().remove(EPHEMERIS_CACHE) self.fail("Cache should not have been written without valid ephem")
#laikad.astro_dog.get_navs(self.first_gps_time) #laikad.astro_dog.get_navs(self.first_gps_time)
msg = verify_messages(logs, laikad, return_one_success=True) msg = verify_messages(logs, laikad, return_one_success=True)

@ -1 +1 @@
02c134e5a0d1f707c79f7a0ad6c1a5b6b038ee7c 7a045a0d17a73bf77c220a16e4d2c0eedc73cfb8

Loading…
Cancel
Save