-
Notifications
You must be signed in to change notification settings - Fork 6
Fixed _sync_read. #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -447,20 +447,26 @@ def _sync_read( | |||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| parameters = [address, data_length, *servo_ids] | ||||||||||||||||||||||||
| packet = self.send_instruction(0xFE, Instruction.SYNC_READ, parameters) | ||||||||||||||||||||||||
| responses: dict[int, Optional[dict[str, object]]] = {} | ||||||||||||||||||||||||
| for servo_id in servo_ids: | ||||||||||||||||||||||||
| response = self.read_response(packet) | ||||||||||||||||||||||||
| if response: | ||||||||||||||||||||||||
| parsed = self.parse_response(response) | ||||||||||||||||||||||||
| self.logger.debug( | ||||||||||||||||||||||||
| f"Servo {servo_id}: received SYNC READ response {parsed}" | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| responses[servo_id] = parsed | ||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||
| responses: dict[int, Optional[dict[str, object]]] = { | ||||||||||||||||||||||||
| servo_id: None for servo_id in servo_ids | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| rx = self.read_response(packet) | ||||||||||||||||||||||||
| if rx is None: | ||||||||||||||||||||||||
| return responses | ||||||||||||||||||||||||
| b = 0 | ||||||||||||||||||||||||
|
Comment on lines
+453
to
+456
|
||||||||||||||||||||||||
| while b+3 < len(rx) and rx[b]==0xFF and rx[b+1]==0xFF: | ||||||||||||||||||||||||
| servo_id = rx[b+2] | ||||||||||||||||||||||||
| paramlen = rx[b+3] | ||||||||||||||||||||||||
| pkglen = paramlen + 4 | ||||||||||||||||||||||||
| if paramlen != data_length + 2: | ||||||||||||||||||||||||
| self.logger.warning( | ||||||||||||||||||||||||
| f"Servo {servo_id}: no response received for SYNC READ" | ||||||||||||||||||||||||
| f"Servo {servo_id}: no valid response for SYNC READ" | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| responses[servo_id] = None | ||||||||||||||||||||||||
| break | ||||||||||||||||||||||||
|
Comment on lines
+461
to
+466
|
||||||||||||||||||||||||
| if b+pkglen <= len(rx): | ||||||||||||||||||||||||
| responses[servo_id] = self.parse_response(rx[b:b+pkglen]) | ||||||||||||||||||||||||
| b += pkglen | ||||||||||||||||||||||||
|
Comment on lines
+457
to
+469
|
||||||||||||||||||||||||
| b += pkglen | |
| b += pkglen | |
| else: | |
| self.logger.warning( | |
| "Truncated SYNC READ response for servo %s: expected %d bytes, " | |
| "but only %d bytes remain; stopping parse", | |
| servo_id, | |
| pkglen, | |
| len(rx) - b, | |
| ) | |
| break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encode_signed_wordwill silently produce an incorrect encoding for out-of-range values (e.g.,-32768becomes0x8000, which decodes back to0with the new sign-bit scheme). Since this helper is callable outside the register methods that have@validate_value_range, it should defensively validate the input range (±32767) and raise a clearValueErrorif exceeded.