| | |
| | | import com.zy.core.network.entity.ZyStationStatusEntity; |
| | | import java.util.List; |
| | | import com.zy.core.network.fake.ZyStationFakeConnect; |
| | | import com.zy.core.network.fake.ZyStationFakeSegConnect; |
| | | import com.zy.core.network.real.ZyStationRealConnect; |
| | | import com.zy.core.network.real.ZyStationV3RealConnect; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.concurrent.ScheduledExecutorService; |
| | |
| | | public class ZyStationConnectDriver implements ThreadHandler { |
| | | |
| | | private static final ZyStationFakeConnect zyStationFakeConnect = new ZyStationFakeConnect(); |
| | | private static final ZyStationFakeSegConnect zyStationFakeSegConnect = new ZyStationFakeSegConnect(); |
| | | |
| | | private boolean connected = false; |
| | | private DeviceConfig deviceConfig; |
| | |
| | | @Override |
| | | public boolean connect() { |
| | | if (deviceConfig.getFake() == 0) { |
| | | zyStationConnectApi = new ZyStationRealConnect(deviceConfig, redisUtil); |
| | | if ("ZyStationV3Thread".equals(deviceConfig.getThreadImpl())) { |
| | | zyStationConnectApi = new ZyStationV3RealConnect(deviceConfig, redisUtil); |
| | | } else { |
| | | zyStationConnectApi = new ZyStationRealConnect(deviceConfig, redisUtil); |
| | | } |
| | | } else { |
| | | zyStationFakeConnect.addFakeConnect(deviceConfig, redisUtil); |
| | | zyStationConnectApi = zyStationFakeConnect; |
| | | if ("ZyStationV3Thread".equals(deviceConfig.getThreadImpl())) { |
| | | zyStationFakeSegConnect.addFakeConnect(deviceConfig, redisUtil); |
| | | zyStationConnectApi = zyStationFakeSegConnect; |
| | | } else { |
| | | zyStationFakeConnect.addFakeConnect(deviceConfig, redisUtil); |
| | | zyStationConnectApi = zyStationFakeConnect; |
| | | } |
| | | } |
| | | |
| | | boolean connect = zyStationConnectApi.connect(); |
| | |
| | | public CommandResponse sendCommand(StationCommand command) { |
| | | return zyStationConnectApi.sendCommand(deviceConfig.getDeviceNo(), command); |
| | | } |
| | | |
| | | public CommandResponse sendOriginCommand(String address, short[] data) { |
| | | return zyStationConnectApi.sendOriginCommand(address, data); |
| | | } |
| | | |
| | | public byte[] readOriginCommand(String address, int length) { |
| | | return zyStationConnectApi.readOriginCommand(address, length); |
| | | } |
| | | } |