eive-tmtc/eive_tmtc/pus_tm/devs/gps.py

40 lines
1.1 KiB
Python
Raw Normal View History

2022-05-19 13:20:22 +02:00
import struct
2022-11-29 16:53:29 +01:00
from eive_tmtc.pus_tm.defs import PrintWrapper
2022-07-08 16:25:46 +02:00
from tmtccmd.util.tmtc_printer import FsfwTmTcPrinter
2022-05-19 13:20:22 +02:00
def handle_gps_data(printer: FsfwTmTcPrinter, hk_data: bytes):
pw = PrintWrapper(printer)
pw.dlog(f"Received GPS data, HK data length {len(hk_data)}")
2022-05-24 01:34:33 +02:00
current_idx = 0
fmt_str = "!ddddBBBHBBBBBI"
inc_len = struct.calcsize(fmt_str)
(
lat,
long,
alt,
speed,
fix,
sats_in_use,
sats_in_view,
year,
month,
day,
hours,
minutes,
seconds,
2022-05-25 10:37:38 +02:00
unix_seconds,
) = struct.unpack(fmt_str, hk_data[current_idx : current_idx + inc_len])
2022-05-24 01:34:33 +02:00
current_idx += inc_len
2022-05-19 13:20:22 +02:00
date_string = f"{day}.{month}.{year} {hours}:{minutes}:{seconds}"
2022-05-24 01:34:33 +02:00
pw.dlog(f"Lat: {lat} deg")
pw.dlog(f"Long: {long} deg")
pw.dlog(f"Altitude: {alt} m | Speed: {speed} m/s")
2022-05-25 10:37:38 +02:00
pw.dlog(
f"Fix Type: {fix} | Sats in View {sats_in_view} | Sats in Use {sats_in_use}"
)
2022-05-24 01:34:33 +02:00
pw.dlog(f"GNSS Date: {date_string}")
pw.dlog(f"Unix seconds {unix_seconds}")
printer.print_validity_buffer(validity_buffer=hk_data[current_idx:], num_vars=14)