Browse Source

feat:手柄控制是否开始预充、加液

master
白凤吉 4 days ago
parent
commit
d08f9091cc
  1. 17
      src/main/java/com/iflytop/handacid/app/command/control/SolutionAddStopCommand.java
  2. 18
      src/main/java/com/iflytop/handacid/app/command/control/SolutionPreFillStopCommand.java
  3. 22
      src/main/java/com/iflytop/handacid/app/core/listener/BleGamepadEventListener.java
  4. 22
      src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java
  5. 65
      src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java

17
src/main/java/com/iflytop/handacid/app/command/control/SolutionAddStopCommand.java

@ -27,28 +27,13 @@ import java.util.concurrent.CompletableFuture;
@RequiredArgsConstructor @RequiredArgsConstructor
@CommandMapping("solution_add_stop") @CommandMapping("solution_add_stop")
public class SolutionAddStopCommand extends BaseCommandHandler { public class SolutionAddStopCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private final ChannelCtrlService channelCtrlService; private final ChannelCtrlService channelCtrlService;
private final DeviceState deviceState;
@Override @Override
public CompletableFuture<Void> handle(CommandDTO commandDTO) { public CompletableFuture<Void> handle(CommandDTO commandDTO) {
return runAsync(() -> { return runAsync(() -> {
List<ChannelState> channelCodeList = deviceState.filterChannelStatesByState(ChannelStateCode.ADD);
deviceState.setSolutionAddStop(true);
try {
List<CommandFuture> commandFutureList = new ArrayList<>();
for (ChannelState channelState : channelCodeList) {
DeviceCommand deviceCommand = channelCtrlService.getPumpStopCommandByChannel(channelState.getChannelCode());
commandFutureList.add(deviceCommandService.sendCommand(deviceCommand));
}
CommandUtil.wait(commandFutureList);
} finally {
for (ChannelState channelCode : channelCodeList) {
channelCode.setStateCode(ChannelStateCode.IDLE);
}
}
channelCtrlService.solutionAddStop();
}); });
} }
} }

18
src/main/java/com/iflytop/handacid/app/command/control/SolutionPreFillStopCommand.java

@ -27,29 +27,13 @@ import java.util.concurrent.CompletableFuture;
@RequiredArgsConstructor @RequiredArgsConstructor
@CommandMapping("solution_pre_fill_stop") @CommandMapping("solution_pre_fill_stop")
public class SolutionPreFillStopCommand extends BaseCommandHandler { public class SolutionPreFillStopCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private final ChannelCtrlService channelCtrlService; private final ChannelCtrlService channelCtrlService;
private final DeviceState deviceState;
@Override @Override
public CompletableFuture<Void> handle(CommandDTO commandDTO) { public CompletableFuture<Void> handle(CommandDTO commandDTO) {
return runAsync(() -> { return runAsync(() -> {
List<ChannelState> channelCodeList = deviceState.filterChannelStatesByState(ChannelStateCode.PRE);
deviceState.setSolutionAddStop(true);
try {
List<CommandFuture> commandFutureList = new ArrayList<>();
for (ChannelState channelState : channelCodeList) {
DeviceCommand deviceCommand = channelCtrlService.getPumpStopCommandByChannel(channelState.getChannelCode());
commandFutureList.add(deviceCommandService.sendCommand(deviceCommand));
}
CommandUtil.wait(commandFutureList);
} finally {
for (ChannelState channelCode : channelCodeList) {
channelCode.setPre(true);
channelCode.setStateCode(ChannelStateCode.IDLE);
}
}
channelCtrlService.solutionPreFillStop();
}); });
} }
} }

22
src/main/java/com/iflytop/handacid/app/core/listener/BleGamepadEventListener.java

@ -1,5 +1,7 @@
package com.iflytop.handacid.app.core.listener; package com.iflytop.handacid.app.core.listener;
import com.iflytop.handacid.app.core.state.DeviceState;
import com.iflytop.handacid.app.service.ChannelCtrlService;
import com.iflytop.handacid.hardware.service.AppEventBusService; import com.iflytop.handacid.hardware.service.AppEventBusService;
import com.iflytop.handacid.hardware.type.A8kPacket; import com.iflytop.handacid.hardware.type.A8kPacket;
import com.iflytop.handacid.hardware.type.CmdId; import com.iflytop.handacid.hardware.type.CmdId;
@ -12,7 +14,6 @@ import org.springframework.stereotype.Component;
/** /**
* 蓝牙手柄按钮事件监听 * 蓝牙手柄按钮事件监听
*
*/ */
@Component @Component
@ -20,6 +21,8 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor @RequiredArgsConstructor
public class BleGamepadEventListener { public class BleGamepadEventListener {
private final AppEventBusService eventBus; private final AppEventBusService eventBus;
private final ChannelCtrlService channelCtrlService;
private final DeviceState deviceState;
@PostConstruct @PostConstruct
synchronized public void init() { synchronized public void init() {
@ -28,6 +31,7 @@ public class BleGamepadEventListener {
/** /**
* 事件总线事件处理 * 事件总线事件处理
*
* @param event e * @param event e
*/ */
private void onAppEvent(AppEvent event) { private void onAppEvent(AppEvent event) {
@ -37,14 +41,24 @@ public class BleGamepadEventListener {
if (CmdId.event_ble_gamepad_liquid_acid.equals(cmdId)) { if (CmdId.event_ble_gamepad_liquid_acid.equals(cmdId)) {
//判断当前的设备状态 //判断当前的设备状态
log.info("蓝牙手柄 加酸按钮 按下"); log.info("蓝牙手柄 加酸按钮 按下");
if(deviceState.isSolutionAdding()){
channelCtrlService.solutionAddStop();
}else{
channelCtrlService.solutionAddStart();
}
} else if (CmdId.event_ble_gamepad_liquid_acid_prefilling.equals(cmdId)) { } else if (CmdId.event_ble_gamepad_liquid_acid_prefilling.equals(cmdId)) {
log.info("蓝牙手柄 预充按钮 按下"); log.info("蓝牙手柄 预充按钮 按下");
if(deviceState.isSolutionPreFillStart()){
channelCtrlService.solutionPreFillStart();
}else{
channelCtrlService.solutionPreFillStop();
} }
else if (CmdId.event_ble_gamepad_connected.equals(cmdId)) {
} else if (CmdId.event_ble_gamepad_connected.equals(cmdId)) {
log.info("蓝牙手柄 连接成功"); log.info("蓝牙手柄 连接成功");
}
else if (CmdId.event_ble_gamepad_disconnected.equals(cmdId)) {
deviceState.setBluetoothConnected(true);
} else if (CmdId.event_ble_gamepad_disconnected.equals(cmdId)) {
log.info("蓝牙手柄 连接断开"); log.info("蓝牙手柄 连接断开");
deviceState.setBluetoothConnected(false);
} }
} }

22
src/main/java/com/iflytop/handacid/app/core/state/DeviceState.java

@ -40,6 +40,9 @@ public class DeviceState {
@Schema(description = "是否是急停状态,true为急停") @Schema(description = "是否是急停状态,true为急停")
private volatile boolean emergencyStop = false; private volatile boolean emergencyStop = false;
@Schema(description = "蓝牙是否连接")
private volatile boolean bluetoothConnected = false;
@Schema(description = "当前登录用户") @Schema(description = "当前登录用户")
private volatile User currentUser; private volatile User currentUser;
@ -51,6 +54,7 @@ public class DeviceState {
json.putOnce("virtual", virtual); json.putOnce("virtual", virtual);
json.putOnce("initComplete", initComplete); json.putOnce("initComplete", initComplete);
json.putOnce("emergencyStop", emergencyStop); json.putOnce("emergencyStop", emergencyStop);
json.putOnce("bluetoothConnected", bluetoothConnected);
json.putOnce("currentUser", currentUser); json.putOnce("currentUser", currentUser);
return json; return json;
} }
@ -81,4 +85,22 @@ public class DeviceState {
.filter(ChannelState::isSelected) .filter(ChannelState::isSelected)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* 是否正在加液
* 如果有任何通道处于 ADD 状态
*/
public boolean isSolutionAdding() {
return channelStateMap.values().stream()
.anyMatch(cs -> cs.getStateCode() == ChannelStateCode.ADD);
}
/**
* 是否正在预充
* 如果有任何通道处于 PRE 状态
*/
public boolean isSolutionPreFillStart() {
return channelStateMap.values().stream()
.anyMatch(cs -> cs.getStateCode() == ChannelStateCode.ADD);
}
} }

65
src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java

@ -74,6 +74,28 @@ public class ChannelCtrlService {
} }
/** /**
* 停止加液
*/
public void solutionAddStop() {
List<ChannelState> channelCodeList = deviceState.filterChannelStatesByState(ChannelStateCode.ADD);
deviceState.setSolutionAddStop(true);
try {
List<CommandFuture> commandFutureList = new ArrayList<>();
for (ChannelState channelState : channelCodeList) {
DeviceCommand deviceCommand = getPumpStopCommandByChannel(channelState.getChannelCode());
commandFutureList.add(deviceCommandService.sendCommand(deviceCommand));
}
CommandUtil.wait(commandFutureList);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
for (ChannelState channelCode : channelCodeList) {
channelCode.setStateCode(ChannelStateCode.IDLE);
}
}
}
/**
* 开始预充 * 开始预充
*/ */
public void solutionPreFillStart() { public void solutionPreFillStart() {
@ -96,6 +118,31 @@ public class ChannelCtrlService {
} }
/** /**
* 结束预充
*/
public void solutionPreFillStop() {
CompletableFuture.runAsync(() -> {
List<ChannelState> channelCodeList = deviceState.filterChannelStatesByState(ChannelStateCode.PRE);
deviceState.setSolutionAddStop(true);
try {
List<CommandFuture> commandFutureList = new ArrayList<>();
for (ChannelState channelState : channelCodeList) {
DeviceCommand deviceCommand = getPumpStopCommandByChannel(channelState.getChannelCode());
commandFutureList.add(deviceCommandService.sendCommand(deviceCommand));
}
CommandUtil.wait(commandFutureList);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
for (ChannelState channelCode : channelCodeList) {
channelCode.setPre(true);
channelCode.setStateCode(ChannelStateCode.IDLE);
}
}
});
}
/**
* 根据通道code获取泵相对移动指令 * 根据通道code获取泵相对移动指令
*/ */
public DeviceCommand getPumpMoveByCommandByChannel(ChannelCode channelCode, Double position) { public DeviceCommand getPumpMoveByCommandByChannel(ChannelCode channelCode, Double position) {
@ -143,23 +190,5 @@ public class ChannelCtrlService {
}; };
} }
/**
* 加液
*
* @param channelCode 通道code
* @param volume 加液量
*/
public void solutionAddStart(ChannelCode channelCode, Double volume) {
}
/**
* 停止加液
*
* @param channelCode 通道code
*/
public void solutionAddStop(ChannelCode channelCode) {
deviceState.getChannelStateMap().get(channelCode).setStateCode(ChannelStateCode.IDLE);
} }
}
Loading…
Cancel
Save