| | |
| | | package com.zy.core.network; |
| | | |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.model.CommandResponse; |
| | | import com.zy.core.model.command.StationCommand; |
| | |
| | | @Slf4j |
| | | public class ZyStationConnectDriver implements ThreadHandler { |
| | | |
| | | private static final ZyStationFakeConnect zyStationFakeConnect = new ZyStationFakeConnect(); |
| | | |
| | | private boolean connected = false; |
| | | private DeviceConfig deviceConfig; |
| | | private RedisUtil redisUtil; |
| | | private ZyStationConnectApi zyStationConnectApi; |
| | | private volatile boolean closed = false; |
| | | private ScheduledExecutorService executor; |
| | | |
| | | public ZyStationConnectDriver(DeviceConfig deviceConfig) { |
| | | public ZyStationConnectDriver(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | | this.deviceConfig = deviceConfig; |
| | | this.redisUtil = redisUtil; |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public boolean connect() { |
| | | if (deviceConfig.getFake() == 0) { |
| | | zyStationConnectApi = new ZyStationRealConnect(deviceConfig); |
| | | zyStationConnectApi = new ZyStationRealConnect(deviceConfig, redisUtil); |
| | | } else { |
| | | zyStationConnectApi = new ZyStationFakeConnect(deviceConfig); |
| | | zyStationFakeConnect.addFakeConnect(deviceConfig, redisUtil); |
| | | zyStationConnectApi = zyStationFakeConnect; |
| | | } |
| | | |
| | | boolean connect = zyStationConnectApi.connect(); |
| | |
| | | if (zyStationConnectApi == null) { |
| | | return null; |
| | | } |
| | | return zyStationConnectApi.getStatus(); |
| | | return zyStationConnectApi.getStatus(deviceConfig.getDeviceNo()); |
| | | } |
| | | |
| | | public CommandResponse sendCommand(StationCommand command) { |
| | | return zyStationConnectApi.sendCommand(command); |
| | | return zyStationConnectApi.sendCommand(deviceConfig.getDeviceNo(), command); |
| | | } |
| | | } |