From 4e4d69f6d6f6e55b40e90804b3b8ecdba10d96f5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 6 Sep 2021 18:26:56 +0200 Subject: [PATCH] export gps to logger --- pus_tm/hk_handling.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pus_tm/hk_handling.py b/pus_tm/hk_handling.py index 62deda9..ab54564 100644 --- a/pus_tm/hk_handling.py +++ b/pus_tm/hk_handling.py @@ -1,5 +1,7 @@ """HK Handling for EIVE OBSW""" import struct +import os +import datetime from typing import Tuple from tmtccmd.tm.service_3_housekeeping import Service3Base @@ -175,11 +177,22 @@ def handle_gps_data(hk_data: bytearray) -> Tuple[list, list, bytearray, int]: minutes = hk_data[31] seconds = hk_data[32] header_array.append('Date') - content_array.append(f'{day}.{month}.{year} {hours}:{minutes}:{seconds}') + date_string = f'{day}.{month}.{year} {hours}:{minutes}:{seconds}' + content_array.append(date_string) unix_seconds = struct.unpack('!I', hk_data[33:37])[0] header_array.append('Unix Seconds') content_array.append(unix_seconds) var_index += 13 + if not os.path.isfile('gps_log.txt'): + with open("gps_log.txt", "w") as gps_file: + gps_file.write( + 'Time, Latitude [deg], Longitude [deg], Altitude [m], Fix Mode, Sats in Use, ' + 'Date, Unix Seconds\n' + ) + with open("gps_log.txt", "a") as gps_file: + gps_file.write( + f'{datetime.datetime.now()}, {latitude}, {longitude}, {altitude}, ' + f'{fix_mode}, {sat_in_use}, {date_string}, {unix_seconds}\n' + ) validity_buffer = hk_data[37:39] - return header_array, content_array, validity_buffer, var_index