13 self.
ser = serial.Serial(
16 parity=serial.PARITY_NONE,
17 stopbits=serial.STOPBITS_ONE,
18 bytesize=serial.EIGHTBITS,
38 return f
"{v:.3f}" if isinstance(v, (int, float))
else "N/A"
41 f
"Latitude: {_fmt(self.latitude)}\n"
42 f
"Longitude: {_fmt(self.longitude)}\n"
43 f
"Altitude: {_fmt(self.altitude)}\n"
46 def update_loop(self):
47 print(
"Serial port opened. Waiting for data...")
51 if self.
ser.in_waiting > 0:
55 data = self.
ser.readline().decode().strip()
58 if data.find(
'GGA') > 0:
60 msg = pynmea2.parse(data)
62 print(msg.timestamp, 'Lat:', round(msg.latitude, 6), 'Lon:', round(msg.longitude, 6),
63 'Alt:', msg.altitude, 'Sats:', msg.num_sats)
72 except Exception
as e:
76 print(
"No data recieved")
79 except Exception
as e:
80 print(f
"An error occurred: {e}")
88 def get_altitude(self):