苏电院真实设备逻辑修改
This commit is contained in:
parent
39482d6b1d
commit
88de80d11b
@ -783,10 +783,13 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
|
||||
@Override
|
||||
public List<RealDeviceVO> getRealDeviceList(String group) {
|
||||
Simulation simulation = this.getSimulationByGroup(group);
|
||||
List<RealDeviceConfig> realDeviceList = simulation.getRealDeviceList();
|
||||
if (!CollectionUtils.isEmpty(realDeviceList)) {
|
||||
Set<ProjectDeviceType> displayDeviceTypes =
|
||||
new HashSet<>(List.of(ProjectDeviceType.PSD, ProjectDeviceType.SWITCH, ProjectDeviceType.SIGNAL, ProjectDeviceType.PLC_GATEWAY));
|
||||
List<RealDeviceConfig> realDeviceList = simulation.getRealDeviceList()
|
||||
realDeviceList = realDeviceList
|
||||
.stream().filter(device -> displayDeviceTypes.contains(device.getDeviceType())).collect(Collectors.toList());
|
||||
}
|
||||
// List<RealDevice> showList = null;
|
||||
// if (!CollectionUtils.isEmpty(realDeviceList)) {
|
||||
// showList = realDeviceList.stream()
|
||||
|
@ -76,8 +76,6 @@ public class VirtualRealityScreenDoor extends VirtualRealityDevice {
|
||||
|
||||
/**
|
||||
* 开始开/关门过程
|
||||
*
|
||||
* @param open
|
||||
*/
|
||||
public synchronized void startSetting(boolean open) {
|
||||
if (this.fault != null) {
|
||||
@ -138,9 +136,6 @@ public class VirtualRealityScreenDoor extends VirtualRealityDevice {
|
||||
|
||||
/**
|
||||
* 全部关门
|
||||
*
|
||||
* @param close
|
||||
* @param lock
|
||||
*/
|
||||
public void updateLockAndClose(boolean close, boolean lock) {
|
||||
this.open2End = false;
|
||||
@ -188,14 +183,16 @@ public class VirtualRealityScreenDoor extends VirtualRealityDevice {
|
||||
@Override
|
||||
public void apply(VirtualRealityScreenDoor door) {
|
||||
door.setFault(this);
|
||||
door.updateOpen2End(true);
|
||||
door.startSetting(true);
|
||||
// door.updateOpen2End(true);
|
||||
}
|
||||
},
|
||||
CANNOT_BE_OPENED {
|
||||
@Override
|
||||
public void apply(VirtualRealityScreenDoor door) {
|
||||
door.setFault(this);
|
||||
door.updateLockAndClose(true, true);
|
||||
door.startSetting(false);
|
||||
// door.updateLockAndClose(true, true);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -5,16 +5,78 @@ import club.joylink.rtss.util.JsonUtils;
|
||||
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
|
||||
import club.joylink.rtss.vo.client.project.sdy.SdyPsdConfigVO;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Getter
|
||||
public class SdyPsdConfig extends RealDeviceConfig {
|
||||
|
||||
private SdyPsdConfigVO configVO;
|
||||
|
||||
/**
|
||||
* 开门到位
|
||||
*/
|
||||
@Setter
|
||||
private Boolean r_km;
|
||||
|
||||
/**
|
||||
* 蜂鸣器响起的时间(为null表示蜂鸣器当前没响)(同时作为开关门流程的开始标志)
|
||||
*/
|
||||
private LocalDateTime buzzerRingingTime;
|
||||
|
||||
/**
|
||||
* 是否触发过开关门控制
|
||||
*/
|
||||
@Setter
|
||||
private boolean triggerOpenOrClose;
|
||||
|
||||
/**
|
||||
* 开关门过程中(即非开/关门到位状态)
|
||||
*/
|
||||
private boolean running;
|
||||
|
||||
public SdyPsdConfig(ProjectDeviceVO projectDevice) {
|
||||
super(projectDevice);
|
||||
if (projectDevice != null) {
|
||||
this.configVO = JsonUtils.read(projectDevice.getConfig(), SdyPsdConfigVO.class);
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.r_km = null;
|
||||
this.buzzerRingingTime = null;
|
||||
this.triggerOpenOrClose = false;
|
||||
this.running = false;
|
||||
}
|
||||
|
||||
public void buzzerRinging(LocalDateTime time) {
|
||||
this.buzzerRingingTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始开/关门
|
||||
*/
|
||||
public void run() {
|
||||
this.running = true;
|
||||
this.triggerOpenOrClose = false; //门已经开始移动,触发状态可以去掉了
|
||||
}
|
||||
|
||||
/**
|
||||
* 开/关门结束
|
||||
*/
|
||||
public void finishRunning() {
|
||||
if (running) {
|
||||
this.buzzerRingingTime = null;
|
||||
this.running = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消控制门的流程
|
||||
*/
|
||||
public void cancelControl() {
|
||||
this.buzzerRingingTime = null;
|
||||
this.triggerOpenOrClose = false;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.sdy;
|
||||
|
||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
|
||||
import club.joylink.rtss.simulation.cbtc.data.map.PSD;
|
||||
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityScreenDoor;
|
||||
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
|
||||
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
|
||||
@ -13,6 +15,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SdyPsdServiceImpl implements RealDeviceService {
|
||||
@ -28,48 +32,111 @@ public class SdyPsdServiceImpl implements RealDeviceService {
|
||||
@Override
|
||||
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
|
||||
PlcGateway plcGateway = simulation.getPlcGateway();
|
||||
SdyPsdConfigVO configVO = ((SdyPsdConfig) deviceConfig).getConfigVO();
|
||||
SdyPsdConfig config = (SdyPsdConfig) deviceConfig;
|
||||
SdyPsdConfigVO configVO = config.getConfigVO();
|
||||
Channel channel = plcGateway.getChannel();
|
||||
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
|
||||
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_kgm(), false, channel); //关门
|
||||
|
||||
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_jb(), false, channel); //关警报
|
||||
if (config.getR_km() != null && config.getR_km()) { //确保关门
|
||||
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_kgm(), false, channel);
|
||||
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_kgm(), true, channel);
|
||||
}
|
||||
config.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
|
||||
VirtualRealityScreenDoor vrPsd = (VirtualRealityScreenDoor) deviceConfig.getMapElement();
|
||||
if (vrPsd == null)
|
||||
return;
|
||||
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
|
||||
if (plcGateway == null) {
|
||||
log.error(String.format("仿真[%s]没有plc", simulation.getGroup()));
|
||||
return;
|
||||
}
|
||||
|
||||
SdyPsdConfig config = (SdyPsdConfig) deviceConfig;
|
||||
SdyPsdConfigVO configVO = config.getConfigVO();
|
||||
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(), configVO.getQuantity());
|
||||
boolean km = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_km());
|
||||
boolean gm = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_gm());
|
||||
boolean w_kgm = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_kgm());
|
||||
boolean w_jb = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_jb());
|
||||
config.setR_km(km);
|
||||
|
||||
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
|
||||
if (plcGateway == null) {
|
||||
log.error(String.format("仿真[%s]没有plc", simulation.getGroup()));
|
||||
return;
|
||||
}
|
||||
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
|
||||
Channel channel = plcGateway.getChannel();
|
||||
this.openOrCloseLoop(config, km, gm, baseAddr, w_kgm, channel);
|
||||
|
||||
if (!km && !gm) {
|
||||
config.run();
|
||||
} else {
|
||||
if (config.isRunning()) {
|
||||
this.plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_jb(), false, channel);
|
||||
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getConfigVO().getW_kgm(), w_kgm, false, channel);
|
||||
config.finishRunning();
|
||||
}
|
||||
}
|
||||
|
||||
VirtualRealityScreenDoor vrPsd = (VirtualRealityScreenDoor) deviceConfig.getMapElement();
|
||||
if (vrPsd != null) {
|
||||
//控制realDevice
|
||||
if (vrPsd.isSettingClose()) {
|
||||
if (!gm && km) {
|
||||
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_kgm(), w_kgm, false, channel);
|
||||
if (km && !gm) {
|
||||
this.openOrClose(config, km, gm, baseAddr, channel);
|
||||
}
|
||||
}
|
||||
if (vrPsd.isSettingOpen()) {
|
||||
if (!km && gm) {
|
||||
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_kgm(), w_kgm, true, channel);
|
||||
this.openOrClose(config, km, gm, baseAddr, channel);
|
||||
}
|
||||
}
|
||||
|
||||
if (!km && !gm)
|
||||
//从realDevice读取并更新状态
|
||||
if (!km && !gm) {
|
||||
vrPsd.turning();
|
||||
if (km && !gm)
|
||||
}
|
||||
if (km && !gm) {
|
||||
vrPsd.updateOpen2End(true);
|
||||
if (gm && !km)
|
||||
}
|
||||
if (gm && !km) {
|
||||
vrPsd.updateLockAndClose(true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 触发开关门流程
|
||||
*/
|
||||
public void openOrClose(SdyPsdConfig config, boolean km, boolean gm, int baseAddr, Channel channel) {
|
||||
LocalDateTime buzzerRingingTime = config.getBuzzerRingingTime();
|
||||
if (buzzerRingingTime != null) { //说明正在开关门流程中
|
||||
return;
|
||||
}
|
||||
if ((km || gm)) {
|
||||
this.plcGatewayService.writeSingleCoil(baseAddr, config.getConfigVO().getW_jb(), true, channel);
|
||||
config.buzzerRinging(LocalDateTime.now());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开关门循环逻辑(响铃3秒,然后开/关门。如果响铃超过6秒门还是没有开始移动(有人卡着屏蔽门,导致无法关闭),中断开关门流程)
|
||||
*/
|
||||
public void openOrCloseLoop(SdyPsdConfig config, boolean km, boolean gm, int baseAddr, boolean w_kgm, Channel channel) {
|
||||
LocalDateTime buzzerRingingTime = config.getBuzzerRingingTime();
|
||||
if (buzzerRingingTime == null) {
|
||||
return;
|
||||
}
|
||||
if (config.isRunning())
|
||||
return;
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if (now.isAfter(buzzerRingingTime.plusSeconds(3))) { //蜂鸣器响了超过3秒
|
||||
if ((km || gm) && !config.isTriggerOpenOrClose()) {
|
||||
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getConfigVO().getW_kgm(), w_kgm, true, channel);
|
||||
config.setTriggerOpenOrClose(true);
|
||||
}
|
||||
if (now.isAfter(buzzerRingingTime.plusSeconds(6))) { //如果响铃超过6秒门还没有进入运动状态,取消触发状态
|
||||
// this.plcGatewayService.writeSingleCoil(baseAddr, config.getConfigVO().getW_jb(), false, channel);
|
||||
// config.cancelControl();
|
||||
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getConfigVO().getW_kgm(), w_kgm, false, channel);
|
||||
config.setTriggerOpenOrClose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,9 @@ public class SdyPslServiceImpl implements RealDeviceService {
|
||||
@Autowired
|
||||
private PlcGatewayService plcGatewayService;
|
||||
|
||||
@Autowired
|
||||
private SdyPsdServiceImpl sdyPsdService;
|
||||
|
||||
@Override
|
||||
public boolean canHandle(RealDeviceConfig deviceConfig) {
|
||||
return deviceConfig instanceof SdyPslConfig;
|
||||
@ -72,12 +75,14 @@ public class SdyPslServiceImpl implements RealDeviceService {
|
||||
//真实屏蔽门的状态等
|
||||
SdyPsdConfigVO psdConfigVO = null;
|
||||
Integer psdBaseAddr = null;
|
||||
Boolean psd_r_km = null;
|
||||
Boolean psd_r_gm = null;
|
||||
Boolean psd_w_kgm = null;
|
||||
if (realPsd != null) {
|
||||
psdConfigVO = realPsd.getConfigVO();
|
||||
psdBaseAddr = plcGateway.getConfig().getAddr() + psdConfigVO.getAddr();
|
||||
ByteBuf psdStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, psdConfigVO.getAddr(), psdConfigVO.getQuantity());
|
||||
psd_r_km = RealDeviceConfig.getBitOf(psdStatus, psdConfigVO.getR_km());
|
||||
psd_r_gm = RealDeviceConfig.getBitOf(psdStatus, psdConfigVO.getR_gm());
|
||||
psd_w_kgm = RealDeviceConfig.getBitOf(psdStatus, psdConfigVO.getW_kgm());
|
||||
}
|
||||
@ -101,8 +106,9 @@ public class SdyPslServiceImpl implements RealDeviceService {
|
||||
//互锁解除灯
|
||||
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_hsjc_light(), w_hsjc_light, r_hsjc_key, channel);
|
||||
}
|
||||
//psl操作灯和开关门按钮
|
||||
//允许禁止钥匙处于允许位
|
||||
if (r_yxjz_key) {
|
||||
if (psd_r_km || psd_r_gm) { //屏蔽门处于开门/关门到位,控制才生效
|
||||
if (vrPsd != null) {
|
||||
if (r_gm_button && !r_km_button) {
|
||||
if (!vrPsd.isSettingClose() && !vrPsd.isClose()) {
|
||||
@ -115,11 +121,12 @@ public class SdyPslServiceImpl implements RealDeviceService {
|
||||
}
|
||||
}
|
||||
} else if (realPsd != null) {
|
||||
if (r_gm_button && !r_km_button) {
|
||||
plcGatewayService.checkEqualAndWriteSingleCoil(psdBaseAddr, psdConfigVO.getW_kgm(), psd_w_kgm, false, channel);
|
||||
if (r_gm_button && !r_km_button && psd_r_km) {
|
||||
sdyPsdService.openOrClose(realPsd, psd_r_km, psd_r_gm, psdBaseAddr, channel);
|
||||
}
|
||||
if (r_km_button && !r_gm_button && psd_r_gm) {
|
||||
sdyPsdService.openOrClose(realPsd, psd_r_km, psd_r_gm, psdBaseAddr, channel);
|
||||
}
|
||||
if (r_km_button && !r_gm_button) {
|
||||
plcGatewayService.checkEqualAndWriteSingleCoil(psdBaseAddr, psdConfigVO.getW_kgm(), psd_w_kgm, true, channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user