Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
J
jensen
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Skye Yu
jensen
Commits
79a69479
Commit
79a69479
authored
Oct 28, 2025
by
martin hou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 增加蓝牙异步扫描接口的实现
parent
56c1b57c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
0 deletions
+75
-0
jensen.d.ts
jensen.d.ts
+12
-0
jensen.js
src/utils/jensen.js
+63
-0
No files found.
jensen.d.ts
View file @
79a69479
...
...
@@ -271,6 +271,18 @@ declare class Jensen {
// 获取蓝牙连接状态
getBluetoothStatus
:
(
seconds
?:
number
)
=>
Promise
<
BluetoothStatus
>
;
// 发起蓝牙扫描请求
startBluetoothScan
:
(
count
:
number
,
seconds
?:
number
)
=>
Promise
<
ReturnStruct
[
'common'
]
>
;
// 停止蓝牙扫描请求
stopBluetoothScan
:
(
seconds
?:
number
)
=>
Promise
<
ReturnStruct
[
'common'
]
>
;
// 获取蓝牙设备列表
getScanResults
:
(
seconds
?:
number
)
=>
Promise
<
BluetoothDevice
[]
>
;
// 写入蓝牙设备列表
writeBluetoothDeviceList
:
(
mac_list
:
string
[],
seconds
?:
number
)
=>
Promise
<
ReturnStruct
[
'common'
]
>
;
// 获取实时音频流的设置信息,主要是确定设备端的实时音频的编码信息
getRealtimeSettings
:
()
=>
Promise
<
any
>
;
...
...
src/utils/jensen.js
View file @
79a69479
...
...
@@ -36,6 +36,10 @@ const BLUETOOTH_SCAN = 0x1001;
const
BLUETOOTH_CMD
=
0x1002
;
const
BLUETOOTH_STATUS
=
0x1003
;
const
BT_SCAN
=
0x1005
;
const
BT_DEV_LIST
=
0x1006
;
const
BT_WRITE_DEV_LIST
=
0x1007
;
const
TEST_SN_WRITE
=
0xf007
;
const
RECORD_TEST_START
=
0xf008
;
const
RECORD_TEST_END
=
0xf009
;
...
...
@@ -705,6 +709,25 @@ Jensen.prototype.getBluetoothStatus = async function (seconds) {
return
this
.
send
(
new
Command
(
BLUETOOTH_STATUS
),
seconds
);
};
// 发起蓝牙扫描请求
Jensen
.
prototype
.
startBluetoothScan
=
async
function
(
count
,
seconds
)
{
if
(
this
.
model
.
indexOf
(
'hidock-p1'
)
==
-
1
)
return
null
;
count
=
count
&
0xff
;
return
this
.
send
(
new
Command
(
BT_SCAN
).
body
([
0x01
,
count
]),
seconds
);
};
// 停止蓝牙扫描
Jensen
.
prototype
.
stopBluetoothScan
=
async
function
(
seconds
)
{
if
(
this
.
model
.
indexOf
(
'hidock-p1'
)
==
-
1
)
return
null
;
return
this
.
send
(
new
Command
(
BT_SCAN
).
body
([
0x00
,
0x00
]),
seconds
);
};
// 获取蓝牙设备列表
Jensen
.
prototype
.
getScanResults
=
async
function
(
seconds
)
{
if
(
this
.
model
.
indexOf
(
'hidock-p1'
)
==
-
1
)
return
null
;
return
this
.
send
(
new
Command
(
BT_DEV_LIST
),
seconds
);
};
Jensen
.
prototype
.
setWebUSBTimeout
=
async
function
(
timeout
,
seconds
)
{
let
data
=
[];
...
...
@@ -1541,5 +1564,45 @@ Jensen.registerHandler(READ_WEBUSB_TIMEOUT, (msg) => {
return
{
timeout
:
timeout
};
});
// 写入蓝牙设备列表
Jensen
.
prototype
.
writeBluetoothDeviceList
=
async
function
(
mac_list
,
seconds
)
{
if
(
this
.
model
.
indexOf
(
'hidock-p1'
)
==
-
1
)
return
null
;
let
data
=
[];
for
(
let
i
=
0
;
i
<
mac_list
.
length
;
i
++
)
{
let
mac
=
mac_list
[
i
];
let
marr
=
mac
.
split
(
':'
);
if
(
marr
.
length
!=
6
)
throw
new
Error
(
'invalid mac'
);
for
(
let
j
=
0
;
j
<
marr
.
length
;
j
++
)
data
.
push
(
parseInt
(
marr
[
j
],
16
));
}
return
this
.
send
(
new
Command
(
BT_WRITE_DEV_LIST
).
body
(
data
),
seconds
);
};
Jensen
.
registerHandler
(
BT_SCAN
,
commonMessageParser
);
Jensen
.
registerHandler
(
BT_WRITE_DEV_LIST
,
commonMessageParser
);
Jensen
.
registerHandler
(
BT_DEV_LIST
,
(
msg
)
=>
{
// console.log('bluetooth-scan', msg);
if
(
msg
.
body
.
length
==
0
)
return
[];
let
nums
=
((
msg
.
body
[
0
]
&
0xff
)
<<
8
)
|
(
msg
.
body
[
1
]
&
0xff
);
let
devices
=
[];
let
decoder
=
new
TextDecoder
(
'UTF-8'
);
for
(
let
i
=
0
,
k
=
2
;
i
<
nums
;
i
++
)
{
let
len
=
((
msg
.
body
[
k
++
]
&
0xff
)
<<
8
)
|
(
msg
.
body
[
k
++
]
&
0xff
);
let
sname
=
new
Uint8Array
(
len
);
for
(
let
f
=
0
;
f
<
len
;
f
++
)
{
sname
[
f
]
=
msg
.
body
[
k
++
]
&
0xff
;
}
let
mac
=
[];
for
(
let
f
=
0
;
f
<
6
;
f
++
)
{
let
m
=
(
msg
.
body
[
k
++
]
&
0xff
).
toString
(
16
).
toUpperCase
();
mac
.
push
(
m
.
length
==
1
?
'0'
+
m
:
m
);
}
devices
.
push
({
name
:
decoder
.
decode
(
sname
),
mac
:
mac
.
join
(
'-'
)
});
}
return
devices
;
});
export
{
Jensen
};
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