更新太和e护配置wifi失败问题
This commit is contained in:
328
lib/pages/mh_page/device/upgrade/tool/device_upgrade_tool.dart
Normal file
328
lib/pages/mh_page/device/upgrade/tool/device_upgrade_tool.dart
Normal file
@@ -0,0 +1,328 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:vbvs_app/common/color/appConstants.dart';
|
||||
import 'package:vbvs_app/common/util/FirmwareVersionService.dart';
|
||||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/component/tool/SelectableTagButton.dart';
|
||||
import 'package:vbvs_app/enum/APPDeviceUpgrade.dart';
|
||||
import 'package:vbvs_app/pages/device_bind/componnet/bind_dialog.dart';
|
||||
import 'package:vbvs_app/pages/mh_page/device/controller/mht_bluetooth_controller.dart';
|
||||
import 'package:vbvs_app/pages/mh_page/device/model/BlueToothDataModel.dart';
|
||||
import 'package:vbvs_app/pages/mh_page/device/upgrade/device_upgrade_controller.dart';
|
||||
|
||||
MHTDeviceUpgradeController mhtDeviceUpgradeController = Get.find();
|
||||
|
||||
Future<void> initDeviceUpgradeType() async {
|
||||
try {
|
||||
// 模拟异步加载
|
||||
// await Future.delayed(const Duration(milliseconds: 300));
|
||||
|
||||
final dataList = APPDeviceUpgradeExtension.list;
|
||||
|
||||
ef.log("✅ 初始化固件升级类型成功,共 ${dataList.length} 项");
|
||||
for (var item in dataList) {
|
||||
ef.log(" ${item['id']} - ${item['name']}");
|
||||
}
|
||||
// 你可以在这里存入 controller 变量中,例如:
|
||||
mhtDeviceUpgradeController.diseaseList.value = dataList;
|
||||
} catch (e) {
|
||||
ef.log("❌ 初始化获取固件版本失败: $e");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> initFirmwareVersions(formFieldController) async {
|
||||
try {
|
||||
const baseUrl = "https://share.file.he-info.cn";
|
||||
const firmwarePath = "/ota/aithv2/";
|
||||
|
||||
final versions = await FirmwareVersionService.getAllFirmwareVersions(
|
||||
baseUrl: baseUrl,
|
||||
firmwarePath: firmwarePath,
|
||||
);
|
||||
|
||||
if (versions.isNotEmpty) {
|
||||
// 这里你可以存到控制器里
|
||||
mhtDeviceUpgradeController.firmwareList = versions;
|
||||
print("✅ 获取到 ${versions.length} 个固件版本:");
|
||||
for (final v in versions) {
|
||||
print("➡ ${v.fileName} (${v.version})");
|
||||
}
|
||||
if (mhtDeviceUpgradeController.selectVerison == null) {
|
||||
mhtDeviceUpgradeController.selectVerison = versions.first;
|
||||
formFieldController.value =
|
||||
mhtDeviceUpgradeController.selectVerison!.version!;
|
||||
|
||||
final MHTBlueToothController _btController = Get.find();
|
||||
_btController.currentUpgradeVersion =
|
||||
mhtDeviceUpgradeController.selectVerison!.version!;
|
||||
_btController.currentUpgradeName =
|
||||
mhtDeviceUpgradeController.selectVerison!.fileName!;
|
||||
_btController.currentUpgradeUrl =
|
||||
mhtDeviceUpgradeController.selectVerison!.downloadUrl!;
|
||||
|
||||
mhtDeviceUpgradeController.updateAll();
|
||||
} else {
|
||||
formFieldController.value =
|
||||
mhtDeviceUpgradeController.selectVerison!.version!;
|
||||
}
|
||||
mhtDeviceUpgradeController.updateAll();
|
||||
} else {
|
||||
print("⚠ 没有获取到固件版本文件");
|
||||
}
|
||||
} catch (e) {
|
||||
print("❌ 初始化获取固件版本失败: $e");
|
||||
}
|
||||
}
|
||||
|
||||
getQueryList() {
|
||||
return Padding(
|
||||
padding: EdgeInsets.all(AppConstants().content_left_right_padding),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"筛选条件".tr,
|
||||
style: TextStyle(
|
||||
fontSize: AppConstants().title_text_fontSize,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
Obx(() {
|
||||
final selectedIds = mhtDeviceUpgradeController.selectedDiseaseIds;
|
||||
final diseases = mhtDeviceUpgradeController.diseaseList;
|
||||
return Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(0.rpx, 40.rpx, 0.rpx, 0),
|
||||
child: Wrap(
|
||||
spacing: 20.rpx,
|
||||
runSpacing: 20.rpx,
|
||||
children: diseases.map<Widget>((disease) {
|
||||
final id = disease['id'];
|
||||
final name = disease['name'];
|
||||
final isSelected = selectedIds!.contains(id);
|
||||
return SelectableTagButton(
|
||||
selectedTextColor: Colors.black,
|
||||
unselectedTextColor: Colors.white,
|
||||
colors: [stringToColor("#84F5FF")],
|
||||
borderRadius: AppConstants().button_container_radius,
|
||||
label: name,
|
||||
selected: isSelected,
|
||||
onTap: () {
|
||||
final allId = APPDeviceUpgrade.ALL.value; // 全部的id(一般是1)
|
||||
|
||||
if (id == allId) {
|
||||
// 👉 点击的是“全部”
|
||||
if (isSelected) {
|
||||
// 当前是选中状态 → 取消“全部”选择(清空所有)
|
||||
selectedIds.clear();
|
||||
} else {
|
||||
// 当前未选中 → 全部选中(添加所有状态的id)
|
||||
selectedIds
|
||||
..clear()
|
||||
..addAll(APPDeviceUpgradeExtension.valueList);
|
||||
}
|
||||
} else {
|
||||
// 👉 点击的不是“全部”
|
||||
if (isSelected) {
|
||||
// 已选中 → 取消当前id
|
||||
selectedIds.remove(id);
|
||||
|
||||
// 若取消后,“全部”还在选中 → 去掉“全部”
|
||||
if (selectedIds.contains(allId)) {
|
||||
selectedIds.remove(allId);
|
||||
}
|
||||
} else {
|
||||
// 未选中 → 选中当前id
|
||||
selectedIds.add(id);
|
||||
|
||||
// 若选中的数量 == 除“全部”外的所有类型数 → 自动勾选“全部”
|
||||
final allOtherIds = APPDeviceUpgradeExtension
|
||||
.valueList
|
||||
.where((v) => v != allId);
|
||||
if (selectedIds.toSet().containsAll(allOtherIds)) {
|
||||
selectedIds
|
||||
..clear()
|
||||
..addAll(APPDeviceUpgradeExtension.valueList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mhtDeviceUpgradeController.updateAll();
|
||||
});
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// int getRemainingDeviceCount() {
|
||||
// // 获取所有设备数据
|
||||
// var allDevices = mhtDeviceUpgradeController.model.blueRawData!;
|
||||
|
||||
// // 获取正在升级的设备数据
|
||||
// var upgradingDevices = mhtDeviceUpgradeController.model.upgradingDevices;
|
||||
|
||||
// // 获取正在升级的设备 mac 地址列表
|
||||
// var upgradingMacs = upgradingDevices!.map((device) => device.mac).toList();
|
||||
|
||||
// // 计算所有设备中不在升级设备列表中的设备数量
|
||||
// var remainingDevices = allDevices
|
||||
// .where((device) => !upgradingMacs.contains(device.mac))
|
||||
// .toList();
|
||||
|
||||
// // 返回剩余设备的数量,最小为 0
|
||||
|
||||
// mhtDeviceUpgradeController.selectVerison;
|
||||
// return remainingDevices.length;
|
||||
// }
|
||||
int getRemainingDeviceCount() {
|
||||
// 获取所有设备数据
|
||||
var allDevices = mhtDeviceUpgradeController.model.blueRawData ?? [];
|
||||
|
||||
// 获取正在升级的设备数据
|
||||
var upgradingDevices =
|
||||
mhtDeviceUpgradeController.model.upgradingDevices ?? [];
|
||||
|
||||
// 获取当前选择的升级版本
|
||||
var selectedVersion = mhtDeviceUpgradeController.selectVerison;
|
||||
|
||||
// 获取正在升级的设备 mac 地址列表
|
||||
var upgradingMacs = upgradingDevices.map((device) => device.mac).toList();
|
||||
|
||||
// 过滤出:
|
||||
// 1. 不在正在升级的设备列表中;
|
||||
// 2. 且版本号不等于当前选中的版本(表示无需升级的排除掉)
|
||||
var remainingDevices = allDevices.where((device) {
|
||||
// bool notUpgrading = !upgradingMacs.contains(device.mac);
|
||||
bool notUpgrading = true;
|
||||
//todo wyf 恢复
|
||||
// bool needUpgrade = device.version.toString() != selectedVersion!.version;
|
||||
bool needUpgrade = true;
|
||||
return notUpgrading && needUpgrade;
|
||||
}).toList();
|
||||
|
||||
// 返回剩余需要升级的设备数量
|
||||
|
||||
List<BlueToothDataModel> displayDevices = [
|
||||
// 用 upgrading 覆盖 raw 中的相同 mac
|
||||
...allDevices.map((d) {
|
||||
final u = upgradingDevices.firstWhereOrNull((x) => x.mac == d.mac);
|
||||
return u ?? d;
|
||||
}),
|
||||
// 加入那些只在 upgradingDevices 中但不在 raw 的
|
||||
...upgradingDevices.where((u) => !allDevices.any((d) => d.mac == u.mac)),
|
||||
];
|
||||
return displayDevices.length;
|
||||
return remainingDevices.length;
|
||||
}
|
||||
|
||||
String judgeUpgradeDeviceCount() {
|
||||
List selectedDevices = mhtDeviceUpgradeController.model.blueRawData!
|
||||
.where((device) => device.selected == true)
|
||||
.toList();
|
||||
if (selectedDevices.length == 0) {
|
||||
return "请至少选择一项设备";
|
||||
}
|
||||
if (selectedDevices.length > mhtDeviceUpgradeController.maxLimit) {
|
||||
return "超出数量限制,请等待";
|
||||
}
|
||||
final devices = mhtDeviceUpgradeController.model.upgradingDevices;
|
||||
if (devices == null || devices.isEmpty) {
|
||||
return "";
|
||||
} else {
|
||||
if (devices.length >= mhtDeviceUpgradeController.maxLimit) {
|
||||
return "超出数量限制,请等待";
|
||||
}
|
||||
if (devices.length + selectedDevices.length >
|
||||
mhtDeviceUpgradeController.maxLimit) {
|
||||
return "超出数量限制,请等待";
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
String getDeviceId(ScanResult result) {
|
||||
// Android:remoteId 就是 MAC
|
||||
if (Platform.isAndroid) {
|
||||
return result.device.remoteId.str.replaceAll(':', '').toUpperCase();
|
||||
}
|
||||
|
||||
// iOS:尝试从 manufacturerData 里解析
|
||||
Map<int, List<int>> mData = result.advertisementData.manufacturerData;
|
||||
for (var key in mData.keys) {
|
||||
List<int>? bytes = mData[key];
|
||||
if (bytes != null && bytes.length == 6) {
|
||||
// 假设这 6 个字节就是 MAC
|
||||
return bytes
|
||||
.map((b) => b.toRadixString(16).padLeft(2, '0'))
|
||||
.join('')
|
||||
.toUpperCase();
|
||||
}
|
||||
}
|
||||
return result.device.remoteId.str.toUpperCase();
|
||||
}
|
||||
|
||||
void removeOldDevices() {
|
||||
final now = DateTime.now();
|
||||
final currentDevices = mhtDeviceUpgradeController.model.blueRawData! ?? [];
|
||||
|
||||
// 移除30秒内未出现的设备
|
||||
final updatedDevices = currentDevices.where((device) {
|
||||
return now.difference(device.lastSeen) < Duration(seconds: 30);
|
||||
}).toList();
|
||||
|
||||
if (updatedDevices.length != currentDevices.length) {
|
||||
mhtDeviceUpgradeController.model.blueRawData = updatedDevices;
|
||||
mhtDeviceUpgradeController.updateAll();
|
||||
}
|
||||
}
|
||||
|
||||
showBluetoothNotEnabledDialog(BuildContext context) async {
|
||||
await showTipDialog(
|
||||
backgroundColor: Colors.white,
|
||||
context,
|
||||
Column(
|
||||
children: [
|
||||
Text(
|
||||
"蓝牙未开启".tr,
|
||||
style: TextStyle(
|
||||
fontSize: AppConstants().title_text_fontSize,
|
||||
color: stringToColor("#333333"),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 20.rpx,
|
||||
),
|
||||
Text(
|
||||
"请先打开蓝牙在进行设备扫描".tr,
|
||||
style: TextStyle(
|
||||
fontSize: AppConstants().normal_text_fontSize,
|
||||
color: stringToColor("#333333"),
|
||||
),
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
List<BlueToothDataModel> filterDeviceType(List<BlueToothDataModel> devices) {
|
||||
final selectedIds = mhtDeviceUpgradeController.selectedDiseaseIds;
|
||||
|
||||
// 如果未选择或包含“全部”,直接返回全部设备
|
||||
if (selectedIds!.isEmpty ||
|
||||
selectedIds.contains(APPDeviceUpgrade.ALL.value)) {
|
||||
return devices;
|
||||
}
|
||||
|
||||
// 否则按类型过滤
|
||||
return devices
|
||||
.where((device) => selectedIds.contains(device.upgradeStatus))
|
||||
.toList();
|
||||
}
|
||||
Reference in New Issue
Block a user