对接远程遥控

This commit is contained in:
2026-06-05 19:06:21 +08:00
parent d8879dad62
commit 7c9734d918
53 changed files with 4683 additions and 1612 deletions

View File

@@ -122,7 +122,7 @@ class DeviceHttpDatasourceImpl implements DeviceHttpDatasource {
final responseData = response.data;
logger.logWithLevel('API 响应成功', level: 'INFO', data: {'statusCode': response.statusCode, 'data': response.data});
if (responseData['code'] != 200 || responseData['data'] != true) {
if (responseData['code'] != 200) {
logger.logWithLevel('API 响应失败', level: 'ERROR', data: {'statusCode': response.statusCode, 'data': response.data});
throw Exception(responseData['msg'] ?? '业务异常');
}

View File

@@ -4,15 +4,21 @@ class DeviceAddPathPointModel {
DeviceAddPathPointModel({required this.latitude, required this.longitude});
Map<String, dynamic> toJson() => {'lat': latitude.toString(), 'lon': longitude.toString()};
Map<String, dynamic> toJson() => {
'lat': latitude.toString(),
'lng': longitude.toString(),
};
factory DeviceAddPathPointModel.fromJson(Map<String, dynamic> json) {
return DeviceAddPathPointModel(
latitude: double.parse((json['lat'] ?? json['latitude']).toString()),
longitude: double.parse((json['lon'] ?? json['longitude']).toString()),
longitude: double.parse(
(json['lng'] ?? json['lon'] ?? json['longitude']).toString(),
),
);
}
@override
String toString() => '{lat: ${latitude.toString()}, lon: ${longitude.toString()}}';
String toString() =>
'{lat: ${latitude.toString()}, lon: ${longitude.toString()}}';
}

View File

@@ -4,7 +4,7 @@ class ReferencePoint {
ReferencePoint({required this.lat, required this.lon});
Map<String, dynamic> toJson() => {'lat': lat, 'lon': lon};
Map<String, dynamic> toJson() => {'lat': lat, 'lng': lon};
}
class OuterBoundary {
@@ -13,7 +13,10 @@ class OuterBoundary {
OuterBoundary({required this.position, required this.sideWidth});
Map<String, dynamic> toJson() => {'position': position.map((p) => p.toJson()).toList(), 'sideWidth': sideWidth};
Map<String, dynamic> toJson() => {
'position': position.map((p) => p.toJson()).toList(),
'sideWidth': sideWidth,
};
}
class HoleBoundary {
@@ -36,13 +39,17 @@ class HoleBoundary {
// 一维数组,包装成二维数组 [[p1,p2,p3]]
return [input];
} else {
throw ArgumentError('position 必须是 List<Position> 或 List<List<Position>> 类型');
throw ArgumentError(
'position 必须是 List<Position> 或 List<List<Position>> 类型',
);
}
}
// 核心修改:toJson 输出二维数组格式
Map<String, dynamic> toJson() => {
'position': position.map((innerList) => innerList.map((p) => p.toJson()).toList()).toList(), // 二维数组:[[{lat,lon}], ...]
'position': position
.map((innerList) => innerList.map((p) => p.toJson()).toList())
.toList(), // 二维数组:[[{lat,lon}], ...]
'sideWidth': sideWidth,
};
@@ -53,7 +60,9 @@ class HoleBoundary {
// 2. 遍历外层数组,将每个内层数组转为 List<Position>
final List<List<Position>> position = outerList.map((innerList) {
// 3. 处理内层数组,转为 Position 对象列表
return (innerList as List).map((p) => Position.fromJson(p as Map<String, dynamic>)).toList();
return (innerList as List)
.map((p) => Position.fromJson(p as Map<String, dynamic>))
.toList();
}).toList();
// 4. 提取sideWidth(确保数字类型)
@@ -72,9 +81,10 @@ class Position {
factory Position.fromJson(Map<String, dynamic> json) {
// 安全解析经纬度,避免空值/非数字
final double lat = (json['lat'] as num?)?.toDouble() ?? 0.0;
final double lon = (json['lon'] as num?)?.toDouble() ?? 0.0;
final double lon =
((json['lng'] ?? json['lon']) as num?)?.toDouble() ?? 0.0;
return Position(lat: lat, lon: lon);
}
Map<String, dynamic> toJson() => {'lat': lat, 'lon': lon};
Map<String, dynamic> toJson() => {'lat': lat, 'lng': lon};
}

View File

@@ -75,25 +75,25 @@ class RunningStatusEntity extends Equatable {
logger.logWithLevel(
'字段总数: ${fields.length}',
level: 'DEBUG',
shouldLog: true,
shouldLog: false,
);
if (fields.length > 14) {
logger.logWithLevel(
'qual原始值(fields[14]): "${fields[14]}"',
level: 'DEBUG',
shouldLog: true,
shouldLog: false,
);
logger.logWithLevel(
'satelliteCnt(fields[13]): "${fields[13]}"',
level: 'DEBUG',
shouldLog: true,
shouldLog: false,
);
logger.logWithLevel(
/* logger.logWithLevel(
'headingStatus(fields[15]): "${fields[15]}"',
level: 'DEBUG',
shouldLog: true,
);
);*/
}
// 确保至少有 24 个字段,不足的用默认值填充

View File

@@ -73,10 +73,10 @@ class DeviceStatusBloc extends Bloc<DeviceStatusEvent, DeviceStatusState> {
.map((p) {
try {
final result = utf8.decode(p.payload, allowMalformed: true);
debugPrint('✅ [DeviceStatusBloc] 收到0x02数据: $result');
// debugPrint('✅ [DeviceStatusBloc] 收到0x02数据: $result');
return result;
} catch (e) {
debugPrint('❌ [DeviceStatusBloc] 解码失败: $e');
// debugPrint('❌ [DeviceStatusBloc] 解码失败: $e');
return '';
}
})
@@ -105,7 +105,7 @@ class DeviceStatusBloc extends Bloc<DeviceStatusEvent, DeviceStatusState> {
final gps = GPSEntity(status.latitude, status.longitude);
//debugPrint('✅ [DeviceStatusBloc] 直接解析成功,更新状态:Lat=${gps.latitude}, Lng=${gps.longitude}');
_logger.log('✅ [DeviceStatusBloc] 直接解析成功,更新状态');
// _logger.log('✅ [DeviceStatusBloc] 直接解析成功,更新状态');
// 🔥 关键修复:BLoC有Equatable去重机制,必须创建新对象才能触发UI更新
if (!isClosed) {
@@ -137,12 +137,12 @@ class DeviceStatusBloc extends Bloc<DeviceStatusEvent, DeviceStatusState> {
obstacleFlag: status.obstacleFlag,
);
final newGps = GPSEntity(status.latitude, status.longitude);
debugPrint('📤 [DeviceStatusBloc] emit DeviceStatusUpdated - 电压:${status.voltage}, 电量:${status.battery}, 模式:${status.controlMode}');
// debugPrint('📤 [DeviceStatusBloc] emit DeviceStatusUpdated - 电压:${status.voltage}, 电量:${status.battery}, 模式:${status.controlMode}');
emit(DeviceStatusUpdated(newStatus, newGps));
}
} catch (e, stack) {
//debugPrint('❌ [DeviceStatusBloc] 直接解析异常:$e\n$stack');
_logger.log('❌ [DeviceStatusBloc] 直接解析异常:$e');
// _logger.log('❌ [DeviceStatusBloc] 直接解析异常:$e');
if (!isClosed) {
emit(DeviceStatusError('解析失败:$e'));
}