| | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.service.BasDevpService; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.core.network.DeviceConnectPool; |
| | | import com.zy.core.thread.StationThread; |
| | | import com.alibaba.fastjson.JSON; |
| | |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.asrs.entity.DeviceConfig; |
| | | import com.zy.asrs.entity.DeviceDataLog; |
| | | import com.zy.asrs.entity.BasStationOpt; |
| | | import com.zy.asrs.service.BasStationOptService; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.network.ZyStationConnectDriver; |
| | | import com.zy.core.cache.MessageQueue; |
| | |
| | | private DeviceConfig deviceConfig; |
| | | private RedisUtil redisUtil; |
| | | private ZyStationConnectDriver zyStationConnectDriver; |
| | | private int deviceLogCollectTime = 200; |
| | | private long deviceDataLogTime = System.currentTimeMillis(); |
| | | |
| | | public ZyStationThread(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | |
| | | @SuppressWarnings("InfiniteLoopStatement") |
| | | public void run() { |
| | | this.connect(); |
| | | deviceLogCollectTime = Utils.getDeviceLogCollectTime(); |
| | | |
| | | //设备读取 |
| | | Thread readThread = new Thread(() -> { |
| | | while (true) { |
| | | try { |
| | | readStatus(); |
| | | Thread.sleep(200); |
| | | } catch (Exception e) { |
| | | log.error("StationThread Fail", e); |
| | | } |
| | | } |
| | | }); |
| | | readThread.start(); |
| | | |
| | | while (true) { |
| | | try { |
| | | int step = 1; |
| | |
| | | step = task.getStep(); |
| | | } |
| | | switch (step) { |
| | | // 读数据 |
| | | case 1: |
| | | readStatus(); |
| | | break; |
| | | case 2: |
| | | sendCommand((StationCommand) task.getData()); |
| | | break; |
| | |
| | | |
| | | OutputQueue.DEVP.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), deviceConfig.getDeviceNo())); |
| | | |
| | | if (System.currentTimeMillis() - deviceDataLogTime > 1000 * 1) { |
| | | if (System.currentTimeMillis() - deviceDataLogTime > deviceLogCollectTime) { |
| | | //保存数据记录 |
| | | DeviceDataLog deviceDataLog = new DeviceDataLog(); |
| | | deviceDataLog.setOriginData(JSON.toJSONString(zyStationStatusEntities)); |
| | |
| | | |
| | | @Override |
| | | public CommandResponse sendCommand(StationCommand command) { |
| | | CommandResponse commandResponse = zyStationConnectDriver.sendCommand(command); |
| | | return commandResponse; |
| | | CommandResponse commandResponse = null; |
| | | try { |
| | | commandResponse = zyStationConnectDriver.sendCommand(command); |
| | | return commandResponse; |
| | | } finally { |
| | | BasStationOptService optService = SpringUtils.getBean(BasStationOptService.class); |
| | | List<ZyStationStatusEntity> statusListEntity = zyStationConnectDriver.getStatus(); |
| | | ZyStationStatusEntity matched = null; |
| | | if (statusListEntity != null) { |
| | | for (ZyStationStatusEntity e : statusListEntity) { |
| | | if (e.getStationId() != null && e.getStationId().equals(command.getStationId())) { |
| | | matched = e; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | BasStationOpt basStationOpt = new BasStationOpt( |
| | | command.getTaskNo(), |
| | | command.getStationId(), |
| | | new Date(), |
| | | "MOVE", |
| | | command.getStationId(), |
| | | command.getTargetStaNo(), |
| | | null, |
| | | null, |
| | | null, |
| | | JSON.toJSONString(command), |
| | | JSON.toJSONString(matched), |
| | | 1, |
| | | JSON.toJSONString(commandResponse) |
| | | ); |
| | | if (optService != null) { |
| | | optService.insert(basStationOpt); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |