Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
laki_icu_app
Project
Project
Details
Activity
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
张宏
laki_icu_app
Commits
bf7e72d1
Commit
bf7e72d1
authored
Jun 24, 2026
by
akari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复蓝牙相关
parent
65c9e3b0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
3 deletions
+34
-3
bluetooth_manager.dart
lib/utils/bluetooth/bluetooth_manager.dart
+23
-2
monitoring_index_cubit.dart
lib/views/monitoring/index/cubit/monitoring_index_cubit.dart
+11
-1
No files found.
lib/utils/bluetooth/bluetooth_manager.dart
View file @
bf7e72d1
...
...
@@ -53,6 +53,7 @@ class BleBluetoothManager<T> {
Uuid
?
notifyCharacteristicUuid
,
Uuid
?
writeCharacteristicUuid
,
this
.
connectionTimeout
=
const
Duration
(
seconds:
15
),
this
.
enableCharacteristicDiscovery
=
false
,
})
:
_parser
=
parser
,
_ble
=
ble
??
FlutterReactiveBle
(),
serviceUuid
=
...
...
@@ -68,6 +69,7 @@ class BleBluetoothManager<T> {
final
Uuid
notifyCharacteristicUuid
;
final
Uuid
writeCharacteristicUuid
;
final
Duration
connectionTimeout
;
final
bool
enableCharacteristicDiscovery
;
final
_scanDevicesController
=
StreamController
<
List
<
BluetoothScanDevice
>>.
broadcast
();
...
...
@@ -94,6 +96,7 @@ class BleBluetoothManager<T> {
StreamSubscription
<
List
<
int
>>?
_notifySubscription
;
Timer
?
_scanTimer
;
Future
<
void
>
_writeQueue
=
Future
<
void
>.
value
();
Future
<
void
>?
_connectInProgress
;
final
Map
<
String
,
BluetoothScanDevice
>
_scannedDevices
=
{};
...
...
@@ -253,7 +256,23 @@ class BleBluetoothManager<T> {
return
connectToDeviceId
(
device
.
remoteId
);
}
Future
<
void
>
connectToDeviceId
(
String
deviceId
)
async
{
Future
<
void
>
connectToDeviceId
(
String
deviceId
)
{
final
pending
=
_connectInProgress
;
if
(
pending
!=
null
)
{
debugPrint
(
'🔥🔥🔥 BLE_CONNECT_DEBUG connect_join_existing deviceId=
$deviceId
'
,
);
return
pending
;
}
final
task
=
_connectToDeviceIdLocked
(
deviceId
);
_connectInProgress
=
task
.
whenComplete
(()
{
_connectInProgress
=
null
;
});
return
_connectInProgress
!;
}
Future
<
void
>
_connectToDeviceIdLocked
(
String
deviceId
)
async
{
debugPrint
(
'🔥🔥🔥 BLE_CONNECT_DEBUG connect_to_device_id start deviceId=
$deviceId
'
);
if
(
deviceId
.
isEmpty
)
{
...
...
@@ -271,6 +290,7 @@ class BleBluetoothManager<T> {
}
await
disconnect
();
await
Future
<
void
>.
delayed
(
const
Duration
(
milliseconds:
600
));
_connectedDeviceId
=
deviceId
;
_notifyCharacteristic
=
QualifiedCharacteristic
(
deviceId:
deviceId
,
...
...
@@ -310,7 +330,9 @@ class BleBluetoothManager<T> {
debugPrint
(
'🔥🔥🔥 BLE_CONNECT_DEBUG state_connected deviceId=
$deviceId
'
);
try
{
if
(
enableCharacteristicDiscovery
)
{
await
_discoverServicesAndResolveWriteCharacteristic
(
deviceId
);
}
final
notifyReady
=
await
_enableNotifications
(
deviceId
);
if
(
notifyReady
)
{
activateDataSource
();
...
...
@@ -536,7 +558,6 @@ class BleBluetoothManager<T> {
)
async
{
try
{
Log
.
warn
(
'🔥🔥🔥 BLE_DISCOVER_DEBUG start deviceId=
$deviceId
'
);
await
_ble
.
discoverAllServices
(
deviceId
);
final
services
=
await
_ble
.
getDiscoveredServices
(
deviceId
);
QualifiedCharacteristic
?
fallbackWriteCharacteristic
;
QualifiedCharacteristic
?
fallbackNotifyCharacteristic
;
...
...
lib/views/monitoring/index/cubit/monitoring_index_cubit.dart
View file @
bf7e72d1
...
...
@@ -47,6 +47,7 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
bool
_isAutoReconnectEnabled
=
false
;
bool
_isAutoConnectingBluetooth
=
false
;
bool
_isManualUnbindingBluetooth
=
false
;
int
_bluetoothReconnectAttempts
=
0
;
bool
_isMqttReconnectEnabled
=
false
;
bool
_isMqttConnecting
=
false
;
String
?
_mqttDeviceSn
;
...
...
@@ -586,8 +587,13 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
return
;
}
final
delaySeconds
=
((
_bluetoothReconnectAttempts
+
1
)
*
5
).
clamp
(
5
,
30
);
debugPrint
(
'🔥🔥🔥 BLE_CONNECT_DEBUG auto_reconnect_scheduled '
'delay=
${delaySeconds}
s attempts=
$_bluetoothReconnectAttempts
'
,
);
_bluetoothReconnectTimer
??=
Timer
(
const
Duration
(
seconds:
5
),
Duration
(
seconds:
delaySeconds
),
()
{
_bluetoothReconnectTimer
=
null
;
_connectBoundBluetoothDevice
();
...
...
@@ -629,7 +635,11 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
:
'蓝牙自动连接未就绪,等待重试'
,
));
}
if
(
_bluetoothManager
.
isConnected
)
{
_bluetoothReconnectAttempts
=
0
;
}
}
catch
(
e
)
{
_bluetoothReconnectAttempts
++;
debugPrint
(
'🔥🔥🔥 BLE_CONNECT_DEBUG auto_connect_error deviceId=
$deviceId
error=
$e
'
);
if
(!
isClosed
)
{
...
...
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