Merge branch 'develop_sky_liyi' into 'develop_sky'

fix:调整mtu设置

See merge request StarlockTeam/app-starlock!273
This commit is contained in:
李仪 2025-09-04 09:04:53 +00:00
commit 1b611ca9de
2 changed files with 41 additions and 6 deletions

View File

@ -144,7 +144,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver, BaseWidget {
break;
case AppLifecycleState.paused:
// AppLog.log('App--->进入后台');
BlueManage().disconnect();
BlueManage.instance.disconnect();
break;
case AppLifecycleState.resumed:
// AppLog.log('App--->进入前台');

View File

@ -85,6 +85,12 @@ class BlueManage {
return _manager;
}
// 访
static BlueManage get instance {
_manager ??= BlueManage._init();
return _manager!;
}
BlueManage? get manager => shareManager();
void _initBlue() {
@ -94,9 +100,13 @@ class BlueManage {
}
void _initGetMtuSubscription() {
_mtuSubscription ??= bluetoothConnectDevice!.mtu.listen((int value) {
//
_mtuSubscription?.cancel();
_mtuSubscription = null;
_mtuSubscription = bluetoothConnectDevice!.mtu.listen((int value) {
_mtuSize = value - 3;
AppLog.log('_mtuSizeValue:$value mtuSize:$_mtuSize');
AppLog.log('设备MTU变化 - 原始值:$value 计算后MTU:$_mtuSize 设备:${bluetoothConnectDevice?.remoteId.str}');
});
}
@ -954,6 +964,12 @@ class BlueManage {
Future<void> disconnect() async {
try {
connectDeviceMacAddress = '';
// MTU监听
_mtuSubscription?.cancel();
_mtuSubscription = null;
_mtuSize = 20; // MTU为默认值
if (bluetoothConnectionState == BluetoothConnectionState.connected) {
//
await bluetoothConnectDevice!.disconnect(timeout: 3);
@ -975,10 +991,29 @@ class BlueManage {
}
}
// MTU信息
String getMtuDebugInfo() {
return 'MTU Debug Info:\n'
'- Current MTU Size: $_mtuSize\n'
'- Connected Device: ${bluetoothConnectDevice?.remoteId.str ?? "None"}\n'
'- Device Name: $connectDeviceName\n'
'- Connection State: $bluetoothConnectionState\n'
'- MTU Subscription Active: ${_mtuSubscription != null}';
}
void disposed() {
_sendStreamSubscription?.cancel();
_mtuSubscription!.cancel();
_adapterStateStateSubscription!.cancel();
_connectionStateSubscription!.cancel();
_mtuSubscription?.cancel();
_adapterStateStateSubscription?.cancel();
_connectionStateSubscription?.cancel();
//
_mtuSize = 20;
connectDeviceName = '';
connectDeviceMacAddress = '';
bluetoothConnectDevice = null;
scanDevices.clear();
allData.clear();
lastTimeData.clear();
}
}