Skip to content

Commit

Permalink
Add message request
Browse files Browse the repository at this point in the history
Merge pull request #35
  • Loading branch information
axlan authored Dec 10, 2021
2 parents efda812 + 128056e commit 2aee413
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions python/fusion_engine_client/messages/internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
ConfigurationDataMessage.MESSAGE_TYPE: ConfigurationDataMessage,
SaveConfigMessage.MESSAGE_TYPE: SaveConfigMessage,
VersionDataMessage.MESSAGE_TYPE: VersionDataMessage,
MessageRequest.MESSAGE_TYPE: MessageRequest,
})
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()

0 comments on commit 2aee413

Please sign in to comment.