|
@@ -0,0 +1,70 @@
|
|
|
|
+class GPS:
|
|
|
|
+ def __init__(self, data):
|
|
|
|
+ data = data[0]
|
|
|
|
+ self.data = data
|
|
|
|
+ self.packet_id = data[2:4]
|
|
|
|
+ self.avl_packet_id = data[5:6]
|
|
|
|
+ self.codec_id = data[23:24]
|
|
|
|
+ self.number_of_data = data[24:25]
|
|
|
|
+ self.gps_data = data[33:200]
|
|
|
|
+
|
|
|
|
+ def decode_gps_data(self):
|
|
|
|
+ longitude = self.gps_data[1:5]
|
|
|
|
+ latitude = self.gps_data[5:9]
|
|
|
|
+ altitude = self.gps_data[9:13]
|
|
|
|
+ angle = self.gps_data[11:13]
|
|
|
|
+ speed = self.gps_data[14:16]
|
|
|
|
+ decoded_data = {
|
|
|
|
+ "Longitude": str(int(longitude.hex(),32)),
|
|
|
|
+ "Latitude": str(int(latitude.hex(),32)),
|
|
|
|
+ "Altitude": str(int(altitude.hex(),32)),
|
|
|
|
+ "Angle": str(int(angle.hex(),16)),
|
|
|
|
+ "Speed": str(int(speed.hex(),16))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return decoded_data
|
|
|
|
+
|
|
|
|
+ def print_gps_data(self):
|
|
|
|
+ gps_file = open("gps_data.txt","a")
|
|
|
|
+ decoded_data = self.decode_gps_data()
|
|
|
|
+ for key, value in decoded_data.items():
|
|
|
|
+ if str(key) == "Latitude" or str(key) == "Longitude":
|
|
|
|
+ key,value = str(key),str(value)
|
|
|
|
+ value = value[0:2]+"."+value[2:len(value)]
|
|
|
|
+ else:
|
|
|
|
+ key,value = str(key),str(value)
|
|
|
|
+ gps_file.write(key+" "+value+"\n")
|
|
|
|
+ print(key, value)
|
|
|
|
+ gps_file.close()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def create_gpx_file(self):
|
|
|
|
+ gpx_data = f"""<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
+ <gpx version="1.1" xmlns="">"""
|
|
|
|
+
|
|
|
|
+ with open("gps_data.gpx", "w", encoding="utf-8") as gpx_file:gpx_file.write(gpx_data)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def add_waypoint(self):
|
|
|
|
+ data = self.decode_gps_data()
|
|
|
|
+
|
|
|
|
+ latitude = data['Latitude'][0:2]+"."+data['Latitude'][2:len(data['Latitude'])]
|
|
|
|
+ longitude = data['Longitude'][0:2]+"."+data['Longitude'][2:len(data['Longitude'])]
|
|
|
|
+ altitude = data['Altitude']
|
|
|
|
+ angle = data['Angle']
|
|
|
|
+ speed = data['Speed']
|
|
|
|
+
|
|
|
|
+ waypoint = f"""
|
|
|
|
+ <wpt lat="{latitude}" lon="{longitude}">
|
|
|
|
+ <ele>{altitude}</ele>
|
|
|
|
+ <magvar>{angle}</magvar>
|
|
|
|
+ <speed>{speed}</speed>
|
|
|
|
+ </wpt>
|
|
|
|
+ """
|
|
|
|
+ with open("gps_data.gpx", "a", encoding="utf-8") as gpx_file:gpx_file.write(waypoint)
|
|
|
|
+
|
|
|
|
+ def close_gpx(self):
|
|
|
|
+ close = f"""</gpx>"""
|
|
|
|
+ with open("gps_data.gpx", "a", encoding="utf-8") as gpx_file:gpx_file.write(close)
|
|
|
|
+
|
|
|
|
+
|