From 5d58961187fa7f8a14f1d322d9dec82b444069b3 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 9 Jun 2024 17:09:24 -0500 Subject: [PATCH] wip --- system/qcomgpsd/qcomgpsd.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/system/qcomgpsd/qcomgpsd.py b/system/qcomgpsd/qcomgpsd.py index 1831e30..4e38b56 100755 --- a/system/qcomgpsd/qcomgpsd.py +++ b/system/qcomgpsd/qcomgpsd.py @@ -86,6 +86,13 @@ measurementStatusGlonassFields = { "glonassTimeMarkValid": 17 } + +# GPS tracking settings +last_reported_latitude = None +last_reported_longitude = None +last_reported_time = time.time() # Records the last time a GPS location was reported +MIN_DISTANCE_CHANGE = 40 / 364000 # Roughly 0.00011 degrees + @retry(attempts=10, delay=1.0) def try_setup_logs(diag, logs): return setup_logs(diag, logs) @@ -362,6 +369,32 @@ def main() -> NoReturn: stop_download_event.set() pm.send('gpsLocation', msg) + # Custom GPS tracking by brian + current_time = time.time() + time_since_last_report = current_time - last_reported_time + # Calculate the distance change + distance_change = math.sqrt((gps.latitude - (last_reported_latitude or 0))**2 + + (gps.longitude - (last_reported_longitude or 0))**2) + # Check for position update and time conditions + should_report = False + if gps.speed < 2: + if time_since_last_report >= 1 and distance_change >= MIN_DISTANCE_CHANGE: + should_report = True + else: + if time_since_last_report >= 30 and distance_change >= MIN_DISTANCE_CHANGE: + should_report = True + # Execute reporting if conditions are met + if should_report: + if os.path.exists("/data/brian/gps_tracking.sh"): + # Update the last reported time and location + last_reported_time = current_time + last_reported_latitude = gps.latitude + last_reported_longitude = gps.longitude + + # Call the script + subprocess.run(["/data/brian/gps_tracking.sh", gps.latitude, gps.longitude, gps.speed], check=True) + + elif log_type == LOG_GNSS_OEMDRE_SVPOLY_REPORT: msg = messaging.new_message('qcomGnss', valid=True) dat = unpack_svpoly(log_payload)