Skip to content

Commit 4022ffe

Browse files
author
BlueRobotics-CI
committed
Update autogenerated files
From https://github.com/bluerobotics/ping-protocol/tree/45711879882166cfc2c1e0928e81cd2632ad03ea Signed-off-by: BlueRobotics-CI <support@bluerobotics.com>
1 parent 55bf457 commit 4022ffe

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

brping/pingmessage.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def __init__(self, msg_id=0, msg_data=None):
456456
def pack_msg_data(self):
457457
# necessary for variable length payloads
458458
# update using current contents for the variable length field
459-
self.payload_length = self.get_payload_length()
459+
self.update_payload_length()
460460

461461
# Prepare struct packing format string
462462
msg_format = PingMessage.endianess + PingMessage.header_format + self.get_payload_format()
@@ -523,21 +523,20 @@ def update_checksum(self):
523523
def verify_checksum(self):
524524
return self.checksum == self.calculate_checksum()
525525

526-
## Get the **current** payload length, including dynamic length fields (if present)
527-
# @return the current payload length
528-
def get_payload_length(self):
526+
## Update the payload_length attribute with the **current** payload length, including dynamic length fields (if present)
527+
def update_payload_length(self):
529528
if self.message_id in variable_msgs or self.message_id in asciiMsgs:
530529
# The last field self.payload_field_names[-1] is always the single dynamic-length field
531-
return payload_dict[self.message_id]["payload_length"] + len(getattr(self, self.payload_field_names[-1]))
530+
self.payload_length = payload_dict[self.message_id]["payload_length"] + len(getattr(self, self.payload_field_names[-1]))
532531
else:
533-
return payload_dict[self.message_id]["payload_length"]
532+
self.payload_length = payload_dict[self.message_id]["payload_length"]
534533

535534
## Get the python struct formatting string for the message payload
536535
# @return the payload struct format string
537536
def get_payload_format(self):
538537
# messages with variable length fields
539538
if self.message_id in variable_msgs or self.message_id in asciiMsgs:
540-
var_length = self.get_payload_length() - payload_dict[self.message_id]["payload_length"] # Subtract static length portion from payload length
539+
var_length = self.payload_length - payload_dict[self.message_id]["payload_length"] # Subtract static length portion from payload length
541540
if var_length <= 0:
542541
return "" # variable data portion is empty
543542

@@ -618,6 +617,7 @@ def parse_byte(self, msg_byte):
618617
msg_byte = ord(msg_byte)
619618
# print("byte: %d, state: %d, rem: %d, id: %d" % (msg_byte, self.state, self.payload_length, self.message_id))
620619
if self.state == PingParser.WAIT_START:
620+
self.buf = bytearray()
621621
if msg_byte == ord('B'):
622622
self.buf.append(msg_byte)
623623
self.state += 1
@@ -665,7 +665,6 @@ def parse_byte(self, msg_byte):
665665

666666
# print(self.rx_msg)
667667

668-
self.buf = bytearray()
669668
self.state = PingParser.WAIT_START
670669
self.payload_length = 0
671670
self.message_id = 0

0 commit comments

Comments
 (0)