expo-ble模块测试demo 联调BLE模块 take 8 新增空数据包测试
This commit is contained in:
@@ -148,7 +148,16 @@ export class BleProtocolService {
|
||||
payload = new Uint8Array(Buffer.from(jsonStr));
|
||||
}
|
||||
|
||||
const frames = ProtocolManager.createFrame(type, payload);
|
||||
const device = this.client.getConnectedDevice();
|
||||
const mtu = device?.mtu || 23;
|
||||
// MTU - 3 bytes (ATT overhead) - Protocol Header - Protocol Footer
|
||||
const maxPayloadSize = mtu - 3 - FRAME_CONSTANTS.HEADER_SIZE - FRAME_CONSTANTS.FOOTER_SIZE;
|
||||
// Ensure reasonable bounds (at least 1 byte, max constrained by protocol constant)
|
||||
const safeMaxDataSize = Math.max(1, Math.min(maxPayloadSize, FRAME_CONSTANTS.MAX_DATA_SIZE));
|
||||
|
||||
console.debug(`[BleProtocolService] Sending with MTU=${mtu}, maxDataSize=${safeMaxDataSize}`);
|
||||
|
||||
const frames = ProtocolManager.createFrame(type, payload, FRAME_CONSTANTS.HEAD_APP_TO_DEVICE, true, safeMaxDataSize);
|
||||
const total = frames.length;
|
||||
console.debug(`Sending ${total} frames`);
|
||||
for (let i = 0; i < total; i++) {
|
||||
@@ -160,6 +169,7 @@ export class BleProtocolService {
|
||||
if (onProgress) {
|
||||
onProgress((i + 1) / total);
|
||||
}
|
||||
|
||||
console.debug("Wrote frame", result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user