白凤吉 2 months ago
parent
commit
12e9cdd771
  1. 24
      src/main/java/com/iflytop/gd/app/command/control/FilledSolutionStopCommand.java
  2. 20
      src/main/java/com/iflytop/gd/app/controller/SystemController.java
  3. 9
      src/main/java/com/iflytop/gd/app/controller/TestController.java
  4. 6
      src/main/java/com/iflytop/gd/app/service/api/SystemConfigService.java
  5. 5
      src/main/java/com/iflytop/gd/app/service/api/TestService.java
  6. 2
      src/main/java/com/iflytop/gd/app/service/device/DeviceEmergencyStopService.java
  7. 54
      src/main/java/com/iflytop/gd/app/service/scheduled/HeatCountdownScheduledTask.java
  8. 4
      src/main/java/com/iflytop/gd/app/ws/client/DeviceEmergencyStopConfig.java
  9. 4
      src/main/java/com/iflytop/gd/common/enums/HeatingType.java
  10. 9
      src/main/java/com/iflytop/gd/common/utils/LocalDateTimeUtil.java

24
src/main/java/com/iflytop/gd/app/command/control/FilledSolutionStopCommand.java

@ -1,6 +1,5 @@
package com.iflytop.gd.app.command.control; package com.iflytop.gd.app.command.control;
import cn.hutool.json.JSONArray;
import com.iflytop.gd.app.core.BaseCommandHandler; import com.iflytop.gd.app.core.BaseCommandHandler;
import com.iflytop.gd.app.model.dto.CmdDTO; import com.iflytop.gd.app.model.dto.CmdDTO;
import com.iflytop.gd.app.service.api.ContainerService; import com.iflytop.gd.app.service.api.ContainerService;
@ -27,17 +26,24 @@ public class FilledSolutionStopCommand extends BaseCommandHandler {
@Override @Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) { public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
return runAsync(() -> { return runAsync(() -> {
JSONArray idJsonArray = cmdDTO.getJSONArrayParam("list");
for (int i = 0; i < idJsonArray.size(); i++) {
String idStr = idJsonArray.getStr(i);
CompletableFuture.runAsync(() -> {
// JSONArray idJsonArray = cmdDTO.getJSONArrayParam("list");
// for (int i = 0; i < idJsonArray.size(); i++) {
// String idStr = idJsonArray.getStr(i);
// CompletableFuture.runAsync(() -> {
// try {
// AcidPumpDeviceCode acidPumpDevice = containerService.getPumpByContainerId(Long.parseLong(idStr));
// solutionModuleService.acidPumpStop(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDevice);
// } catch (Exception e) {
// log.error("停止预充失败", e);
// }
// });
// }
for (AcidPumpDeviceCode acidPumpDeviceCode : AcidPumpDeviceCode.values()) {
try { try {
AcidPumpDeviceCode acidPumpDevice = containerService.getPumpByContainerId(Long.parseLong(idStr));
solutionModuleService.acidPumpStop(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDevice);
solutionModuleService.acidPumpStop(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDeviceCode);
} catch (Exception e) { } catch (Exception e) {
log.error("停止预充失败", e);
log.error("停止预充错误", e);
} }
});
} }
Thread.sleep(1000); Thread.sleep(1000);
solutionModuleService.dualRobotOrigin(); solutionModuleService.dualRobotOrigin();

20
src/main/java/com/iflytop/gd/app/controller/SystemController.java

@ -12,9 +12,6 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.time.Instant;
import java.time.LocalDateTime;
@Tag(name = "系统") @Tag(name = "系统")
@RestController @RestController
@RequestMapping("/api/sys") @RequestMapping("/api/sys")
@ -24,6 +21,19 @@ public class SystemController {
private final SystemConfigService systemConfigService; private final SystemConfigService systemConfigService;
private final DeviceStateService deviceStateService; private final DeviceStateService deviceStateService;
@Operation(summary = "是否启动虚拟模式")
@PostMapping("/virtual")
public Result<?> changeVirtualMode(Boolean mode) {
deviceStateService.getDeviceState().setVirtual(mode);
return Result.success();
}
@Operation(summary = "模拟向硬件写入完毕")
@PostMapping("/initComplete")
public Result<?> setInitComplete(Boolean initComplete) {
deviceStateService.getDeviceState().setInitComplete(initComplete);
return Result.success();
}
@Operation(summary = "系统状态") @Operation(summary = "系统状态")
@GetMapping("/device-status") @GetMapping("/device-status")
@ -38,10 +48,10 @@ public class SystemController {
return Result.success(); return Result.success();
} }
@Operation(summary = "获取系统时间")
@Operation(summary = "获取系统时间 yyyy-MM-dd HH:mm:ss")
@GetMapping("/datetime") @GetMapping("/datetime")
public Result<?> getDatetime() { public Result<?> getDatetime() {
return Result.success(Instant.now().toEpochMilli());
return Result.success(deviceStateService.getDeviceState());
} }
} }

9
src/main/java/com/iflytop/gd/app/controller/TestController.java

@ -7,7 +7,7 @@ import com.iflytop.gd.app.service.device.DeviceEmergencyStopService;
import com.iflytop.gd.app.service.device.DeviceStateService; import com.iflytop.gd.app.service.device.DeviceStateService;
import com.iflytop.gd.app.service.device.module.CapModuleService; import com.iflytop.gd.app.service.device.module.CapModuleService;
import com.iflytop.gd.app.service.device.module.OtherModuleService; import com.iflytop.gd.app.service.device.module.OtherModuleService;
import com.iflytop.gd.app.service.device.module.SolutionModuleService;
import com.iflytop.gd.common.enums.HeatModuleCode;
import com.iflytop.gd.common.result.Result; import com.iflytop.gd.common.result.Result;
import com.iflytop.gd.hardware.exception.HardwareException; import com.iflytop.gd.hardware.exception.HardwareException;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -92,4 +92,11 @@ public class TestController {
otherModuleService.craftsFinishBeepRemind(); otherModuleService.craftsFinishBeepRemind();
return Result.success(); return Result.success();
} }
@Operation(summary = "设置当前温度")
@PostMapping("/set-temperature")
public Result<?> setTemperature(HeatModuleCode code, Double temperature) throws Exception {
testService.setTemperature(code, temperature);
return Result.success();
}
} }

6
src/main/java/com/iflytop/gd/app/service/api/SystemConfigService.java

@ -83,4 +83,10 @@ public class SystemConfigService extends ServiceImpl<SystemConfigMapper, SystemC
} }
} }
public String getDatetime(){
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return now.format(formatter);
}
} }

5
src/main/java/com/iflytop/gd/app/service/api/TestService.java

@ -2,6 +2,7 @@ package com.iflytop.gd.app.service.api;
import com.iflytop.gd.app.model.dto.AllSensorDTO; import com.iflytop.gd.app.model.dto.AllSensorDTO;
import com.iflytop.gd.app.service.device.DeviceStateService; import com.iflytop.gd.app.service.device.DeviceStateService;
import com.iflytop.gd.common.enums.HeatModuleCode;
import com.iflytop.gd.hardware.exception.HardwareException; import com.iflytop.gd.hardware.exception.HardwareException;
import com.iflytop.gd.hardware.service.GDDeviceStatusService; import com.iflytop.gd.hardware.service.GDDeviceStatusService;
import com.iflytop.gd.hardware.type.IO.InputIOMId; import com.iflytop.gd.hardware.type.IO.InputIOMId;
@ -45,4 +46,8 @@ public class TestService {
deviceStateService.getDeviceState().reset(); deviceStateService.getDeviceState().reset();
} }
public void setTemperature(HeatModuleCode code, Double temperature){
deviceStateService.getDeviceState().getHeatModuleByCode(code).setTemperature(temperature);
}
} }

2
src/main/java/com/iflytop/gd/app/service/device/DeviceEmergencyStopService.java

@ -29,7 +29,7 @@ public class DeviceEmergencyStopService {
} }
/** /**
* 处理接触急停
* 处理解除急停
*/ */
public void release(){ public void release(){
commandPoolManager.restartExecutor(); commandPoolManager.restartExecutor();

54
src/main/java/com/iflytop/gd/app/service/scheduled/HeatCountdownScheduledTask.java

@ -32,7 +32,7 @@ public class HeatCountdownScheduledTask {
private final HeatModuleService heatModuleService; private final HeatModuleService heatModuleService;
private final WebSocketSender webSocketSender; private final WebSocketSender webSocketSender;
@Scheduled(fixedRate = 1000)
@Scheduled(fixedDelay = 1000)
public void fetchTemperature() { public void fetchTemperature() {
try { try {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
@ -40,39 +40,43 @@ public class HeatCountdownScheduledTask {
for (HeatModuleState heatModuleState : deviceStateService.getDeviceState().getHeatModule()) { for (HeatModuleState heatModuleState : deviceStateService.getDeviceState().getHeatModule()) {
if (heatModuleState.getHeatingType() == HeatingType.thermostatic) {//如果这个加热模块在加热中 if (heatModuleState.getHeatingType() == HeatingType.thermostatic) {//如果这个加热模块在加热中
if (heatModuleState.getTemperature() + 1 > heatModuleState.getHeatTemperature()) {//当前温度达到目标温度允许有1度以内的误差 if (heatModuleState.getTemperature() + 1 > heatModuleState.getHeatTemperature()) {//当前温度达到目标温度允许有1度以内的误差
heatModuleState.setHeatingType(HeatingType.constant);//修改状态为恒温中
if (heatModuleState.getStartHeatTime() == null) {
//设定开始加热时间
heatModuleState.setStartHeatTime(now); heatModuleState.setStartHeatTime(now);
} else {
LocalDateTime endTime = heatModuleState.getStartHeatTime().minusSeconds(heatModuleState.getTargetTime());
heatModuleState.setHeatingType(HeatingType.constant);//修改状态为恒温中
}
} else if (heatModuleState.getHeatingType() == HeatingType.constant) {
LocalDateTime endTime = heatModuleState.getStartHeatTime().plusSeconds(heatModuleState.getTargetTime());
//判断是否达到目标加热时间 //判断是否达到目标加热时间
if (endTime.isBefore(now)) {//加热完毕
long diffSeconds = Duration.between(now, endTime).getSeconds();//计算剩余时间
if (diffSeconds <= 0) {//加热完毕
double trayLift = devicePositionService.getPosition(DevicePositionCode.trayLift).getDistance(); double trayLift = devicePositionService.getPosition(DevicePositionCode.trayLift).getDistance();
//抬起托盘 //抬起托盘
heatModuleService.heaterMotorMove(heatModuleState.getModuleCode(), trayLift); heatModuleService.heaterMotorMove(heatModuleState.getModuleCode(), trayLift);
heatModuleState.setTrayUp(1); heatModuleState.setTrayUp(1);
//关闭加棒 //关闭加棒
heatModuleService.heatRodClose(heatModuleState.getModuleCode()); heatModuleService.heatRodClose(heatModuleState.getModuleCode());
heatModuleState.setHeatingType(HeatingType.stop);
//还原状态 //还原状态
heatModuleState.setStartHeatTime(null);
heatModuleState.setTargetTime(null);
heatModuleState.setWarmUpTemperature(null);
heatModuleState.setHeatTemperature(null);
heatModuleState.setTargetTemperature(null);
heatModuleState.setHeatingType(HeatingType.stop);
} else {//加热中
long diffSeconds = Duration.between(now, endTime).getSeconds();//计算剩余时间
HeatCountdownVO heatCountdownVO = new HeatCountdownVO();
heatCountdownVO.setHeatModuleCode(heatModuleState.getModuleCode());
heatCountdownVO.setCountdown((int) diffSeconds);
heatCountdownVO.setCountdownStr(LocalDateTimeUtil.formatSecondsToHMS(diffSeconds));
heatCountdownVO.setStartTime(heatModuleState.getStartHeatTime());
heatCountdownVO.setEndTime(endTime);
heatCountdownVOList.add(heatCountdownVO);
}
}
// heatModuleState.setStartHeatTime(null);
// heatModuleState.setTargetTime(null);
// heatModuleState.setWarmUpTemperature(null);
// heatModuleState.setHeatTemperature(null);
// heatModuleState.setTargetTemperature(null);
heatModuleState.setHeatingType(HeatingType.finish);
// HeatCountdownVO heatCountdownVO = new HeatCountdownVO();
// heatCountdownVO.setHeatModuleCode(heatModuleState.getModuleCode());
// heatCountdownVO.setCountdown((int) diffSeconds);
// heatCountdownVO.setCountdownStr("加热完毕");
// heatCountdownVO.setStartTime(heatModuleState.getStartHeatTime());
// heatCountdownVO.setEndTime(endTime);
// heatCountdownVOList.add(heatCountdownVO);
} else {//加热中 推送倒计时
// HeatCountdownVO heatCountdownVO = new HeatCountdownVO();
// heatCountdownVO.setHeatModuleCode(heatModuleState.getModuleCode());
// heatCountdownVO.setCountdown((int) diffSeconds);
// heatCountdownVO.setCountdownStr(LocalDateTimeUtil.formatSecondsToHMS(diffSeconds));
// heatCountdownVO.setStartTime(heatModuleState.getStartHeatTime());
// heatCountdownVO.setEndTime(endTime);
// heatCountdownVOList.add(heatCountdownVO);
} }
} }
} }

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

@ -1,10 +1,6 @@
package com.iflytop.gd.app.ws.client; package com.iflytop.gd.app.ws.client;
import com.iflytop.gd.app.core.CommandPoolManager;
import com.iflytop.gd.app.service.api.CraftsService;
import com.iflytop.gd.app.service.device.DeviceEmergencyStopService; import com.iflytop.gd.app.service.device.DeviceEmergencyStopService;
import com.iflytop.gd.app.service.device.DeviceStateService;
import com.iflytop.gd.app.service.device.DeviceStepCommandService;
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;

4
src/main/java/com/iflytop/gd/common/enums/HeatingType.java

@ -20,4 +20,8 @@ public enum HeatingType {
* 恒温中 * 恒温中
*/ */
constant, constant,
/**
* 加热完成
*/
finish,
} }

9
src/main/java/com/iflytop/gd/common/utils/LocalDateTimeUtil.java

@ -3,16 +3,13 @@ package com.iflytop.gd.common.utils;
public class LocalDateTimeUtil { public class LocalDateTimeUtil {
/** /**
* 秒数格式化为 HH:mm:ss 格式
* @param diffSeconds 两个时间点相差的秒数可以为正或负
* @return 格式化后的 HH:mm:ss 字符串
* 秒数格式化为 mm:ss 格式
*/ */
public static String formatSecondsToHMS(long diffSeconds) { public static String formatSecondsToHMS(long diffSeconds) {
long absSeconds = Math.abs(diffSeconds); long absSeconds = Math.abs(diffSeconds);
long hours = absSeconds / 3600;
long minutes = (absSeconds % 3600) / 60;
long minutes = absSeconds / 60;
long seconds = absSeconds % 60; long seconds = absSeconds % 60;
return String.format("%02d:%02d:%02d", hours, minutes, seconds);
return String.format("%02d:%02d", minutes, seconds);
} }
} }
Loading…
Cancel
Save