From 56a5d0d45e55692f65414e17317b2b2f890f1d62 Mon Sep 17 00:00:00 2001 From: Yudi Xiao <463708580@qq.com> Date: Wed, 10 Dec 2025 16:43:22 +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=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ble/package.json | 31 ++++++++++++++++++------------- ble/protocol/ProtocolManager.ts | 12 +++++++++--- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/ble/package.json b/ble/package.json index b5d01ec..052bffc 100644 --- a/ble/package.json +++ b/ble/package.json @@ -5,36 +5,41 @@ "main": "index.ts", "types": "index.ts", "scripts": { - "build": "tsc" + "build": "tsc", + "clean": "rimraf lib" }, "keywords": [ "react-native", "ble", "bluetooth", "protocol", - "loomart" + "loomart", + "expo" ], "author": "Bowong", "license": "MIT", "peerDependencies": { - "react": ">=18.0.0", - "react-native": ">=0.70.0" + "react": "*", + "react-native": "*", + "react-native-ble-plx": "*", + "expo-file-system": "*", + "expo-image-picker": "*", + "expo-image-manipulator": "*" }, "dependencies": { - "react-native-ble-plx": "^3.5.0", "buffer": "^5.7.0" }, "devDependencies": { - "@types/react": "^19.0.0", - "@types/react-native": "^0.73.0", - "typescript": "^5.9.0" + "@types/react": "^18.0.0", + "@types/react-native": "^0.70.0", + "typescript": "^5.0.0" }, "files": [ + "core", + "hooks", + "protocol", + "services", "index.ts", - "manager/", - "utils/", - "hooks/", - "types/", - "README.md" + "package.json" ] } diff --git a/ble/protocol/ProtocolManager.ts b/ble/protocol/ProtocolManager.ts index 0a7cfae..3874a37 100644 --- a/ble/protocol/ProtocolManager.ts +++ b/ble/protocol/ProtocolManager.ts @@ -5,13 +5,19 @@ export class ProtocolManager { static calculateChecksum(frameData: Uint8Array): number { let sum = 0; + 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) - // But here we are calculating FOR the last byte. + // Example: 0xA0 03 00 01 01 5B + // 0xA0 + 0x03 + 0x00 + 0x01 + 0x01 = 0xA5 + // 0 - 0xA5 = 0x5B for (let i = 0; i < frameData.length; i++) { sum += frameData[i]; } - console.debug(`[ProtocolManager] Checksum calculated: 0 - ${sum} = ${(0 - sum) & 0xff}`); - return (0 - sum) & 0xff; + const checksumV1 = (0 - sum) & 0xff + const checksum = (~sum + 1) & 0xff + console.debug(`[ProtocolManager] Checksum V1 calculated: 0 - ${sum} = ${checksumV1}`); + console.debug(`[ProtocolManager] Checksum calculated: 0 - ${sum} = ${checksum}`); + return checksum; } static verifyChecksum(frameData: Uint8Array, expectedChecksum: number): boolean {