|
|
@ -4,7 +4,6 @@ import cn.hutool.json.JSONUtil; |
|
|
|
import com.qyft.gd.common.constant.Commands; |
|
|
|
import com.qyft.gd.common.result.CMDResultCode; |
|
|
|
import com.qyft.gd.config.WebSocketServer; |
|
|
|
import com.qyft.gd.device.model.bo.DeviceStatus; |
|
|
|
import com.qyft.gd.device.service.DeviceService; |
|
|
|
import com.qyft.gd.device.service.DeviceStateService; |
|
|
|
import com.qyft.gd.model.form.CMDForm; |
|
|
@ -13,7 +12,6 @@ import com.qyft.gd.model.vo.WebsocketResult; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.sql.Array; |
|
|
|
import java.util.*; |
|
|
|
import java.util.function.Function; |
|
|
|
import java.util.function.Supplier; |
|
|
@ -24,6 +22,7 @@ public class CMDService { |
|
|
|
DeviceService deviceService; |
|
|
|
DeviceStateService deviceStateService; |
|
|
|
Map<String, Function<CMDForm, Boolean>> commandMap; |
|
|
|
CMDForm form = new CMDForm(); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
public CMDService(DeviceService deviceService) { |
|
|
@ -33,15 +32,11 @@ public class CMDService { |
|
|
|
commandMap.put(Commands.UP_TRAY, this::upTray); |
|
|
|
commandMap.put(Commands.DOWN_TRAY, this::downTray); |
|
|
|
commandMap.put(Commands.INJECT_FLUID, this::injectFluid); |
|
|
|
commandMap.put(Commands.KEEP_HEAT, this::keepHeat); |
|
|
|
commandMap.put(Commands.MOVE_TO_ACTION_AREA, this::moveToActionArea); |
|
|
|
commandMap.put(Commands.CHECK_ACTION_AREA, this::checkActionArea); |
|
|
|
commandMap.put(Commands.SHAKE_UP, this::shakeUp); |
|
|
|
commandMap.put(Commands.START_HEAT, this::startHeat); |
|
|
|
commandMap.put(Commands.STOP_HEAT, this::stopHeat); |
|
|
|
commandMap.put(Commands.TAKE_PHOTO, this::takePhoto); |
|
|
|
commandMap.put(Commands.MOVE_TO_UNUSUAL, this::moveToUnusual); |
|
|
|
commandMap.put(Commands.MOVE_TO_HEAT_AREA, this::moveToHeatArea); |
|
|
|
commandMap.put(Commands.TAKE_OFF_CAP, this::takeOffCap); |
|
|
|
commandMap.put(Commands.PUT_BACK_CAP, this::putBackCap); |
|
|
|
commandMap.put(Commands.MOVE_MACHINE_ARM, this::moveMachineArm); |
|
|
@ -73,16 +68,6 @@ public class CMDService { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
// 移出异常 |
|
|
|
private Boolean moveToHeatArea(CMDForm cmdForm) { |
|
|
|
//TODO 执行指令 |
|
|
|
return true; |
|
|
|
} |
|
|
|
// 移至异常 |
|
|
|
private Boolean moveToUnusual(CMDForm cmdForm) { |
|
|
|
//TODO 获取异常区位置 |
|
|
|
return true; |
|
|
|
} |
|
|
|
// 拍照 |
|
|
|
private Boolean takePhoto(CMDForm cmdForm) { |
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
@ -92,72 +77,68 @@ public class CMDService { |
|
|
|
// 停止加热 |
|
|
|
private Boolean stopHeat(CMDForm cmdForm) { |
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
cmdList.add(() -> deviceService.stopHeating()); |
|
|
|
cmdList.add(() -> deviceService.stopHeating((String) cmdForm.getParams().get("areaId"))); |
|
|
|
return run(cmdList); |
|
|
|
} |
|
|
|
// 开始加热 |
|
|
|
private Boolean startHeat(CMDForm cmdForm) { |
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
cmdList.add(() -> deviceService.startHeating((String) cmdForm.getParams().get("heaterId"),(Double) cmdForm.getParams().get("temperature"))); |
|
|
|
cmdList.add(() -> deviceService.startHeating((String) cmdForm.getParams().get("areaId"),(Double) cmdForm.getParams().get("temperature"))); |
|
|
|
return run(cmdList); |
|
|
|
} |
|
|
|
// 摇匀 |
|
|
|
private Boolean shakeUp(CMDForm cmdForm) { |
|
|
|
deviceService.startShaking(); |
|
|
|
Timer timer = new Timer(); |
|
|
|
TimerTask task = new TimerTask() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
deviceService.stopShaking(); |
|
|
|
} |
|
|
|
}; |
|
|
|
timer.schedule(task, 1000); |
|
|
|
return true; |
|
|
|
} |
|
|
|
// 检查加液位状态(是否被占用) |
|
|
|
private Boolean checkActionArea(CMDForm cmdForm) { |
|
|
|
// deviceService.startShaking(); |
|
|
|
// Timer timer = new Timer(); |
|
|
|
// TimerTask task = new TimerTask() { |
|
|
|
// @Override |
|
|
|
// public void run() { |
|
|
|
// deviceService.stopShaking(); |
|
|
|
// } |
|
|
|
// }; |
|
|
|
// timer.schedule(task, 1000); |
|
|
|
// return true; |
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
cmdList.add(() -> deviceService.startShaking()); |
|
|
|
cmdList.add(() -> deviceService.setShakingSpeed((Integer) cmdForm.getParams().get("speed"))); |
|
|
|
return run(cmdList); |
|
|
|
} |
|
|
|
|
|
|
|
// 移至加液 |
|
|
|
private Boolean moveToActionArea(CMDForm cmdForm) { |
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
// 加液位是否有托盘 |
|
|
|
Boolean liquidTrayStatus = deviceStateService.getDeviceStatus().getLiquidTrayStatus(); |
|
|
|
if(liquidTrayStatus) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
// Boolean liquidTrayStatus = deviceStateService.getDeviceStatus().getLiquidTrayStatus(); |
|
|
|
// if(liquidTrayStatus) { |
|
|
|
// return false; |
|
|
|
// } |
|
|
|
cmdList.add(() -> deviceService.moveRailArmToPoint(1, 2, 3)); |
|
|
|
cmdList.add(() -> deviceService.openClaw()); |
|
|
|
cmdList.add(() -> deviceService.moveRailArmToPoint(4,5,6)); |
|
|
|
cmdList.add(() -> deviceService.closeClaw()); |
|
|
|
return run(cmdList); |
|
|
|
|
|
|
|
} |
|
|
|
// 恒温 |
|
|
|
private Boolean keepHeat(CMDForm cmdForm) { |
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
// TODO 加热到指定温度,通过传感器使其恒温 |
|
|
|
return run(cmdList); |
|
|
|
} |
|
|
|
// 加液 |
|
|
|
private Boolean injectFluid(CMDForm cmdForm) { |
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
// TODO 计算出试管的坐标 |
|
|
|
// TODO 溶液id 容量 |
|
|
|
Map<String, Object> params = cmdForm.getParams(); |
|
|
|
cmdList.add(() -> deviceService.moveLiquidArmToPoint(1,2,3)); |
|
|
|
cmdList.add(() -> deviceService.addLiquid((String) params.get("pumpId"), ((Integer)params.get("volume")))); |
|
|
|
return run(cmdList); |
|
|
|
} |
|
|
|
// 放下托盘 |
|
|
|
private boolean downTray(CMDForm cmdForm) { |
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
cmdList.add(() -> deviceService.moveTrayToHeight(0)); |
|
|
|
cmdList.add(() -> deviceService.moveTrayToHeight((Double) cmdForm.getParams().get("height"))); |
|
|
|
return run(cmdList); |
|
|
|
} |
|
|
|
// 抬起托盘 |
|
|
|
private boolean upTray(CMDForm cmdForm) { |
|
|
|
List<Supplier<Boolean>> cmdList = new ArrayList<>(); |
|
|
|
cmdList.add(() -> deviceService.moveTrayToHeight(20)); |
|
|
|
cmdList.add(() -> deviceService.moveTrayToHeight((Double) cmdForm.getParams().get("height"))); |
|
|
|
return run(cmdList); |
|
|
|
} |
|
|
|
|
|
|
@ -173,6 +154,7 @@ public class CMDService { |
|
|
|
} |
|
|
|
|
|
|
|
public boolean executeCommand(CMDForm cmdForm) { |
|
|
|
form = cmdForm; |
|
|
|
String commandName = cmdForm.getCommand(); |
|
|
|
Function<CMDForm, Boolean> command = commandMap.get(commandName); |
|
|
|
if (command == null) { |
|
|
|