Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
visualcloud
/
Vmatrix-client-taro
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a46f8b91
authored
Nov 28, 2019
by
hank
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改蓝牙包解析问题
parent
fa869c73
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
6 deletions
+19
-6
project.config.json
+1
-1
src/common/utils.ts
+18
-5
No files found.
project.config.json
View file @
a46f8b91
...
...
@@ -9,9 +9,9 @@
"postcss"
:
false
,
"minified"
:
false
,
"newFeature"
:
true
,
"coverView"
:
true
,
"autoAudits"
:
false
,
"checkInvalidKey"
:
true
,
"coverView"
:
true
,
"checkSiteMap"
:
true
,
"uploadWithSourceMap"
:
true
,
"babelSetting"
:
{
...
...
src/common/utils.ts
View file @
a46f8b91
...
...
@@ -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
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment