From 35be95db380c8f7ecf3b32553dcf2cfb6a4d30c4 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" <robin.mueller.m@gmail.com> Date: Thu, 23 Apr 2020 10:01:50 +0200 Subject: [PATCH] introducing framing solution --- .../tmtcclient_Module_Test_Serial.xml | 2 +- comIF/obsw_serial_com_if.py | 30 +++++++++++-------- obsw_tmtc_client.py | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.idea/runConfigurations/tmtcclient_Module_Test_Serial.xml b/.idea/runConfigurations/tmtcclient_Module_Test_Serial.xml index e9f787a..edc3069 100644 --- a/.idea/runConfigurations/tmtcclient_Module_Test_Serial.xml +++ b/.idea/runConfigurations/tmtcclient_Module_Test_Serial.xml @@ -13,7 +13,7 @@ <option name="ADD_SOURCE_ROOTS" value="true" /> <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" /> <option name="SCRIPT_NAME" value="$PROJECT_DIR$/obsw_tmtc_client.py" /> - <option name="PARAMETERS" value="-m 5 -c 1 --hk --np" /> + <option name="PARAMETERS" value="-m 5 -c 1 --hk" /> <option name="SHOW_COMMAND_LINE" value="false" /> <option name="EMULATE_TERMINAL" value="true" /> <option name="MODULE_MODE" value="false" /> diff --git a/comIF/obsw_serial_com_if.py b/comIF/obsw_serial_com_if.py index e759243..321190b 100644 --- a/comIF/obsw_serial_com_if.py +++ b/comIF/obsw_serial_com_if.py @@ -9,7 +9,7 @@ import sys import time import logging from typing import Tuple, List, Union, Optional - +import pprint import serial import config.obsw_config as g from comIF.obsw_com_interface import CommunicationInterface, PusTmQueueT @@ -18,7 +18,7 @@ from tm.obsw_pus_tm_factory import pus_telemetry_factory from tm.obsw_pus_tm_base import PusTmInfoQueueT, PusTmTupleQueueT, PusTmListT from tc.obsw_pus_tc_base import PusTcInfoT -SERIAL_PACKET_MAX_SIZE = 1024 +SERIAL_FRAME_LENGTH = 256 HEADER_BYTES_BEFORE_SIZE = 5 @@ -85,17 +85,19 @@ class SerialComIF(CommunicationInterface): def __poll_pus_packets(self) -> Tuple[List[Optional[bytes]], int]: pus_data_list = [] - self.data = self.serial.read(1024) - packet_size = (self.data[4] << 8 | self.data[5]) + 7 + self.data = self.serial.read(SERIAL_FRAME_LENGTH) + payload_length = (self.data[4] << 8 | self.data[5]) + packet_size = payload_length + 7 + if payload_length == 0: + return [], 0 read_size = len(self.data) self.number_of_packets = 1 - if read_size < packet_size: - print("Serial Com IF: Size missmatch when polling PUS wiretapping_packet. Packet Size: " + - str(packet_size) + ". Read Size: " + str(read_size) + ". Check timeout too") + pus_data_list.append(self.data) + #if read_size < packet_size: + # print("Serial Com IF: Size missmatch when polling PUS wiretapping_packet. Packet Size: " + + # str(packet_size) + ". Read Size: " + str(read_size) + ". Check timeout too") if read_size > packet_size: self.__handle_multiple_packets(packet_size, read_size, pus_data_list) - else: - pus_data_list.append(self.data) return pus_data_list, self.number_of_packets def __handle_multiple_packets(self, packet_size: int, read_size: int, pus_data_list: list): @@ -110,12 +112,16 @@ class SerialComIF(CommunicationInterface): def __parse_next_packets(self, end_index: int, pus_data_list: list) -> int: start_index = end_index end_index = end_index + 5 - next_packet_size = (self.data[end_index - 1] << 8 | self.data[end_index]) + 7 - if next_packet_size > SERIAL_PACKET_MAX_SIZE: + next_payload_len = (self.data[end_index - 1] << 8 | self.data[end_index]) + next_packet_size = next_payload_len + 7 + if next_packet_size > SERIAL_FRAME_LENGTH: print("PUS Polling: Very Large wiretapping_packet detected, " "large wiretapping_packet reading not implemented yet !") print("Detected Size: " + str(next_packet_size)) - return SERIAL_PACKET_MAX_SIZE + return end_index + elif next_payload_len == 0: + end_index = SERIAL_FRAME_LENGTH + return end_index end_index = start_index + next_packet_size pus_data = self.data[start_index:end_index] pus_data_list.append(pus_data) diff --git a/obsw_tmtc_client.py b/obsw_tmtc_client.py index 68f65e4..76ef4bf 100644 --- a/obsw_tmtc_client.py +++ b/obsw_tmtc_client.py @@ -182,7 +182,7 @@ def set_communication_interface(tmtc_printer: TmTcPrinterT) -> ComIfT: else: com_port = g.G_COM_PORT baud_rate = 115200 - g.G_SERIAL_TIMEOUT = 0.01 + g.G_SERIAL_TIMEOUT = 1 communication_interface = SerialComIF( tmtc_printer=tmtc_printer, com_port=com_port, baud_rate=baud_rate, serial_timeout=g.G_SERIAL_TIMEOUT) -- GitLab