|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; |
|
|
import 'package:get/get.dart'; |
|
|
import 'package:get/get.dart'; |
|
|
import 'package:logger/web.dart'; |
|
|
import 'package:logger/web.dart'; |
|
|
import '../../../data/services/ble_manager.dart'; |
|
|
import '../../../data/services/ble_manager.dart'; |
|
|
|
|
|
import '../../../data/services/bluetooth_manager.dart'; // 添加蓝牙管理器导入 |
|
|
import '../../../data/models/appconfig.dart'; |
|
|
import '../../../data/models/appconfig.dart'; |
|
|
import '../../../data/models/appconfig_model.dart'; |
|
|
import '../../../data/models/appconfig_model.dart'; |
|
|
|
|
|
|
|
|
@ -9,6 +10,8 @@ import '../../../data/models/appconfig_model.dart'; |
|
|
/// 整合设备检查、版本管理和状态管理功能 |
|
|
/// 整合设备检查、版本管理和状态管理功能 |
|
|
class OtaCoreService { |
|
|
class OtaCoreService { |
|
|
final BleManager _bleManager = Get.find<BleManager>(); |
|
|
final BleManager _bleManager = Get.find<BleManager>(); |
|
|
|
|
|
final BluetoothManager _bluetoothManager = |
|
|
|
|
|
Get.find<BluetoothManager>(); // 添加蓝牙管理器引用 |
|
|
final int maxRetryAttempts = 3; |
|
|
final int maxRetryAttempts = 3; |
|
|
int currentRetryCount = 0; |
|
|
int currentRetryCount = 0; |
|
|
|
|
|
|
|
|
@ -261,6 +264,35 @@ class OtaCoreService { |
|
|
|
|
|
|
|
|
// ==================== 版本管理功能 ==================== |
|
|
// ==================== 版本管理功能 ==================== |
|
|
|
|
|
|
|
|
|
|
|
/// 动态获取当前连接的设备名称 |
|
|
|
|
|
/// 参考home_controller中的getDeviceName方法实现 |
|
|
|
|
|
String getDeviceName() { |
|
|
|
|
|
try { |
|
|
|
|
|
// 优先从经典蓝牙获取设备名称 |
|
|
|
|
|
final currentDevice = _bluetoothManager.currentDevice; |
|
|
|
|
|
if (currentDevice?.name != null && currentDevice!.name.isNotEmpty) { |
|
|
|
|
|
return currentDevice.name; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 其次从BLE设备信息获取 |
|
|
|
|
|
final deviceInfo = _bleManager.deviceInfo.value; |
|
|
|
|
|
if (deviceInfo?.name != null && deviceInfo!.name.isNotEmpty) { |
|
|
|
|
|
return deviceInfo.name; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 最后从BLE管理器的最后连接设备名称获取 |
|
|
|
|
|
// if (_bleManager.currentDeviceName.isNotEmpty) { |
|
|
|
|
|
// return _bleManager.currentDeviceName; |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// 如果都获取不到,返回默认值 |
|
|
|
|
|
return "unknownEquipment"; |
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
Logger().e("获取设备名称失败: $e"); |
|
|
|
|
|
return "unknownEquipment"; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// 获取当前设备版本信息 |
|
|
/// 获取当前设备版本信息 |
|
|
/// 返回包含当前版本、产品ID和设备信息的Map |
|
|
/// 返回包含当前版本、产品ID和设备信息的Map |
|
|
/// 抛出异常如果获取失败 |
|
|
/// 抛出异常如果获取失败 |
|
|
@ -288,10 +320,16 @@ class OtaCoreService { |
|
|
throw "获取设备信息失败,请检查连接"; |
|
|
throw "获取设备信息失败,请检查连接"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String deviceName = getDeviceName(); |
|
|
|
|
|
|
|
|
// 获取产品信息以确定设备类型 |
|
|
// 获取产品信息以确定设备类型 |
|
|
DBProduct? product = AppConfig.getproduct("DeapSound"); |
|
|
DBProduct? product = AppConfig.getproduct(deviceName); |
|
|
if (product == null) { |
|
|
if (product == null) { |
|
|
throw "无法获取产品信息"; |
|
|
// 如果根据设备名称找不到产品,尝试使用默认产品名称 |
|
|
|
|
|
product = AppConfig.getproduct("DeapSound"); |
|
|
|
|
|
if (product == null) { |
|
|
|
|
|
throw "无法获取产品信息,设备名称: $deviceName"; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 根据设备类型进行不同的版本校验 |
|
|
// 根据设备类型进行不同的版本校验 |
|
|
@ -342,10 +380,16 @@ class OtaCoreService { |
|
|
/// 返回包含最新版本、更新描述和更新包地址的Map |
|
|
/// 返回包含最新版本、更新描述和更新包地址的Map |
|
|
/// 抛出异常如果获取失败 |
|
|
/// 抛出异常如果获取失败 |
|
|
Future<Map<String, dynamic>> getLatestVersionInfo() async { |
|
|
Future<Map<String, dynamic>> getLatestVersionInfo() async { |
|
|
DBProduct? product = AppConfig.getproduct("DeapSound"); |
|
|
// 动态获取当前连接的设备名称 |
|
|
|
|
|
String deviceName = getDeviceName(); |
|
|
|
|
|
|
|
|
|
|
|
DBProduct? product = AppConfig.getproduct(deviceName); |
|
|
if (product == null) { |
|
|
if (product == null) { |
|
|
throw "无法获取产品信息"; |
|
|
// 如果根据设备名称找不到产品,尝试使用默认产品名称 |
|
|
|
|
|
product = AppConfig.getproduct("DeapSound"); |
|
|
|
|
|
if (product == null) { |
|
|
|
|
|
throw "无法获取产品信息,设备名称: $deviceName"; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
|