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