diff --git a/tc/obsw_tc_service23.py b/tc/obsw_tc_service23.py index ea2081941f5a4818efaa9ebbc93a97ca8aeaea0a..3013a88f5e521ec5a166be2c5c103054155ce8c4 100644 --- a/tc/obsw_tc_service23.py +++ b/tc/obsw_tc_service23.py @@ -49,8 +49,8 @@ def generate_service23_subservice9_packet(directory_name: str, repository_path: return PusTelecommand(service=23, subservice=9, ssc=21, app_data=data_to_pack) -def generateService23Subservice10Packet(directory_name: str, repository_path: str = "", - object_id=bytearray([])): +def generate_service23_subservice10_packet(directory_name: str, repository_path: str = "", + object_id=bytearray([])): """ This function generates the application data field for a PUS packet with service 23 and subservie 10. This service deletes the directory dirname. @@ -69,17 +69,27 @@ def generateService23Subservice10Packet(directory_name: str, repository_path: st return PusTelecommand(service=23, subservice=10, ssc=21, app_data=data_to_pack) -def generate_service23_subservice128_packet(repository_path: str, filename: str, - object_id: bytearray = bytearray([]), - file_data: bytearray = bytearray([])): - """ This function generates the application data field for a PUS packet with service - 23 and subservie 128. Subservice 128 is a custom service to write data in a file. - Additionally file is created if not already existing. +def generate_service23_subservice128_packet( + tc_queue: Deque, repository_path: str, filename: str, max_size_of_app_data: int, + object_id: bytearray = g.SD_CARD_HANDLER_ID, file_data: bytearray = bytearray([]), + init_ssc: int = 0): + """ + This function generates PUS packets with service 23 and subservie 128 and packs the into the + supplied deque container. + Subservice 128 is a custom service to write data in a file. A new file will be created if not + already existing. + + If the file data is larger than the maximum allowed size of application data, this function + will split the data into multiple packets and increment the initial SSC number by one for + each packet. + + @param tc_queue: Deque containing the PusTelecommand objects to send. @param repository_path: The path of the target file @param filename: Name of file from which the content shall be read + @param max_size_of_app_data: Maximum size of one data block. The file @param object_id: object ID of the memory handler (e.g. SD Card Handler) @param file_data: The data to write in the file - @return: The application data field of the (23,128) PUS packet + @param init_ssc: First SSC, which will be incremented for each packet. """ data_to_pack = object_id data_to_pack += bytearray(repository_path, 'utf-8') @@ -88,37 +98,42 @@ def generate_service23_subservice128_packet(repository_path: str, filename: str, data_to_pack += bytearray(filename, 'utf-8') # Add string terminator of filename data_to_pack.append(0) - return split_large_file(data_to_pack, 236, file_data) + split_large_file(tc_queue, data_to_pack, max_size_of_app_data, file_data, init_ssc) -def split_large_file(data_to_pack: bytearray, size_of_data_blocks, data: bytearray): +def split_large_file(tc_queue: Deque, data_to_pack: bytearray, size_of_data_blocks: int, + data: bytearray, init_ssc: int): """ This function splits a large file in multiple packets. This is necessary because the packet size is limited. + @param tc_queue: Deque which will contain a a PusTelecommand tuple. @param data_to_pack: bytearray of data. data will be split and appended to this bytearray @param size_of_data_blocks: The file is splitted in data blocks of this size @param data: The data to pack in multiple packets + @param init_ssc: The ssc of the first command, will be incremented by one for each packet. @return List containing the PUS packets generated for each data block """ - numberOfPackets = math.floor(len(data) / size_of_data_blocks) + number_of_packets = math.floor(len(data) / size_of_data_blocks) + packet_number = 0 - packetNumber = 0 - - commands = [] - for i in range(numberOfPackets): - data_to_pack.append(packetNumber >> 8) - data_to_pack.append(0xFF & packetNumber) + for i in range(number_of_packets): + data_to_pack.append(packet_number >> 8) + data_to_pack.append(0xFF & packet_number) data_to_pack += data[i * size_of_data_blocks:(i + 1) * size_of_data_blocks] - commands.append(PusTelecommand(service=23, subservice=128, ssc=21, app_data=data_to_pack)) + + commands = PusTelecommand(service=23, subservice=128, ssc=init_ssc + i, app_data=data_to_pack) + tc_queue.appendleft(commands.pack_command_tuple()) + # Last data block, packet number and data block size is removed to create new command with # next data block, packet number data_to_pack = data_to_pack[:len(data_to_pack) - size_of_data_blocks - 2] - packetNumber = packetNumber + 1 - data_to_pack.append(packetNumber >> 8) - data_to_pack.append(0xFF & packetNumber) - data_to_pack += data[numberOfPackets * size_of_data_blocks:len(data)] - commands.append(PusTelecommand(service=23, subservice=128, ssc=21, app_data=data_to_pack)) - return commands + packet_number = packet_number + 1 + data_to_pack.append(packet_number >> 8) + data_to_pack.append(0xFF & packet_number) + data_to_pack += data[number_of_packets * size_of_data_blocks:len(data)] + commands = PusTelecommand(service=23, subservice=128, ssc=init_ssc + packet_number, + app_data=data_to_pack) + tc_queue.appendleft(commands.pack_command_tuple()) def generate_service23_subservice129_packet(repository_path: str, filename: str, diff --git a/utility/obsw_binary_uploader.py b/utility/obsw_binary_uploader.py index 5c9cc8bef3b166d2bb1979a55634df00c6aa990b..a3dbe97772f8af3427e34552397c1b9aafed3dc0 100644 --- a/utility/obsw_binary_uploader.py +++ b/utility/obsw_binary_uploader.py @@ -8,7 +8,7 @@ It will be possible to encode the data (for example using DLE encoding) """ import tkinter as tk from tkinter import filedialog - +from tc.obsw_tc_service23 import split_large_file import config.obsw_config as g @@ -27,8 +27,8 @@ def perform_binary_upload(): calc_hamming_code = False print("Hamming code will not be calculated") - # Right now, the size of PUS packets is limited to 1024 bytes. Therefore, we split up the - # binary in 1000 byte packets + # Right now, the size of PUS packets is limited to 1500 bytes. Therefore, we split up the + # binary. frame_length = g.G_MAX_BINARY_FRAME_LENGTH if calc_hamming_code: @@ -36,4 +36,4 @@ def perform_binary_upload(): pass # We have to split the binary here first - + split_large_file()