Skip to content

Commit 9d8a318

Browse files
jefdriesenmikeller
authored andcommitted
Ignore invalid start bytes
Ignoring all received bytes until an START bytes is encountered makes the re-synchronization on the start of the packet a bit more robust.
1 parent 1254cb7 commit 9d8a318

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/seac_screen.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,25 @@ seac_screen_receive (seac_screen_device_t *device, unsigned short cmd, unsigned
146146
dc_device_t *abstract = (dc_device_t *) device;
147147
unsigned char packet[SZ_MAXRSP + 8] = {0};
148148

149-
// Read the packet header.
150-
status = dc_iostream_read (device->iostream, packet, 3, NULL);
151-
if (status != DC_STATUS_SUCCESS) {
152-
ERROR (abstract->context, "Failed to receive the packet header.");
153-
return status;
149+
// Read the packet start byte.
150+
while (1) {
151+
status = dc_iostream_read (device->iostream, packet + 0, 1, NULL);
152+
if (status != DC_STATUS_SUCCESS) {
153+
ERROR (abstract->context, "Failed to receive the packet start byte.");
154+
return status;
155+
}
156+
157+
if (packet[0] == START)
158+
break;
159+
160+
WARNING (abstract->context, "Unexpected packet header byte (%02x).", packet[0]);
154161
}
155162

156-
// Verify the start byte.
157-
if (packet[0] != START) {
158-
ERROR (abstract->context, "Unexpected start byte (%02x).", packet[0]);
159-
return DC_STATUS_PROTOCOL;
163+
// Read the packet length.
164+
status = dc_iostream_read (device->iostream, packet + 1, 2, NULL);
165+
if (status != DC_STATUS_SUCCESS) {
166+
ERROR (abstract->context, "Failed to receive the packet length.");
167+
return status;
160168
}
161169

162170
// Verify the length.

0 commit comments

Comments
 (0)