Browse Source

ota升级bug修复

newdev_shunjiawei
fdp 1 year ago
parent
commit
a5478db82b
  1. 38
      lib/data/services/ble_manager.dart
  2. 8
      local_plugins/ota/android/src/main/kotlin/com/example/ota/OtaPlugin.kt

38
lib/data/services/ble_manager.dart

@ -472,13 +472,37 @@ class BleManager extends GetxService {
firmwareProductColor: '',
);
}
// 并行获取所有设备信息,不使用延迟
final results = await Future.wait([
_bleService.getBatteryInfo(),
_bleService.getDeviceVersion(),
_bleService.getProductId(),
]);
final commands = [
_bleService.getBatteryInfo,
_bleService.getDeviceVersion,
_bleService.getProductId,
];
final delays = [
Duration.zero, // 第一个命令立即执行
const Duration(milliseconds: 100), // 第二个命令延迟100ms
const Duration(milliseconds: 200), // 第三个命令延迟200ms
];
final futures = commands
.asMap()
.map((index, command) {
final delay = delays[index];
return MapEntry(
index,
Future.delayed(delay, command),
);
})
.values
.toList();
final results = await Future.wait(futures);
// // 并行获取所有设备信息,不使用延迟
// final results = await Future.wait([
// _bleService.getBatteryInfo(),
// _bleService.getDeviceVersion(),
// _bleService.getProductId(),
// ]);
Logger.info(
'设备信息获取结果: 电池=${results[0]}, 版本=${results[1]}, 产品ID=${results[2]}');

8
local_plugins/ota/android/src/main/kotlin/com/example/ota/OtaPlugin.kt

@ -337,10 +337,10 @@ class OtaPlugin : BleService.Callback, FlutterPlugin, MethodCallHandler {
BleService.isEnterOta = false
isDisconnect = false
if(otaManager!= null) {
otaManager?.bluetoothHelper?.stopScan()
otaManager?.bluetoothHelper?.disconnectDevice(otaDevice)
BleService.removeCallback(this)
otaManager?.release()
otaManager= null
bluetoothHelper=null
}
result.success("")
} else {

Loading…
Cancel
Save