merge commit

This commit is contained in:
Chen Li
2025-08-22 17:35:02 +08:00
parent 926f162287
commit e39f42a3df
6 changed files with 71 additions and 59 deletions

View File

@@ -9,8 +9,7 @@ class VehicleCommandService {
Future<VehicleCommandResponse?> getCommandFromText(String text) async {
try {
final uri = Uri.parse(
'http://143.64.185.20:18606/control');
final uri = Uri.parse('http://143.64.185.20:18606/control');
final response = await http.post(
uri,
@@ -24,9 +23,9 @@ class VehicleCommandService {
final commandList = decoded['commands'];
List<VehicleCommand> vehicleCommandList = (commandList as List)
.map<VehicleCommand>((item) => VehicleCommand.fromString(
item['command'] as String,
item['params'] as Map<String, dynamic>?,
item['error'] ?? ''))
item['command'] as String,
item['params'] as Map<String, dynamic>?,
item['error'] ?? ''))
.toList();
return VehicleCommandResponse(tips: tips, commands: vehicleCommandList);
} else {
@@ -40,30 +39,23 @@ class VehicleCommandService {
}
}
// 执行车辆控制命令的方法
Future<bool> executeCommand(VehicleCommand command) async {
Future<String> getControlResponse(List<String> successCommandList) async {
String reply = "";
try {
final uri = Uri.parse('http://143.64.185.20:18607/executeCommand');
final uri = Uri.parse('http://143.64.185.20:18606/control_resp');
final response = await http.post(
uri,
headers: {'Content-Type': 'application/json'},
body: json.encode({
'command': command.commandString, // 使用getter转换为字符串
'params': command.params,
}),
body: json.encode(successCommandList),
);
if (response.statusCode == 200) {
print('命令执行成功: ${command.commandString}');
return true;
return response.body;
} else {
print('命令执行失败: ${response.statusCode}, ${response.body}');
return false;
print("请求控制回复失败: ${response.statusCode}");
}
} catch (e) {
print('命令执行出错: $e');
return false;
print('请求控制回复异常: $e');
}
return reply;
}
}