forked from yudi_xiao/expo-ble-app-demo
expo-ble模块测试demo 联调BLE模块 take 2
This commit is contained in:
parent
d2dcd39411
commit
56a5d0d45e
|
|
@ -5,36 +5,41 @@
|
||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
"types": "index.ts",
|
"types": "index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc"
|
"build": "tsc",
|
||||||
|
"clean": "rimraf lib"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"react-native",
|
"react-native",
|
||||||
"ble",
|
"ble",
|
||||||
"bluetooth",
|
"bluetooth",
|
||||||
"protocol",
|
"protocol",
|
||||||
"loomart"
|
"loomart",
|
||||||
|
"expo"
|
||||||
],
|
],
|
||||||
"author": "Bowong",
|
"author": "Bowong",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"react": ">=18.0.0",
|
"react": "*",
|
||||||
"react-native": ">=0.70.0"
|
"react-native": "*",
|
||||||
|
"react-native-ble-plx": "*",
|
||||||
|
"expo-file-system": "*",
|
||||||
|
"expo-image-picker": "*",
|
||||||
|
"expo-image-manipulator": "*"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react-native-ble-plx": "^3.5.0",
|
|
||||||
"buffer": "^5.7.0"
|
"buffer": "^5.7.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/react": "^19.0.0",
|
"@types/react": "^18.0.0",
|
||||||
"@types/react-native": "^0.73.0",
|
"@types/react-native": "^0.70.0",
|
||||||
"typescript": "^5.9.0"
|
"typescript": "^5.0.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
"core",
|
||||||
|
"hooks",
|
||||||
|
"protocol",
|
||||||
|
"services",
|
||||||
"index.ts",
|
"index.ts",
|
||||||
"manager/",
|
"package.json"
|
||||||
"utils/",
|
|
||||||
"hooks/",
|
|
||||||
"types/",
|
|
||||||
"README.md"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,19 @@ export class ProtocolManager {
|
||||||
|
|
||||||
static calculateChecksum(frameData: Uint8Array): number {
|
static calculateChecksum(frameData: Uint8Array): number {
|
||||||
let sum = 0;
|
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)
|
// 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++) {
|
for (let i = 0; i < frameData.length; i++) {
|
||||||
sum += frameData[i];
|
sum += frameData[i];
|
||||||
}
|
}
|
||||||
console.debug(`[ProtocolManager] Checksum calculated: 0 - ${sum} = ${(0 - sum) & 0xff}`);
|
const checksumV1 = (0 - sum) & 0xff
|
||||||
return (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 {
|
static verifyChecksum(frameData: Uint8Array, expectedChecksum: number): boolean {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue