Skip to content

Commit 6ff0f91

Browse files
authored
Merge pull request #18 from sysdevrun/claude/verify-crc-frame-structure-BusJn
Strip leading DLE bytes (0x10) from device responses
2 parents 4749f99 + 20c209a commit 6ff0f91

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/lib/web-serial.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,15 @@ export async function transceiveSerial(
149149
await device.writer.write(command);
150150

151151
// Read response
152-
const response = await readWithTimeout(device, timeout);
152+
let response = await readWithTimeout(device, timeout);
153153
log('RX', `Response (${response.length} bytes): ${toHexSerial(response)}`);
154154

155+
// Strip leading DLE bytes (0x10) - device sends these on first command after connect
156+
while (response.length > 0 && response[0] === 0x10) {
157+
log('INFO', 'Stripping DLE byte (0x10)');
158+
response = response.slice(1);
159+
}
160+
155161
// Handle ACK prefix (0x01)
156162
if (response.length > 1 && response[0] === 0x01) {
157163
return response.slice(1);
@@ -233,6 +239,15 @@ function combineChunks(chunks: Uint8Array[], totalLength: number): Uint8Array {
233239
function isCompleteFrame(data: Uint8Array): boolean {
234240
if (data.length < 4) return false;
235241

242+
// Skip leading DLE bytes (0x10) - device sends these on first command after connect
243+
let offset = 0;
244+
while (offset < data.length && data[offset] === 0x10) {
245+
offset++;
246+
}
247+
if (offset > 0) {
248+
return isCompleteFrame(data.slice(offset));
249+
}
250+
236251
const len = data[0];
237252

238253
// ACK responses

0 commit comments

Comments
 (0)