using dle encoder in tm tcp server

This commit is contained in:
Ulrich Mohr 2022-05-18 17:01:48 +02:00 committed by Uli
parent bde8a29473
commit b0bdb2208f
1 changed files with 5 additions and 6 deletions

View File

@ -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)