and so on
This commit is contained in:
@@ -28,6 +28,7 @@ import '../../domain/entities/drone_station_entity.dart'; // 🔥 添加 DroneSt
|
||||
import 'robot_list_page.dart';
|
||||
import 'robot_control_page.dart';
|
||||
import 'drone_station_detail_page.dart';
|
||||
import '../../../../../core/network/mqtt/data/datasources/drone_osd_datasource.dart';
|
||||
import 'qr_scanner_page.dart';
|
||||
import 'bind_device_page.dart';
|
||||
import '../../../../remote_control/presentation/bloc/remote_control_cubit.dart';
|
||||
@@ -756,6 +757,12 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
return DroneStationItemCard(
|
||||
station: station,
|
||||
onTap: () {
|
||||
// 预启动 OSD 订阅:进入详情页前就让 MQTT 数据流跑起来
|
||||
// 这样详情页一进来就能从 stream 读到数据,无需等待首帧推送
|
||||
sl<DroneOsdDataSource>().startListening(
|
||||
deviceSn: station.deviceSn,
|
||||
gatewaySn: station.gatewaySn,
|
||||
);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
@@ -936,7 +943,8 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
if (result != null && mounted) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => BindDevicePage(scanResult: result),
|
||||
builder: (_) =>
|
||||
BindDevicePage(scanResult: result),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1129,6 +1137,11 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
|
||||
}
|
||||
|
||||
if (matchedStation != null) {
|
||||
// 预启动 OSD 订阅:进入详情页前就让 MQTT 数据流跑起来
|
||||
sl<DroneOsdDataSource>().startListening(
|
||||
deviceSn: matchedStation.deviceSn,
|
||||
gatewaySn: matchedStation.gatewaySn,
|
||||
);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
|
||||
@@ -37,18 +37,22 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
late DroneOsdDataSource _osdDataSource;
|
||||
StreamSubscription<DroneOsdEntity>? _stationOsdSubscription;
|
||||
|
||||
/// 静态缓存:跨页面实例保留上次的 host 数据
|
||||
static final Map<String, dynamic> _cachedHostData = {};
|
||||
/// 静态缓存:按 gatewaySn 分区,跨页面实例保留每个机场上次的 host 数据
|
||||
/// 避免进入新机场时显示上一个机场的缓存数据
|
||||
static final Map<String, Map<String, dynamic>> _cachedHostDataBySn = {};
|
||||
|
||||
final ValueNotifier<Map<String, dynamic>> _stationHostData =
|
||||
ValueNotifier<Map<String, dynamic>>(
|
||||
// 初始化时从缓存加载,进入页面立即显示
|
||||
Map<String, dynamic>.from(_cachedHostData),
|
||||
);
|
||||
ValueNotifier<Map<String, dynamic>>({});
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 进入页面时加载当前机场的缓存数据(切回时立即显示)
|
||||
final cached = _cachedHostDataBySn[widget.station.gatewaySn];
|
||||
if (cached != null && cached.isNotEmpty) {
|
||||
_stationHostData.value = Map<String, dynamic>.from(cached);
|
||||
}
|
||||
|
||||
_bloc = sl<DroneStationBloc>();
|
||||
_bloc.add(
|
||||
UAVDetailLoad(
|
||||
@@ -64,8 +68,10 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
}
|
||||
|
||||
void _startStationOsdListening() {
|
||||
// 使用 station 自带的 deviceSn + gatewaySn,与列表页预订阅参数一致
|
||||
// 避免因参数不同导致 DataSource 重新订阅、打断数据流
|
||||
_osdDataSource.startListening(
|
||||
deviceSn: '',
|
||||
deviceSn: widget.station.deviceSn,
|
||||
gatewaySn: widget.station.gatewaySn,
|
||||
);
|
||||
|
||||
@@ -76,18 +82,32 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
}
|
||||
|
||||
void _parseAndUpdateHostData(DroneOsdEntity osd) {
|
||||
// 防护:验证消息来源 SN 是否匹配当前机场,避免串台
|
||||
final sourceSn = osd.rawData['_sourceSn'];
|
||||
if (sourceSn != null && sourceSn != widget.station.gatewaySn) {
|
||||
debugPrint(
|
||||
'⚠️ [DetailPage] 丢弃非当前机场 OSD: source=$sourceSn, current=${widget.station.gatewaySn}',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final data = osd.rawData;
|
||||
final hostData = data['data'] is Map ? (data['data'] as Map)['host'] : null;
|
||||
if (hostData == null || hostData is! Map) return;
|
||||
|
||||
// 🔥 基于已有数据合并,只更新非 null 字段,避免 Type 2 消息覆盖已有值
|
||||
final Map<String, dynamic> merged = Map<String, dynamic>.from(_stationHostData.value);
|
||||
final Map<String, dynamic> merged = Map<String, dynamic>.from(
|
||||
_stationHostData.value,
|
||||
);
|
||||
|
||||
void _put(String key, dynamic value) {
|
||||
if (value != null) merged[key] = value;
|
||||
}
|
||||
|
||||
_put('environment_temperature', (hostData['environment_temperature'] as num?)?.toDouble());
|
||||
_put(
|
||||
'environment_temperature',
|
||||
(hostData['environment_temperature'] as num?)?.toDouble(),
|
||||
);
|
||||
_put('humidity', (hostData['humidity'] as num?)?.toDouble());
|
||||
_put('wind_speed', (hostData['wind_speed'] as num?)?.toDouble());
|
||||
_put('rainfall', hostData['rainfall']?.toString());
|
||||
@@ -95,7 +115,10 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
_put('drone_in_dock', hostData['drone_in_dock']?.toString());
|
||||
_put('temperature', (hostData['temperature'] as num?)?.toDouble());
|
||||
_put('putter_state', hostData['putter_state']?.toString());
|
||||
_put('supplement_light_state', hostData['supplement_light_state']?.toString());
|
||||
_put(
|
||||
'supplement_light_state',
|
||||
hostData['supplement_light_state']?.toString(),
|
||||
);
|
||||
_put('alarm_state', hostData['alarm_state']?.toString());
|
||||
_put('emergency_stop_state', hostData['emergency_stop_state']?.toString());
|
||||
_put('silent_mode', hostData['silent_mode']?.toString());
|
||||
@@ -104,28 +127,42 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
_put('height', (hostData['height'] as num?)?.toDouble());
|
||||
_put('latitude', (hostData['latitude'] as num?)?.toDouble());
|
||||
_put('longitude', (hostData['longitude'] as num?)?.toDouble());
|
||||
_put('home_position_is_valid', hostData['home_position_is_valid']?.toString());
|
||||
_put(
|
||||
'home_position_is_valid',
|
||||
hostData['home_position_is_valid']?.toString(),
|
||||
);
|
||||
_put('battery_store_mode', hostData['battery_store_mode']?.toString());
|
||||
_put('first_power_on', hostData['first_power_on']?.toString());
|
||||
_put('drone_charge_state', hostData['drone_charge_state']);
|
||||
_put('air_conditioner', hostData['air_conditioner']);
|
||||
_put('network_state', hostData['network_state']);
|
||||
_put('position_state', hostData['position_state']);
|
||||
_put('storage', hostData['storage']);
|
||||
_put('sub_device', hostData['sub_device']);
|
||||
_put('alternate_land_point', hostData['alternate_land_point']);
|
||||
|
||||
if (hostData['air_conditioner'] is Map) {
|
||||
final ac = hostData['air_conditioner'] as Map;
|
||||
_put('air_conditioner_state', ac['air_conditioner_state']?.toString());
|
||||
_put('air_conditioner_switch_time', ac['switch_time']?.toString());
|
||||
// 🔥 优先处理空调信息(确保第一时间解析,避免与其他卡片显示不同步)
|
||||
final acData = hostData['air_conditioner'];
|
||||
if (acData is Map) {
|
||||
_put('air_conditioner', acData);
|
||||
|
||||
// 解析空调开关状态
|
||||
final acStateVal = int.tryParse(acData['air_conditioner_state']?.toString() ?? '') ?? -1;
|
||||
if (acStateVal == 0 || acStateVal == 1) {
|
||||
_put('air_conditioner_state', acStateVal.toString());
|
||||
}
|
||||
|
||||
// 解析空调运行时间
|
||||
final switchTime = acData['switch_time'];
|
||||
if (switchTime != null) {
|
||||
_put('air_conditioner_switch_time', '$switchTime');
|
||||
}
|
||||
}
|
||||
|
||||
_stationHostData.value = merged;
|
||||
// 同步写入静态缓存
|
||||
_cachedHostData
|
||||
..clear()
|
||||
..addAll(merged);
|
||||
// 同步写入按 gatewaySn 分区的静态缓存
|
||||
_cachedHostDataBySn[widget.station.gatewaySn] = Map<String, dynamic>.from(
|
||||
merged,
|
||||
);
|
||||
}
|
||||
|
||||
/// 🔥 页面重新激活时调用(从其他页面返回时)
|
||||
@@ -161,6 +198,9 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
@override
|
||||
void dispose() {
|
||||
_stationOsdSubscription?.cancel();
|
||||
// 只调用 stopListening 减少引用计数,不调用 dispose()
|
||||
// 因为 DroneOsdDataSource 是 LazySingleton,被列表页和详情页共享
|
||||
// 详情页退出后列表页可能仍需要该订阅
|
||||
_osdDataSource.stopListening();
|
||||
_stationHostData.dispose();
|
||||
_bloc.close();
|
||||
@@ -291,11 +331,14 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
|
||||
Widget _buildContent(UAVDetailEntity detail) {
|
||||
_detail = detail;
|
||||
_droneSn = detail.deviceSn;
|
||||
final newDroneSn = detail.deviceSn;
|
||||
|
||||
if (_droneSn != null && _droneSn!.isNotEmpty) {
|
||||
// 只在 droneSn 真正变化时才重新订阅,避免 Bloc 刷新时重复 startListening
|
||||
// 导致引用计数虚增、dispose 时无法真正取消订阅
|
||||
if (newDroneSn != null && newDroneSn.isNotEmpty && newDroneSn != _droneSn) {
|
||||
_droneSn = newDroneSn;
|
||||
_osdDataSource.startListening(
|
||||
deviceSn: _droneSn!,
|
||||
deviceSn: newDroneSn,
|
||||
gatewaySn: widget.station.gatewaySn,
|
||||
);
|
||||
}
|
||||
@@ -499,13 +542,18 @@ class _DroneStationDetailPageState extends State<DroneStationDetailPage> {
|
||||
String acStr = '未知';
|
||||
Color acColor = const Color(0xFF86909C);
|
||||
if (acState != null) {
|
||||
final state = int.tryParse(acState) ?? -1;
|
||||
if (state == 1) {
|
||||
// 🔥 增强兼容性:尝试多种数据格式(int、string等)
|
||||
final acValue = acState is int ? acState : int.tryParse(acState.toString()) ?? -1;
|
||||
if (acValue == 1) {
|
||||
acStr = '开启';
|
||||
acColor = const Color(0xFF00B42A);
|
||||
} else if (state == 0) {
|
||||
} else if (acValue == 0) {
|
||||
acStr = '关闭';
|
||||
acColor = const Color(0xFF86909C);
|
||||
} else if (acValue == 2) {
|
||||
// 部分设备使用 2 表示待机或其他状态
|
||||
acStr = '待机';
|
||||
acColor = const Color(0xFFFF7D00);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:maibu_satabot_v2/core/theme/AppTheme.dart';
|
||||
|
||||
/// 底部导航栏组件
|
||||
class DeviceBottomNavBar extends StatelessWidget {
|
||||
@@ -15,9 +16,9 @@ class DeviceBottomNavBar extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
color: context.appColors.cardBackground,
|
||||
border: Border(
|
||||
top: BorderSide(color: const Color(0xFFF2F3F5), width: 0.5),
|
||||
top: BorderSide(color: context.appColors.divider, width: 0.5),
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
@@ -26,30 +27,35 @@ class DeviceBottomNavBar extends StatelessWidget {
|
||||
child: Row(
|
||||
children: [
|
||||
_buildNavItem(
|
||||
context,
|
||||
icon: Icons.home_outlined,
|
||||
label: '首页',
|
||||
isSelected: currentIndex == 0,
|
||||
onTap: () => onTap(0),
|
||||
),
|
||||
_buildNavItem(
|
||||
context,
|
||||
icon: Icons.devices,
|
||||
label: '设备',
|
||||
isSelected: currentIndex == 1,
|
||||
onTap: () => onTap(1),
|
||||
),
|
||||
_buildNavItem(
|
||||
context,
|
||||
icon: Icons.notifications_outlined,
|
||||
label: '告警',
|
||||
isSelected: currentIndex == 2,
|
||||
onTap: () => onTap(2),
|
||||
),
|
||||
_buildNavItem(
|
||||
context,
|
||||
icon: Icons.assignment_outlined,
|
||||
label: '工单',
|
||||
isSelected: currentIndex == 3,
|
||||
onTap: () => onTap(3),
|
||||
),
|
||||
_buildNavItem(
|
||||
context,
|
||||
icon: Icons.person_outlined,
|
||||
label: '我的',
|
||||
isSelected: currentIndex == 4,
|
||||
@@ -62,7 +68,8 @@ class DeviceBottomNavBar extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNavItem({
|
||||
Widget _buildNavItem(
|
||||
BuildContext context, {
|
||||
required IconData icon,
|
||||
required String label,
|
||||
required bool isSelected,
|
||||
@@ -78,7 +85,7 @@ class DeviceBottomNavBar extends StatelessWidget {
|
||||
icon,
|
||||
color: isSelected
|
||||
? const Color(0xFF004CFD)
|
||||
: const Color(0xFF86909C),
|
||||
: context.appColors.textTertiary,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
@@ -88,7 +95,7 @@ class DeviceBottomNavBar extends StatelessWidget {
|
||||
fontSize: 11,
|
||||
color: isSelected
|
||||
? const Color(0xFF004FFF)
|
||||
: const Color(0xFF86909C),
|
||||
: context.appColors.textTertiary,
|
||||
fontWeight: isSelected ? FontWeight.w500 : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -166,10 +166,29 @@ class _DroneOsdCardState extends State<DroneOsdCard> {
|
||||
oldWidget.gatewaySn != widget.gatewaySn ||
|
||||
oldWidget.isDroneOnline != widget.isDroneOnline) {
|
||||
_subscription?.cancel();
|
||||
// 切换机场/无人机:重置状态,避免显示上一个机场的旧数据
|
||||
_resetStateForNewDevice();
|
||||
_subscribeStream();
|
||||
}
|
||||
}
|
||||
|
||||
/// 切换到新机场/无人机时重置所有状态
|
||||
void _resetStateForNewDevice() {
|
||||
_hasReceivedData = false;
|
||||
_isWaitingForPush = droneTaskStateManager.isWaitingForOsdPush.value;
|
||||
_localWaitTimeoutTimer?.cancel();
|
||||
if (_isWaitingForPush) {
|
||||
_startLocalWaitTimeout();
|
||||
}
|
||||
// 重置所有字段为"未知"
|
||||
for (final def in _fieldDefs) {
|
||||
_valueNotifiers[def.key]?.value = '未知';
|
||||
_colorNotifiers[def.key]?.value = def.defaultColor;
|
||||
}
|
||||
// 触发一次重建以切换回离线/等待卡片
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
droneTaskStateManager.isWaitingForOsdPush.removeListener(_onWaitingChanged);
|
||||
@@ -208,6 +227,12 @@ class _DroneOsdCardState extends State<DroneOsdCard> {
|
||||
}
|
||||
|
||||
void _parseOsdFields(DroneOsdEntity osd) {
|
||||
// 防护:验证消息来源 SN 是否匹配当前无人机,避免串台
|
||||
final sourceSn = osd.rawData['_sourceSn'];
|
||||
if (sourceSn != null && sourceSn != widget.deviceSn) {
|
||||
return;
|
||||
}
|
||||
|
||||
final data = osd.rawData;
|
||||
final dataMap = data['data'] is Map ? data['data'] as Map : null;
|
||||
Map? droneData;
|
||||
|
||||
@@ -182,9 +182,9 @@ class _DroneStationOsdCardState extends State<DroneStationOsdCard> {
|
||||
final Map<String, ValueNotifier<String>> _valueNotifiers = {};
|
||||
final Map<String, ValueNotifier<Color>> _colorNotifiers = {};
|
||||
|
||||
/// 静态缓存:跨页面实例保留上次收到的值,进入页面立即显示
|
||||
static final Map<String, String> _cachedValues = {};
|
||||
static final Map<String, Color> _cachedColors = {};
|
||||
/// 静态缓存:按 gatewaySn 分区,每个机场独立缓存
|
||||
static final Map<String, Map<String, String>> _cachedValuesBySn = {};
|
||||
static final Map<String, Map<String, Color>> _cachedColorsBySn = {};
|
||||
|
||||
/// 是否已收到过有效数据(用于首次标记)
|
||||
bool _hasReceivedData = false;
|
||||
@@ -197,17 +197,18 @@ class _DroneStationOsdCardState extends State<DroneStationOsdCard> {
|
||||
}
|
||||
|
||||
void _initNotifiers() {
|
||||
final sn = widget.gatewaySn;
|
||||
final cachedVals = _cachedValuesBySn[sn] ?? {};
|
||||
final cachedCols = _cachedColorsBySn[sn] ?? {};
|
||||
for (final def in _fieldDefs) {
|
||||
// 优先用缓存值,没有缓存则显示'未知'
|
||||
_valueNotifiers[def.key] = ValueNotifier(
|
||||
_cachedValues[def.key] ?? '未知',
|
||||
);
|
||||
// 优先用该机场的缓存值,没有缓存则显示'未知'
|
||||
_valueNotifiers[def.key] = ValueNotifier(cachedVals[def.key] ?? '未知');
|
||||
_colorNotifiers[def.key] = ValueNotifier(
|
||||
_cachedColors[def.key] ?? def.defaultColor,
|
||||
cachedCols[def.key] ?? def.defaultColor,
|
||||
);
|
||||
}
|
||||
// 如果有缓存数据,标记为已收到
|
||||
if (_cachedValues.isNotEmpty) {
|
||||
// 如果该机场有缓存数据,标记为已收到
|
||||
if (cachedVals.isNotEmpty) {
|
||||
_hasReceivedData = true;
|
||||
}
|
||||
}
|
||||
@@ -218,10 +219,39 @@ class _DroneStationOsdCardState extends State<DroneStationOsdCard> {
|
||||
if (oldWidget.gatewaySn != widget.gatewaySn ||
|
||||
oldWidget.isOnline != widget.isOnline) {
|
||||
_subscription?.cancel();
|
||||
// 切换机场:重置状态,立即清空旧机场数据
|
||||
_resetStateForNewDevice();
|
||||
_subscribeStream();
|
||||
}
|
||||
}
|
||||
|
||||
/// 切换到新机场时重置所有状态
|
||||
/// 优先从静态缓存加载该机场的历史数据(实现切回时立即显示)
|
||||
/// 无缓存则重置为"未知",避免显示上一个机场的旧数据
|
||||
void _resetStateForNewDevice() {
|
||||
final sn = widget.gatewaySn;
|
||||
final cachedVals = _cachedValuesBySn[sn] ?? {};
|
||||
final cachedCols = _cachedColorsBySn[sn] ?? {};
|
||||
|
||||
_hasReceivedData = cachedVals.isNotEmpty;
|
||||
|
||||
for (final def in _fieldDefs) {
|
||||
final newVal = cachedVals[def.key] ?? '未知';
|
||||
final newCol = cachedCols[def.key] ?? def.defaultColor;
|
||||
final vNotifier = _valueNotifiers[def.key];
|
||||
if (vNotifier != null && vNotifier.value != newVal) {
|
||||
vNotifier.value = newVal;
|
||||
}
|
||||
final cNotifier = _colorNotifiers[def.key];
|
||||
if (cNotifier != null && cNotifier.value != newCol) {
|
||||
cNotifier.value = newCol;
|
||||
}
|
||||
}
|
||||
|
||||
// 触发一次重建以切换离线/数据卡片显示
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_subscription?.cancel();
|
||||
@@ -246,10 +276,11 @@ class _DroneStationOsdCardState extends State<DroneStationOsdCard> {
|
||||
/// 更新单个字段的值和颜色(仅当值变化时才触发 ValueNotifier 重建)
|
||||
/// 同时写入静态缓存,下次进入页面可立即显示
|
||||
void _updateField(String key, String value, [Color? color]) {
|
||||
// 写入缓存
|
||||
_cachedValues[key] = value;
|
||||
// 写入该机场的缓存
|
||||
final sn = widget.gatewaySn;
|
||||
_cachedValuesBySn.putIfAbsent(sn, () => {})[key] = value;
|
||||
if (color != null) {
|
||||
_cachedColors[key] = color;
|
||||
_cachedColorsBySn.putIfAbsent(sn, () => {})[key] = color;
|
||||
}
|
||||
final vNotifier = _valueNotifiers[key];
|
||||
if (vNotifier != null && vNotifier.value != value) {
|
||||
@@ -263,13 +294,19 @@ class _DroneStationOsdCardState extends State<DroneStationOsdCard> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _parseOsdFields(DroneOsdEntity osd) {
|
||||
// 防护:验证消息来源 SN 是否匹配当前机场,避免串台
|
||||
final sourceSn = osd.rawData['_sourceSn'];
|
||||
if (sourceSn != null && sourceSn != widget.gatewaySn) {
|
||||
return;
|
||||
}
|
||||
|
||||
final data = osd.rawData;
|
||||
final hostData = data['data'] is Map ? (data['data'] as Map)['host'] : null;
|
||||
if (hostData == null || hostData is! Map) {
|
||||
debugPrint('⚠️ [StationOsdCard] hostData 为空,rawData keys: ${data.keys.toList()}');
|
||||
debugPrint(
|
||||
'⚠️ [StationOsdCard] hostData 为空,rawData keys: ${data.keys.toList()}',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -278,17 +315,35 @@ class _DroneStationOsdCardState extends State<DroneStationOsdCard> {
|
||||
|
||||
// 🔥 调试日志:对比卡片期望的字段 vs 实际推送中存在的字段
|
||||
final expectedKeys = [
|
||||
'air_conditioner', 'cover_state', 'putter_state', 'supplement_light_state',
|
||||
'temperature', 'drone_in_dock', 'drone_charge_state', 'humidity',
|
||||
'wind_speed', 'rainfall', 'environment_temperature', 'alarm_state',
|
||||
'emergency_stop_state', 'silent_mode', 'mode_code', 'network_state',
|
||||
'position_state', 'storage', 'heading', 'height', 'sub_device',
|
||||
'air_conditioner',
|
||||
'cover_state',
|
||||
'putter_state',
|
||||
'supplement_light_state',
|
||||
'temperature',
|
||||
'drone_in_dock',
|
||||
'drone_charge_state',
|
||||
'humidity',
|
||||
'wind_speed',
|
||||
'rainfall',
|
||||
'environment_temperature',
|
||||
'alarm_state',
|
||||
'emergency_stop_state',
|
||||
'silent_mode',
|
||||
'mode_code',
|
||||
'network_state',
|
||||
'position_state',
|
||||
'storage',
|
||||
'heading',
|
||||
'height',
|
||||
'sub_device',
|
||||
'battery_store_mode',
|
||||
];
|
||||
final hostMap = hostData as Map;
|
||||
final found = expectedKeys.where((k) => hostMap.containsKey(k)).toList();
|
||||
final missing = expectedKeys.where((k) => !hostMap.containsKey(k)).toList();
|
||||
debugPrint('[StationOsdCard] host keys(${hostMap.length}): ${hostMap.keys.join(", ")}');
|
||||
debugPrint(
|
||||
'[StationOsdCard] host keys(${hostMap.length}): ${hostMap.keys.join(", ")}',
|
||||
);
|
||||
debugPrint('[StationOsdCard] matched: ${found.join(", ")}');
|
||||
if (missing.isNotEmpty) {
|
||||
debugPrint('[StationOsdCard] MISSING: ${missing.join(", ")}');
|
||||
@@ -303,9 +358,7 @@ class _DroneStationOsdCardState extends State<DroneStationOsdCard> {
|
||||
_updateField(
|
||||
'acState',
|
||||
acState == 1 ? '开启' : '关闭',
|
||||
acState == 1
|
||||
? const Color(0xFF00B42A)
|
||||
: const Color(0xFF86909C),
|
||||
acState == 1 ? const Color(0xFF00B42A) : const Color(0xFF86909C),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -322,9 +375,7 @@ class _DroneStationOsdCardState extends State<DroneStationOsdCard> {
|
||||
_updateField(
|
||||
'coverState',
|
||||
coverState == 1 ? '开启' : '关闭',
|
||||
coverState == 1
|
||||
? const Color(0xFFFF7D00)
|
||||
: const Color(0xFF00B42A),
|
||||
coverState == 1 ? const Color(0xFFFF7D00) : const Color(0xFF00B42A),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -335,23 +386,19 @@ class _DroneStationOsdCardState extends State<DroneStationOsdCard> {
|
||||
_updateField(
|
||||
'putterState',
|
||||
putterState == 1 ? '动作中' : '归位',
|
||||
putterState == 1
|
||||
? const Color(0xFFFF7D00)
|
||||
: const Color(0xFF00B42A),
|
||||
putterState == 1 ? const Color(0xFFFF7D00) : const Color(0xFF00B42A),
|
||||
);
|
||||
}
|
||||
|
||||
// 补光灯
|
||||
final lightState =
|
||||
int.tryParse(hostData['supplement_light_state']?.toString() ?? '') ??
|
||||
-1;
|
||||
-1;
|
||||
if (lightState == 0 || lightState == 1) {
|
||||
_updateField(
|
||||
'lightState',
|
||||
lightState == 1 ? '开启' : '关闭',
|
||||
lightState == 1
|
||||
? const Color(0xFFFF7D00)
|
||||
: const Color(0xFF86909C),
|
||||
lightState == 1 ? const Color(0xFFFF7D00) : const Color(0xFF86909C),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -376,9 +423,7 @@ class _DroneStationOsdCardState extends State<DroneStationOsdCard> {
|
||||
_updateField(
|
||||
'droneDock',
|
||||
droneDock == 1 ? '在库内' : '出库',
|
||||
droneDock == 1
|
||||
? const Color(0xFF00B42A)
|
||||
: const Color(0xFFFF7D00),
|
||||
droneDock == 1 ? const Color(0xFF00B42A) : const Color(0xFFFF7D00),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -391,9 +436,7 @@ class _DroneStationOsdCardState extends State<DroneStationOsdCard> {
|
||||
_updateField(
|
||||
'chargeState',
|
||||
chargeState == 1 ? '充电中' : '未充电',
|
||||
chargeState == 1
|
||||
? const Color(0xFFFF7D00)
|
||||
: const Color(0xFF86909C),
|
||||
chargeState == 1 ? const Color(0xFFFF7D00) : const Color(0xFF86909C),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -423,21 +466,18 @@ class _DroneStationOsdCardState extends State<DroneStationOsdCard> {
|
||||
}
|
||||
|
||||
// 降雨
|
||||
final rainfall =
|
||||
int.tryParse(hostData['rainfall']?.toString() ?? '') ?? -1;
|
||||
final rainfall = int.tryParse(hostData['rainfall']?.toString() ?? '') ?? -1;
|
||||
if (rainfall >= 0) {
|
||||
_updateField(
|
||||
'rainfall',
|
||||
rainfall == 1 ? '降雨中' : '无降雨',
|
||||
rainfall == 1
|
||||
? const Color(0xFF165DFF)
|
||||
: const Color(0xFF00B42A),
|
||||
rainfall == 1 ? const Color(0xFF165DFF) : const Color(0xFF00B42A),
|
||||
);
|
||||
}
|
||||
|
||||
// 外部温度
|
||||
final externalTemp =
|
||||
(hostData['environment_temperature'] as num?)?.toDouble();
|
||||
final externalTemp = (hostData['environment_temperature'] as num?)
|
||||
?.toDouble();
|
||||
if (externalTemp != null) {
|
||||
_updateField(
|
||||
'externalTemp',
|
||||
@@ -457,23 +497,18 @@ class _DroneStationOsdCardState extends State<DroneStationOsdCard> {
|
||||
_updateField(
|
||||
'alarmState',
|
||||
alarmState != 0 ? '告警中' : '无告警',
|
||||
alarmState != 0
|
||||
? const Color(0xFFF53F3F)
|
||||
: const Color(0xFF00B42A),
|
||||
alarmState != 0 ? const Color(0xFFF53F3F) : const Color(0xFF00B42A),
|
||||
);
|
||||
}
|
||||
|
||||
// 急停状态
|
||||
if (hostData.containsKey('emergency_stop_state')) {
|
||||
final emergencyStop =
|
||||
int.tryParse(hostData['emergency_stop_state']?.toString() ?? '') ??
|
||||
0;
|
||||
int.tryParse(hostData['emergency_stop_state']?.toString() ?? '') ?? 0;
|
||||
_updateField(
|
||||
'emergencyStop',
|
||||
emergencyStop == 1 ? '已触发' : '未触发',
|
||||
emergencyStop == 1
|
||||
? const Color(0xFFF53F3F)
|
||||
: const Color(0xFF00B42A),
|
||||
emergencyStop == 1 ? const Color(0xFFF53F3F) : const Color(0xFF00B42A),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -484,9 +519,7 @@ class _DroneStationOsdCardState extends State<DroneStationOsdCard> {
|
||||
_updateField(
|
||||
'silentMode',
|
||||
silentMode == 1 ? '开启' : '关闭',
|
||||
silentMode == 1
|
||||
? const Color(0xFFFF7D00)
|
||||
: const Color(0xFF86909C),
|
||||
silentMode == 1 ? const Color(0xFFFF7D00) : const Color(0xFF86909C),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -577,7 +610,6 @@ class _DroneStationOsdCardState extends State<DroneStationOsdCard> {
|
||||
: const Color(0xFF86909C),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user