完成远程控制页面中急停的长按选中类别的操作-待测试
This commit is contained in:
@@ -36,7 +36,7 @@ class RemoteControlRepositoryImpl implements RemoteControlRepository {
|
||||
|
||||
debugPrint('🎮 [摇杆数据] originX: ${status.originX}, originY: ${status.originY}');
|
||||
debugPrint('⚙️ [电机速度] left: ${speeds['left']}, right: ${speeds['right']}');
|
||||
|
||||
debugPrint('🚨 [急停状态] emergency: ${status.isEmergency ? 1 : 0}');
|
||||
|
||||
// 2. 调用 Codec:仅生成协议要求的 8 字节 Payload 负载数据
|
||||
final payload = MachineProtocolCodec.encodeRemoteControlPayload(
|
||||
@@ -48,13 +48,14 @@ class RemoteControlRepositoryImpl implements RemoteControlRepository {
|
||||
emergency: status.isEmergency ? 1 : 0,
|
||||
);
|
||||
debugPrint('📦 [发送数据] payload: ${payload}');
|
||||
|
||||
debugPrint('📦 [发送数据] emergency 字节值:${payload[7]}');
|
||||
// 3. 调用 TcpClient:发送指令。
|
||||
// TcpClient.sendRaw 会自动帮你加上 [0xAB, 0xAA] 头和 [0xAA, 0xAB] 尾
|
||||
_tcpClient.sendRaw(
|
||||
MachineProtocolConstants.cmdRemoteControl, // 这里通常是 0x00
|
||||
payload,
|
||||
);
|
||||
debugPrint('✅ [TCP] 指令已发送');
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/data/models/running_status_model.dart';
|
||||
import 'package:maibu_satabot_v2/features/remote_control/presentation/bloc/remote_control_state.dart';
|
||||
@@ -134,13 +135,19 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
|
||||
// 4. 更新功能开关 (比如割刀速度、灯光、点火等)
|
||||
void updateFunction({int? mower, int? lift, int? ignition, bool? emergency}) {
|
||||
debugPrint('🔧 [updateFunction] 调用 - mower: $mower, lift: $lift, ignition: $ignition, emergency: $emergency');
|
||||
final updatedEntity = state.controlEntity.copyWith(
|
||||
mower: mower,
|
||||
lift: lift,
|
||||
ignition: ignition,
|
||||
emergency: emergency,
|
||||
);
|
||||
emit(state.copyWith(controlEntity: updatedEntity));
|
||||
//emit(state.copyWith(controlEntity: updatedEntity));
|
||||
emit(state.copyWith(
|
||||
controlEntity: updatedEntity,
|
||||
isEmergency: emergency ?? state.isEmergency,
|
||||
));
|
||||
debugPrint('✅ [updateFunction] 状态已更新并 emit');
|
||||
}
|
||||
|
||||
void updateOriginY(int y) {
|
||||
@@ -186,7 +193,10 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
|
||||
void updateChassisLift(int i) {}
|
||||
|
||||
void updateEmergency(bool bool) {}
|
||||
void updateEmergency(bool bool) {
|
||||
debugPrint('🚨 [急停] ${bool ? "触发急停!" : "解除急停"}');
|
||||
updateFunction(emergency: bool);
|
||||
}
|
||||
|
||||
void respondPermission(bool bool, String deviceId) {
|
||||
emit(state.copyWith(showPermissionRequestDialog: false));
|
||||
@@ -243,16 +253,19 @@ class RemoteControlCubit extends Cubit<RemoteControlState> {
|
||||
}
|
||||
/// 发送底盘指令
|
||||
void sendChassisCommand(int i) {
|
||||
debugPrint(' [底盘指令] ${i}');
|
||||
updateFunction(lift: i);
|
||||
}
|
||||
/// 发送割刀指令
|
||||
void sendMowerCommand(int i) {
|
||||
debugPrint(' [割刀指令] ${i}');
|
||||
updateFunction(mower: i);
|
||||
}
|
||||
/// 发送点火指令
|
||||
void sendFireCommand(int i) {
|
||||
//void updateFunction({int? mower, int? lift, int? ignition, bool? emergency})
|
||||
// updateFunction(mower:0, lift: 0, ignition: i, emergency: false);
|
||||
debugPrint(' [点火指令] ${i}');
|
||||
updateFunction(ignition: i);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user