diff --git a/lib/core/bluetooth/ble_protocol_decoder.dart b/lib/core/bluetooth/ble_protocol_decoder.dart index 9ccfd4fb..789fb3c1 100644 --- a/lib/core/bluetooth/ble_protocol_decoder.dart +++ b/lib/core/bluetooth/ble_protocol_decoder.dart @@ -173,11 +173,13 @@ class BleProtocolDecoder { } String obstacleText(String v) { - final o = int.tryParse(v) ?? -1; + // 障碍物只有 0/1 两种状态;无法识别为数字时一律显示 '--', + // 绝不回吐原始值,避免数据包尾字节导致的乱码显示。 + final o = int.tryParse(v.trim()); return switch (o) { 0 => '无障碍', 1 => '有障碍', - _ => v.isNotEmpty ? v : '--', + _ => '--', }; } diff --git a/lib/features/v2/device_list/presentation/pages/ble_device_detail_page.dart b/lib/features/v2/device_list/presentation/pages/ble_device_detail_page.dart index eb97b52f..32e82657 100644 --- a/lib/features/v2/device_list/presentation/pages/ble_device_detail_page.dart +++ b/lib/features/v2/device_list/presentation/pages/ble_device_detail_page.dart @@ -15,7 +15,16 @@ class BleDeviceDetailPage extends StatefulWidget { final BluetoothDevice device; final ScanResult? scanResult; - const BleDeviceDetailPage({super.key, required this.device, this.scanResult}); + /// 后端设备长名称(如 MC700PLUS-CN-JS-1760408682847-0000002A-A9), + /// 由列表页跳转时传入;为空时回退到蓝牙广播名 + final String? displayName; + + const BleDeviceDetailPage({ + super.key, + required this.device, + this.scanResult, + this.displayName, + }); @override State createState() => _BleDeviceDetailPageState(); @@ -408,7 +417,9 @@ class _BleDeviceDetailPageState extends State { final advData = widget.scanResult?.advertisementData; // 优先使用广告数据中的名称(含扫描响应),手机蓝牙列表也是这样显示的 final name = - _resolvedName ?? + (widget.displayName?.isNotEmpty == true + ? widget.displayName! + : _resolvedName) ?? (advData?.advName.isNotEmpty == true ? advData!.advName : (device.platformName.isNotEmpty @@ -445,8 +456,6 @@ class _BleDeviceDetailPageState extends State { _buildServicesList(), ], if (_isConnected) ...[ - const SizedBox(height: 16), - _buildCommandSection(), const SizedBox(height: 16), _buildDeviceConfigCard(), const SizedBox(height: 16), @@ -502,14 +511,6 @@ class _BleDeviceDetailPageState extends State { color: Color(0xFF1D2129), ), ), - const SizedBox(height: 4), - Text( - '${widget.device.remoteId}', - style: const TextStyle( - fontSize: 12, - color: Color(0xFF86909C), - ), - ), ], ), ), @@ -520,7 +521,6 @@ class _BleDeviceDetailPageState extends State { const Divider(height: 1, color: Color(0xFFE5E6EB)), const SizedBox(height: 12), _buildInfoRow('设备名称', name), - _buildInfoRow('设备ID', '${widget.device.remoteId}'), if (scanResult != null) ...[ _buildInfoRow('信号强度', '${scanResult.rssi} dBm'), _buildInfoRow( @@ -661,6 +661,25 @@ class _BleDeviceDetailPageState extends State { : Text(_isConnected ? '断开连接' : '连接设备'), ), ), + if (_isConnected) ...[ + const SizedBox(height: 12), + SizedBox( + width: double.infinity, + child: ElevatedButton.icon( + onPressed: _sendReadConfig, + icon: const Icon(Icons.settings, size: 18), + label: const Text('读配置'), + style: ElevatedButton.styleFrom( + backgroundColor: const Color(0xFF165DFF), + foregroundColor: Colors.white, + padding: const EdgeInsets.symmetric(vertical: 12), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + ), + ), + ), + ), + ], ], ), ); @@ -680,21 +699,21 @@ class _BleDeviceDetailPageState extends State { ), ], ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - '服务列表', - style: TextStyle( - fontSize: 15, - fontWeight: FontWeight.bold, - color: Color(0xFF1D2129), - ), - ), - const SizedBox(height: 12), - ..._services.map((service) => _buildServiceTile(service)), - ], - ), + // child: Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // const Text( + // '服务列表', + // style: TextStyle( + // fontSize: 15, + // fontWeight: FontWeight.bold, + // color: Color(0xFF1D2129), + // ), + // ), + // const SizedBox(height: 12), + // ..._services.map((service) => _buildServiceTile(service)), + // ], + // ), ); } @@ -800,55 +819,11 @@ class _BleDeviceDetailPageState extends State { ); } - Widget _buildCommandSection() { - return Container( - padding: const EdgeInsets.all(16), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(12), - boxShadow: [ - BoxShadow( - color: Colors.black.withOpacity(0.05), - blurRadius: 8, - offset: const Offset(0, 2), - ), - ], - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - '发送指令', - style: TextStyle( - fontSize: 15, - fontWeight: FontWeight.bold, - color: Color(0xFF1D2129), - ), - ), - const SizedBox(height: 12), - SizedBox( - width: double.infinity, - child: ElevatedButton.icon( - onPressed: _sendReadConfig, - icon: const Icon(Icons.settings, size: 18), - label: const Text('读配置'), - style: ElevatedButton.styleFrom( - backgroundColor: const Color(0xFF165DFF), - foregroundColor: Colors.white, - padding: const EdgeInsets.symmetric(vertical: 12), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - ), - ), - ), - ), - ], - ), - ); - } - Widget _buildCommLogSection() { - final pushes = _latestPushByCommand.values.toList(); + // 数据推送栏只展示 0x02 状态信息;其余命令(如 0x00 远程遥控、0x05 读配置等)不在此栏渲染。 + final pushes = _latestPushByCommand.values + .where((p) => p.command == MachineProtocolConstants.cmdStatusInfo) + .toList(); return Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( @@ -1063,7 +1038,7 @@ class _BleDeviceDetailPageState extends State { children: [ const Expanded( child: Text( - '设备配置 (0x05)', + '设备配置', style: TextStyle( fontSize: 15, fontWeight: FontWeight.bold,