|
|
@ -1,19 +1,11 @@ |
|
|
|
package com.iflytop.sgs.app.service.device; |
|
|
|
|
|
|
|
import com.iflytop.sgs.app.core.listener.DeviceStateListener; |
|
|
|
import com.iflytop.sgs.app.model.bo.status.CommandMutexState; |
|
|
|
import com.iflytop.sgs.app.model.bo.status.device.*; |
|
|
|
import com.iflytop.sgs.app.model.entity.Tasks; |
|
|
|
import com.iflytop.sgs.app.model.entity.User; |
|
|
|
import com.iflytop.sgs.app.model.vo.SetTargetTemperatureVO; |
|
|
|
import com.iflytop.sgs.common.enums.ContainerCode; |
|
|
|
import com.iflytop.sgs.common.enums.HeatModuleCode; |
|
|
|
import com.iflytop.sgs.app.model.bo.status.device.DeviceState; |
|
|
|
import lombok.Getter; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.beans.PropertyChangeSupport; |
|
|
|
import java.util.List; |
|
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
|
|
|
|
|
|
/** |
|
|
@ -22,361 +14,10 @@ import java.util.concurrent.atomic.AtomicReference; |
|
|
|
@Service |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class DeviceStateService { |
|
|
|
private final transient PropertyChangeSupport support = new PropertyChangeSupport(this); |
|
|
|
|
|
|
|
@Getter |
|
|
|
private final DeviceState deviceState = new DeviceState(); |
|
|
|
|
|
|
|
@Getter |
|
|
|
private final AtomicReference<CommandMutexState> commandState = new AtomicReference<>(new CommandMutexState()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public synchronized DeviceState getDeviceState() { |
|
|
|
return deviceState; |
|
|
|
} |
|
|
|
|
|
|
|
public void addListener(DeviceStateListener deviceStateListener) { |
|
|
|
support.addPropertyChangeListener(deviceStateListener); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public synchronized HeatModuleState getHeatModuleState(HeatModuleCode moduleCode) { |
|
|
|
HeatModuleState heatModuleState = null; |
|
|
|
for (HeatModuleState t : deviceState.getHeatModule()) { |
|
|
|
if (moduleCode.equals(t.getModuleCode())) { |
|
|
|
heatModuleState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
return heatModuleState; |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized TrayState getTrayState(String trayUUID) { |
|
|
|
TrayState foundTrayState = null; |
|
|
|
for (TrayState t : deviceState.getTray()) { |
|
|
|
if (trayUUID.equals(t.getUuid())) { |
|
|
|
foundTrayState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
return foundTrayState; |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized TrayState getTrayInSolutionModule() { |
|
|
|
List<TrayState> trayList = deviceState.getTray(); |
|
|
|
return trayList.stream() |
|
|
|
.filter(TrayState::isInSolutionModule) |
|
|
|
.findFirst() |
|
|
|
.orElse(null); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setVirtual(boolean virtual) { |
|
|
|
boolean oldValue = deviceState.isVirtual(); |
|
|
|
deviceState.setVirtual(virtual); |
|
|
|
support.firePropertyChange("setVirtual", oldValue, virtual); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setInitComplete(boolean initComplete) { |
|
|
|
boolean oldValue = deviceState.isInitComplete(); |
|
|
|
deviceState.setInitComplete(initComplete); |
|
|
|
support.firePropertyChange("setInitComplete", oldValue, initComplete); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setEmergencyStop(boolean emergencyStop) { |
|
|
|
boolean oldValue = deviceState.isEmergencyStop(); |
|
|
|
deviceState.setEmergencyStop(emergencyStop); |
|
|
|
support.firePropertyChange("setEmergencyStop", oldValue, emergencyStop); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setSelfTest(boolean selfTest) { |
|
|
|
boolean oldValue = deviceState.isSelfTest(); |
|
|
|
deviceState.setSelfTest(selfTest); |
|
|
|
support.firePropertyChange("setSelfTest", oldValue, selfTest); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setDoorStatus(boolean status) { |
|
|
|
boolean oldValue = deviceState.getDoorModule().isOpen(); |
|
|
|
deviceState.getDoorModule().setOpen(status); |
|
|
|
support.firePropertyChange("setDoorStatus", oldValue, status); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setGantryArmStateIdle(boolean idle) { |
|
|
|
boolean oldValue = deviceState.getTransferModule().isIdle(); |
|
|
|
deviceState.getTransferModule().setIdle(idle); |
|
|
|
support.firePropertyChange("setGantryArmStateIdle", oldValue, idle); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setHeatModuleStateTrayUp(HeatModuleCode heatModuleId, int trayStatusUp) { |
|
|
|
HeatModuleState heatModuleState = null; |
|
|
|
for (HeatModuleState t : deviceState.getHeatModule()) { |
|
|
|
if (heatModuleId.equals(t.getModuleCode())) { |
|
|
|
heatModuleState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
assert heatModuleState != null; |
|
|
|
int oldValue = heatModuleState.getTrayUp(); |
|
|
|
heatModuleState.setTrayUp(trayStatusUp); |
|
|
|
support.firePropertyChange("setHeatModuleStateTrayUp", oldValue, trayStatusUp); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setHeatModuleStateTrayStatus(HeatModuleCode heatModuleId, int trayStatus) { |
|
|
|
HeatModuleState heatModuleState = null; |
|
|
|
for (HeatModuleState t : deviceState.getHeatModule()) { |
|
|
|
if (heatModuleId.equals(t.getModuleCode())) { |
|
|
|
heatModuleState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
assert heatModuleState != null; |
|
|
|
int oldValue = heatModuleState.getTrayStatus(); |
|
|
|
heatModuleState.setTrayStatus(trayStatus); |
|
|
|
support.firePropertyChange("setHeatModuleStateTrayStatus", oldValue, trayStatus); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setHeatModuleStateHeating(HeatModuleCode heatModuleId, boolean heating) { |
|
|
|
HeatModuleState heatModuleState = null; |
|
|
|
for (HeatModuleState t : deviceState.getHeatModule()) { |
|
|
|
if (heatModuleId.equals(t.getModuleCode())) { |
|
|
|
heatModuleState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
assert heatModuleState != null; |
|
|
|
boolean oldValue = heatModuleState.isHeating(); |
|
|
|
heatModuleState.setHeating(heating); |
|
|
|
support.firePropertyChange("setHeatModuleStateHeating", oldValue, heating); |
|
|
|
} |
|
|
|
public synchronized void setHeatModuleStateDrying(HeatModuleCode heatModuleId, boolean drying) { |
|
|
|
HeatModuleState heatModuleState = null; |
|
|
|
for (HeatModuleState t : deviceState.getHeatModule()) { |
|
|
|
if (heatModuleId.equals(t.getModuleCode())) { |
|
|
|
heatModuleState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
assert heatModuleState != null; |
|
|
|
boolean oldValue = heatModuleState.isDrying(); |
|
|
|
heatModuleState.setDrying(drying); |
|
|
|
support.firePropertyChange("setHeatModuleStateDrying", oldValue, drying); |
|
|
|
} |
|
|
|
public synchronized void setHeatModuleStateAnnealing(HeatModuleCode heatModuleId, boolean annealing) { |
|
|
|
HeatModuleState heatModuleState = null; |
|
|
|
for (HeatModuleState t : deviceState.getHeatModule()) { |
|
|
|
if (heatModuleId.equals(t.getModuleCode())) { |
|
|
|
heatModuleState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
assert heatModuleState != null; |
|
|
|
boolean oldValue = heatModuleState.isAnnealing(); |
|
|
|
heatModuleState.setAnnealing(annealing); |
|
|
|
support.firePropertyChange("setHeatModuleStateHeating", oldValue, annealing); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setHeatModuleStateFanOpen(HeatModuleCode heatModuleId, boolean fanOpen) { |
|
|
|
HeatModuleState heatModuleState = null; |
|
|
|
for (HeatModuleState t : deviceState.getHeatModule()) { |
|
|
|
if (heatModuleId.equals(t.getModuleCode())) { |
|
|
|
heatModuleState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
assert heatModuleState != null; |
|
|
|
boolean oldValue = heatModuleState.isFanOpen(); |
|
|
|
heatModuleState.setFanOpen(fanOpen); |
|
|
|
support.firePropertyChange("setHeatModuleStateFanOpen", oldValue, fanOpen); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public synchronized void setHeatModuleStatePreSetTemperature(HeatModuleCode heatModuleId, SetTargetTemperatureVO setTargetTemperatureVO) { |
|
|
|
HeatModuleState heatModuleState = null; |
|
|
|
for (HeatModuleState t : deviceState.getHeatModule()) { |
|
|
|
if (heatModuleId.equals(t.getModuleCode())) { |
|
|
|
heatModuleState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
assert heatModuleState != null; |
|
|
|
heatModuleState.setHeatTemperature(setTargetTemperatureVO.getHeatTemperature()); |
|
|
|
heatModuleState.setAnnealTemperature(setTargetTemperatureVO.getAnnealTemperature()); |
|
|
|
heatModuleState.setDryTemperature(setTargetTemperatureVO.getDryTemperature()); |
|
|
|
//support.firePropertyChange("setHeatModuleStateTargetTemperature", oldValue, targetTemperature); |
|
|
|
} |
|
|
|
public synchronized void setHeatModuleStateTargetTemperature(HeatModuleCode heatModuleId, double targetTemperature) { |
|
|
|
HeatModuleState heatModuleState = null; |
|
|
|
for (HeatModuleState t : deviceState.getHeatModule()) { |
|
|
|
if (heatModuleId.equals(t.getModuleCode())) { |
|
|
|
heatModuleState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
assert heatModuleState != null; |
|
|
|
double oldValue = heatModuleState.getTargetTemperature(); |
|
|
|
heatModuleState.setTargetTemperature(targetTemperature); |
|
|
|
support.firePropertyChange("setHeatModuleStateTargetTemperature", oldValue, targetTemperature); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setHeatModuleStateTemperature(HeatModuleCode heatModuleId, double temperature) { |
|
|
|
HeatModuleState heatModuleState = null; |
|
|
|
for (HeatModuleState t : deviceState.getHeatModule()) { |
|
|
|
if (heatModuleId.equals(t.getModuleCode())) { |
|
|
|
heatModuleState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
assert heatModuleState != null; |
|
|
|
Double oldValue = heatModuleState.getTemperature(); |
|
|
|
heatModuleState.setTemperature(temperature); |
|
|
|
support.firePropertyChange("setHeatModuleStateTemperature", oldValue, temperature); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setSolutionModuleStateIdle(boolean idle) { |
|
|
|
boolean oldValue = deviceState.getSolutionModule().isIdle(); |
|
|
|
deviceState.getSolutionModule().setIdle(idle); |
|
|
|
support.firePropertyChange("setSolutionModuleStateIdle", oldValue, idle); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public synchronized void setSolutionModuleStateTrayStatus(int trayStatus) { |
|
|
|
int oldValue = deviceState.getSolutionModule().getTrayStatus(); |
|
|
|
deviceState.getSolutionModule().setTrayStatus(trayStatus); |
|
|
|
support.firePropertyChange("setSolutionModuleStateTrayStatus", oldValue, trayStatus); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setSolutionModuleStatePumping(boolean pumping) { |
|
|
|
boolean oldValue = deviceState.getSolutionModule().isPumping(); |
|
|
|
deviceState.getSolutionModule().setPumping(pumping); |
|
|
|
support.firePropertyChange("setSolutionModuleStatePumping", oldValue, pumping); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setSolutionContainerStateEmpty(ContainerCode containerCode, boolean empty) { |
|
|
|
SolutionContainerState solutionContainerState = null; |
|
|
|
for (SolutionContainerState t : deviceState.getSolutionModule().getSolutionContainer()) { |
|
|
|
if (containerCode.equals(t.getContainerCode())) { |
|
|
|
solutionContainerState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
assert solutionContainerState != null; |
|
|
|
boolean oldValue = solutionContainerState.isEmpty(); |
|
|
|
solutionContainerState.setEmpty(empty); |
|
|
|
support.firePropertyChange("setSolutionContainerStateEmpty", oldValue, empty); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setSolutionContainerStateFull(ContainerCode containerCode, boolean full) { |
|
|
|
SolutionContainerState solutionContainerState = null; |
|
|
|
for (SolutionContainerState t : deviceState.getSolutionModule().getSolutionContainer()) { |
|
|
|
if (containerCode.equals(t.getContainerCode())) { |
|
|
|
solutionContainerState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
assert solutionContainerState != null; |
|
|
|
boolean oldValue = solutionContainerState.isFull(); |
|
|
|
solutionContainerState.setFull(full); |
|
|
|
support.firePropertyChange("setSolutionContainerStateFull", oldValue, full); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setTrayStateHeatModuleId(String trayUUID, HeatModuleCode heatModuleId) { |
|
|
|
TrayState foundTrayState = null; |
|
|
|
for (TrayState t : deviceState.getTray()) { |
|
|
|
if (trayUUID.equals(t.getUuid())) { |
|
|
|
foundTrayState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
assert foundTrayState != null; |
|
|
|
HeatModuleCode oldValue = foundTrayState.getHeatModuleId(); |
|
|
|
foundTrayState.setHeatModuleId(heatModuleId); |
|
|
|
support.firePropertyChange("setTrayStateHeatModuleId", oldValue, heatModuleId); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setTrayStateInSolutionModule(String trayUUID, boolean inSolutionModule) { |
|
|
|
TrayState foundTrayState = null; |
|
|
|
for (TrayState t : deviceState.getTray()) { |
|
|
|
if (trayUUID.equals(t.getUuid())) { |
|
|
|
foundTrayState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
assert foundTrayState != null; |
|
|
|
boolean oldValue = foundTrayState.isInSolutionModule(); |
|
|
|
foundTrayState.setInSolutionModule(inSolutionModule); |
|
|
|
support.firePropertyChange("traySetInSolutionModule", oldValue, inSolutionModule); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setTrayStateInHeatModule(String trayUUID, boolean inHeatModule) { |
|
|
|
TrayState foundTrayState = null; |
|
|
|
for (TrayState t : deviceState.getTray()) { |
|
|
|
if (trayUUID.equals(t.getUuid())) { |
|
|
|
foundTrayState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
assert foundTrayState != null; |
|
|
|
boolean oldValue = foundTrayState.isInHeatModule(); |
|
|
|
foundTrayState.setInHeatModule(inHeatModule); |
|
|
|
support.firePropertyChange("setTrayStateInHeatModule", oldValue, inHeatModule); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public synchronized void setTrayStateTubes(String trayUUID, TubeState[] tubes) { |
|
|
|
TrayState foundTrayState = null; |
|
|
|
for (TrayState t : deviceState.getTray()) { |
|
|
|
if (trayUUID.equals(t.getUuid())) { |
|
|
|
foundTrayState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
assert foundTrayState != null; |
|
|
|
TubeState[] oldValue = foundTrayState.getTubes(); |
|
|
|
foundTrayState.setTubes(tubes); |
|
|
|
support.firePropertyChange("setTrayStateTubes", oldValue, tubes); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setTubeStateExists(String trayUUID, int tubeNum, boolean exists) { |
|
|
|
TrayState foundTrayState = null; |
|
|
|
for (TrayState t : deviceState.getTray()) { |
|
|
|
if (trayUUID.equals(t.getUuid())) { |
|
|
|
foundTrayState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
assert foundTrayState != null; |
|
|
|
TubeState tubeState = foundTrayState.getTubes()[tubeNum]; |
|
|
|
boolean oldValue = tubeState.isExists(); |
|
|
|
tubeState.setExists(exists); |
|
|
|
support.firePropertyChange("setTubeStateExists", oldValue, exists); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setTubeStateAddSolution(String trayUUID, int tubeNum, boolean addSolution) { |
|
|
|
TrayState foundTrayState = null; |
|
|
|
for (TrayState t : deviceState.getTray()) { |
|
|
|
if (trayUUID.equals(t.getUuid())) { |
|
|
|
foundTrayState = t; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
assert foundTrayState != null; |
|
|
|
TubeState tubeState = foundTrayState.getTubes()[tubeNum]; |
|
|
|
boolean oldValue = tubeState.isAddSolution(); |
|
|
|
tubeState.setAddSolution(addSolution); |
|
|
|
support.firePropertyChange("setTubeStateAddSolution", oldValue, addSolution); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setCurrentUser(User currentUser) { |
|
|
|
User oldValue = deviceState.getCurrentUser(); |
|
|
|
deviceState.setCurrentUser(currentUser); |
|
|
|
support.firePropertyChange("setCurrentUser", oldValue, currentUser); |
|
|
|
} |
|
|
|
|
|
|
|
public synchronized void setCurrentTasks(Tasks currentTasks) { |
|
|
|
User oldValue = deviceState.getCurrentUser(); |
|
|
|
deviceState.setCurrentTasks(currentTasks); |
|
|
|
support.firePropertyChange("setCurrentTasks", oldValue, currentTasks); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private final AtomicReference<CommandMutexState> commandMutexState = new AtomicReference<>(new CommandMutexState()); |
|
|
|
|
|
|
|
} |