From 6e0fc4cf90e815a6f5be724370f1a569d890e0ff Mon Sep 17 00:00:00 2001 From: Aryan0826 <165449842+Aryan0826@users.noreply.github.com> Date: Sat, 20 Dec 2025 21:57:25 -0600 Subject: [PATCH] add ack option to parse_send function --- soti/message.py | 4 +++- soti/parser.py | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/soti/message.py b/soti/message.py index f6103fc..b58ca0a 100644 --- a/soti/message.py +++ b/soti/message.py @@ -12,6 +12,7 @@ class Message: cmd_id: CmdID body: bytes = field(default_factory=([0] * 7)) # additional parameters + is_ack: bool = field(default=False) source: str = field(default="unspecified") time: datetime = field(default_factory= lambda: datetime.now().strftime("%T") @@ -56,5 +57,6 @@ def as_dict(self) -> dict: "sender-id": self.sender, "recipient-id": self.recipient, "cmd": self.cmd_id, - "body": parse_msg_body(self.cmd_id, self.body) + "body": parse_msg_body(self.cmd_id, self.body), + "ack": self.is_ack, } \ No newline at end of file diff --git a/soti/parser.py b/soti/parser.py index ebe0393..e1da81a 100644 --- a/soti/parser.py +++ b/soti/parser.py @@ -88,6 +88,8 @@ def parse_send(args: str, default_sender: NodeID) -> Message: priority: int = COMM_INFO[cmd_id]["priority"] sender_id: NodeID = default_sender recipient_id: NodeID | None = COMM_INFO[cmd_id]["dest"] + is_ack: bool = False + # represents the bytes that will be sent in the data section of the message data = bytearray() @@ -112,6 +114,13 @@ def parse_send(args: str, default_sender: NodeID) -> Message: recipient_id = NodeID(parse_int(value)) except ValueError as exc: raise ArgumentException(f"Invalid node ID '{value}'") from exc + elif key == "ack": + if value.lower() == "true": + is_ack = True + elif value.lower() == "false": + is_ack = False + else: + raise ArgumentException(f"Invalid value for ack '{value}'. Expected true or false") else: raise ArgumentException(f"Unknown option '{key}'") @@ -160,4 +169,4 @@ def parse_send(args: str, default_sender: NodeID) -> Message: if recipient_id is None: raise ArgumentException(f"You must specify a recipient with the 'to' option for {cmd_id.name}") - return Message(priority, sender_id, recipient_id, cmd_id, bytes(data), source="user") + return Message(priority, sender_id, recipient_id, cmd_id, bytes(data), is_ack=is_ack, source="user")