Assisted GPS qcom (#28278)

* Assisted GPS works

* cleanup

* add error handling

* use pycurl instead with timeout

* Add file size check

* More cleanup

* more cleanup

* Dont crash on large file
old-commit-hash: b35d525cc9
beeps
Harald Schäfer 2 years ago committed by GitHub
parent fcc06d092d
commit c957a61c12
  1. 43
      system/sensord/rawgps/rawgpsd.py

@ -5,7 +5,9 @@ import signal
import itertools
import math
import time
import pycurl
import subprocess
from datetime import datetime
from typing import NoReturn
from struct import unpack_from, calcsize, pack
@ -107,6 +109,38 @@ def gps_enabled() -> bool:
except subprocess.CalledProcessError as exc:
raise Exception("failed to execute QGPS mmcli command") from exc
def download_and_inject_assistance():
assist_data_file = '/tmp/xtra3grc.bin'
assistance_url = 'http://xtrapath3.izatcloud.net/xtra3grc.bin'
try:
c = pycurl.Curl()
c.setopt(c.URL, assistance_url)
c.setopt(c.NOBODY, 1)
c.setopt(pycurl.CONNECTTIMEOUT, 2)
c.perform()
c.close()
bytes_n = c.getinfo(c.CONTENT_LENGTH_DOWNLOAD)
if bytes_n > 1e5:
cloudlog.exception("Qcom assistance data larger than expected")
return
with open(assist_data_file, "wb") as fp:
c = pycurl.Curl()
c.setopt(pycurl.URL, assistance_url)
c.setopt(pycurl.CONNECTTIMEOUT, 5)
c.setopt(pycurl.WRITEDATA, fp)
c.perform()
c.close()
except pycurl.error as e:
cloudlog.exception(f'Failed to download assistance file with error: {e}')
if os.path.isfile(assist_data_file):
try:
subprocess.check_call(f"mmcli -m any --timeout 30 --location-inject-assistance-data={assist_data_file}", shell=True)
except subprocess.CalledProcessError:
cloudlog.exception("rawgps.mmcli_command_failed")
if os.path.isfile(assist_data_file):
os.remove(assist_data_file)
def setup_quectel(diag: ModemDiag):
# enable OEMDRE in the NV
# TODO: it has to reboot for this to take effect
@ -120,13 +154,20 @@ def setup_quectel(diag: ModemDiag):
if gps_enabled():
at_cmd("AT+QGPSEND")
#at_cmd("AT+QGPSDEL=0")
# disable DPO power savings for more accuracy
at_cmd("AT+QGPSCFG=\"dpoenable\",0")
# don't automatically turn on GNSS on powerup
at_cmd("AT+QGPSCFG=\"autogps\",0")
at_cmd("AT+QGPSSUPLURL=\"supl.google.com:7275\"")
# Do internet assistance
at_cmd("AT+QGPSXTRA=1")
download_and_inject_assistance()
#at_cmd("AT+QGPSXTRADATA?")
time_str = datetime.utcnow().strftime("%Y/%m/%d,%H:%M:%S")
at_cmd(f"AT+QGPSXTRATIME=0,\"{time_str}\",1,1,1000")
at_cmd("AT+QGPSCFG=\"outport\",\"usbnmea\"")
at_cmd("AT+QGPS=1")

Loading…
Cancel
Save