Browse Source

add:蜂鸣器打开新增参数 增加deviceStopService服务

master
王梦远 2 months ago
parent
commit
e9e5eb7182
  1. 36
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugBeeCloseCommand.java
  2. 38
      src/main/java/com/iflytop/sgs/app/cmd/debug/DebugBeeOpenCommand.java
  3. 32
      src/main/java/com/iflytop/sgs/app/service/device/DeviceStopService.java
  4. 4
      src/main/java/com/iflytop/sgs/app/ws/client/DeviceEmergencyStopConfig.java
  5. 4
      src/main/java/com/iflytop/sgs/common/cmd/DeviceCommandGenerator.java
  6. 1
      src/main/java/com/iflytop/sgs/common/cmd/DeviceCommandParams.java

36
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugBeeCloseCommand.java

@ -0,0 +1,36 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.device.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandDebugMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import com.iflytop.sgs.common.utils.CommandUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 蜂鸣器关闭
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandDebugMapping("door_close")
public class DebugBeeCloseCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> {
DeviceCommandBundle beepCloseDeviceCommandBundle = DeviceCommandGenerator.beepClose();
CommandFuture doorSetDeviceCommandSetFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), beepCloseDeviceCommandBundle);
CommandUtil.wait(doorSetDeviceCommandSetFuture);
});
}
}

38
src/main/java/com/iflytop/sgs/app/cmd/debug/DebugBeeOpenCommand.java

@ -0,0 +1,38 @@
package com.iflytop.sgs.app.cmd.debug;
import com.iflytop.sgs.app.core.BaseCommandHandler;
import com.iflytop.sgs.app.model.dto.CmdDTO;
import com.iflytop.sgs.app.service.device.DeviceCommandService;
import com.iflytop.sgs.common.annotation.CommandDebugMapping;
import com.iflytop.sgs.common.cmd.CommandFuture;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import com.iflytop.sgs.common.utils.CommandUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture;
/**
* 蜂鸣器打开
*/
@Slf4j
@Component
@RequiredArgsConstructor
@CommandDebugMapping("door_close")
public class DebugBeeOpenCommand extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
String mode = cmdDTO.getStringParam("mode");
return runAsync(() -> {
DeviceCommandBundle beeOpenDeviceCommand = DeviceCommandGenerator.beepOpen(mode);
CommandFuture doorMoveDeviceCommandFuture = deviceCommandService.sendCommand(cmdDTO.getCommandId(), cmdDTO.getCommand(), beeOpenDeviceCommand);
CommandUtil.wait(doorMoveDeviceCommandFuture);
});
}
}

32
src/main/java/com/iflytop/sgs/app/service/device/DeviceStopService.java

@ -0,0 +1,32 @@
package com.iflytop.sgs.app.service.device;
import com.iflytop.sgs.common.cmd.DeviceCommandBundle;
import com.iflytop.sgs.common.cmd.DeviceCommandGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service
@RequiredArgsConstructor
public class DeviceStopService {
private final DeviceCommandService deviceCommandService;
public void stopAll() {
//门电机
DeviceCommandBundle doorStopDeviceCommandBundle = DeviceCommandGenerator.doorStop();
deviceCommandService.sendCommand(null, null, doorStopDeviceCommandBundle);
//x轴
DeviceCommandBundle xStopDeviceCommandBundle = DeviceCommandGenerator.transferXStop();
deviceCommandService.sendCommand(null, null, xStopDeviceCommandBundle);
//z轴
DeviceCommandBundle yStopDeviceCommandBundle = DeviceCommandGenerator.transferZStop();
deviceCommandService.sendCommand(null, null, yStopDeviceCommandBundle);
//机械臂
DeviceCommandBundle liquidMotorStopDeviceCommandBundle = DeviceCommandGenerator.liquidMotorStop();
deviceCommandService.sendCommand(null, null, liquidMotorStopDeviceCommandBundle);
//蠕动泵
DeviceCommandBundle liquidPumpStopDeviceCommandBundle = DeviceCommandGenerator.liquidPumpStop();
deviceCommandService.sendCommand(null, null, liquidPumpStopDeviceCommandBundle);
}
}

4
src/main/java/com/iflytop/sgs/app/ws/client/DeviceEmergencyStopConfig.java

@ -2,6 +2,7 @@ package com.iflytop.sgs.app.ws.client;
import com.iflytop.sgs.app.core.CommandPoolManager; import com.iflytop.sgs.app.core.CommandPoolManager;
import com.iflytop.sgs.app.service.device.DeviceStateService; import com.iflytop.sgs.app.service.device.DeviceStateService;
import com.iflytop.sgs.app.service.device.DeviceStopService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -16,6 +17,7 @@ import java.net.URI;
public class DeviceEmergencyStopConfig { public class DeviceEmergencyStopConfig {
private final DeviceStateService deviceStateService; private final DeviceStateService deviceStateService;
private final CommandPoolManager commandPoolManager; private final CommandPoolManager commandPoolManager;
private final DeviceStopService deviceStopService;
@Value("${iflytophald.ip}") @Value("${iflytophald.ip}")
String ip; String ip;
@ -31,7 +33,7 @@ public class DeviceEmergencyStopConfig {
log.info("触发急停{}", s); log.info("触发急停{}", s);
try { try {
commandPoolManager.forceShutdownAll();//强制终止现在运行的所有指令 commandPoolManager.forceShutdownAll();//强制终止现在运行的所有指令
//stepCommandService.stopAll();
deviceStopService.stopAll();
deviceStateService.getDeviceState().setEmergencyStop(true); deviceStateService.getDeviceState().setEmergencyStop(true);
} catch (Exception e) { } catch (Exception e) {
log.error("设备急停失败:{}", e.getMessage()); log.error("设备急停失败:{}", e.getMessage());

4
src/main/java/com/iflytop/sgs/common/cmd/DeviceCommandGenerator.java

@ -558,7 +558,9 @@ public class DeviceCommandGenerator {
* 蜂鸣器 * 蜂鸣器
* *
*/ */
public static DeviceCommandBundle beepOpen() {
public static DeviceCommandBundle beepOpen(String mode) {
DeviceCommandParams params = new DeviceCommandParams();
params.setMode(mode);
return controlCmd(CmdDevice.beep, CmdAction.open, null, "蜂鸣器 开启"); return controlCmd(CmdDevice.beep, CmdAction.open, null, "蜂鸣器 开启");
} }

1
src/main/java/com/iflytop/sgs/common/cmd/DeviceCommandParams.java

@ -22,4 +22,5 @@ public class DeviceCommandParams {
private Double y; private Double y;
private Double z; private Double z;
private Integer channel; private Integer channel;
private String mode;
} }
Loading…
Cancel
Save