fix(frontend): route DATA through sendCommand for readValue() fallback
sendCommandWithRetry now delegates to sendCommand() instead of using raw writeValueWithResponse + await ackPromise. This ensures DATA chunks also benefit from the readValue() state poll fallback when Android BLE notify is unreliable after idle.
This commit is contained in:
parent
4a6ef8ce57
commit
cad90ebd2e
|
|
@ -410,25 +410,17 @@ export class BLEHardwareDeployer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async sendCommandWithRetry(cmd: number, index: number, data: Uint8Array, chunkCRC: number): Promise<void> {
|
private async sendCommandWithRetry(cmd: number, index: number, data: Uint8Array, _chunkCRC: number): Promise<void> {
|
||||||
const payload = new Uint8Array(4 + data.length + 4);
|
/* Route through sendCommand() which has readValue() state poll
|
||||||
payload[0] = cmd;
|
* fallback for DATA (same as INIT/END). The _chunkCRC is kept
|
||||||
payload[1] = index & 0xFF;
|
* for API compatibility — sendCommand computes CRC internally. */
|
||||||
payload[2] = (index >> 8) & 0xFF;
|
|
||||||
payload[3] = data.length;
|
|
||||||
payload.set(data, 4);
|
|
||||||
payload.set([
|
|
||||||
chunkCRC & 0xFF, (chunkCRC >> 8) & 0xFF, (chunkCRC >> 16) & 0xFF, (chunkCRC >> 24) & 0xFF
|
|
||||||
], 4 + data.length);
|
|
||||||
|
|
||||||
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
||||||
try {
|
try {
|
||||||
const ackPromise = this.waitForAck(index);
|
await this.sendCommand(cmd, index, data);
|
||||||
await this.flashingChar!.writeValueWithResponse(payload);
|
|
||||||
await ackPromise;
|
|
||||||
return;
|
return;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (attempt === MAX_RETRIES - 1) throw err;
|
if (attempt === MAX_RETRIES - 1) throw err;
|
||||||
|
console.log(`[BLE-CMD] DATA idx=${index}: retry ${attempt + 1}/${MAX_RETRIES}`, err);
|
||||||
await new Promise(r => setTimeout(r, 500));
|
await new Promise(r => setTimeout(r, 500));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue