Browse Source

同步现场代码

master
白凤吉 2 months ago
parent
commit
17193498c4
  1. 11
      src/main/java/com/iflytop/gd/app/command/control/HeatStartCommand.java
  2. 2
      src/main/java/com/iflytop/gd/app/command/control/HeatStopCommand.java
  3. 20
      src/main/java/com/iflytop/gd/app/command/control/SolutionAddCommand.java
  4. 11
      src/main/java/com/iflytop/gd/app/command/control/TrayDownCommand.java
  5. 10
      src/main/java/com/iflytop/gd/app/controller/TestController.java
  6. 2
      src/main/java/com/iflytop/gd/app/core/CraftsContext.java
  7. 5
      src/main/java/com/iflytop/gd/app/model/bo/status/device/HeatModuleState.java
  8. 4
      src/main/java/com/iflytop/gd/app/model/entity/Container.java
  9. 7
      src/main/java/com/iflytop/gd/app/service/api/ContainerService.java
  10. 15
      src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java
  11. 4
      src/main/java/com/iflytop/gd/app/service/device/DeviceInitService.java
  12. 6
      src/main/java/com/iflytop/gd/app/ws/server/WebSocketSender.java
  13. 5
      src/main/java/com/iflytop/gd/common/constant/WebSocketMessageType.java
  14. 10
      src/main/java/com/iflytop/gd/common/enums/HeatingType.java
  15. 21
      src/main/resources/sql/init.sql

11
src/main/java/com/iflytop/gd/app/command/control/HeatStartCommand.java

@ -2,15 +2,18 @@ package com.iflytop.gd.app.command.control;
import com.iflytop.gd.app.core.BaseCommandHandler;
import com.iflytop.gd.app.model.dto.CmdDTO;
import com.iflytop.gd.app.service.api.DevicePositionService;
import com.iflytop.gd.app.service.device.DeviceStateService;
import com.iflytop.gd.app.service.device.module.HeatModuleService;
import com.iflytop.gd.common.annotation.CommandMapping;
import com.iflytop.gd.common.enums.HeatModuleCode;
import com.iflytop.gd.common.enums.HeatingType;
import com.iflytop.gd.common.enums.data.DevicePositionCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.concurrent.CompletableFuture;
/**
@ -24,14 +27,16 @@ public class HeatStartCommand extends BaseCommandHandler {
private final HeatModuleService heatModuleService;
private final DeviceStateService deviceStateService;
@Override
public CompletableFuture<Void> handle(CmdDTO cmdDTO) {
String heatId = cmdDTO.getStringParam("heatId");
Integer time = cmdDTO.getIntegerParam("time");
Integer minutes = cmdDTO.getIntegerParam("minutes");
Integer seconds = cmdDTO.getIntegerParam("seconds");
Integer time = cmdDTO.getIntegerParam("time");
Integer minutes = cmdDTO.getIntegerParam("minutes");
Integer seconds = cmdDTO.getIntegerParam("seconds");
Double temperature = cmdDTO.getDoubleParam("temperature");
HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatId);
return runAsync(() -> {
heatModuleService.heatRodOpen(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode, temperature);
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTargetTime(time);

2
src/main/java/com/iflytop/gd/app/command/control/HeatStopCommand.java

@ -11,6 +11,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.concurrent.CompletableFuture;
/**
@ -31,6 +32,7 @@ public class HeatStopCommand extends BaseCommandHandler {
return runAsync(() -> {
//关闭加热
heatModuleService.heatRodClose(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode);
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setStartHeatTime(null);
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTargetTime(null);
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setWarmUpTemperature(null);
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatTemperature(null);

20
src/main/java/com/iflytop/gd/app/command/control/SolutionAddCommand.java

@ -5,6 +5,7 @@ import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.iflytop.gd.app.core.BaseCommandHandler;
import com.iflytop.gd.app.model.dto.CmdDTO;
import com.iflytop.gd.app.model.entity.Container;
import com.iflytop.gd.app.service.api.ContainerService;
import com.iflytop.gd.app.service.device.DeviceStateService;
import com.iflytop.gd.app.service.device.module.SolutionModuleService;
@ -21,6 +22,7 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
/**
@ -46,13 +48,13 @@ public class SolutionAddCommand extends BaseCommandHandler {
|| deviceStateService.getCommandMutexState().get().isShakeStartCommandExecuting()) {
throw new AppException(ResultCode.CMD_BUSY);
}
if(deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() != 1){
if (deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() != 1) {
throw new AppException(ResultCode.SOLUTION_MODULE_NO_TRAY);
}
deviceStateService.getCommandMutexState().get().setSolutionAddCommandExecuting(true);
deviceStateService.getDeviceState().getSolutionModule().setPumping(true);
return runAsync(() -> {
try{
try {
JSONArray dataList = JSONUtil.parseArray(cmdDTO.getParams().get("dataList"));
for (int i = 0; i < dataList.size(); i++) {//遍历前端传入的加液配置
JSONObject tubeSol = dataList.getJSONObject(i);
@ -68,11 +70,17 @@ public class SolutionAddCommand extends BaseCommandHandler {
JSONObject addSolution = solutionList.getJSONObject(k);
Long solId = addSolution.getLong("solutionId");
Double volume = addSolution.getDouble("volume");
AcidPumpDeviceCode acidPumpDevice = containerService.getPumpBySolutionId(solId);//获取溶液对应的泵
if (acidPumpDevice == null) {
//AcidPumpDeviceCode acidPumpDevice = containerService.getPumpBySolutionId(solId);//获取溶液对应的泵
Container container = containerService.getContainerBySolutionId(solId);
if (container == null) {
throw new AppException(ResultCode.CRAFT_CONTAINER_NOT_FOUND);//未找到对应溶液容器
}
CommandFuture deviceCommandFuture = solutionModuleService.acidPumpMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDevice, volume);//添加溶液
AcidPumpDeviceCode acidPumpDevice = AcidPumpDeviceCode.valueOf(container.getPumpId());//
int scale = container.getScale() == null ? 120 : container.getScale();//系数
// Integer scale = Optional.ofNullable(container)
// .map(Container::getScale)
// .orElse(500);
CommandFuture deviceCommandFuture = solutionModuleService.acidPumpMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDevice, volume * ((double) scale /100));//添加溶液
futuresList.add(deviceCommandFuture);
}
CommandUtil.wait(futuresList.toArray(new CommandFuture[0]));
@ -81,7 +89,7 @@ public class SolutionAddCommand extends BaseCommandHandler {
solutionModuleService.dualRobotOrigin();
deviceStateService.getCommandMutexState().get().setSolutionAddCommandExecuting(false);
deviceStateService.getDeviceState().getSolutionModule().setPumping(false);
}finally {
} finally {
deviceStateService.getCommandMutexState().get().setSolutionAddCommandExecuting(false);
}

11
src/main/java/com/iflytop/gd/app/command/control/TrayDownCommand.java

@ -40,22 +40,11 @@ public class TrayDownCommand extends BaseCommandHandler {
HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatId);
//从数据库获取加热位下降托盘位置
double trayLower = devicePositionService.getPosition(DevicePositionCode.trayLower).getDistance();
double trayLift = devicePositionService.getPosition(DevicePositionCode.trayLift).getDistance();
return runAsync(() -> {
try {
//下降加热位托盘
heatModuleService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode, trayLower);
deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(0);
// if (deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getHeatingType() == HeatingType.thermostatic) {
// schedulerManager.scheduleOnce(heatModuleCode,() -> {
// try {
// heatModuleService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode, trayLift);
// deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(1);
// } catch (Exception e) {
// log.error("加热完毕抬起托盘错误{}", heatModuleCode, e);
// }
// }, deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTargetTime(), TimeUnit.SECONDS);
// }
} catch (Exception e) {
log.error("降下托盘失败", e);
}

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

@ -6,6 +6,7 @@ import com.iflytop.gd.app.service.api.TestService;
import com.iflytop.gd.app.service.device.DeviceEmergencyStopService;
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.OtherModuleService;
import com.iflytop.gd.app.service.device.module.SolutionModuleService;
import com.iflytop.gd.common.result.Result;
import com.iflytop.gd.hardware.exception.HardwareException;
@ -32,7 +33,7 @@ public class TestController {
private final TestService testService;
private final CapModuleService capModuleService;
private final DeviceStateService deviceStateService;
private final SolutionModuleService solutionModuleService;
private final OtherModuleService otherModuleService;
private final DeviceEmergencyStopService deviceEmergencyStopService;
@Operation(summary = "获取所有传感器读数")
@ -84,4 +85,11 @@ public class TestController {
deviceEmergencyStopService.release();
return Result.success();
}
@Operation(summary = "工艺执行完毕蜂鸣器提醒")
@PostMapping("/crafts-finish-beep-remind")
public Result<?> craftsFinishBeepRemind() throws Exception {
otherModuleService.craftsFinishBeepRemind();
return Result.success();
}
}

2
src/main/java/com/iflytop/gd/app/core/CraftsContext.java

@ -94,7 +94,7 @@ public class CraftsContext implements Runnable {
}
}
if (sm.getState().getId() == CraftStates.RUNNING) {
craftsStepService.finish(heatModuleCode);
craftsStepService.finish(heatModuleCode);//工艺执行完毕将托盘移动至加液模块
Message<CraftEvents> finishMsg = MessageBuilder.withPayload(CraftEvents.FINISH).build();
Mono.from(sm.sendEvent(Mono.just(finishMsg))).block();
}

5
src/main/java/com/iflytop/gd/app/model/bo/status/device/HeatModuleState.java

@ -9,6 +9,8 @@ import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
@Schema(description = "加热模块")
@Data
@Component
@ -46,6 +48,9 @@ public class HeatModuleState {
@Schema(description = "加热器目标加热时间,单位秒")
private Integer targetTime = null;
@Schema(description = "开始加热时间")
private LocalDateTime startHeatTime = null;
@Schema(description = "加热器当前温度")
private Double temperature = null;

4
src/main/java/com/iflytop/gd/app/model/entity/Container.java

@ -34,6 +34,10 @@ public class Container extends BaseEntity {
@Schema(description = "泵id")
private String pumpId;
@Schema(description = "加液系数")
private Integer scale=120;
@Positive(message = "总容量 必须是正数")
@NotNull
@Schema(description = "总容量")

7
src/main/java/com/iflytop/gd/app/service/api/ContainerService.java

@ -33,6 +33,13 @@ public class ContainerService extends ServiceImpl<ContainerMapper, Container> {
}
return null;
}
/**
* 根据溶液id获取容器
*/
public Container getContainerBySolutionId(Long solutionId) {
Container container = this.getOne(new LambdaQueryWrapper<Container>().eq(Container::getSolutionId, solutionId));
return container;
}
/**
* 根据容器id获取泵id

15
src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java

@ -9,20 +9,24 @@ import com.iflytop.gd.app.service.api.ContainerService;
import com.iflytop.gd.app.service.api.DevicePositionService;
import com.iflytop.gd.app.service.device.DeviceCommandTempUtilService;
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.GantryModuleService;
import com.iflytop.gd.app.service.device.module.HeatModuleService;
import com.iflytop.gd.app.service.device.module.SolutionModuleService;
import com.iflytop.gd.app.service.device.module.*;
import com.iflytop.gd.app.ws.server.WebSocketSender;
import com.iflytop.gd.common.enums.AcidPumpDeviceCode;
import com.iflytop.gd.common.enums.HeatModuleCode;
import com.iflytop.gd.common.enums.data.DevicePositionCode;
import com.iflytop.gd.common.exception.AppException;
import com.iflytop.gd.common.result.ResultCode;
import com.iflytop.gd.hardware.drivers.DODriver.OutputIOCtrlDriver;
import com.iflytop.gd.hardware.drivers.TricolorLightDriver;
import com.iflytop.gd.hardware.exception.HardwareException;
import com.iflytop.gd.hardware.type.IO.OutputIOMId;
import com.iflytop.gd.hardware.type.MId;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.concurrent.CompletableFuture;
/**
* 工艺步骤执行服务
*/
@ -40,6 +44,7 @@ public class CraftsStepService {
private final DevicePositionService devicePositionService;
private final DeviceStateService deviceStateService;
private final DeviceCommandTempUtilService deviceCommandTempUtilService;
private final OtherModuleService otherModuleService;
/**
* 执行单个工艺步骤
@ -160,6 +165,8 @@ public class CraftsStepService {
*/
public void finish(HeatModuleCode heatModuleCode) throws Exception {
moveToSolutionModule(heatModuleCode);
//蜂鸣器提示
otherModuleService.craftsFinishBeepRemind();
}
/**

4
src/main/java/com/iflytop/gd/app/service/device/DeviceInitService.java

@ -65,7 +65,7 @@ public class DeviceInitService {
try {
tricolorLightDriver.open(MId.TriColorLight, TricolorLightDriver.Color.BLUE);
} catch (HardwareException e) {
log.error("设备初始化灯光失败,Color.BLUE");
log.error("设备初始化灯光失败,Color.BLUE", e);
}
});
initDeviceState();
@ -75,7 +75,7 @@ public class DeviceInitService {
try {
tricolorLightDriver.open(MId.TriColorLight, TricolorLightDriver.Color.GREEN);
} catch (HardwareException e) {
log.error("设备初始化灯光失败,Color.GREEN");
log.error("设备初始化灯光失败,Color.GREEN", e);
}
deviceStateService.getDeviceState().setInitComplete(true);
log.info("初始化完毕");

6
src/main/java/com/iflytop/gd/app/ws/server/WebSocketSender.java

@ -4,8 +4,10 @@ import cn.hutool.json.JSONUtil;
import com.iflytop.gd.app.model.bo.Notification;
import com.iflytop.gd.app.model.dto.WebsocketResult;
import com.iflytop.gd.common.constant.WebSocketMessageType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class WebSocketSender {
@ -14,6 +16,7 @@ public class WebSocketSender {
websocketResult.setType(type);
websocketResult.setData(data);
WebSocketServer.sendMessageToClients(JSONUtil.toJsonStr(websocketResult));
log.info("WS::{}", JSONUtil.toJsonStr(websocketResult));
}
public void pushCraftsDebug(Object data) {
@ -32,6 +35,9 @@ public class WebSocketSender {
push(WebSocketMessageType.SELF_MOVE_TEST, data);
}
public void pushHeatCountdown(Object data) {
push(WebSocketMessageType.HEAT_COUNTDOWN, data);
}
public void pushNotification(Notification notification) {
push("notification", notification);

5
src/main/java/com/iflytop/gd/common/constant/WebSocketMessageType.java

@ -43,4 +43,9 @@ public class WebSocketMessageType {
*/
public static final String CMD_DEBUG = "cmd_debug";
/**
* 加热倒计时
*/
public static final String HEAT_COUNTDOWN = "heat_countdown";
}

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

@ -8,6 +8,16 @@ import lombok.Getter;
@Getter
public enum HeatingType {
stop,
/**
* 预热中
*/
warm_up,
/**
* 加热中
*/
thermostatic,
/**
* 恒温中
*/
constant,
}

21
src/main/resources/sql/init.sql

@ -50,20 +50,21 @@ CREATE TABLE IF NOT EXISTS container
capacity_total INTEGER,
capacity_used INTEGER,
filled REAL,
scale INTEGER,
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
INSERT OR IGNORE INTO container (id, type, code, solution_id, pump_id, capacity_total, capacity_used)
VALUES (1, 0, 'container_01', 1, 'acid_pump_01', 5000, 0),
(2, 0, 'container_02', 2, 'acid_pump_02', 5000, 2500),
(3, 0, 'container_03', 3, 'acid_pump_03', 5000, 2600),
(4, 0, 'container_04', 4, 'acid_pump_04', 5000, 4000),
(5, 0, 'container_05', 5, 'acid_pump_05', 5000, 2400),
(6, 0, 'container_06', 6, 'acid_pump_06', 5000, 4500),
(7, 0, 'container_07', 7, 'acid_pump_07', 5000, 4900),
(8, 0, 'container_08', 3, 'acid_pump_08', 5000, 100),
(9, 1, 'container_09', NULL, null, 5000, 0);
INSERT OR IGNORE INTO container (id, type, code, solution_id, pump_id, scale,capacity_total, capacity_used)
VALUES (1, 0, 'container_01', 1, 'acid_pump_01', 120,5000, 0),
(2, 0, 'container_02', 2, 'acid_pump_02', 100,5000, 2500),
(3, 0, 'container_03', 3, 'acid_pump_03', 111,5000, 2600),
(4, 0, 'container_04', 4, 'acid_pump_04', 107,5000, 4000),
(5, 0, 'container_05', 5, 'acid_pump_05', 117,5000, 2400),
(6, 0, 'container_06', 6, 'acid_pump_06', 105,5000, 4500),
(7, 0, 'container_07', 7, 'acid_pump_07', 187,5000, 4900),
(8, 0, 'container_08', 3, 'acid_pump_08', 120,5000, 100),
(9, 1, 'container_09', NULL, null, 120,5000, 0);
-- solutions 溶液 表

Loading…
Cancel
Save