Browse Source

增加泵位置的获取和ws推送

master
王梦远 4 days ago
parent
commit
c73df2be35
  1. 12
      src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java
  2. 28
      src/main/java/com/iflytop/handacid/app/core/command/DeviceCommandGenerator.java
  3. 13
      src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java
  4. 38
      src/main/java/com/iflytop/handacid/app/websocket/server/WebSocketMessageType.java
  5. 16
      src/main/java/com/iflytop/handacid/app/websocket/server/WebSocketSender.java

12
src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java

@ -11,6 +11,7 @@ import com.iflytop.handacid.app.core.state.DeviceState;
import com.iflytop.handacid.app.model.dto.CommandDTO;
import com.iflytop.handacid.app.service.ChannelCtrlService;
import com.iflytop.handacid.app.service.DeviceCommandService;
import com.iflytop.handacid.app.websocket.server.WebSocketSender;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@ -27,6 +28,7 @@ import java.util.concurrent.CompletableFuture;
public class PumpRotateStartCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private final ChannelCtrlService channelCtrlService;
private final WebSocketSender webSocketSender;
@Override
public CompletableFuture<Void> handle(CommandDTO commandDTO) {
@ -39,11 +41,17 @@ public class PumpRotateStartCommand extends BaseCommandHandler {
throw new IllegalArgumentException("参数 direction 不能为空");
}
return runAsync(() -> {
if(Direction.FORWARD.equals(direction)) {
if (Direction.FORWARD.equals(direction)) {
DeviceCommand getPositionDeviceCommand = channelCtrlService.getPumpForwardRotateCommandByChannel(channelCode);
CommandFuture positionCommandFuture = deviceCommandService.sendCommand(getPositionDeviceCommand);
CommandUtil.wait(positionCommandFuture);
Integer currentPosition = (Integer) positionCommandFuture.getResponseResult().get("position");
DeviceCommand deviceCommand = channelCtrlService.getPumpForwardRotateCommandByChannel(channelCode);
CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand);
CommandUtil.wait(commandFuture);
}else{
Integer newPosition = (Integer) commandFuture.getResponseResult().get("position");
webSocketSender.pushPumpPosition(newPosition - currentPosition);
} else {
DeviceCommand deviceCommand = channelCtrlService.getPumpBackwardRotateCommandByChannel(channelCode);
CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand);
CommandUtil.wait(commandFuture);

28
src/main/java/com/iflytop/handacid/app/core/command/DeviceCommandGenerator.java

@ -64,6 +64,13 @@ public class DeviceCommandGenerator {
}
/**
* 1当前转数
*/
public static DeviceCommand pump1GetPosition() {
return controlCmd(Device.PUMP_1, Action.GET, null);
}
/**
* 2 设置速度
*/
public static DeviceCommand pump2SetSpeed(double speed) {
@ -114,6 +121,13 @@ public class DeviceCommandGenerator {
}
/**
* 2当前转数
*/
public static DeviceCommand pump2GetPosition() {
return controlCmd(Device.PUMP_2, Action.GET, null);
}
/**
* 3 设置速度
*/
public static DeviceCommand pump3SetSpeed(double speed) {
@ -164,6 +178,13 @@ public class DeviceCommandGenerator {
}
/**
* 3当前转数
*/
public static DeviceCommand pump3GetPosition() {
return controlCmd(Device.PUMP_3, Action.GET, null);
}
/**
* 4 设置速度
*/
public static DeviceCommand pump4SetSpeed(double speed) {
@ -212,6 +233,13 @@ public class DeviceCommandGenerator {
public static DeviceCommand pump4Enable() {
return controlCmd(Device.PUMP_4, Action.ENABLE, null);
}
/**
* 4当前转数
*/
public static DeviceCommand pump4GetPosition() {
return controlCmd(Device.PUMP_4, Action.GET, null);
}
//=========================================== 私有方法 ============================================================
/**

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

@ -165,6 +165,19 @@ public class ChannelCtrlService {
};
}
/**
* 根据通道code获取泵转数指令
*/
public DeviceCommand getPumpPositionCommandByChannel(ChannelCode channelCode) {
return switch (channelCode) {
case CHANNEL_1 -> DeviceCommandGenerator.pump1GetPosition();
case CHANNEL_2 -> DeviceCommandGenerator.pump2GetPosition();
case CHANNEL_3 -> DeviceCommandGenerator.pump3GetPosition();
case CHANNEL_4 -> DeviceCommandGenerator.pump4GetPosition();
};
}
/**
* 根据通道code获取泵反转指令
*/

38
src/main/java/com/iflytop/handacid/app/websocket/server/WebSocketMessageType.java

@ -6,54 +6,24 @@ public class WebSocketMessageType {
*/
public static final String STATUS = "status";
/**
* 设备报警
*/
public static final String ALARM = "alarm";
/**
* 滴定日志
*/
public static final String LOG = "log";
/**
* 自检移动电机测试
*/
public static final String SELF_MOVE_TEST = "self_move_test";
/**
* 指令反馈
*/
public static final String CMD_RESPONSE = "cmd_response";
/**
* 工艺执行步骤反馈
*/
public static final String CRAFTS_STEP = "crafts_step";
/**
* 工艺执行状态反馈
*/
public static final String CRAFTS_STATE = "crafts_state";
/**
* 工艺DEBUG
*/
public static final String CRAFTS_DEBUG = "crafts_debug";
/**
* 容器剩余状态
*/
public static final String CONTAINER = "container";
/**
* DEBUG消息推送
*/
public static final String CMD_DEBUG = "cmd_debug";
/**
* 加热倒计时
* 泵转数统计推送
*/
public static final String HEAT_COUNTDOWN = "heat_countdown";
/**
* 照片
*/
public static final String PHOTO = "photo";
public static final String PUMP_POSITION = "pump_position";
}

16
src/main/java/com/iflytop/handacid/app/websocket/server/WebSocketSender.java

@ -19,12 +19,8 @@ public class WebSocketSender {
websocketResult.setData(data);
websocketResult.setTimestamp(Instant.now().toEpochMilli());
WebSocketServer.sendMessageToClients(JSONUtil.toJsonStr(websocketResult));
// log.info("WS::{}", JSONUtil.toJsonStr(websocketResult));
}
public void pushCraftsDebug(Object data) {
push(WebSocketMessageType.CRAFTS_DEBUG, data);
}
public void pushDebug(Object data) {
push(WebSocketMessageType.CMD_DEBUG, data);
@ -44,16 +40,8 @@ public class WebSocketSender {
push(WebSocketMessageType.CMD_RESPONSE, data);
}
public void pushSelfMoveTest(Object data) {
push(WebSocketMessageType.SELF_MOVE_TEST, data);
}
public void pushHeatCountdown(Object data) {
push(WebSocketMessageType.HEAT_COUNTDOWN, data);
public void pushPumpPosition(Object data) {
push(WebSocketMessageType.PUMP_POSITION, data);
}
/* public void pushNotification(Notification notification) {
push("notification", notification);
}*/
}
Loading…
Cancel
Save