From 3d61b2abd8634783e6c7560631d7c9c2d6aec85a Mon Sep 17 00:00:00 2001 From: sige Date: Wed, 21 Feb 2024 15:55:16 +0800 Subject: [PATCH] ~~ --- .../move/MoveHeatPlateSlotHeating.java | 16 ++- .../resource/ResHeatingTubeRackSlot.java | 30 +----- .../resource/ResHeatingTubeRackSlotManager.java | 10 +- .../my/graphiteDigesterBg/task/TaskHeating.java | 24 +++-- src/web/src/pages/main/contents/Operation.vue | 23 ++++- .../main/contents/OperationTubeRackTemperature.vue | 107 ++++++++++++++++----- 6 files changed, 145 insertions(+), 65 deletions(-) diff --git a/src/src/main/java/com/my/graphiteDigesterBg/move/MoveHeatPlateSlotHeating.java b/src/src/main/java/com/my/graphiteDigesterBg/move/MoveHeatPlateSlotHeating.java index e0fa490..4190f18 100644 --- a/src/src/main/java/com/my/graphiteDigesterBg/move/MoveHeatPlateSlotHeating.java +++ b/src/src/main/java/com/my/graphiteDigesterBg/move/MoveHeatPlateSlotHeating.java @@ -16,6 +16,8 @@ public class MoveHeatPlateSlotHeating extends DiTaskMoveBase { public Integer temperature; // duration public Integer duration; + // task uuid + public String taskUuid; // done callback private FinishCallback finishCallback; // slot @@ -27,10 +29,12 @@ public class MoveHeatPlateSlotHeating extends DiTaskMoveBase { public void run() { var slotMan = this.getResourceManager(ResHeatingTubeRackSlotManager.class); this.slot = slotMan.getSlotByIndex(this.slotIndex); + this.slot.srcTemperature = this.slot.temperature; this.slot.destTemperature = this.temperature * 100; this.slot.heatingDuration = this.duration * 60; this.slot.heatingStartedAt = null; this.slot.isHeating = true; + this.slot.taskUuid = this.taskUuid; this.isHeatingOn = false; String message = String.format("试管架%d : 开始加热", this.slotIndex); @@ -38,6 +42,12 @@ public class MoveHeatPlateSlotHeating extends DiTaskMoveBase { this.heating(); } + // cancel + public void cancel() { + this.slot.heatingDuration = 0; + this.slot.destTemperature = null; + } + // on done public void onFinish( FinishCallback callback ) { this.finishCallback = callback; @@ -47,7 +57,7 @@ public class MoveHeatPlateSlotHeating extends DiTaskMoveBase { public void heating() { String heaterKey = "HeatPlateSlotHeater" + this.slotIndex; // 如果温度低于目标温度,打开加热器 - if ( this.slot.temperature < this.slot.destTemperature ) { + if ( null != this.slot.destTemperature && this.slot.temperature < this.slot.destTemperature ) { if ( !this.isHeatingOn ) { this.getDevice().getIO().setValue(heaterKey, 1); this.isHeatingOn = true; @@ -69,10 +79,12 @@ public class MoveHeatPlateSlotHeating extends DiTaskMoveBase { // 检查时间到了没有 ~~~ var duration = System.currentTimeMillis()/1000 - this.slot.heatingStartedAt; - if ( duration > this.slot.heatingDuration ) { + if ( duration >= this.slot.heatingDuration ) { String message = String.format("试管架%d : 加热完成", this.slotIndex); this.getDevice().getRuntimeVariables().setString(message, "StatusMessage"); this.slot.isHeating = false; + this.slot.heatingStartedAt = null; + this.slot.taskUuid = null; this.finishCallback.callback(); return ; } diff --git a/src/src/main/java/com/my/graphiteDigesterBg/resource/ResHeatingTubeRackSlot.java b/src/src/main/java/com/my/graphiteDigesterBg/resource/ResHeatingTubeRackSlot.java index bcf965a..26f7fbf 100644 --- a/src/src/main/java/com/my/graphiteDigesterBg/resource/ResHeatingTubeRackSlot.java +++ b/src/src/main/java/com/my/graphiteDigesterBg/resource/ResHeatingTubeRackSlot.java @@ -12,6 +12,8 @@ public class ResHeatingTubeRackSlot { public Integer destTemperature; // temperature public Integer temperature; + // src temperature + public Integer srcTemperature; // heating started at public Integer heatingStartedAt; // heating duration @@ -26,10 +28,12 @@ public class ResHeatingTubeRackSlot { private Boolean isLocked; // is heating public Boolean isHeating; + // task uuid + public String taskUuid; // manager private final ResHeatingTubeRackSlotManager manager; // tube status list - private List tubeStatusList; + private final List tubeStatusList; // constructor public ResHeatingTubeRackSlot( ResHeatingTubeRackSlotManager manager, Integer index ) { @@ -78,28 +82,4 @@ public class ResHeatingTubeRackSlot { } return indexes; } - - // heating on - public void heatingOn() { - LOG.info("[Resource TubeRackSlot#{}] Heating On", this.index); - this.isHeating = true; - - // @TODO : 加热未实现 - LOG.error("开始加热未实现"); - this.temperature = this.destTemperature; - } - - // heating off - public void heatingOff() { - LOG.info("[Resource TubeRackSlot#{}] Heating Off", this.index); - // @TODO : 加热未实现 - LOG.error("停止加热未实现"); - - this.isHeating = false; - } - - // get is heating - public Boolean getIsHeating() { - return this.isHeating; - } } diff --git a/src/src/main/java/com/my/graphiteDigesterBg/resource/ResHeatingTubeRackSlotManager.java b/src/src/main/java/com/my/graphiteDigesterBg/resource/ResHeatingTubeRackSlotManager.java index 0816b9e..dc4f540 100644 --- a/src/src/main/java/com/my/graphiteDigesterBg/resource/ResHeatingTubeRackSlotManager.java +++ b/src/src/main/java/com/my/graphiteDigesterBg/resource/ResHeatingTubeRackSlotManager.java @@ -41,11 +41,11 @@ public class ResHeatingTubeRackSlotManager extends DiResourceManagerBase { // refresh slot temperature public void refreshSlotTemperature() { -// var registers = this.getDevice().getRegisters(); -// for (ResHeatingTubeRackSlot slot : this.slots) { -// slot.temperature = registers.getValue("HeatingPlateSlotTemperature" + slot.index); -// LOG.info("[Heating Slot {}] temperature: {}", slot.index, slot.temperature); -// } + var registers = this.getDevice().getRegisters(); + for (ResHeatingTubeRackSlot slot : this.slots) { + slot.temperature = registers.getValue("HeatingPlateSlotTemperature" + slot.index); + LOG.info("[Heating Slot {}] temperature: {}", slot.index, slot.temperature); + } } // get resource data diff --git a/src/src/main/java/com/my/graphiteDigesterBg/task/TaskHeating.java b/src/src/main/java/com/my/graphiteDigesterBg/task/TaskHeating.java index bb32001..5cdf88c 100644 --- a/src/src/main/java/com/my/graphiteDigesterBg/task/TaskHeating.java +++ b/src/src/main/java/com/my/graphiteDigesterBg/task/TaskHeating.java @@ -13,22 +13,28 @@ public class TaskHeating extends DiTaskBase { public Integer temperature; // duration public Integer duration; - // timer - private Timer timer; + // heating move + private MoveHeatPlateSlotHeating heating; @Override public void run() { MdbOperationLog.log(this.getUser(), "试管架%d : 样本加热 温度=%d, 时间=%d", this.slotIndex, this.temperature, this.duration); - var heating = new MoveHeatPlateSlotHeating(); - heating.slotIndex = this.slotIndex; - heating.temperature = this.temperature; - heating.duration = this.duration; - heating.setDevice(this.getDevice()); - heating.onFinish(() -> { + this.heating = new MoveHeatPlateSlotHeating(); + this.heating.taskUuid = this.getUUID(); + this.heating.slotIndex = this.slotIndex; + this.heating.temperature = this.temperature; + this.heating.duration = this.duration; + this.heating.setDevice(this.getDevice()); + this.heating.onFinish(() -> { this.setStatus(DiTask.TaskStatus.FINISHED); }); - heating.run(); + this.heating.run(); this.setStatus(DiTask.TaskStatus.WAITING); } + + // cancel + public void cancel() { + this.heating.cancel(); + } } diff --git a/src/web/src/pages/main/contents/Operation.vue b/src/web/src/pages/main/contents/Operation.vue index f26a64d..9b7d98c 100644 --- a/src/web/src/pages/main/contents/Operation.vue +++ b/src/web/src/pages/main/contents/Operation.vue @@ -112,7 +112,7 @@ - + @@ -130,6 +130,18 @@ + + @@ -282,6 +294,15 @@ async function actionHeatingOk() { function actionHeatingCancel() { heating.value.enable = false; } + +// 加热停止 +async function actionHeatingStop() { + let slotIndex = heating.value.slotIndex * 1; + let taskId = tubeRackSlots.value[slotIndex].taskUuid; + heating.value.enable = false; + let client = ApiClient.getClient(); + await client.taskActionExecute(taskId, 'cancel'); +} \ No newline at end of file