Commit a46f8b91 by hank

修改蓝牙包解析问题

parent fa869c73
......@@ -9,9 +9,9 @@
"postcss": false,
"minified": false,
"newFeature": true,
"coverView": true,
"autoAudits": false,
"checkInvalidKey": true,
"coverView": true,
"checkSiteMap": true,
"uploadWithSourceMap": true,
"babelSetting": {
......
......@@ -118,10 +118,19 @@ export function getBLEState(buffer: ArrayBuffer) {
/** 解析蓝牙接收到的数据 */
export function getBLEData(buffer: ArrayBuffer) {
console.log(Utf8ArrayToStr(new Uint8Array(buffer.slice(1, buffer.byteLength))), buffer.byteLength)
// return String.fromCharCode.apply(null, new Uint8Array(buffer.slice(1, buffer.byteLength)))
return Utf8ArrayToStr(new Uint8Array(buffer.slice(1, buffer.byteLength)))
}
export function getBLEDataTwo(buffer: Uint8Array) {
// return String.fromCharCode.apply(null, new Uint8Array(buffer.slice(1, buffer.byteLength)))
return Utf8ArrayToStr(buffer)
}
export function BufferToArray(buffer: ArrayBuffer) {
// return String.fromCharCode.apply(null, new Uint8Array(buffer.slice(1, buffer.byteLength)))
let Uint8 = new Uint8Array(buffer.slice(1, buffer.byteLength))
return Uint8.join().split(',')
}
/** 获取蓝牙的 */
export function getAdverts(BleInfo: Taro.onBluetoothDeviceFound.ParamParamPropDevicesItem): string {
......@@ -140,7 +149,7 @@ export function strToAb(id: number, str: string) {
}
let advertisData = ''
let advertisData2 = ''
let advertisData2: any = []
type ICallBack = {
page: number
state: number
......@@ -163,14 +172,18 @@ export function analysisPage(value: arrayBuffer): Promise<ICallBack> {
if ((state & 0x40) !== 0) {
// 新包
advertisData = getBLEData(value)
// advertisData2 = String.fromCharCode.apply(null, new Uint8Array(value))
advertisData2 = BufferToArray(value)
} else {
// 累加包
advertisData = getBLEData(value) + advertisData
advertisData2 = BufferToArray(value).concat(advertisData2)
// advertisData2 = String.fromCharCode.apply(null, new Uint8Array(value)) + advertisData2
}
console.log(value, 'arrayBuffer')
resolve({ page, advertisData, state })
if (page === 0) {
console.log(page, '转换汉字', getBLEDataTwo(new Uint8Array(advertisData2)))
}
resolve({ page, advertisData: getBLEDataTwo(new Uint8Array(advertisData2)), state })
// callBack({ page, advertisData, state })
} else {
resolve({ page, advertisData, state })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment