From ff5a2e51e97e0d54a0c48df565ad028a23c15159 Mon Sep 17 00:00:00 2001 From: Innovation Date: Tue, 11 Jun 2024 10:38:19 +0100 Subject: [PATCH] Make no-fix state of navigationd make more sense (such as not just defaulting to Detroit or some shit). --- src/modules/navigationd/navigationd.py | 38 ++++++++++++++++---------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/modules/navigationd/navigationd.py b/src/modules/navigationd/navigationd.py index 3de2280..d0b66e7 100644 --- a/src/modules/navigationd/navigationd.py +++ b/src/modules/navigationd/navigationd.py @@ -31,14 +31,16 @@ def disconnectCyberware(): except: print("Cannot disconnect Cyberware.") -gpsdData = None - -def getMapImage(distance): +def getMapImage(distance, gpsdData): ox.settings.use_cache = True + # We don't want to send any data if we don't have a fix. if(gpsdData.lat == 0 and gpsdData.lon == 0): - point = (42.352593, -83.2640164) + return + #point = (42.352593, -83.2640164) + + point = (gpsdData.lat, gpsdData.lon) try: G = ox.graph_from_point(point, dist=distance, dist_type="bbox", network_type="drive") @@ -62,17 +64,20 @@ def getMapImage(distance): # # G = ox.graph_from_bbox(bbox=bbox, network_type="drive_service") -def sendLocation(): - try: - #request = requests.post(urlLocation, json={ 'x': gpsdData.lat, 'y': gpsdData.lon, 'z': gpsdData.alt, 'o': gpsdData.track }) - request = requests.post(urlLocation, json={ 'x': None, 'y': None, 'z': None, 'o': None, 'uuid': uuid }) - except: - print('Could not contact NightCall') +def sendLocation(gpsdData): + # We don't want to hit the API if we don't have a fix. + if(gpsdData.lat != 0 and gpsdData.lon !=0): + try: + request = requests.post(urlLocation, json={ 'x': gpsdData.lat, 'y': gpsdData.lon, 'z': gpsdData.alt, 'o': None, 'uuid': uuid }) + except: + print('Could not contact NightCall') def sendMapImage(): try: files = { 'image': open(uuid+".png", 'rb') } request = requests.post(urlImage, files=files) + except FileNotFoundError: # Occurs if we don't have a fix yet. + return except: print("Could not contact NightCall") @@ -90,11 +95,10 @@ while continueFlag: try: gpsdData = gpsd.get_current() except gpsd.NoFixError: - gpsdData = None - print("No GPS fix yet! Using default coordinates.") + print("No GPS fix!") - getMapImage(1000) - sendLocation() + getMapImage(1000, gpsdData) + sendLocation(gpsdData) sendMapImage() #print(packet.position()) @@ -106,4 +110,8 @@ print("Removing Cyberware") disconnectCyberware() print("Cleaning up") -os.remove(uuid+".png") + +try: + os.remove(uuid+".png") +except: + print("No minimap image was ever made. GPS probably never had a fix.")