From 128056ecc5608b006bf69de0861784c36e940014 Mon Sep 17 00:00:00 2001 From: jdiamond Date: Fri, 10 Dec 2021 14:26:05 -0800 Subject: [PATCH] Add message request. --- .../messages/internal/__init__.py | 1 + .../messages/internal/config_and_control.py | 37 +++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/python/fusion_engine_client/messages/internal/__init__.py b/python/fusion_engine_client/messages/internal/__init__.py index 93437ccf..3920a76b 100644 --- a/python/fusion_engine_client/messages/internal/__init__.py +++ b/python/fusion_engine_client/messages/internal/__init__.py @@ -26,4 +26,5 @@ ConfigurationDataMessage.MESSAGE_TYPE: ConfigurationDataMessage, SaveConfigMessage.MESSAGE_TYPE: SaveConfigMessage, VersionDataMessage.MESSAGE_TYPE: VersionDataMessage, + MessageRequest.MESSAGE_TYPE: MessageRequest, }) diff --git a/python/fusion_engine_client/messages/internal/config_and_control.py b/python/fusion_engine_client/messages/internal/config_and_control.py index b6ea58db..034a26b2 100644 --- a/python/fusion_engine_client/messages/internal/config_and_control.py +++ b/python/fusion_engine_client/messages/internal/config_and_control.py @@ -444,9 +444,6 @@ def __str__(self): string += f'\t{field}: {val}\n' return string.rstrip() - def calcsize(self) -> int: - return len(self.pack()) - @classmethod def calcsize(cls) -> int: return cls.SaveConfigMessageConstruct.sizeof() @@ -601,3 +598,37 @@ def __str__(self): def calcsize(self) -> int: return len(self.pack()) + + +class MessageRequest(MessagePayload): + """! + @brief Command to request a message be sent. + """ + MESSAGE_TYPE = MessageType.MESSAGE_REQ + MESSAGE_VERSION = 0 + + MessageRequestConstruct = Struct( + "message_type" / Enum(Int16ul, MessageType), + Padding(2) + ) + + def __init__(self): + self.message_type = MessageType.INVALID + + def pack(self, buffer: bytes = None, offset: int = 0, return_buffer: bool = True) -> (bytes, int): + packed_data = self.MessageRequestConstruct.build({"message_type": self.message_type}) + return PackedDataToBuffer(packed_data, buffer, offset, return_buffer) + + def unpack(self, buffer: bytes, offset: int = 0) -> int: + parsed = self.MessageRequestConstruct.parse(buffer[offset:]) + self.message_type = parsed.message_type + return parsed._io.tell() + + def __str__(self): + string = 'Save Config Command\n' + string += f'\tmessage_type: {self.message_type}' + return string + + @classmethod + def calcsize(cls) -> int: + return cls.MessageRequestConstruct.sizeof()