|
|
@ -6,6 +6,27 @@ 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'; |
|
|
|
|
|
|
|
|
|
|
|
enum OtaCoreErrorType { |
|
|
|
|
|
deviceInfoUnavailable, |
|
|
|
|
|
productInfoUnavailable, |
|
|
|
|
|
firmwareVersionFormatInvalid, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class OtaCoreException implements Exception { |
|
|
|
|
|
final OtaCoreErrorType type; |
|
|
|
|
|
final Map<String, String> params; |
|
|
|
|
|
final String debugMessage; |
|
|
|
|
|
|
|
|
|
|
|
OtaCoreException({ |
|
|
|
|
|
required this.type, |
|
|
|
|
|
this.params = const {}, |
|
|
|
|
|
this.debugMessage = '', |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
|
String toString() => debugMessage; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// OTA核心服务 |
|
|
/// OTA核心服务 |
|
|
/// 整合设备检查、版本管理和状态管理功能 |
|
|
/// 整合设备检查、版本管理和状态管理功能 |
|
|
class OtaCoreService { |
|
|
class OtaCoreService { |
|
|
@ -450,7 +471,10 @@ class OtaCoreService { |
|
|
if (deviceInfo == null || |
|
|
if (deviceInfo == null || |
|
|
deviceInfo.firmwareVersion.isEmpty || |
|
|
deviceInfo.firmwareVersion.isEmpty || |
|
|
deviceInfo.firmwareProductId.isEmpty) { |
|
|
deviceInfo.firmwareProductId.isEmpty) { |
|
|
throw "获取设备信息失败,请检查连接"; |
|
|
throw OtaCoreException( |
|
|
|
|
|
type: OtaCoreErrorType.deviceInfoUnavailable, |
|
|
|
|
|
debugMessage: 'deviceInfoUnavailable', //获取设备信息失败,请检查连接 |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
String deviceName = getDeviceName(); |
|
|
String deviceName = getDeviceName(); |
|
|
@ -461,7 +485,11 @@ class OtaCoreService { |
|
|
// 如果根据设备名称找不到产品,尝试使用默认产品名称 |
|
|
// 如果根据设备名称找不到产品,尝试使用默认产品名称 |
|
|
product = AppConfig.getproduct("DeapSound"); |
|
|
product = AppConfig.getproduct("DeapSound"); |
|
|
if (product == null) { |
|
|
if (product == null) { |
|
|
throw "无法获取产品信息,设备名称: $deviceName"; |
|
|
throw OtaCoreException( |
|
|
|
|
|
type: OtaCoreErrorType.productInfoUnavailable, |
|
|
|
|
|
params: {'deviceName': deviceName}, |
|
|
|
|
|
debugMessage: 'productInfoUnavailable: $deviceName', //根据设备名称未找到产品信息 |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -471,7 +499,12 @@ class OtaCoreService { |
|
|
// 单端耳机:固件版本只有三位数(如:1.2.3) |
|
|
// 单端耳机:固件版本只有三位数(如:1.2.3) |
|
|
final firmwareParts = deviceInfo.firmwareVersion.split('.'); |
|
|
final firmwareParts = deviceInfo.firmwareVersion.split('.'); |
|
|
if (firmwareParts.length < 3) { |
|
|
if (firmwareParts.length < 3) { |
|
|
throw "单端耳机固件版本格式错误:${deviceInfo.firmwareVersion},应为三位数格式(如:1.2.3)"; |
|
|
throw OtaCoreException( |
|
|
|
|
|
type: OtaCoreErrorType.firmwareVersionFormatInvalid, |
|
|
|
|
|
params: {'firmwareVersion': deviceInfo.firmwareVersion}, |
|
|
|
|
|
debugMessage: |
|
|
|
|
|
'single firmwareVersion format invalid: ${deviceInfo.firmwareVersion}', //单端耳机固件版本格式无效 |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
currentVersion = firmwareParts.sublist(0, 3).join('.'); |
|
|
currentVersion = firmwareParts.sublist(0, 3).join('.'); |
|
|
Logger().d("单端耳机版本: $currentVersion"); |
|
|
Logger().d("单端耳机版本: $currentVersion"); |
|
|
@ -480,7 +513,12 @@ class OtaCoreService { |
|
|
// 双端耳机:固件版本有六位数(如:1.2.3.1.2.3) |
|
|
// 双端耳机:固件版本有六位数(如:1.2.3.1.2.3) |
|
|
final firmwareParts = deviceInfo.firmwareVersion.split('.'); |
|
|
final firmwareParts = deviceInfo.firmwareVersion.split('.'); |
|
|
if (firmwareParts.length < 6) { |
|
|
if (firmwareParts.length < 6) { |
|
|
throw "双端耳机固件版本格式错误:${deviceInfo.firmwareVersion},应为六位数格式(如:1.2.3.1.2.3)"; |
|
|
throw OtaCoreException( |
|
|
|
|
|
type: OtaCoreErrorType.firmwareVersionFormatInvalid, |
|
|
|
|
|
params: {'firmwareVersion': deviceInfo.firmwareVersion}, |
|
|
|
|
|
debugMessage: |
|
|
|
|
|
'double firmwareVersion length invalid: ${deviceInfo.firmwareVersion}', //双端耳机固件版本格式无效 |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
final firstPart = firmwareParts.sublist(0, 3).join('.'); |
|
|
final firstPart = firmwareParts.sublist(0, 3).join('.'); |
|
|
final secondPart = firmwareParts.sublist(3, 6).join('.'); |
|
|
final secondPart = firmwareParts.sublist(3, 6).join('.'); |
|
|
@ -488,7 +526,12 @@ class OtaCoreService { |
|
|
Logger().d("双端耳机版本 - firstPart: $firstPart, secondPart: $secondPart"); |
|
|
Logger().d("双端耳机版本 - firstPart: $firstPart, secondPart: $secondPart"); |
|
|
|
|
|
|
|
|
if (firstPart != secondPart) { |
|
|
if (firstPart != secondPart) { |
|
|
throw "双端耳机固件版本格式错误:${deviceInfo.firmwareVersion},前三位和后三位应该相同"; |
|
|
throw OtaCoreException( |
|
|
|
|
|
type: OtaCoreErrorType.firmwareVersionFormatInvalid, |
|
|
|
|
|
params: {'firmwareVersion': deviceInfo.firmwareVersion}, |
|
|
|
|
|
debugMessage: |
|
|
|
|
|
'double firmwareVersion mismatch: ${deviceInfo.firmwareVersion}', //双端耳机固件版本不一致,前三位和后三位不一样 |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
currentVersion = firstPart; |
|
|
currentVersion = firstPart; |
|
|
} else { |
|
|
} else { |
|
|
|