完善遥控权限、控制发送和急停反馈

This commit is contained in:
2026-11-21 14:37:46 +08:00
parent c284aefc7d
commit 9a8a42a0a1
55 changed files with 5009 additions and 1308 deletions

View File

@@ -0,0 +1,43 @@
import 'package:dio/dio.dart';
import '../../../../core/consts/http_api_consts.dart';
import '../../domain/entities/emergency_stop_target.dart';
class EmergencyStopRemoteDatasource {
const EmergencyStopRemoteDatasource(this.dio);
// 注入统一 Dio,沿用登录鉴权和测试/生产环境配置。
final Dio dio;
Future<void> request(String deviceId, EmergencyStopTarget target) async {
final response = await dio.get<dynamic>(
HttpApiConsts.hostEmergencyStopChange,
queryParameters: {'deviceId': deviceId, 'eStop': target.value},
options: Options(
receiveTimeout: const Duration(seconds: 10),
headers: {'Cache-Control': 'no-store', 'Pragma': 'no-cache'},
),
);
final body = response.data;
// 沿用相邻 /iot/host 接口的业务响应约定;未知响应不视为成功。
if (response.statusCode != 200 || body is! Map || body['code'] == null) {
throw const EmergencyStopRemoteException('急停接口响应格式错误或请求失败');
}
final data = body['data'];
if ('${body['code']}' != '200' ||
data == false ||
body['accepted'] == false ||
(data is Map && data['accepted'] == false)) {
final message = body['msg'];
throw EmergencyStopRemoteException(
message is String && message.trim().isNotEmpty ? message : '急停请求未被接受',
rejected: true,
);
}
}
}
class EmergencyStopRemoteException implements Exception {
const EmergencyStopRemoteException(this.message, {this.rejected = false});
final String message;
final bool rejected;
}