|
|
@ -53,6 +53,123 @@ class OtaCoreService { |
|
|
|
|
|
|
|
|
// ==================== 设备检查功能 ==================== |
|
|
// ==================== 设备检查功能 ==================== |
|
|
|
|
|
|
|
|
|
|
|
/// 检查BLE设备连接状态 |
|
|
|
|
|
/// 返回true表示设备已连接,可以进行升级 |
|
|
|
|
|
/// 返回false表示设备未连接,不能进行升级 |
|
|
|
|
|
bool checkBleConnectionStatus() { |
|
|
|
|
|
try { |
|
|
|
|
|
// 检查BLE管理器的连接状态 |
|
|
|
|
|
if (!_bleManager.isConnected) { |
|
|
|
|
|
//_showBleDisconnectedDialog(); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查设备信息是否可用 |
|
|
|
|
|
final deviceInfo = _bleManager.deviceInfo.value; |
|
|
|
|
|
if (deviceInfo == null) { |
|
|
|
|
|
_showDeviceInfoUnavailableDialog(); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
_showBleCheckFailedSnackbar('检查BLE连接状态时发生错误:$e'); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// 显示BLE设备未连接对话框 |
|
|
|
|
|
void _showBleDisconnectedDialog() { |
|
|
|
|
|
Get.dialog( |
|
|
|
|
|
AlertDialog( |
|
|
|
|
|
title: Text( |
|
|
|
|
|
'BLE设备未连接', |
|
|
|
|
|
style: TextStyle( |
|
|
|
|
|
color: Colors.red[700], |
|
|
|
|
|
fontWeight: FontWeight.w600, |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
|
|
|
content: Text( |
|
|
|
|
|
'固件升级需要连接BLE设备\n请确保设备已正确连接后再试', |
|
|
|
|
|
style: TextStyle( |
|
|
|
|
|
color: Colors.red[600], |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
|
|
|
actions: [ |
|
|
|
|
|
TextButton( |
|
|
|
|
|
onPressed: () => Get.back(), |
|
|
|
|
|
style: TextButton.styleFrom( |
|
|
|
|
|
foregroundColor: Colors.red[700], |
|
|
|
|
|
), |
|
|
|
|
|
child: const Text('确定'), |
|
|
|
|
|
), |
|
|
|
|
|
], |
|
|
|
|
|
shape: RoundedRectangleBorder( |
|
|
|
|
|
borderRadius: BorderRadius.circular(12), |
|
|
|
|
|
side: BorderSide( |
|
|
|
|
|
color: Colors.red.withValues(alpha: 0.3), |
|
|
|
|
|
width: 1, |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
|
|
|
backgroundColor: Colors.red[50], |
|
|
|
|
|
), |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// 显示设备信息不可用对话框 |
|
|
|
|
|
void _showDeviceInfoUnavailableDialog() { |
|
|
|
|
|
Get.dialog( |
|
|
|
|
|
AlertDialog( |
|
|
|
|
|
title: Text( |
|
|
|
|
|
'设备信息不可用', |
|
|
|
|
|
style: TextStyle( |
|
|
|
|
|
color: Colors.orange[700], |
|
|
|
|
|
fontWeight: FontWeight.w600, |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
|
|
|
content: Text( |
|
|
|
|
|
'无法获取设备信息\n请重新连接设备或稍后再试', |
|
|
|
|
|
style: TextStyle( |
|
|
|
|
|
color: Colors.orange[600], |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
|
|
|
actions: [ |
|
|
|
|
|
TextButton( |
|
|
|
|
|
onPressed: () => Get.back(), |
|
|
|
|
|
style: TextButton.styleFrom( |
|
|
|
|
|
foregroundColor: Colors.orange[700], |
|
|
|
|
|
), |
|
|
|
|
|
child: const Text('确定'), |
|
|
|
|
|
), |
|
|
|
|
|
], |
|
|
|
|
|
shape: RoundedRectangleBorder( |
|
|
|
|
|
borderRadius: BorderRadius.circular(12), |
|
|
|
|
|
side: BorderSide( |
|
|
|
|
|
color: Colors.orange.withValues(alpha: 0.3), |
|
|
|
|
|
width: 1, |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
|
|
|
backgroundColor: Colors.orange[50], |
|
|
|
|
|
), |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// 显示BLE连接检查失败提示 |
|
|
|
|
|
/// [message] 错误信息 |
|
|
|
|
|
void _showBleCheckFailedSnackbar(String message) { |
|
|
|
|
|
Get.snackbar( |
|
|
|
|
|
'BLE连接检查失败', |
|
|
|
|
|
message, |
|
|
|
|
|
snackPosition: SnackPosition.BOTTOM, |
|
|
|
|
|
backgroundColor: Colors.red[600], |
|
|
|
|
|
colorText: Colors.white, |
|
|
|
|
|
icon: const Icon( |
|
|
|
|
|
Icons.bluetooth_disabled, |
|
|
|
|
|
color: Colors.white, |
|
|
|
|
|
), |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// 检查设备电量是否满足升级条件 |
|
|
/// 检查设备电量是否满足升级条件 |
|
|
/// 返回true表示电量充足,可以进行升级 |
|
|
/// 返回true表示电量充足,可以进行升级 |
|
|
/// 返回false表示电量不足,不能进行升级 |
|
|
/// 返回false表示电量不足,不能进行升级 |
|
|
|