| | |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.model.CommandResponse; |
| | | import com.zy.core.model.command.StationCommand; |
| | | import com.zy.core.network.api.ZyStationConnectApi; |
| | |
| | | import java.util.List; |
| | | import com.zy.core.network.fake.ZyStationFakeConnect; |
| | | import com.zy.core.network.fake.ZyStationFakeSegConnect; |
| | | import com.zy.core.network.fake.ZyStationV4FakeSegConnect; |
| | | import com.zy.core.network.real.ZyStationRealConnect; |
| | | import com.zy.core.network.real.ZyStationV3RealConnect; |
| | | import com.zy.core.network.real.ZyStationV4RealConnect; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.concurrent.ScheduledExecutorService; |
| | |
| | | |
| | | private static final ZyStationFakeConnect zyStationFakeConnect = new ZyStationFakeConnect(); |
| | | private static final ZyStationFakeSegConnect zyStationFakeSegConnect = new ZyStationFakeSegConnect(); |
| | | private static final ZyStationV4FakeSegConnect zyStationV4FakeSegConnect = new ZyStationV4FakeSegConnect(); |
| | | |
| | | private boolean connected = false; |
| | | private DeviceConfig deviceConfig; |
| | |
| | | if (deviceConfig.getFake() == 0) { |
| | | if ("ZyStationV3Thread".equals(deviceConfig.getThreadImpl())) { |
| | | zyStationConnectApi = new ZyStationV3RealConnect(deviceConfig, redisUtil); |
| | | } else if ("ZyStationV4Thread".equals(deviceConfig.getThreadImpl())) { |
| | | zyStationConnectApi = new ZyStationV4RealConnect(deviceConfig, redisUtil); |
| | | } else { |
| | | zyStationConnectApi = new ZyStationRealConnect(deviceConfig, redisUtil); |
| | | } |
| | |
| | | if ("ZyStationV3Thread".equals(deviceConfig.getThreadImpl())) { |
| | | zyStationFakeSegConnect.addFakeConnect(deviceConfig, redisUtil); |
| | | zyStationConnectApi = zyStationFakeSegConnect; |
| | | } else if ("ZyStationV4Thread".equals(deviceConfig.getThreadImpl())) { |
| | | zyStationV4FakeSegConnect.addFakeConnect(deviceConfig, redisUtil); |
| | | zyStationConnectApi = zyStationV4FakeSegConnect; |
| | | } else { |
| | | zyStationFakeConnect.addFakeConnect(deviceConfig, redisUtil); |
| | | zyStationConnectApi = zyStationFakeConnect; |
| | |
| | | } |
| | | |
| | | public CommandResponse sendCommand(StationCommand command) { |
| | | return zyStationConnectApi.sendCommand(deviceConfig.getDeviceNo(), command); |
| | | while (true) { |
| | | Object lock = redisUtil.get(RedisKeyType.STATION_EXECUTE_COMMAND_LOCK.key); |
| | | if(lock != null) { |
| | | try { |
| | | Thread.sleep(500); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }else { |
| | | redisUtil.set(RedisKeyType.STATION_EXECUTE_COMMAND_LOCK.key, "lock", 60 * 5); |
| | | break; |
| | | } |
| | | } |
| | | CommandResponse commandResponse = zyStationConnectApi.sendCommand(deviceConfig.getDeviceNo(), command); |
| | | redisUtil.del(RedisKeyType.STATION_EXECUTE_COMMAND_LOCK.key); |
| | | return commandResponse; |
| | | } |
| | | |
| | | public CommandResponse sendOriginCommand(String address, short[] data) { |