From 81c02c5110df06659705751c4de0529c838c9e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Tue, 18 Feb 2025 15:18:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:TCP=E7=A1=AC=E4=BB=B6=E9=80=9A=E4=BF=A1?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qyft/gd/device/controller/TestController.java | 231 ----------------- .../com/qyft/gd/device/service/DeviceService.java | 280 +++++++++++++++------ src/main/java/com/qyft/gd/service/CMDService.java | 4 +- 3 files changed, 209 insertions(+), 306 deletions(-) diff --git a/src/main/java/com/qyft/gd/device/controller/TestController.java b/src/main/java/com/qyft/gd/device/controller/TestController.java index dc24dc3..3e0fa27 100644 --- a/src/main/java/com/qyft/gd/device/controller/TestController.java +++ b/src/main/java/com/qyft/gd/device/controller/TestController.java @@ -22,237 +22,6 @@ public class TestController { private final DeviceService deviceService; private final DeviceStateService deviceStateService; - @Operation(summary = "开门") - @GetMapping("/openDoor") - public Result openDoor() { - boolean success = deviceService.openDoor(); - if (success) { - return Result.success(); - } else { - return Result.failed("开门失败"); - } - } - - @Operation(summary = "关门") - @GetMapping("/closeDoor") - public Result closeDoor() { - boolean success = deviceService.closeDoor(); - if (success) { - return Result.success(); - } else { - return Result.failed("关门失败"); - } - } - - @Operation(summary = "张开夹爪") - @GetMapping("/openClaw") - public Result openClaw() { - boolean success = deviceService.openClaw(); - if (success) { - return Result.success(); - } else { - return Result.failed("张开夹爪失败"); - } - } - - @Operation(summary = "收合夹爪") - @GetMapping("/closeClaw") - public Result closeClaw() { - boolean success = deviceService.closeClaw(); - if (success) { - return Result.success(); - } else { - return Result.failed("收合夹爪失败"); - } - } - - @Operation(summary = "移动导轨机械臂的导轨") - @GetMapping("/moveRailArmRail") - public Result moveRailArmRail(@RequestParam double distance) { - boolean success = deviceService.moveRailArmRail(distance); - if (success) { - return Result.success(); - } else { - return Result.failed("移动导轨机械臂的导轨失败"); - } - } - - @Operation(summary = "移动导轨机械臂的关节") - @GetMapping("/moveRailArmJoint") - public Result moveRailArmJoint(@RequestParam double joint1, @RequestParam double joint2, @RequestParam double distance) { - boolean success = deviceService.moveRailArmJoint(joint1, joint2, distance); - if (success) { - return Result.success(); - } else { - return Result.failed("移动导轨机械臂的关节失败"); - } - } - - @Operation(summary = "导轨机械臂运动到指定点位") - @GetMapping("/moveRailArmToPoint") - public Result moveRailArmToPoint(@RequestParam int x, @RequestParam int y, @RequestParam int z) { - boolean success = deviceService.moveRailArmToPoint(x, y, z); - if (success) { - return Result.success(); - } else { - return Result.failed("导轨机械臂运动到指定点位失败"); - } - } - - @Operation(summary = "设置导轨机械臂的速度") - @GetMapping("/setRailArmSpeed") - public Result setRailArmSpeed(@RequestParam int speed) { - boolean success = deviceService.setRailArmSpeed(speed); - if (success) { - return Result.success(); - } else { - return Result.failed("设置导轨机械臂的速度失败"); - } - } - - @Operation(summary = "移动加液机械臂的关节") - @GetMapping("/moveLiquidArmJoint") - public Result moveLiquidArmJoint(@RequestParam double joint1, @RequestParam double joint2) { - boolean success = deviceService.moveLiquidArmJoint(joint1, joint2); - if (success) { - return Result.success(); - } else { - return Result.failed("移动加液机械臂的关节失败"); - } - } - - @Operation(summary = "加液机械臂运动到指定点位") - @GetMapping("/moveLiquidArmToPoint") - public Result moveLiquidArmToPoint(@RequestParam int x, @RequestParam int y, @RequestParam int z) { - boolean success = deviceService.moveLiquidArmToPoint(x, y, z); - if (success) { - return Result.success(); - } else { - return Result.failed("加液机械臂运动到指定点位失败"); - } - } - - @Operation(summary = "设置加液机械臂的速度") - @GetMapping("/setLiquidArmSpeed") - public Result setLiquidArmSpeed(@RequestParam int speed) { - boolean success = deviceService.setLiquidArmSpeed(speed); - if (success) { - return Result.success(); - } else { - return Result.failed("设置加液机械臂的速度失败"); - } - } - - @Operation(summary = "加液") - @GetMapping("/addLiquid") - public Result addLiquid(@RequestParam String pumpId, @RequestParam int volume) { - boolean success = deviceService.addLiquid(pumpId, volume); - if (success) { - return Result.success(); - } else { - return Result.failed("加液失败"); - } - } - - @Operation(summary = "设置加液泵流量") - @GetMapping("/setFlowRate") - public Result setFlowRate(@RequestParam int pumpId, @RequestParam int flowRate) { - boolean success = deviceService.setFlowRate(pumpId, flowRate); - if (success) { - return Result.success(); - } else { - return Result.failed("设置加液泵流量失败"); - } - } - - @Operation(summary = "开始摇匀") - @GetMapping("/startShaking") - public Result startShaking() { - boolean success = deviceService.startShaking(); - if (success) { - return Result.success(); - } else { - return Result.failed("开始摇匀失败"); - } - } - - @Operation(summary = "停止摇匀") - @GetMapping("/stopShaking") - public Result stopShaking() { - boolean success = deviceService.stopShaking(); - if (success) { - return Result.success(); - } else { - return Result.failed("停止摇匀失败"); - } - } - - @Operation(summary = "设置摇匀速度") - @GetMapping("/setShakingSpeed") - public Result setShakingSpeed(@RequestParam int speed) { - boolean success = deviceService.setShakingSpeed(speed); - if (success) { - return Result.success(); - } else { - return Result.failed("设置摇匀速度失败"); - } - } - - @Operation(summary = "开始加热") - @GetMapping("/startHeating") - public Result startHeating(@RequestParam String heaterId, @RequestParam Double temperature) { - boolean success = deviceService.startHeating(heaterId, temperature); - if (success) { - return Result.success(); - } else { - return Result.failed("开始加热失败"); - } - } - - @Operation(summary = "停止加热") - @GetMapping("/stopHeating") - public Result stopHeating(@RequestParam String heaterId) { - boolean success = deviceService.stopHeating(heaterId); - if (success) { - return Result.success(); - } else { - return Result.failed("停止加热失败"); - } - } - - @Operation(summary = "抬起托盘到指定高度") - @GetMapping("/moveTrayToHeight") - public Result moveTrayToHeight(@RequestParam double distance) { - boolean success = deviceService.moveTrayToHeight(distance); - if (success) { - return Result.success(); - } else { - return Result.failed("抬起托盘到指定高度失败"); - } - } - - @Operation(summary = "设置托盘抬起速度") - @GetMapping("/setTraySpeed") - public Result setTraySpeed(@RequestParam int speed) { - boolean success = deviceService.setTraySpeed(speed); - if (success) { - return Result.success(); - } else { - return Result.failed("设置托盘抬起速度失败"); - } - } - - @Operation(summary = "拍照") - @GetMapping("/takePhoto") - public Result takePhoto() { - boolean success = deviceService.takePhoto(); - if (success) { - return Result.success(); - } else { - return Result.failed("拍照失败"); - } - } - @Operation(summary = "生成设备状态实体") @GetMapping("/getDeviceStatus") public Result getDeviceStatus() { diff --git a/src/main/java/com/qyft/gd/device/service/DeviceService.java b/src/main/java/com/qyft/gd/device/service/DeviceService.java index 29eefbd..ecb027f 100644 --- a/src/main/java/com/qyft/gd/device/service/DeviceService.java +++ b/src/main/java/com/qyft/gd/device/service/DeviceService.java @@ -78,7 +78,7 @@ public class DeviceService { * * @param speed 速度值 */ - public boolean setRailArmSpeed(int speed) { + public synchronized boolean setRailArmSpeed(int speed) { Map params = new HashMap<>(); params.put("speed", speed); DeviceFeedback deviceFeedback = tcpClient.sendCommand("setRailArmSpeed", params); @@ -90,48 +90,12 @@ public class DeviceService { } /** - * 开门 + * 轨道机械臂移动停止移动 */ - public boolean openDoor() { - DeviceFeedback deviceFeedback = tcpClient.sendCommand("openDoor"); + public synchronized boolean stopRailArm() { + DeviceFeedback deviceFeedback = tcpClient.sendCommand("setRailArmSpeed"); if (deviceFeedback == null || deviceFeedback.getError() != null) { - log.error("TCP openDoor 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); - return false; - } - return true; - } - - /** - * 关门 - */ - public boolean closeDoor() { - DeviceFeedback deviceFeedback = tcpClient.sendCommand("closeDoor"); - if (deviceFeedback == null || deviceFeedback.getError() != null) { - log.error("TCP closeDoor 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); - return false; - } - return true; - } - - /** - * 张开夹爪 - */ - public boolean openClaw() { - DeviceFeedback deviceFeedback = tcpClient.sendCommand("openClaw"); - if (deviceFeedback == null || deviceFeedback.getError() != null) { - log.error("TCP openClaw 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); - return false; - } - return true; - } - - /** - * 收合夹爪 - */ - public boolean closeClaw() { - DeviceFeedback deviceFeedback = tcpClient.sendCommand("closeClaw"); - if (deviceFeedback == null || deviceFeedback.getError() != null) { - log.error("TCP closeClaw 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); + log.error("TCP stopRailArm 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); return false; } return true; @@ -176,11 +140,11 @@ public class DeviceService { } /** - * 设置加液机械臂的速度 + * 设置加液机械臂的移动速度 * * @param speed 速度值 */ - public boolean setLiquidArmSpeed(int speed) { + public synchronized boolean setLiquidArmSpeed(int speed) { Map params = new HashMap<>(); params.put("speed", speed); DeviceFeedback deviceFeedback = tcpClient.sendCommand("setLiquidArmSpeed", params); @@ -192,6 +156,62 @@ public class DeviceService { } /** + * 加液机械臂移动停止 + */ + public synchronized boolean stopLiquidArm() { + DeviceFeedback deviceFeedback = tcpClient.sendCommand("stopLiquidArm"); + if (deviceFeedback == null || deviceFeedback.getError() != null) { + log.error("TCP stopLiquidArm 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); + return false; + } + return true; + } + + /** + * 张开夹爪 + */ + public synchronized boolean openClaw() { + DeviceFeedback deviceFeedback = tcpClient.sendCommand("openClaw"); + if (deviceFeedback == null || deviceFeedback.getError() != null) { + log.error("TCP openClaw 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); + return false; + } + return true; + } + + /** + * 收合夹爪 + */ + public synchronized boolean closeClaw() { + DeviceFeedback deviceFeedback = tcpClient.sendCommand("closeClaw"); + if (deviceFeedback == null || deviceFeedback.getError() != null) { + log.error("TCP closeClaw 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); + return false; + } + return true; + } + + /** + * 设置夹爪移动速度 + * + * @param mode 夹取模式 "FULL_CLOSED":完全闭合 "TUBE_RACK": 夹取试管架 "CAP": 夹取拍子 + * @param speed 电机的速度值 + * @param targetPos 电机目标位置 + */ + public synchronized boolean setClawParams(String mode, int speed, int targetPos) { + Map params = new HashMap<>(); + params.put("mode", mode); + params.put("speed", speed); + params.put("targetPos", targetPos); + DeviceFeedback deviceFeedback = tcpClient.sendCommand("setClawParams", params); + if (deviceFeedback == null || deviceFeedback.getError() != null) { + log.error("TCP setClawParams 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); + return false; + } + return true; + } + + /** * 加液 * * @param pumpId 泵id @@ -209,6 +229,66 @@ public class DeviceService { return true; } + /** + * 设置加热位试管架拍子密封状态 + * + * @param heaterId 加热位id + * @param on true 密封, false 解除密封 + */ + public synchronized boolean setSealLid(int heaterId, boolean on) { + Map params = new HashMap<>(); + params.put("heaterId", heaterId); + params.put("on", on); + DeviceFeedback deviceFeedback = tcpClient.sendCommand("setSealLid", params); + if (deviceFeedback == null || deviceFeedback.getError() != null) { + log.error("TCP setSealLid 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); + return false; + } + return true; + } + + + /** + * 开门 + */ + public synchronized boolean openDoor() { + DeviceFeedback deviceFeedback = tcpClient.sendCommand("openDoor"); + if (deviceFeedback == null || deviceFeedback.getError() != null) { + log.error("TCP openDoor 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); + return false; + } + return true; + } + + /** + * 关门 + */ + public synchronized boolean closeDoor() { + DeviceFeedback deviceFeedback = tcpClient.sendCommand("closeDoor"); + if (deviceFeedback == null || deviceFeedback.getError() != null) { + log.error("TCP closeDoor 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); + return false; + } + return true; + } + + /** + * 设置门参数 + * + * @param speed 电机的速度值 + * @param targetPos 电机目标位置 + */ + public synchronized boolean setDoorParams(int speed, int targetPos) { + Map params = new HashMap<>(); + params.put("speed", speed); + params.put("targetPos", targetPos); + DeviceFeedback deviceFeedback = tcpClient.sendCommand("setDoorParams", params); + if (deviceFeedback == null || deviceFeedback.getError() != null) { + log.error("TCP setDoorParams 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); + return false; + } + return true; + } /** * 设置加液泵流量 @@ -216,7 +296,7 @@ public class DeviceService { * @param pumpId 泵id * @param flowRate 流量值 */ - public boolean setFlowRate(int pumpId, int flowRate) { + public synchronized boolean setFlowRate(int pumpId, int flowRate) { Map params = new HashMap<>(); params.put("pumpId", pumpId); params.put("flowRate", flowRate); @@ -231,7 +311,7 @@ public class DeviceService { /** * 开始摇匀 */ - public boolean startShaking() { + public synchronized boolean startShaking() { DeviceFeedback deviceFeedback = tcpClient.sendCommand("startShaking"); if (deviceFeedback == null || deviceFeedback.getError() != null) { log.error("TCP startShaking 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); @@ -243,7 +323,7 @@ public class DeviceService { /** * 停止摇匀 */ - public boolean stopShaking() { + public synchronized boolean stopShaking() { DeviceFeedback deviceFeedback = tcpClient.sendCommand("stopShaking"); if (deviceFeedback == null || deviceFeedback.getError() != null) { log.error("TCP stopShaking 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); @@ -257,7 +337,7 @@ public class DeviceService { * * @param speed 速度值 */ - public boolean setShakingSpeed(int speed) { + public synchronized boolean setShakingSpeed(int speed) { Map params = new HashMap<>(); params.put("speed", speed); DeviceFeedback deviceFeedback = tcpClient.sendCommand("setShakingSpeed", params); @@ -269,66 +349,120 @@ public class DeviceService { } /** - * 开始加热 + * 抬起托盘 * - * @param heaterId 加热器id - * @param temperature 温度值 + * @param heaterId 加热位ID */ - public boolean startHeating(String heaterId, double temperature) { + public boolean raiseTray(String heaterId) { Map params = new HashMap<>(); params.put("heaterId", heaterId); - params.put("temperature", temperature); - DeviceFeedback deviceFeedback = tcpClient.sendCommand("startHeating", params); + DeviceFeedback deviceFeedback = tcpClient.sendCommand("raiseTray", params); if (deviceFeedback == null || deviceFeedback.getError() != null) { - log.error("TCP startHeating 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); + log.error("TCP raiseTray 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); return false; } return true; } /** - * 停止加热 - * @param heaterId 加热器id + * 放下托盘 + * + * @param heaterId 加热位ID */ - public boolean stopHeating(String heaterId) { + public boolean lowerTray(String heaterId) { Map params = new HashMap<>(); params.put("heaterId", heaterId); - DeviceFeedback deviceFeedback = tcpClient.sendCommand("stopHeating", params); + DeviceFeedback deviceFeedback = tcpClient.sendCommand("lowerTray", params); if (deviceFeedback == null || deviceFeedback.getError() != null) { - log.error("TCP stopHeating 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); + log.error("TCP lowerTray 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); return false; } return true; } + /** + * 设置加热区托盘电机参数 + * + * @param heaterId 加热位ID + * @param speed 电机的速度值 + * @param targetPos 电机目标位置 + */ + public synchronized boolean setTrayParams(int heaterId, int speed, int targetPos) { + Map params = new HashMap<>(); + params.put("heaterId", heaterId); + params.put("speed", speed); + params.put("targetPos", targetPos); + DeviceFeedback deviceFeedback = tcpClient.sendCommand("setTrayParams", params); + if (deviceFeedback == null || deviceFeedback.getError() != null) { + log.error("TCP setTrayParams 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); + return false; + } + return true; + } /** - * 抬起托盘到指定高度 + * 调整拍子存放区高度 * - * @param distance 距离 + * @param level 高度等级 0-6 */ - public boolean moveTrayToHeight(double distance) { + public synchronized boolean setCapHeight(int level) { Map params = new HashMap<>(); - params.put("distance", distance); - DeviceFeedback deviceFeedback = tcpClient.sendCommand("moveTrayToHeight", params); + params.put("level", level); + DeviceFeedback deviceFeedback = tcpClient.sendCommand("setCapHeight", params); if (deviceFeedback == null || deviceFeedback.getError() != null) { - log.error("TCP moveTrayToHeight 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); + log.error("TCP setCapHeight 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); return false; } return true; } /** - * 设置托盘抬起速度 + * 设定拍子存放区电机参数 * - * @param speed 速度值 + * @param speed 电机的速度值 + * @param targetPos 电机每一个等级目标位置 */ - public boolean setTraySpeed(int speed) { + public synchronized boolean setCapParams(int speed, int targetPos) { Map params = new HashMap<>(); params.put("speed", speed); - DeviceFeedback deviceFeedback = tcpClient.sendCommand("setTraySpeed", params); + params.put("targetPos", targetPos); + DeviceFeedback deviceFeedback = tcpClient.sendCommand("setCapParams", params); + if (deviceFeedback == null || deviceFeedback.getError() != null) { + log.error("TCP setCapParams 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); + return false; + } + return true; + } + + /** + * 开始加热 + * + * @param heaterId 加热区id + * @param temperature 温度值 + */ + public boolean startHeating(String heaterId, double temperature) { + Map params = new HashMap<>(); + params.put("heaterId", heaterId); + params.put("temperature", temperature); + DeviceFeedback deviceFeedback = tcpClient.sendCommand("startHeating", params); + if (deviceFeedback == null || deviceFeedback.getError() != null) { + log.error("TCP startHeating 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); + return false; + } + return true; + } + + /** + * 停止加热 + * + * @param heaterId 加热区id + */ + public boolean stopHeating(String heaterId) { + Map params = new HashMap<>(); + params.put("heaterId", heaterId); + DeviceFeedback deviceFeedback = tcpClient.sendCommand("stopHeating", params); if (deviceFeedback == null || deviceFeedback.getError() != null) { - log.error("TCP setTraySpeed 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); + log.error("TCP stopHeating 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); return false; } return true; @@ -337,7 +471,7 @@ public class DeviceService { /** * 拍照 */ - public boolean takePhoto() { + public synchronized boolean takePhoto() { DeviceFeedback deviceFeedback = tcpClient.sendCommand("takePhoto"); if (deviceFeedback == null || deviceFeedback.getError() != null) { log.error("TCP takePhoto 指令执行错误 {}", JSONUtil.toJsonStr(deviceFeedback)); @@ -347,9 +481,9 @@ public class DeviceService { } /** - * 触发报警 + * 测试用,触发报警 */ - public boolean alarmTest(String code, String msg, String module) { + public synchronized boolean alarmTest(String code, String msg, String module) { Map params = new HashMap<>(); params.put("code", code); params.put("msg", msg); diff --git a/src/main/java/com/qyft/gd/service/CMDService.java b/src/main/java/com/qyft/gd/service/CMDService.java index 1c2b3e2..5fb7d61 100644 --- a/src/main/java/com/qyft/gd/service/CMDService.java +++ b/src/main/java/com/qyft/gd/service/CMDService.java @@ -141,13 +141,13 @@ public class CMDService { // 放下托盘 private boolean downTray(CMDForm cmdForm) { List> cmdList = new ArrayList<>(); - cmdList.add(() -> deviceService.moveTrayToHeight((Double) cmdForm.getParams().get("height"))); + cmdList.add(() -> deviceService.lowerTray((String) cmdForm.getParams().get("heaterId"))); return run(cmdList); } // 抬起托盘 private boolean upTray(CMDForm cmdForm) { List> cmdList = new ArrayList<>(); - cmdList.add(() -> deviceService.moveTrayToHeight((Double) cmdForm.getParams().get("height"))); + cmdList.add(() -> deviceService.raiseTray((String) cmdForm.getParams().get("heaterId"))); return run(cmdList); }