From 0f09809d21ceec9878396fb80b645868a0286c2a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 6 Sep 2021 14:52:41 +0200 Subject: [PATCH] HK handling for GPS packet added --- pus_tm/hk_handling.py | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/pus_tm/hk_handling.py b/pus_tm/hk_handling.py index add4b27..62deda9 100644 --- a/pus_tm/hk_handling.py +++ b/pus_tm/hk_handling.py @@ -10,8 +10,10 @@ from config.object_ids import SYRLINKS_HANDLER, IMTQ_HANDLER_ID, GPS_HANDLER_0_I LOGGER = get_console_logger() -def handle_user_hk_packet(object_id: bytes, set_id: int, hk_data: bytearray, - service3_packet: Service3Base) -> Tuple[list, list, bytearray, int]: +def handle_user_hk_packet( + object_id: bytes, set_id: int, hk_data: bytearray, + service3_packet: Service3Base +) -> Tuple[list, list, bytearray, int]: """This function is called when a Service 3 Housekeeping packet is received. """ if object_id == SYRLINKS_HANDLER: @@ -148,4 +150,36 @@ def handle_self_test_data(hk_data: bytearray) -> Tuple[list, list, bytearray, in def handle_gps_data(hk_data: bytearray) -> Tuple[list, list, bytearray, int]: LOGGER.info(f'Received GPS data, HK data length {len(hk_data)}') - return [], [], bytearray(), 0 + var_index = 0 + header_array = [] + content_array = [] + latitude = struct.unpack('!d', hk_data[0:8])[0] + header_array.append('Latitude') + content_array.append(latitude) + longitude = struct.unpack('!d', hk_data[8:16])[0] + header_array.append('Longitude') + content_array.append(longitude) + altitude = struct.unpack('!d', hk_data[16:24])[0] + header_array.append('Altitude') + content_array.append(altitude) + fix_mode = hk_data[24] + header_array.append('Fix Mode') + content_array.append(fix_mode) + sat_in_use = hk_data[25] + header_array.append('Sats in Use') + content_array.append(sat_in_use) + year = struct.unpack('!H', hk_data[26:28])[0] + month = hk_data[28] + day = hk_data[29] + hours = hk_data[30] + minutes = hk_data[31] + seconds = hk_data[32] + header_array.append('Date') + content_array.append(f'{day}.{month}.{year} {hours}:{minutes}:{seconds}') + unix_seconds = struct.unpack('!I', hk_data[33:37])[0] + header_array.append('Unix Seconds') + content_array.append(unix_seconds) + var_index += 13 + validity_buffer = hk_data[37:39] + + return header_array, content_array, validity_buffer, var_index