Skip to content

Commit c80b3a1

Browse files
committed
fix(discovery): correct modern protocol status offset to 0x8A
Status code is at offset 0x8A, not 0x90. The old offset was reading the LAN mode flag byte instead. Also corrects serial number field size from 130 to 128 bytes to match actual packet layout.
1 parent e6991ea commit c80b3a1

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

flashforge/discovery/discovery.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,18 +427,18 @@ def parse_discovery_response(
427427
return None
428428

429429
def parse_modern_protocol(self, buffer: bytes, ip_address: str) -> DiscoveredPrinter:
430-
"""Parse a modern 276-byte discovery response."""
430+
"""Parse a modern 276-byte (0x114) discovery response."""
431431
if len(buffer) < MODERN_PROTOCOL_SIZE:
432432
raise InvalidResponseError(len(buffer), ip_address)
433433

434434
name = buffer[0:0x84].decode("utf-8", errors="ignore").split("\x00", 1)[0]
435435
command_port = int.from_bytes(buffer[0x84:0x86], byteorder="big")
436436
vendor_id = int.from_bytes(buffer[0x86:0x88], byteorder="big")
437437
product_id = int.from_bytes(buffer[0x88:0x8A], byteorder="big")
438+
status_code = int.from_bytes(buffer[0x8A:0x8C], byteorder="big")
438439
product_type = int.from_bytes(buffer[0x8C:0x8E], byteorder="big")
439440
event_port = int.from_bytes(buffer[0x8E:0x90], byteorder="big")
440-
status_code = int.from_bytes(buffer[0x90:0x92], byteorder="big")
441-
serial_number = buffer[0x92 : 0x92 + 130].decode("utf-8", errors="ignore").split("\x00", 1)[0]
441+
serial_number = buffer[0x92 : 0x92 + 128].decode("utf-8", errors="ignore").split("\x00", 1)[0]
442442
model = self.detect_modern_model(name, product_type)
443443

444444
return DiscoveredPrinter(

tests/test_discovery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def _build_modern_buffer(
3535
buffer[0x84:0x86] = command_port.to_bytes(2, byteorder="big")
3636
buffer[0x86:0x88] = vendor_id.to_bytes(2, byteorder="big")
3737
buffer[0x88:0x8A] = product_id.to_bytes(2, byteorder="big")
38+
buffer[0x8A:0x8C] = status_code.to_bytes(2, byteorder="big")
3839
buffer[0x8C:0x8E] = product_type.to_bytes(2, byteorder="big")
3940
buffer[0x8E:0x90] = event_port.to_bytes(2, byteorder="big")
40-
buffer[0x90:0x92] = status_code.to_bytes(2, byteorder="big")
4141
buffer[0x92 : 0x92 + len(serial_number)] = serial_number.encode("utf-8")
4242
return bytes(buffer)
4343

0 commit comments

Comments
 (0)