绑定设备+覆盖模式+控制显示bug+在线更新
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:maibu_satabot_v2/core/theme/AppTheme.dart';
|
||||
import 'dart:developer' as developer;
|
||||
import 'dart:typed_data';
|
||||
@@ -11,6 +12,9 @@ import '../../../../../core/bluetooth/protocol_parser.dart';
|
||||
import '../../../../../core/protocol/machine_protocol_constants.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import '../../../../../core/services/device_permission_service.dart';
|
||||
import '../../domain/entities/device_entity.dart';
|
||||
import '../../domain/usecases/get_all_devices_usecase.dart';
|
||||
import 'bind_device_page.dart';
|
||||
|
||||
class BleDeviceDetailPage extends StatefulWidget {
|
||||
final BluetoothDevice device;
|
||||
@@ -34,6 +38,7 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
StreamSubscription<BluetoothDevice?>? _connectingSubscription;
|
||||
StreamSubscription<BlePacket>? _packetSubscription;
|
||||
final List<_ReceivedPacket> _receivedPackets = [];
|
||||
|
||||
/// 按命令类型分组的最新推送:command → 最新数据
|
||||
final Map<int, _ReceivedPacket> _latestPushByCommand = {};
|
||||
bool _pushExpanded = false; // 数据推送默认折叠
|
||||
@@ -44,6 +49,7 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
|
||||
/// 等待设备返回 0x06 写配置应答
|
||||
Completer<bool>? _writeRespCompleter;
|
||||
|
||||
/// 等待回读 0x05 应答,携带期望字段值用于对比
|
||||
Completer<Uint8List?>? _readbackCompleter;
|
||||
Map<String, String>? _expectedFieldValues;
|
||||
@@ -247,6 +253,107 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
await BleManager.instance.disconnect();
|
||||
}
|
||||
|
||||
/// 获取当前蓝牙设备的显示名称
|
||||
String get _bleDeviceName {
|
||||
final advData = widget.scanResult?.advertisementData;
|
||||
return _resolvedName ??
|
||||
(advData?.advName.isNotEmpty == true
|
||||
? advData!.advName
|
||||
: (widget.device.platformName.isNotEmpty
|
||||
? widget.device.platformName
|
||||
: (advData?.localName?.isNotEmpty == true
|
||||
? advData!.localName!
|
||||
: (widget.device.advName.isNotEmpty
|
||||
? widget.device.advName
|
||||
: ''))));
|
||||
}
|
||||
|
||||
/// 绑定设备:调接口获取设备列表,用蓝牙名(时间戳)匹配后跳转绑定页
|
||||
Future<void> _bindDevice() async {
|
||||
final bleName = _bleDeviceName;
|
||||
if (bleName.isEmpty) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('无法获取蓝牙设备名称')));
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示 loading
|
||||
BuildContext? loadingCtx;
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (ctx) {
|
||||
loadingCtx = ctx;
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
},
|
||||
);
|
||||
|
||||
try {
|
||||
final getAllDevicesUseCase = GetIt.instance<GetAllDevicesUseCase>();
|
||||
final devices = await getAllDevicesUseCase.execute();
|
||||
|
||||
if (loadingCtx != null && Navigator.canPop(loadingCtx!)) {
|
||||
Navigator.pop(loadingCtx!);
|
||||
}
|
||||
|
||||
debugPrint(
|
||||
'>>> [BindDevice] bleName=$bleName, devices=${devices.length}',
|
||||
);
|
||||
for (int i = 0; i < devices.length && i < 10; i++) {
|
||||
debugPrint(
|
||||
'>>> [BindDevice] device[$i]: id=${devices[i].deviceId}, name=${devices[i].name}',
|
||||
);
|
||||
}
|
||||
|
||||
// 用蓝牙名(时间戳)匹配设备名中包含该时间戳的设备
|
||||
DeviceEntity? matchedDevice;
|
||||
for (final device in devices) {
|
||||
if (device.name.contains(bleName)) {
|
||||
matchedDevice = device;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (matchedDevice == null) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('未找到名称包含「$bleName」的设备')));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (matchedDevice.deviceId.isEmpty) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('匹配到的设备缺少设备ID')));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
// 复用扫一扫的绑定页面流程
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => BindDevicePage(scanResult: matchedDevice!.deviceId),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
if (loadingCtx != null && Navigator.canPop(loadingCtx!)) {
|
||||
Navigator.pop(loadingCtx!);
|
||||
}
|
||||
debugPrint('>>> [BindDevice] error: $e');
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('绑定设备失败: $e')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_connSubscription?.cancel();
|
||||
@@ -348,8 +455,8 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
final hex = payload.isEmpty
|
||||
? ''
|
||||
: payload
|
||||
.map((b) => b.toRadixString(16).toUpperCase().padLeft(2, '0'))
|
||||
.join(' ');
|
||||
.map((b) => b.toRadixString(16).toUpperCase().padLeft(2, '0'))
|
||||
.join(' ');
|
||||
setState(() {
|
||||
_receivedPackets.insert(
|
||||
0,
|
||||
@@ -372,7 +479,6 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
await _sendAndLog(MachineProtocolConstants.cmdReadConfig, []);
|
||||
}
|
||||
|
||||
|
||||
String _bytesToHex(List<int> bytes) {
|
||||
if (bytes.isEmpty) return '';
|
||||
return bytes
|
||||
@@ -382,16 +488,26 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
|
||||
String _commandName(int command) {
|
||||
switch (command) {
|
||||
case MachineProtocolConstants.cmdRemoteControl: return '远程遥控';
|
||||
case MachineProtocolConstants.cmdPathPlanning: return '路径规划';
|
||||
case MachineProtocolConstants.cmdStatusInfo: return '状态信息';
|
||||
case MachineProtocolConstants.cmdGetId: return '查询ID';
|
||||
case MachineProtocolConstants.cmdGetAuth: return '获取授权';
|
||||
case MachineProtocolConstants.cmdReadConfig: return '读配置';
|
||||
case MachineProtocolConstants.cmdWriteConfig: return '写配置';
|
||||
case MachineProtocolConstants.cmdObstacleAvoid: return '避障';
|
||||
case MachineProtocolConstants.cmdHeartbeat: return '心跳包';
|
||||
default: return '未知(0x${command.toRadixString(16).toUpperCase().padLeft(2, '0')})';
|
||||
case MachineProtocolConstants.cmdRemoteControl:
|
||||
return '远程遥控';
|
||||
case MachineProtocolConstants.cmdPathPlanning:
|
||||
return '路径规划';
|
||||
case MachineProtocolConstants.cmdStatusInfo:
|
||||
return '状态信息';
|
||||
case MachineProtocolConstants.cmdGetId:
|
||||
return '查询ID';
|
||||
case MachineProtocolConstants.cmdGetAuth:
|
||||
return '获取授权';
|
||||
case MachineProtocolConstants.cmdReadConfig:
|
||||
return '读配置';
|
||||
case MachineProtocolConstants.cmdWriteConfig:
|
||||
return '写配置';
|
||||
case MachineProtocolConstants.cmdObstacleAvoid:
|
||||
return '避障';
|
||||
case MachineProtocolConstants.cmdHeartbeat:
|
||||
return '心跳包';
|
||||
default:
|
||||
return '未知(0x${command.toRadixString(16).toUpperCase().padLeft(2, '0')})';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,13 +702,19 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
width: 80,
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(fontSize: 13, color: context.appColors.textTertiary),
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: context.appColors.textTertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
style: TextStyle(fontSize: 13, color: context.appColors.textPrimary),
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: context.appColors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -626,33 +748,66 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: _isConnecting
|
||||
? null
|
||||
: (_isConnected ? _disconnect : _connect),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
backgroundColor: _isConnected
|
||||
? context.appColors.danger
|
||||
: context.appColors.primary,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
Row(
|
||||
children: [
|
||||
// 连接/断开 按钮
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: _isConnecting
|
||||
? null
|
||||
: (_isConnected ? _disconnect : _connect),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
backgroundColor: _isConnected
|
||||
? context.appColors.danger
|
||||
: context.appColors.primary,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: _isConnecting
|
||||
? Text(
|
||||
'连接中 ${_connectingCountdown}s',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
)
|
||||
: Text(_isConnected ? '断开连接' : '连接设备'),
|
||||
),
|
||||
),
|
||||
child: _isConnecting
|
||||
? Text(
|
||||
'连接中 ${_connectingCountdown}s',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
)
|
||||
: Text(_isConnected ? '断开连接' : '连接设备'),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// 绑定设备 按钮(未连接时灰色禁用)
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: _isConnected ? _bindDevice : null,
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
backgroundColor: _isConnected
|
||||
? context.appColors.primary
|
||||
: context.appColors.fillBackground,
|
||||
foregroundColor: _isConnected
|
||||
? Colors.white
|
||||
: context.appColors.textTertiary,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
'绑定设备',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: _isConnected
|
||||
? Colors.white
|
||||
: context.appColors.textTertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -785,7 +940,10 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
),
|
||||
child: Text(
|
||||
p,
|
||||
style: TextStyle(fontSize: 10, color: context.appColors.primary),
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: context.appColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
@@ -871,14 +1029,21 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
if (pushes.isNotEmpty) ...[
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: context.appColors.primary,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
'${pushes.length}',
|
||||
style: const TextStyle(fontSize: 11, color: Colors.white, fontWeight: FontWeight.w600),
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -894,7 +1059,10 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
},
|
||||
child: Text(
|
||||
'清空',
|
||||
style: TextStyle(fontSize: 13, color: context.appColors.primary),
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: context.appColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -906,16 +1074,23 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
child: Center(
|
||||
child: Text(
|
||||
'等待接收数据...',
|
||||
style: TextStyle(fontSize: 13, color: context.appColors.textTertiary),
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: context.appColors.textTertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
Column(
|
||||
children: pushes.map((p) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: _buildPushCard(p),
|
||||
)).toList(),
|
||||
children: pushes
|
||||
.map(
|
||||
(p) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: _buildPushCard(p),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -970,35 +1145,46 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
'${p.time.hour.toString().padLeft(2, '0')}:'
|
||||
'${p.time.minute.toString().padLeft(2, '0')}:'
|
||||
'${p.time.second.toString().padLeft(2, '0')}',
|
||||
style: TextStyle(fontSize: 11, color: context.appColors.textTertiary),
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: context.appColors.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (hasParsed) ...[
|
||||
const SizedBox(height: 8),
|
||||
...p.parsedFields!.map((f) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 2),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 68,
|
||||
child: Text(
|
||||
f.label,
|
||||
style: TextStyle(fontSize: 11, color: context.appColors.textTertiary),
|
||||
...p.parsedFields!.map(
|
||||
(f) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 2),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 68,
|
||||
child: Text(
|
||||
f.label,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: context.appColors.textTertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
f.value,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 11, color: context.appColors.textPrimary),
|
||||
Expanded(
|
||||
child: Text(
|
||||
f.value,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: context.appColors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
)),
|
||||
),
|
||||
] else if (p.hex.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
@@ -1019,12 +1205,7 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
}
|
||||
|
||||
/// 可编辑的字段白名单:仅这四个增益属性可修改
|
||||
static const _editableFields = {
|
||||
'左轮前进增益',
|
||||
'左轮后退增益',
|
||||
'右轮前进增益',
|
||||
'右轮后退增益',
|
||||
};
|
||||
static const _editableFields = {'左轮前进增益', '左轮后退增益', '右轮前进增益', '右轮后退增益'};
|
||||
|
||||
bool _isEditableField(String label) => _editableFields.contains(label);
|
||||
|
||||
@@ -1156,7 +1337,9 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
),
|
||||
TextSpan(
|
||||
text: ' | ',
|
||||
style: TextStyle(color: context.appColors.divider),
|
||||
style: TextStyle(
|
||||
color: context.appColors.divider,
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: mod.newValue,
|
||||
@@ -1219,7 +1402,10 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
hintText: '输入新值',
|
||||
border: const OutlineInputBorder(),
|
||||
suffixText: '当前: $currentValue',
|
||||
suffixStyle: TextStyle(fontSize: 11, color: context.appColors.textTertiary),
|
||||
suffixStyle: TextStyle(
|
||||
fontSize: 11,
|
||||
color: context.appColors.textTertiary,
|
||||
),
|
||||
errorText: errorText,
|
||||
),
|
||||
),
|
||||
@@ -1236,7 +1422,9 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
Navigator.pop(ctx);
|
||||
return;
|
||||
}
|
||||
final pkt = _latestPushByCommand[MachineProtocolConstants.cmdReadConfig];
|
||||
final pkt =
|
||||
_latestPushByCommand[MachineProtocolConstants
|
||||
.cmdReadConfig];
|
||||
final entity = pkt?.configEntity;
|
||||
if (entity == null) {
|
||||
Navigator.pop(ctx);
|
||||
@@ -1269,7 +1457,8 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
|
||||
try {
|
||||
// 🔐 前置权限校验:使用读配置(0x05)中的芯片序列号(chipUid)作为设备ID
|
||||
final readConfigPacket = _latestPushByCommand[MachineProtocolConstants.cmdReadConfig];
|
||||
final readConfigPacket =
|
||||
_latestPushByCommand[MachineProtocolConstants.cmdReadConfig];
|
||||
final chipUid = readConfigPacket?.configEntity?.chipUid ?? '';
|
||||
if (chipUid.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
@@ -1305,7 +1494,11 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
builder: (dialogCtx) => AlertDialog(
|
||||
title: Row(
|
||||
children: [
|
||||
Icon(Icons.check_circle, color: context.appColors.success, size: 28),
|
||||
Icon(
|
||||
Icons.check_circle,
|
||||
color: context.appColors.success,
|
||||
size: 28,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('权限通过'),
|
||||
],
|
||||
@@ -1343,7 +1536,10 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
|
||||
// 2. 发送 0x06 并等待设备应答
|
||||
_writeRespCompleter = Completer<bool>();
|
||||
developer.log('[WriteConfig] ⏳ 发送 0x06, 等待应答...', name: 'BleDeviceDetail');
|
||||
developer.log(
|
||||
'[WriteConfig] ⏳ 发送 0x06, 等待应答...',
|
||||
name: 'BleDeviceDetail',
|
||||
);
|
||||
await BleManager.instance.sendCommand(
|
||||
MachineProtocolConstants.cmdWriteConfig,
|
||||
configBytes.toList(),
|
||||
@@ -1363,7 +1559,9 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
if (!mounted) return;
|
||||
|
||||
// 3. 记录期望值,自动回读对比(无论是否收到显式确认都回读)
|
||||
_expectedFieldValues = Map<String, String>.from(p.configEntity!.toFieldMap());
|
||||
_expectedFieldValues = Map<String, String>.from(
|
||||
p.configEntity!.toFieldMap(),
|
||||
);
|
||||
|
||||
// 4. 自动回读配置
|
||||
_readbackCompleter = Completer<Uint8List?>();
|
||||
@@ -1430,14 +1628,13 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
rawPayload: readbackPayload,
|
||||
configEntity: newEntity,
|
||||
);
|
||||
_latestPushByCommand[MachineProtocolConstants.cmdReadConfig] = updatedEntry;
|
||||
_latestPushByCommand[MachineProtocolConstants.cmdReadConfig] =
|
||||
updatedEntry;
|
||||
});
|
||||
}
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'校验不一致: ${mismatched.join('、')},已恢复为设备实际值',
|
||||
),
|
||||
content: Text('校验不一致: ${mismatched.join('、')},已恢复为设备实际值'),
|
||||
backgroundColor: context.appColors.warning,
|
||||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
@@ -1462,7 +1659,8 @@ class _BleDeviceDetailPageState extends State<BleDeviceDetailPage> {
|
||||
rawPayload: readbackPayload,
|
||||
configEntity: newEntity,
|
||||
);
|
||||
_latestPushByCommand[MachineProtocolConstants.cmdReadConfig] = updatedEntry;
|
||||
_latestPushByCommand[MachineProtocolConstants.cmdReadConfig] =
|
||||
updatedEntry;
|
||||
_configModifications = {};
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
|
||||
@@ -119,15 +119,29 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 🔥 机器人设备名称前缀,用于从通用设备列表中过滤掉机器人
|
||||
static const _robotPrefixes = [
|
||||
'RCHETD-CN',
|
||||
'MC700PLUS-CN',
|
||||
'MC700-CN',
|
||||
'MC700PRO-CN',
|
||||
'RCETD-CN',
|
||||
'MC700AIR-CN',
|
||||
];
|
||||
/// 🔥 机器人型号家族前缀(小写,startsWith 匹配,覆盖 MC700/MC700STD/MC700PLUS/MCAIR/RCHWD/RCHETD 等全系列)
|
||||
static const _robotPrefixes = ['mc', 'rch', 'rcetd', 'rchetd'];
|
||||
|
||||
/// 🔥 机器人类型中文名关键字(接口 deviceTypeName 可能是纯中文)
|
||||
static const _robotTypeKeywords = ['除草', '巡检', '清洗', '割草', '机器人'];
|
||||
|
||||
/// 🔥 通用判断:是否机器人(型号前缀 + 中文关键字双重匹配,新型号也能自动识别)
|
||||
static bool _isRobotDevice(String type, String name, String deviceId) {
|
||||
final haystacks = [
|
||||
type.toLowerCase(),
|
||||
name.toLowerCase(),
|
||||
deviceId.toLowerCase(),
|
||||
];
|
||||
for (final s in haystacks) {
|
||||
for (final p in _robotPrefixes) {
|
||||
if (s.startsWith(p)) return true;
|
||||
}
|
||||
}
|
||||
for (final k in _robotTypeKeywords) {
|
||||
if (type.contains(k) || name.contains(k)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -186,7 +200,11 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
children: [
|
||||
const Flexible(child: SiteSelectorWidget(compact: true)),
|
||||
const SizedBox(width: 8),
|
||||
Container(width: 1, height: 20, color: context.appColors.divider),
|
||||
Container(
|
||||
width: 1,
|
||||
height: 20,
|
||||
color: context.appColors.divider,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
AppLocalizations.of(
|
||||
@@ -310,7 +328,10 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
style: TextStyle(fontSize: 14, color: context.appColors.textPrimary),
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: context.appColors.textPrimary,
|
||||
),
|
||||
onSubmitted: (value) {
|
||||
context.read<DeviceListBloc.DeviceStatusBloc>().add(
|
||||
DeviceListEvent.DeviceStatusSearch(value),
|
||||
@@ -490,13 +511,16 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
} else {
|
||||
// 🔥 "全部"模式下,排除已由专用组件渲染的类型,避免重复展示
|
||||
// drone_station 已通过 _buildDroneStationList 渲染
|
||||
// 机器人(通过名称前缀识别)已通过 _buildEmbeddedRobotList 渲染
|
||||
// 机器人通过下面的 _isRobotDevice 通用匹配识别,已由 _buildEmbeddedRobotList 渲染
|
||||
filteredByType = state.devices.where((device) {
|
||||
if (device.type == 'drone_station') return false;
|
||||
final isRobot = _robotPrefixes.any(
|
||||
(prefix) =>
|
||||
device.name.startsWith(prefix) ||
|
||||
device.deviceId.startsWith(prefix),
|
||||
final isRobot = _isRobotDevice(
|
||||
device.type,
|
||||
device.name,
|
||||
device.deviceId,
|
||||
);
|
||||
debugPrint(
|
||||
'🔍 [全部-过滤] deviceId=${device.deviceId} type=${device.type} name=${device.name} → isRobot=$isRobot ${isRobot ? '✅排除' : ''}',
|
||||
);
|
||||
return !isRobot;
|
||||
}).toList();
|
||||
@@ -722,7 +746,9 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
builder: (context, state) {
|
||||
if (state is DroneStationLoading) {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(color: context.appColors.primary),
|
||||
child: CircularProgressIndicator(
|
||||
color: context.appColors.primary,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1042,9 +1068,8 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
debugPrint('🔍 [DeviceStatusPage] 设备ID: $deviceId');
|
||||
debugPrint('🔍 [DeviceStatusPage] 设备类型: $deviceType');
|
||||
|
||||
// 🔥 判断是否为机器人(根据设备类型前缀)
|
||||
final robotPrefixes = _robotPrefixes;
|
||||
bool isRobot = robotPrefixes.any((prefix) => deviceType.startsWith(prefix));
|
||||
// 🔥 判断是否为机器人:用通用匹配(型号前缀 + 中文关键字)
|
||||
bool isRobot = _isRobotDevice(deviceType, deviceName, deviceId);
|
||||
|
||||
// 🔥 判断是否为无人机机场(根据设备类型包含关键字)
|
||||
final droneStationKeywords = [
|
||||
@@ -1065,22 +1090,8 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
(deviceType.isEmpty || deviceType == '未知设备' || deviceType == '未知类型')) {
|
||||
debugPrint('⚠️ [DeviceStatusPage] type 字段无效,使用设备名称进行二次判断');
|
||||
|
||||
// 检查每个机器人前缀是否匹配
|
||||
for (final prefix in robotPrefixes) {
|
||||
final nameMatch = deviceName.startsWith(prefix);
|
||||
final idMatch = deviceId.startsWith(prefix);
|
||||
if (nameMatch || idMatch) {
|
||||
debugPrint(
|
||||
'🔍 [DeviceStatusPage] 机器人前缀匹配: "$prefix" -> 名称匹配=$nameMatch, ID匹配=$idMatch',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 根据设备名称前缀判断机器人
|
||||
isRobot = robotPrefixes.any(
|
||||
(prefix) =>
|
||||
deviceName.startsWith(prefix) || deviceId.startsWith(prefix),
|
||||
);
|
||||
// 根据通用匹配重新判断(已统一用 lowercase)
|
||||
isRobot = _isRobotDevice(deviceType, deviceName, deviceId);
|
||||
|
||||
// 检查每个无人机关键字是否匹配
|
||||
for (final keyword in droneStationKeywords) {
|
||||
|
||||
@@ -1460,7 +1460,7 @@ class _DroneVideoControlPageState extends State<DroneVideoControlPage> {
|
||||
try {
|
||||
final dio = DioClient.create();
|
||||
final response = await dio.post(
|
||||
'http://1.95.137.212:59003/iot/UAV/flightTaskCommand',
|
||||
'${HttpApiConsts.baseUrl}/iot/UAV/flightTaskCommand',
|
||||
data: {'command': command, 'deviceSn': widget.droneSn},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user