|
|
@ -11,6 +11,7 @@ import a8k.teststate.VirtualDevice; |
|
|
|
import jakarta.annotation.PostConstruct; |
|
|
|
import jakarta.annotation.Resource; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
@Component |
|
|
@ -35,10 +36,15 @@ public class TemperatureCtrlService { |
|
|
|
|
|
|
|
AppError error = null; |
|
|
|
|
|
|
|
@Value("${a8k.enableTemperatureCtrl}") |
|
|
|
Boolean enableTemperatureCtrl = true; |
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
public void init() { |
|
|
|
// eventBus.regListener(this::onAppEvent); |
|
|
|
if(!enableTemperatureCtrl){ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
temperatureCtrlThread = new Thread(() -> { |
|
|
|
OS.forceSleep(3000); //等待webSocket连接 |
|
|
@ -60,6 +66,7 @@ public class TemperatureCtrlService { |
|
|
|
setAppError(e); |
|
|
|
log.error("Temperature control error: {}", e.getMessage()); |
|
|
|
} |
|
|
|
OS.forceSleep(1000); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
@ -78,6 +85,7 @@ public class TemperatureCtrlService { |
|
|
|
synchronized public void clearTargetTemperature() { |
|
|
|
targetTemperatureSetVal = null; |
|
|
|
} |
|
|
|
|
|
|
|
synchronized public Integer getTargetTemperature() { |
|
|
|
return targetTemperature; |
|
|
|
} |
|
|
@ -95,6 +103,7 @@ public class TemperatureCtrlService { |
|
|
|
} |
|
|
|
|
|
|
|
private void startCtrlTemperature(Integer temperature) throws AppException { |
|
|
|
log.info("start control temperature: {}", temperature); |
|
|
|
temperatureControlDriver.startCtrlTemperature(temperature.doubleValue()); |
|
|
|
targetTemperature = temperature; |
|
|
|
workingFlag = true; |
|
|
@ -112,107 +121,5 @@ public class TemperatureCtrlService { |
|
|
|
error = null; |
|
|
|
} |
|
|
|
|
|
|
|
// |
|
|
|
// synchronized public Integer getTargetTemperature() { |
|
|
|
// return targetTemperature; |
|
|
|
// } |
|
|
|
// |
|
|
|
// /** |
|
|
|
// * 控制温度,当APP配置发生变化时,自动调整温度 |
|
|
|
// * @throws AppException 温度控制异常 |
|
|
|
// */ |
|
|
|
// synchronized public void startTemperatureControl() throws AppException { |
|
|
|
// stopTemperatureControl(); |
|
|
|
// targetTemperature = 0; |
|
|
|
// startTemperatureControlInternal(); |
|
|
|
// } |
|
|
|
// |
|
|
|
// /** |
|
|
|
// * 控制温度,根据设定值控制温度 |
|
|
|
// * @param tem 设定温度 |
|
|
|
// * @throws AppException 温度控制异常 |
|
|
|
// */ |
|
|
|
// synchronized public void startFixTemperatureControl(Integer tem) throws AppException { |
|
|
|
// stopTemperatureControl(); |
|
|
|
// targetTemperature = tem; |
|
|
|
// startTemperatureControlInternal(); |
|
|
|
// } |
|
|
|
// |
|
|
|
// synchronized public boolean isTemperatureControlRunning() { |
|
|
|
// return temperatureCtrlThread != null; |
|
|
|
// } |
|
|
|
// |
|
|
|
// |
|
|
|
// synchronized public void startTemperatureControlInternal() throws AppException { |
|
|
|
// if (virtualDevice.isEnable()) { |
|
|
|
// return; |
|
|
|
// } |
|
|
|
// |
|
|
|
// if (temperatureCtrlThread != null) { |
|
|
|
// return; |
|
|
|
// } |
|
|
|
// |
|
|
|
// if (controlMode.equals(TemperaControlMode.kAutoChangeFromAppSetting)) { |
|
|
|
// var setting = appSettingsMgrService.getDeviceSetting(); |
|
|
|
// targetTemperature = setting.getTemperature(); |
|
|
|
// } |
|
|
|
// |
|
|
|
// |
|
|
|
// /* |
|
|
|
// * 启动线程,定时检查温度设定值,如果发生变化则调用温度控制器 |
|
|
|
// */ |
|
|
|
// workingFlag = true; |
|
|
|
// temperatureCtrlThread = new Thread(() -> { |
|
|
|
// log.info("Temperature thread run start"); |
|
|
|
// |
|
|
|
// temperatureControlDriver.startCtrlTemperature(targetTemperature.doubleValue()); |
|
|
|
// |
|
|
|
// while (workingFlag) { |
|
|
|
// try { |
|
|
|
// |
|
|
|
// OS.forceSleep(1000); |
|
|
|
// if (controlMode.equals(TemperaControlMode.kAutoChangeFromAppSetting)) { |
|
|
|
// Integer settingTem = appSettingsMgrService.getDeviceSetting().getTemperature(); |
|
|
|
// if (!targetTemperature.equals(settingTem)) { |
|
|
|
// targetTemperature = settingTem; |
|
|
|
// temperatureControlDriver.startCtrlTemperature(targetTemperature.doubleValue()); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// |
|
|
|
// } catch (AppException e) { |
|
|
|
// log.error("Temperature control error: {}", e.getMessage()); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// |
|
|
|
// try { |
|
|
|
// temperatureControlDriver.stopCtrlTemperature(); |
|
|
|
// } catch (AppException e) { |
|
|
|
// throw new RuntimeException(e); |
|
|
|
// } |
|
|
|
// |
|
|
|
// log.info("Temperature thread run end"); |
|
|
|
// }); |
|
|
|
// temperatureCtrlThread.start(); |
|
|
|
// temperatureCtrlThread.setName("TemperatureCtrlThread"); |
|
|
|
// } |
|
|
|
// |
|
|
|
// synchronized public void stopTemperatureControl() throws AppException { |
|
|
|
// if (virtualDevice.isEnable()) { |
|
|
|
// return; |
|
|
|
// } |
|
|
|
// |
|
|
|
// if (temperatureCtrlThread != null) { |
|
|
|
// temperatureCtrlThread.interrupt(); |
|
|
|
// workingFlag = false; |
|
|
|
// try { |
|
|
|
// temperatureCtrlThread.join(); |
|
|
|
// } catch (InterruptedException e) { |
|
|
|
// throw new RuntimeException(e); |
|
|
|
// } |
|
|
|
// temperatureCtrlThread = null; |
|
|
|
// } |
|
|
|
// log.info("Temperature control stopped"); |
|
|
|
// |
|
|
|
// } |
|
|
|
|
|
|
|
} |