From eab4d172e6710a400a40ce2f73fbe5568a561130 Mon Sep 17 00:00:00 2001 From: Yudi Xiao <463708580@qq.com> Date: Thu, 11 Dec 2025 17:26:06 +0800 Subject: [PATCH] =?UTF-8?q?expo-ble=E6=A8=A1=E5=9D=97=E6=B5=8B=E8=AF=95dem?= =?UTF-8?q?o=20=E8=81=94=E8=B0=83BLE=E6=A8=A1=E5=9D=97=20take=2012=20?= =?UTF-8?q?=E5=87=8F=E5=B0=91=E6=97=A0=E7=94=A8=E7=9A=84log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ble/protocol/ProtocolManager.ts | 11 ++++++----- ble/services/BleProtocolService.ts | 6 ++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ble/protocol/ProtocolManager.ts b/ble/protocol/ProtocolManager.ts index 11caa1e..372237a 100644 --- a/ble/protocol/ProtocolManager.ts +++ b/ble/protocol/ProtocolManager.ts @@ -5,7 +5,7 @@ export class ProtocolManager { static calculateChecksum(frameData: Uint8Array): number { let sum = 0; - console.debug(`[ProtocolManager] Calculating checksum for frame count: ${frameData.length}`); + // console.debug(`[ProtocolManager] Calculating checksum for frame count: ${frameData.length}`); // Checksum is calculated on all bytes except the last one (which is the checksum itself) // Example: 0xA0 03 00 01 01 5B // 0xA0 + 0x03 + 0x00 + 0x01 + 0x01 = 0xA5 @@ -14,7 +14,7 @@ export class ProtocolManager { sum += frameData[i]; } const checksum = (~sum + 1) & 0xff - console.debug(`[ProtocolManager] Checksum calculated: 0 - ${sum} = ${checksum.toString(16).padStart(2, '0')}`); + // console.debug(`[ProtocolManager] Checksum calculated: 0 - ${sum} = ${checksum.toString(16).padStart(2, '0')}`); return checksum; } @@ -61,7 +61,7 @@ export class ProtocolManager { buffer[offset++] = (data.length >> 8) & 0xff; buffer[offset++] = data.length & 0xff; const hexHeader = Array.from(buffer.slice(0, offset)).map(b => b.toString(16).padStart(2, '0')).join(' '); - console.debug(`chunk length = ${data.length}, buffer 8 header = ${hexHeader}`) + // console.debug(`chunk length = ${data.length}, buffer 8 header = ${hexHeader}`) // data buffer.set(data, offset); @@ -104,8 +104,9 @@ export class ProtocolManager { // dataLen buffer[offset++] = (chunk.length >> 8) & 0xff; buffer[offset++] = chunk.length & 0xff; - const hexHeader = Array.from(buffer.slice(0, offset)).map(b => b.toString(16).padStart(2, '0')).join(' '); - console.debug(`chunk length = ${chunk.length}, buffer 8 header = ${hexHeader}`) + // const hexHeader = Array.from(buffer.slice(0, offset)).map(b => b.toString(16).padStart(2, '0')).join(' '); + // console.debug(`chunk length = ${chunk.length}, buffer 8 header = ${hexHeader}`) + // data buffer.set(chunk, offset); offset += chunk.length; diff --git a/ble/services/BleProtocolService.ts b/ble/services/BleProtocolService.ts index 119b4da..ad25b35 100644 --- a/ble/services/BleProtocolService.ts +++ b/ble/services/BleProtocolService.ts @@ -169,8 +169,10 @@ export class BleProtocolService { console.debug(`Sending ${total} frames`); for (let i = 0; i < total; i++) { const frame = frames[i]; - if (i < 5) - console.debug("raw frame \n", Array.from(frame).map(b => b.toString(16).padStart(2, '0')).join(' ')); + if (i < 3) { + const rawFrame = Array.from(frame).map(b => b.toString(16).padStart(2, '0')).join(' ') + console.debug(`raw ${i + 1} frame \n ${rawFrame}`); + } console.debug(`Writing frame ${i + 1}/${total}, length = ${frame.length}`); const base64 = Buffer.from(frame).toString('base64'); const result = await this.client.write(deviceId, BLE_UUIDS.SERVICE, BLE_UUIDS.WRITE_CHARACTERISTIC, base64, false);