11 changed files with 315 additions and 50 deletions
-
92src/main/java/com/qyft/gd/common/constant/Commands.java
-
28src/main/java/com/qyft/gd/common/result/CMDResultCode.java
-
2src/main/java/com/qyft/gd/config/WebSocketConfig.java
-
46src/main/java/com/qyft/gd/controller/CMDController.java
-
7src/main/java/com/qyft/gd/controller/WebSocketController.java
-
10src/main/java/com/qyft/gd/device/service/DeviceService.java
-
23src/main/java/com/qyft/gd/model/form/CMDForm.java
-
20src/main/java/com/qyft/gd/model/vo/ExecutionResult.java
-
41src/main/java/com/qyft/gd/service/CMDService.java
@ -0,0 +1,92 @@ |
|||
package com.qyft.gd.common.constant; |
|||
|
|||
/** |
|||
* 操作指令 |
|||
*/ |
|||
public class Commands { |
|||
/** |
|||
* 抬起托盘 |
|||
*/ |
|||
public static final String UP_TRAY = "upTray"; |
|||
|
|||
/** |
|||
* 降下托盘 |
|||
*/ |
|||
public static final String DOWN_TRAY = "downTray"; |
|||
|
|||
/** |
|||
* 添加溶液 |
|||
*/ |
|||
public static final String INJECT_FLUID = "injectFluid"; |
|||
|
|||
/** |
|||
* 恒温 |
|||
*/ |
|||
public static final String KEEP_HEAT = "keepHeat"; |
|||
|
|||
/** |
|||
* 移至加液 |
|||
*/ |
|||
public static final String MOVE_TO_ACTION_AREA = "moveToActionArea"; |
|||
|
|||
/** |
|||
* 检查加液位状态(是否被占用) |
|||
*/ |
|||
public static final String CHECK_ACTION_AREA = "checkActionArea"; |
|||
|
|||
/** |
|||
* 摇匀试管架 |
|||
*/ |
|||
public static final String SHAKE_UP = "shakeUp"; |
|||
|
|||
/** |
|||
* 开始加热 |
|||
*/ |
|||
public static final String START_HEAT = "startHeat"; |
|||
|
|||
/** |
|||
* 停止加热 |
|||
*/ |
|||
public static final String STOP_HEAT = "stopHeat"; |
|||
|
|||
/** |
|||
* 拍照 |
|||
*/ |
|||
public static final String TAKE_PHOTO = "takePhoto"; |
|||
|
|||
/** |
|||
* 移至异常区 |
|||
*/ |
|||
public static final String MOVE_TO_UNUSUAL = "moveToUnusual"; |
|||
|
|||
/** |
|||
* 从异常区移回加热区 |
|||
*/ |
|||
public static final String MOVE_TO_HEAT_AREA = "moveToHeatArea"; |
|||
|
|||
/** |
|||
* 取试管架盖 |
|||
*/ |
|||
public static final String TAKE_OFF_CAP = "takeOffCap"; |
|||
|
|||
/** |
|||
* 装回试管架盖 |
|||
*/ |
|||
public static final String PUT_BACK_CAP = "putBackCap"; |
|||
|
|||
/** |
|||
* 机械臂移动至指定坐标(x, y, z) |
|||
*/ |
|||
public static final String MOVE_MACHINE_ARM = "moveMachineArm"; |
|||
|
|||
/** |
|||
* 获取当前某种溶液的数量 |
|||
*/ |
|||
public static final String GET_LIQUID_AMOUNT = "getLiquidAmount"; |
|||
|
|||
/** |
|||
* 移动单个试管 |
|||
*/ |
|||
public static final String MOVE_TUBE = "moveTube"; |
|||
|
|||
} |
@ -0,0 +1,28 @@ |
|||
package com.qyft.gd.common.result; |
|||
|
|||
import com.qyft.gd.system.common.result.IResultCode; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
@AllArgsConstructor |
|||
@NoArgsConstructor |
|||
public enum CMDResultCode implements IResultCode, Serializable { |
|||
SUCCESS("D0000", "执行完毕"), |
|||
FAILURE("D0000", "执行失败"); |
|||
|
|||
@Override |
|||
public String getCode() { |
|||
return code; |
|||
} |
|||
|
|||
@Override |
|||
public String getMsg() { |
|||
return msg; |
|||
} |
|||
|
|||
private String code; |
|||
|
|||
private String msg; |
|||
} |
@ -1,4 +1,4 @@ |
|||
package com.qyft.gd.system.config; |
|||
package com.qyft.gd.config; |
|||
|
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
@ -0,0 +1,46 @@ |
|||
package com.qyft.gd.controller; |
|||
|
|||
import cn.hutool.json.JSONUtil; |
|||
import com.qyft.gd.model.form.CMDForm; |
|||
import com.qyft.gd.service.CMDService; |
|||
import com.qyft.gd.system.common.result.Result; |
|||
import io.swagger.v3.oas.annotations.Operation; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
@Tag(name = "控制指令") |
|||
@RestController |
|||
@RequestMapping("/api/cmd") |
|||
@RequiredArgsConstructor |
|||
@Slf4j |
|||
public class CMDController { |
|||
|
|||
private final CMDService cmdService; |
|||
|
|||
@Operation(summary = "发送指令") |
|||
@PostMapping("/") |
|||
public Result<String> send(@RequestBody CMDForm cmdForm) { |
|||
try { |
|||
String commandId = UUID.randomUUID().toString(); |
|||
if (cmdForm.getCommandId() == null || cmdForm.getCommandId().isEmpty()) { |
|||
cmdForm.setCommandId(commandId); |
|||
} |
|||
log.info("接收到指令: {}", JSONUtil.toJsonStr(cmdForm)); |
|||
if (cmdService.executeCommand(cmdForm)) { |
|||
return Result.success(commandId); |
|||
} else { |
|||
return Result.failed("无效命令"); |
|||
} |
|||
} catch (Exception e) { |
|||
log.error("指令执行异常: {}", JSONUtil.toJsonStr(cmdForm), e); |
|||
return Result.failed("执行失败"); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,10 @@ |
|||
package com.qyft.gd.device.service; |
|||
|
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
@Service |
|||
@RequiredArgsConstructor |
|||
public class DeviceService { |
|||
|
|||
} |
@ -0,0 +1,23 @@ |
|||
package com.qyft.gd.model.form; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import jakarta.validation.constraints.NotBlank; |
|||
import lombok.Data; |
|||
|
|||
import java.util.Map; |
|||
|
|||
@Schema(description = "指令") |
|||
@Data |
|||
public class CMDForm { |
|||
|
|||
@Schema(description = "指令id,不指定后台会自动生成uuid") |
|||
private String commandId; |
|||
|
|||
@NotBlank() |
|||
@Schema(description = "指令类型", example = "upTray") |
|||
private String command; |
|||
|
|||
@Schema(description = "参数") |
|||
private Map<String, Object> params; |
|||
|
|||
} |
@ -0,0 +1,20 @@ |
|||
package com.qyft.gd.model.vo; |
|||
|
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class ExecutionResult { |
|||
/** |
|||
* 任务id |
|||
*/ |
|||
private String commandId; |
|||
/** |
|||
* 执行结果 |
|||
*/ |
|||
private String status; |
|||
/** |
|||
* 结果描述 |
|||
*/ |
|||
private String message; |
|||
|
|||
} |
@ -0,0 +1,41 @@ |
|||
package com.qyft.gd.service; |
|||
|
|||
import com.qyft.gd.common.constant.Commands; |
|||
import com.qyft.gd.common.result.CMDResultCode; |
|||
import com.qyft.gd.device.service.DeviceService; |
|||
import com.qyft.gd.model.form.CMDForm; |
|||
import com.qyft.gd.model.vo.ExecutionResult; |
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.messaging.simp.SimpMessagingTemplate; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
@Service |
|||
@RequiredArgsConstructor |
|||
public class CMDService { |
|||
|
|||
DeviceService deviceService; |
|||
|
|||
private final SimpMessagingTemplate messagingTemplate; |
|||
|
|||
public boolean executeCommand(CMDForm cmdForm) { |
|||
switch (cmdForm.getCommand()) { |
|||
case Commands.UP_TRAY: |
|||
upTray(cmdForm); |
|||
break; |
|||
case Commands.DOWN_TRAY: |
|||
break; |
|||
default: |
|||
return false; |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
private void upTray(CMDForm cmdForm) { |
|||
ExecutionResult executionResult = new ExecutionResult(); |
|||
executionResult.setCommandId(cmdForm.getCommandId()); |
|||
executionResult.setStatus(CMDResultCode.SUCCESS.getCode()); |
|||
executionResult.setMessage(CMDResultCode.SUCCESS.getMsg()); |
|||
messagingTemplate.convertAndSend("/topic/cmd", executionResult); |
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue