From b0bdb2208fd518ba46d0d493a4747e473e8f541a Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Wed, 18 May 2022 17:01:48 +0200 Subject: [PATCH] using dle encoder in tm tcp server --- pus_tm/tm_tcp_server.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pus_tm/tm_tcp_server.py b/pus_tm/tm_tcp_server.py index bc4dfd5..4bf0138 100644 --- a/pus_tm/tm_tcp_server.py +++ b/pus_tm/tm_tcp_server.py @@ -5,7 +5,7 @@ import base64 from tmtccmd.logging import get_console_logger from tmtccmd.utility.obj_id import ObjectId - +from dle_encoder import DleEncoder # TODO add to configuration parameters SERVER_HOST = "" @@ -32,6 +32,8 @@ class TmTcpServer: self.client_connection: Optional[socket.socket] = None + self.dle_encoder = DleEncoder() + def __del__(self): try: self.close() @@ -62,11 +64,8 @@ class TmTcpServer: data_json_bytes = json.dumps(dictionary).encode() # dle encode the bytes - # Taking a shortcut as json is inherently - # not binary (we also encoded it as utf-8), so there - # can not be any 0x02 or 0x03 be in there - # TODO use dle encoder to be format compliant - data_json_bytes = b'\x02' + data_json_bytes + b'\n' + b'\x03' + # adding a newline because someone might want to look at it in a console + data_json_bytes = self.dle_encoder.encode(data_json_bytes + b'\n') try: sent_length = self.client_connection.send(data_json_bytes)