|
|
@ -1,16 +1,16 @@ |
|
|
|
package a8k.extui.page.extapp; |
|
|
|
|
|
|
|
import a8k.app.type.param.TemperatureCtrlParam; |
|
|
|
import a8k.app.service.param.pos.TemperatureCtrlParamMgr; |
|
|
|
import a8k.extui.type.ret.ExtApiCurve; |
|
|
|
import a8k.extui.factory.CurveBuilder; |
|
|
|
import a8k.extui.type.ExtApiStatu; |
|
|
|
import a8k.app.service.background.TemperatureCtrlService; |
|
|
|
import a8k.app.hardware.driver.TemperatureControlDriver; |
|
|
|
import a8k.app.service.background.TemperatureCtrlService; |
|
|
|
import a8k.app.service.param.pos.TemperatureCtrlParamMgr; |
|
|
|
import a8k.app.type.exception.AppException; |
|
|
|
import a8k.app.type.param.TemperatureCtrlParam; |
|
|
|
import a8k.extui.factory.CurveBuilder; |
|
|
|
import a8k.extui.mgr.ExtApiPageMgr; |
|
|
|
import jakarta.annotation.Resource; |
|
|
|
import a8k.extui.type.ExtApiStatu; |
|
|
|
import a8k.extui.type.ret.ExtApiCurve; |
|
|
|
import jakarta.annotation.PostConstruct; |
|
|
|
import jakarta.annotation.Resource; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
@ -20,146 +20,151 @@ import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* |
|
|
|
*/ |
|
|
|
@Component |
|
|
|
@Slf4j |
|
|
|
public class P02A8kTemperaturaVerfication { |
|
|
|
@Resource |
|
|
|
ExtApiPageMgr extApiPageMgr; |
|
|
|
|
|
|
|
@Resource |
|
|
|
TemperatureCtrlService temperatureCtrlService; |
|
|
|
@Resource |
|
|
|
TemperatureControlDriver temperatureControlDriver; |
|
|
|
@Resource |
|
|
|
TemperatureCtrlParamMgr temperatureCtrlParamMgr; |
|
|
|
|
|
|
|
|
|
|
|
List<Object[]> incubateBoxTemperatureCurve = new ArrayList<>(); |
|
|
|
List<Object[]> plateBoxTemperatureCurve = new ArrayList<>(); |
|
|
|
|
|
|
|
Thread tempSampleThread; |
|
|
|
|
|
|
|
Double incubateBoxTemperatureCache = 0.0; |
|
|
|
Double plateBoxTemperatureCache = 0.0; |
|
|
|
Integer hasStartedTimeMS = 0; |
|
|
|
Double targetTemp; |
|
|
|
Boolean workingFlag = false; |
|
|
|
|
|
|
|
|
|
|
|
@ExtApiStatu(name = "", group = "孵育盘温度", order = 3) |
|
|
|
public Double readIncubateBoxTemperature() throws AppException { |
|
|
|
return (incubateBoxTemperatureCache); |
|
|
|
} |
|
|
|
|
|
|
|
@ExtApiStatu(name = "", group = "板夹仓温度", order = 4) |
|
|
|
public Double readPlateBoxTemperature() throws AppException { |
|
|
|
return (plateBoxTemperatureCache); |
|
|
|
} |
|
|
|
|
|
|
|
@ExtApiStatu(name = "", group = "状态", order = 5) |
|
|
|
public String hasStartedTime() { |
|
|
|
int S = hasStartedTimeMS / 1000; |
|
|
|
return String.format("%s:%s:%s", (int) Math.floor((double) S / 3600), (int) Math.floor((double) (S % 3600) / 60), S % 60); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
public void init() throws NoSuchMethodException { |
|
|
|
var page = extApiPageMgr.newPage(this); |
|
|
|
|
|
|
|
page.newGroup("基础"); |
|
|
|
page.addFunction("设置孵育盘温度偏移", this::setIncubatorBoxTemperatureOff) |
|
|
|
.setParamVal("offset", ()->temperatureCtrlParamMgr.getParam(TemperatureCtrlParam.IncubatorTCMTempOffset)); |
|
|
|
page.addFunction("设置板夹仓温度偏移", this::setPlatesBoxTCMTempOffset) |
|
|
|
.setParamVal("offset", ()->temperatureCtrlParamMgr.getParam(TemperatureCtrlParam.PlatesBoxTCMTempOffset)); |
|
|
|
|
|
|
|
page.newGroup("操作"); |
|
|
|
page.addFunction("启动温度控制", this::startCtrl); |
|
|
|
page.addFunction("停止温度控制", this::stopCtrl); |
|
|
|
page.addFunction("查看孵育盘温度曲线", this::showIncubateBoxTemperatureCurve); |
|
|
|
page.addFunction("查看板夹仓温度曲线", this::showPlateBoxTemperatureCurve); |
|
|
|
extApiPageMgr.addPage(page); |
|
|
|
} |
|
|
|
|
|
|
|
public void setIncubatorBoxTemperatureOff(Double offset) throws AppException, InterruptedException { |
|
|
|
temperatureCtrlParamMgr.setParam(TemperatureCtrlParam.IncubatorTCMTempOffset, offset); |
|
|
|
if (workingFlag) { |
|
|
|
startCtrl(targetTemp.intValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setPlatesBoxTCMTempOffset(Double offset) throws AppException, InterruptedException { |
|
|
|
temperatureCtrlParamMgr.setParam(TemperatureCtrlParam.PlatesBoxTCMTempOffset, offset); |
|
|
|
if (workingFlag) { |
|
|
|
startCtrl(targetTemp.intValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
synchronized public void startCtrl(Integer targetTemperature) throws AppException, InterruptedException { |
|
|
|
temperatureCtrlService.setTargetTemperature(targetTemperature); |
|
|
|
if (tempSampleThread != null) { |
|
|
|
tempSampleThread.interrupt(); |
|
|
|
tempSampleThread.join(); |
|
|
|
} |
|
|
|
hasStartedTimeMS = 0; |
|
|
|
targetTemp = (double) targetTemperature; |
|
|
|
|
|
|
|
tempSampleThread = new Thread(() -> { |
|
|
|
while (true) { |
|
|
|
try { |
|
|
|
Thread.sleep(2000); |
|
|
|
hasStartedTimeMS += 2000; |
|
|
|
incubateBoxTemperatureCache = temperatureControlDriver.readIncubateBoxTemperature(); |
|
|
|
plateBoxTemperatureCache = temperatureControlDriver.readPlateBoxTemperature(); |
|
|
|
addIncubateBoxTemperatureCurve(incubateBoxTemperatureCache); |
|
|
|
addPlateBoxTemperatureCurve(plateBoxTemperatureCache); |
|
|
|
log.info("孵育盘[ 温度:{} PWM:{} ], 板夹仓[ 温度:{} PWM:{} ]", |
|
|
|
incubateBoxTemperatureCache, temperatureControlDriver.readIncubateBoxPWMOutput(), |
|
|
|
plateBoxTemperatureCache, temperatureControlDriver.readPlateBoxPWMOutput()); |
|
|
|
} catch (InterruptedException ignored) { |
|
|
|
break; |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("温度采样线程异常", e); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
tempSampleThread.start(); |
|
|
|
workingFlag = true; |
|
|
|
} |
|
|
|
|
|
|
|
synchronized public void stopCtrl() throws AppException, InterruptedException { |
|
|
|
temperatureCtrlService.clearTargetTemperature(); |
|
|
|
if (tempSampleThread != null) { |
|
|
|
tempSampleThread.interrupt(); |
|
|
|
tempSampleThread.join(); |
|
|
|
} |
|
|
|
workingFlag = false; |
|
|
|
} |
|
|
|
|
|
|
|
public ExtApiCurve showIncubateBoxTemperatureCurve() { |
|
|
|
return CurveBuilder.buidCurve("孵育盘温度曲线", "time", "value", targetTemp - 10, targetTemp + 10, incubateBoxTemperatureCurve); |
|
|
|
} |
|
|
|
|
|
|
|
public ExtApiCurve showPlateBoxTemperatureCurve() { |
|
|
|
return CurveBuilder.buidCurve("板夹仓温度曲线", "time", "value", targetTemp - 10, targetTemp + 10, plateBoxTemperatureCurve); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void addIncubateBoxTemperatureCurve(Double temperature) { |
|
|
|
incubateBoxTemperatureCurve.add(new Object[]{System.currentTimeMillis(), temperature}); |
|
|
|
if (incubateBoxTemperatureCurve.size() > 3000) { |
|
|
|
incubateBoxTemperatureCurve.remove(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void addPlateBoxTemperatureCurve(Double temperature) { |
|
|
|
plateBoxTemperatureCurve.add(new Object[]{System.currentTimeMillis(), temperature}); |
|
|
|
if (plateBoxTemperatureCurve.size() > 3000) { |
|
|
|
plateBoxTemperatureCurve.remove(0); |
|
|
|
} |
|
|
|
} |
|
|
|
@Resource |
|
|
|
ExtApiPageMgr extApiPageMgr; |
|
|
|
|
|
|
|
@Resource |
|
|
|
TemperatureCtrlService temperatureCtrlService; |
|
|
|
@Resource |
|
|
|
TemperatureControlDriver temperatureControlDriver; |
|
|
|
@Resource |
|
|
|
TemperatureCtrlParamMgr temperatureCtrlParamMgr; |
|
|
|
|
|
|
|
|
|
|
|
List<Object[]> incubateBoxTemperatureCurve = new ArrayList<>(); |
|
|
|
List<Object[]> plateBoxTemperatureCurve = new ArrayList<>(); |
|
|
|
|
|
|
|
Thread tempSampleThread; |
|
|
|
|
|
|
|
Double incubateBoxTemperatureCache = 0.0; |
|
|
|
Double plateBoxTemperatureCache = 0.0; |
|
|
|
Integer hasStartedTimeMS = 0; |
|
|
|
Double targetIncubateBoxTemp; |
|
|
|
Double targetPlateBoxTemp; |
|
|
|
Boolean workingFlag = false; |
|
|
|
|
|
|
|
|
|
|
|
@ExtApiStatu(name = "", group = "孵育盘温度", order = 3) |
|
|
|
public Double readIncubateBoxTemperature() throws AppException { |
|
|
|
return (incubateBoxTemperatureCache); |
|
|
|
} |
|
|
|
|
|
|
|
@ExtApiStatu(name = "", group = "板夹仓温度", order = 4) |
|
|
|
public Double readPlateBoxTemperature() throws AppException { |
|
|
|
return (plateBoxTemperatureCache); |
|
|
|
} |
|
|
|
|
|
|
|
@ExtApiStatu(name = "", group = "状态", order = 5) |
|
|
|
public String hasStartedTime() { |
|
|
|
int S = hasStartedTimeMS / 1000; |
|
|
|
return String.format("%s:%s:%s", (int) Math.floor((double) S / 3600), (int) Math.floor((double) (S % 3600) / 60), S % 60); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
public void init() throws NoSuchMethodException { |
|
|
|
var page = extApiPageMgr.newPage(this); |
|
|
|
|
|
|
|
page.newGroup("基础"); |
|
|
|
page.addFunction("设置孵育盘温度偏移", this::setIncubatorBoxTemperatureOff) |
|
|
|
.setParamVal("offset", () -> temperatureCtrlParamMgr.getParam(TemperatureCtrlParam.IncubatorTCMTempOffset)); |
|
|
|
page.addFunction("设置板夹仓温度偏移", this::setPlatesBoxTCMTempOffset) |
|
|
|
.setParamVal("offset", () -> temperatureCtrlParamMgr.getParam(TemperatureCtrlParam.PlatesBoxTCMTempOffset)); |
|
|
|
|
|
|
|
page.newGroup("操作"); |
|
|
|
page.addFunction("启动温度控制", this::startCtrl); |
|
|
|
page.addFunction("停止温度控制", this::stopCtrl); |
|
|
|
page.addFunction("查看孵育盘温度曲线", this::showIncubateBoxTemperatureCurve); |
|
|
|
page.addFunction("查看板夹仓温度曲线", this::showPlateBoxTemperatureCurve); |
|
|
|
extApiPageMgr.addPage(page); |
|
|
|
} |
|
|
|
|
|
|
|
public void setIncubatorBoxTemperatureOff(Double offset) throws AppException, InterruptedException { |
|
|
|
temperatureCtrlParamMgr.setParam(TemperatureCtrlParam.IncubatorTCMTempOffset, offset); |
|
|
|
if (workingFlag) { |
|
|
|
startCtrl(targetIncubateBoxTemp.intValue(), null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setPlatesBoxTCMTempOffset(Double offset) throws AppException, InterruptedException { |
|
|
|
temperatureCtrlParamMgr.setParam(TemperatureCtrlParam.PlatesBoxTCMTempOffset, offset); |
|
|
|
if (workingFlag) { |
|
|
|
startCtrl(null, targetPlateBoxTemp.intValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
synchronized public void startCtrl(Integer targetIncubatorBoxTemperature, Integer targetPlatesBoxTemperature) throws AppException, InterruptedException { |
|
|
|
if (targetIncubatorBoxTemperature != null) { |
|
|
|
temperatureCtrlService.setTargetIncubatorTemperature(targetIncubatorBoxTemperature); |
|
|
|
targetIncubateBoxTemp = targetIncubatorBoxTemperature.doubleValue(); |
|
|
|
} |
|
|
|
if (targetPlatesBoxTemperature != null) { |
|
|
|
temperatureCtrlService.setTargetPlatesBoxTemperature(targetPlatesBoxTemperature); |
|
|
|
targetPlateBoxTemp = targetPlatesBoxTemperature.doubleValue(); |
|
|
|
} |
|
|
|
if (tempSampleThread != null) { |
|
|
|
tempSampleThread.interrupt(); |
|
|
|
tempSampleThread.join(); |
|
|
|
} |
|
|
|
hasStartedTimeMS = 0; |
|
|
|
tempSampleThread = new Thread(() -> { |
|
|
|
while (true) { |
|
|
|
try { |
|
|
|
Thread.sleep(2000); |
|
|
|
hasStartedTimeMS += 2000; |
|
|
|
incubateBoxTemperatureCache = temperatureControlDriver.readIncubateBoxTemperature(); |
|
|
|
plateBoxTemperatureCache = temperatureControlDriver.readPlateBoxTemperature(); |
|
|
|
addIncubateBoxTemperatureCurve(incubateBoxTemperatureCache); |
|
|
|
addPlateBoxTemperatureCurve(plateBoxTemperatureCache); |
|
|
|
log.info("孵育盘[ 温度:{} PWM:{} ], 板夹仓[ 温度:{} PWM:{} ]", |
|
|
|
incubateBoxTemperatureCache, temperatureControlDriver.readIncubateBoxPWMOutput(), |
|
|
|
plateBoxTemperatureCache, temperatureControlDriver.readPlateBoxPWMOutput()); |
|
|
|
} catch (InterruptedException ignored) { |
|
|
|
break; |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("温度采样线程异常", e); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
tempSampleThread.start(); |
|
|
|
workingFlag = true; |
|
|
|
} |
|
|
|
|
|
|
|
synchronized public void stopCtrl() throws AppException, InterruptedException { |
|
|
|
temperatureCtrlService.clearTargetTemperature(); |
|
|
|
if (tempSampleThread != null) { |
|
|
|
tempSampleThread.interrupt(); |
|
|
|
tempSampleThread.join(); |
|
|
|
} |
|
|
|
workingFlag = false; |
|
|
|
} |
|
|
|
|
|
|
|
public ExtApiCurve showIncubateBoxTemperatureCurve() { |
|
|
|
return CurveBuilder.buidCurve("孵育盘温度曲线", "time", "value", targetIncubateBoxTemp - 10, targetIncubateBoxTemp + 10, incubateBoxTemperatureCurve); |
|
|
|
} |
|
|
|
|
|
|
|
public ExtApiCurve showPlateBoxTemperatureCurve() { |
|
|
|
return CurveBuilder.buidCurve("板夹仓温度曲线", "time", "value", targetPlateBoxTemp - 10, targetPlateBoxTemp + 10, plateBoxTemperatureCurve); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void addIncubateBoxTemperatureCurve(Double temperature) { |
|
|
|
incubateBoxTemperatureCurve.add(new Object[]{System.currentTimeMillis(), temperature}); |
|
|
|
if (incubateBoxTemperatureCurve.size() > 3000) { |
|
|
|
incubateBoxTemperatureCurve.remove(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void addPlateBoxTemperatureCurve(Double temperature) { |
|
|
|
plateBoxTemperatureCurve.add(new Object[]{System.currentTimeMillis(), temperature}); |
|
|
|
if (plateBoxTemperatureCurve.size() > 3000) { |
|
|
|
plateBoxTemperatureCurve.remove(0); |
|
|
|
} |
|
|
|
} |
|
|
|
} |