|  |  | 
 |  |  |                 return motionList; | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             BasConveyorSta basConveyorStaDest = basConveyorStaService.selectBySiteNo(task.getDestSite()); | 
 |  |  |             if (basConveyorStaDest == null) { | 
 |  |  |                 return motionList; | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             //检测穿梭车是否有任务绑定 | 
 |  |  |             boolean shuttleResult = Utils.checkShuttleHasBinding(shuttleDevice, task.getTaskNo()); | 
 |  |  |             if (shuttleResult) { | 
 |  |  | 
 |  |  |                             dto.setLiftNo(transferLiftDevice.getId().intValue()); | 
 |  |  |                             dto.setLev(Utils.getLev(task.getDestLoc())); | 
 |  |  |                             dto.setStaNo(Integer.parseInt(task.getDestSite())); | 
 |  |  |                             dto.setDevpNo(basConveyorStaDest.getConveyorDeviceId().intValue()); | 
 |  |  |                             dto.setReleaseLift(1);//执行完成后释放提升机 | 
 |  |  |                         })) | 
 |  |  |                 )); | 
 
 |  |  | 
 |  |  |             motion.setMotionCtg(MotionCtgType.LIFT_WITH_GOODS.val()); | 
 |  |  |  | 
 |  |  |             if (null != origin) { | 
 |  |  |                 motion.setOrigin(String.valueOf(liftDispatcher.getLiftLevOffset(target.getLiftNo(), origin.getLev()))); | 
 |  |  |                 motion.setOriDrt(origin.getStaNo());//源站 | 
 |  |  | //                motion.setOrigin(String.valueOf(liftDispatcher.getLiftLevOffset(target.getLiftNo(), origin.getLev()))); | 
 |  |  | //                motion.setOriDrt(origin.getStaNo());//源站 | 
 |  |  |                 motion.setOrigin(String.valueOf(origin.getStaNo())); | 
 |  |  |             } | 
 |  |  |             motion.setTarget(String.valueOf(liftDispatcher.getLiftLevOffset(target.getLiftNo(), target.getLev()))); | 
 |  |  |             motion.setTarDrt(target.getStaNo());//目标站 | 
 |  |  | //            motion.setTarget(String.valueOf(liftDispatcher.getLiftLevOffset(target.getLiftNo(), target.getLev()))); | 
 |  |  | //            motion.setTarDrt(target.getStaNo());//目标站 | 
 |  |  |             motion.setTarget(String.valueOf(target.getStaNo())); | 
 |  |  |  | 
 |  |  |             if (target.getDevpNo() != null) { | 
 |  |  |                 motion.setDockNo(String.valueOf(target.getDevpNo()));//输送线ID | 
 
 |  |  | 
 |  |  | //                    return false; | 
 |  |  | //                } | 
 |  |  |  | 
 |  |  |                 //判断目标站是否有托盘 | 
 |  |  |                 Integer conveyorDeviceId = Integer.parseInt(motion.getDockNo()); | 
 |  |  |                 DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Conveyor, conveyorDeviceId); | 
 |  |  |                 if (devpThread == null) { | 
 |  |  |                     return false; | 
 |  |  |                 } | 
 |  |  | //                //*************标准系统代码******************** | 
 |  |  | //                StaProtocol staProtocol = devpThread.getStation().get(motion.getTarDrt()); | 
 |  |  | //                if (staProtocol == null) { | 
 |  |  | 
 |  |  | //                } | 
 |  |  | //                //************************************************* | 
 |  |  |  | 
 |  |  |  | 
 |  |  |                 //*************此代码为光泰定制代码******************** | 
 |  |  |                 Integer tarDrt = motion.getTarDrt(); | 
 |  |  |                 if (tarDrt == 31001) { | 
 |  |  |                     tarDrt = 31004; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 StaProtocol staProtocol = devpThread.getStation().get(tarDrt); | 
 |  |  |                 if (staProtocol == null) { | 
 |  |  |                     return false; | 
 |  |  |                 } | 
 |  |  |                 if (!staProtocol.isAutoing()) { | 
 |  |  |                     return false; | 
 |  |  |                 } | 
 |  |  |                 if (staProtocol.isLoading()) { | 
 |  |  |                     return false; | 
 |  |  |                 } | 
 |  |  |                 if (staProtocol.getWorkNo().intValue() != 0) { | 
 |  |  |                     return false; | 
 |  |  |                 } | 
 |  |  |                 //************************************************* | 
 |  |  |  | 
 |  |  |                 command = liftThread.getPalletInOutCommand(assignCommand.getDeviceTaskNo(), Integer.parseInt(motion.getOrigin()), Integer.parseInt(motion.getTarget()), motion.getOriDrt(), motion.getTarDrt(), LiftCommandModeType.PALLET_INOUT); | 
 |  |  |                 command = liftThread.getPalletInOutCommand(assignCommand.getDeviceTaskNo(), Integer.parseInt(motion.getOrigin()), Integer.parseInt(motion.getTarget()), motion.getOriDrt(), motion.getTarDrt(), task.getTaskSts() < 100 ? LiftCommandModeType.PALLET_IN : LiftCommandModeType.PALLET_OUT); | 
 |  |  |                 list.addAll(command); | 
 |  |  |  | 
 |  |  |                 motion.setTemp(String.valueOf(assignCommand.getDeviceTaskNo())); | 
 
 |  |  | 
 |  |  |  | 
 |  |  |     NONE(-1, "未知类型"), | 
 |  |  |     MOVE(1, "提升机升降"), | 
 |  |  |     PALLET_INOUT(2, "托盘出入"), | 
 |  |  | //    PALLET_INOUT(2, "托盘出入"), | 
 |  |  |     LOCK(3, "锁定提升机"), | 
 |  |  |     UNLOCK(4, "解锁提升机"), | 
 |  |  |     RESET(5, "复位"), | 
 |  |  |     MOVE_CAR(6, "提升机升降小车"), | 
 |  |  |     PALLET_IN(7, "托盘入"), | 
 |  |  |     PALLET_OUT(8, "托盘出"), | 
 |  |  |     ; | 
 |  |  |  | 
 |  |  |     public Integer id; | 
 
 |  |  | 
 |  |  |                             continue; | 
 |  |  |                         } | 
 |  |  |  | 
 |  |  |                         // 获取条码扫描仪信息 | 
 |  |  |                         DeviceBarcode deviceBarcode = deviceBarcodeService.getById(basConveyorSta.getBarcodeId()); | 
 |  |  |                         if(deviceBarcode == null) { | 
 |  |  |                             continue; | 
 |  |  |                         } | 
 |  |  |                         BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, Integer.parseInt(deviceBarcode.getDeviceId())); | 
 |  |  |                         if (barcodeThread == null) { | 
 |  |  |                             continue; | 
 |  |  |                         } | 
 |  |  |                         String barcode = barcodeThread.getBarcode(); | 
 |  |  | //                        // 获取条码扫描仪信息 | 
 |  |  | //                        DeviceBarcode deviceBarcode = deviceBarcodeService.getById(basConveyorSta.getBarcodeId()); | 
 |  |  | //                        if(deviceBarcode == null) { | 
 |  |  | //                            continue; | 
 |  |  | //                        } | 
 |  |  | //                        BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, Integer.parseInt(deviceBarcode.getDeviceId())); | 
 |  |  | //                        if (barcodeThread == null) { | 
 |  |  | //                            continue; | 
 |  |  | //                        } | 
 |  |  | //                        String barcode = barcodeThread.getBarcode(); | 
 |  |  | //                        if (!Cools.isEmpty(barcode)) { | 
 |  |  | //                            News.info("{}号条码扫描器检测条码信息:{}", deviceBarcode.getId(), barcode); | 
 |  |  | //                        } | 
 |  |  |  | 
 |  |  |                         String barcode = staProtocol.getBarcode(); | 
 |  |  |                         if (!Cools.isEmpty(barcode)) { | 
 |  |  |                             News.info("{}号条码扫描器检测条码信息:{}", deviceBarcode.getId(), barcode); | 
 |  |  |                             News.info("条码扫描器检测条码信息:{}", barcode); | 
 |  |  |                         } | 
 |  |  |  | 
 |  |  |                         // 判断重复工作档 | 
 
 |  |  | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             String liftLocNo = Utils.getLocNo(Utils.getRow(standby.getDeviceStandbyLoc()), Utils.getBay(standby.getDeviceStandbyLoc()), Utils.getLev(locNo)); | 
 |  |  |  | 
 |  |  |             if (locNo.equals(liftLocNo)) { | 
 |  |  |                 finalDistance = 100; | 
 |  |  |                 recentLiftThread = liftThread; | 
 |  |  |                 continue; | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             List<NavigateNode> nodeList = navigateUtils.calc(locNo, liftLocNo, NavigationMapType.NONE.id, null); | 
 |  |  |             if (nodeList == null) { | 
 |  |  |                 continue; | 
 
 |  |  | 
 |  |  |                 continue; | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             if (shuttleProtocol.getCurrentLocNo() == null) { | 
 |  |  |                 continue; | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             int shuttleLev = Utils.getLev(shuttleProtocol.getCurrentLocNo()); | 
 |  |  |             if (shuttleLev == lev) { | 
 |  |  |                 currentLevDevices.add(device); | 
 
 |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  | //                staProtocol.setWorkMode((int) siemensS7Net.getByteTransform().TransInt16(result.Content, i * 40 + 8));// 工作模式 | 
 |  |  |                 staProtocol.setWorkNo((short) siemensS7Net.getByteTransform().TransInt32(result.Content, i * 18 + 10));     // 工作号 | 
 |  |  |                 staProtocol.setStaNo((short) siemensS7Net.getByteTransform().TransInt32(result.Content, i * 18 + 14));   // 目标站 | 
 |  |  |  | 
 |  |  |                 staProtocol.setWorkNo((short) siemensS7Net.getByteTransform().TransInt16(result.Content, i * 18 + 10));     // 工作号 | 
 |  |  |                 staProtocol.setStaNo((short) siemensS7Net.getByteTransform().TransInt16(result.Content, i * 18 + 12));   // 目标站 | 
 |  |  |  | 
 |  |  |                 if (!staProtocol.isPakMk() && !staProtocol.isLoading()) { | 
 |  |  |                     staProtocol.setPakMk(true); | 
 |  |  | 
 |  |  |     @Override | 
 |  |  |     public boolean writeWorkNo(int siteId, short workNo) { | 
 |  |  |         int index = staNos1.indexOf(siteId); | 
 |  |  |         index += 1; | 
 |  |  |  | 
 |  |  |         OperateResult write = siemensS7Net.Write("DB83." + (index *8+6),(int) workNo);    // 工作号 | 
 |  |  |  | 
 |  |  | 
 |  |  |     @Override | 
 |  |  |     public boolean writeStaNo(int siteId,short staNo) { | 
 |  |  |         int index = staNos1.indexOf(siteId); | 
 |  |  |         index += 1; | 
 |  |  |  | 
 |  |  |         OperateResult write = siemensS7Net.Write("DB101." + (index * 8 + 4),(int) staNo);    // 目标站 | 
 |  |  |  | 
 |  |  | 
 |  |  |     @Override | 
 |  |  |     public boolean writeWorkSta(int siteId, short workNo, short staNo) { | 
 |  |  |         int index = staNos1.indexOf(siteId); | 
 |  |  |         index += 1; | 
 |  |  |  | 
 |  |  |         short[] array = new short[2]; | 
 |  |  |         array[0] = workNo; | 
 |  |  |         array[1] = staNo; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         String workNoAddress = "DB101." + (index * 8 + 6); | 
 |  |  |         String staNoAddress = "DB101." + (index * 8 + 4); | 
 |  |  |         String workNoAddress = "DB83." + (index * 8 + 6); | 
 |  |  |         String staNoAddress = "DB83." + (index * 8 + 4); | 
 |  |  |         OperateResult write1 = null;    // 工作号 | 
 |  |  |         OperateResult write2 = null;     // 目标站 | 
 |  |  |  | 
 |  |  |         //任务下发次数 | 
 |  |  |         int writeCount = 0; | 
 |  |  |         do { | 
 |  |  |             write1 = siemensS7Net.Write(workNoAddress, (int) workNo);    // 工作号 | 
 |  |  |             write2 = siemensS7Net.Write(staNoAddress, (int) staNo); | 
 |  |  |             write1 = siemensS7Net.Write(workNoAddress,  workNo);    // 工作号 | 
 |  |  |             write2 = siemensS7Net.Write(staNoAddress, staNo); | 
 |  |  |             if ((write1.IsSuccess && write2.IsSuccess)) { | 
 |  |  |                 OperateResultExOne<byte[]> readResult = siemensS7Net.Read(staNoAddress, (short) 8); | 
 |  |  |                 if (readResult.IsSuccess) { | 
 |  |  |                     int staNo2 = siemensS7Net.getByteTransform().TransInt32(readResult.Content, 0); | 
 |  |  |                     int workNo2 = siemensS7Net.getByteTransform().TransInt32(readResult.Content, 4); | 
 |  |  |                     int staNo2 = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 0); | 
 |  |  |                     int workNo2 = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 4); | 
 |  |  |                     if (workNo == workNo2 && staNo == staNo2) { | 
 |  |  |                         //任务命令写入成功 | 
 |  |  |                         log.info("写入输送线命令后返回成功,并且回读成功。输送线plc编号={},{},{},写入次数={}", siteId, JSON.toJSON(workNo), JSON.toJSON(staNo), writeCount); | 
 
 |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         LiftDispatcher liftDispatcher = SpringUtils.getBean(LiftDispatcher.class); | 
 |  |  |         Integer lev = liftDispatcher.getLiftLevOffset(this.device.getId().intValue(), liftProtocol.getLev()); | 
 |  |  |         if (null == lev){ | 
 |  |  |             News.error("提升机获取当前层为空"); | 
 |  |  |             response.setMessage("提升机获取当前层为空"); | 
 |  |  |             return response; | 
 |  |  |  | 
 |  |  |         Integer origin = command.getOriginLev(); | 
 |  |  |         Integer target = command.getTargetLev(); | 
 |  |  |         if (command.getMode() == 2) { | 
 |  |  |             origin = liftDispatcher.getLiftLevOffset(this.device.getId().intValue(), liftProtocol.getLev()); | 
 |  |  |             target = liftDispatcher.getLiftLevOffset(this.device.getId().intValue(), command.getTargetLev()); | 
 |  |  |         } | 
 |  |  |         array[1] = lev.shortValue(); | 
 |  |  |         Integer targetLev = liftDispatcher.getLiftLevOffset(this.device.getId().intValue(), command.getTargetLev()); | 
 |  |  |         if (null == targetLev){ | 
 |  |  |             News.error("提升机获取目标层为空"); | 
 |  |  |             response.setMessage("提升机获取目标层为空"); | 
 |  |  |             return response; | 
 |  |  |         } | 
 |  |  |         array[2] = targetLev.shortValue(); | 
 |  |  |  | 
 |  |  |         array[1] = origin.shortValue(); | 
 |  |  |         array[2] = target.shortValue(); | 
 |  |  |  | 
 |  |  |         OperateResult result = siemensS7Net.Write("DB83.0", array); | 
 |  |  |         if (result != null && result.IsSuccess) { | 
 |  |  | 
 |  |  |     public List<LiftCommand> getMoveCommand(Integer taskNo, Integer sourceLev, Integer targetLev, LiftCommandModeType mode) { | 
 |  |  |         /** | 
 |  |  |          * 任务类型 | 
 |  |  |          * 1=移托盘;升降机将源站台托盘移到目标站台 | 
 |  |  |          * 2=移小车,升降机移到目标层,等待 | 
 |  |  |          1=移托盘;升降机将源站台托盘移到目标站台 | 
 |  |  |          2=换层,升降机移到目标层,等待 | 
 |  |  |          3=入库托盘,升降机将源站台托盘移到目标层数; | 
 |  |  |          4=出库托盘,升降机将源站台托盘移到目标站台 | 
 |  |  |          */ | 
 |  |  |         short taskMode = 2; | 
 |  |  |         if (mode.equals(LiftCommandModeType.PALLET_INOUT)) { | 
 |  |  |             taskMode = 1; | 
 |  |  |         if (mode.equals(LiftCommandModeType.PALLET_IN)) { | 
 |  |  |             taskMode = 3; | 
 |  |  |         } else if (mode.equals(LiftCommandModeType.PALLET_OUT)) { | 
 |  |  |             taskMode = 4; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 开始任务 | 
 |  |  | 
 |  |  |         LiftCommand command = new LiftCommand(); | 
 |  |  |         command.setLiftNo(Integer.valueOf(this.device.getDeviceNo())); | 
 |  |  |         command.setBody(JSON.toJSONString(array)); | 
 |  |  |         command.setMode(LiftCommandModeType.MOVE.id); | 
 |  |  |         command.setMode(mode.id); | 
 |  |  |         command.setOriginLev(sourceLev); | 
 |  |  |         command.setTargetLev(targetLev); | 
 |  |  |  | 
 
 |  |  | 
 |  |  |  | 
 |  |  |     private static final boolean DEBUG = false;//调试模式 | 
 |  |  |  | 
 |  |  |     private List<JSONObject> socketReadResults = new ArrayList<>(); | 
 |  |  |     private List<JSONObject> socketResults = new ArrayList<>(); | 
 |  |  |  | 
 |  |  |     //原始设备数据 | 
 |  |  | 
 |  |  |             while (true) { | 
 |  |  |                 try { | 
 |  |  |                     listenSocketMessage(); | 
 |  |  |                     listenInit();//监听初始化事件 | 
 |  |  |                 } catch (Exception e) { | 
 |  |  |                     e.printStackTrace(); | 
 |  |  |                 } | 
 |  |  | 
 |  |  |         Thread otherThread = new Thread(() -> { | 
 |  |  |             while (true) { | 
 |  |  |                 try { | 
 |  |  |                     listenInit();//监听初始化事件 | 
 |  |  |                     saveLog();//保存数据 | 
 |  |  |                 } catch (Exception e) { | 
 |  |  |                     e.printStackTrace(); | 
 |  |  | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             JSONObject result = JSON.parseObject(sb.toString());//得到响应结果集 | 
 |  |  |             if (!socketResults.isEmpty() && socketResults.size() >= 5) { | 
 |  |  |  | 
 |  |  |             String msgType = result.getString("msgType"); | 
 |  |  |             if ("responseMsg".equals(msgType)) { | 
 |  |  |                 JSONObject response = result.getJSONObject("response"); | 
 |  |  |                 JSONObject body = response.getJSONObject("body"); | 
 |  |  |                 if (body.containsKey("workingMode")) { | 
 |  |  |                     //read | 
 |  |  |                     socketReadResults.add(body); | 
 |  |  |                     return; | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             if (!socketResults.isEmpty() && socketResults.size() >= 20) { | 
 |  |  |                 socketResults.remove(0);//清理头节点 | 
 |  |  |             } | 
 |  |  |             socketResults.add(result);//添加数据 | 
 |  |  | 
 |  |  |  | 
 |  |  |             //----------读取四向穿梭车状态----------- | 
 |  |  |             NyShuttleHttpCommand readStatusCommand = getReadStatusCommand(Integer.parseInt(device.getDeviceNo())); | 
 |  |  |             JSONObject data = requestCommand(readStatusCommand); | 
 |  |  |             requestCommandAsync(readStatusCommand);//请求状态 | 
 |  |  |  | 
 |  |  |             if (this.socketReadResults.isEmpty()) { | 
 |  |  |                 if (System.currentTimeMillis() - shuttleProtocol.getLastOnlineTime() > 1000 * 60) { | 
 |  |  |                     //最后一次上线时间超过60s,认定离线 | 
 |  |  |                     this.shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.OFFLINE); | 
 |  |  |                 } | 
 |  |  |                 return; | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             JSONObject data = this.socketReadResults.get(0); | 
 |  |  |             this.socketReadResults.remove(0); | 
 |  |  |             if (data == null) { | 
 |  |  |                 if (System.currentTimeMillis() - shuttleProtocol.getLastOnlineTime() > 1000 * 60) { | 
 |  |  |                     //最后一次上线时间超过60s,认定离线 | 
 |  |  | 
 |  |  |                 ///读取四向穿梭车状态-end | 
 |  |  |  | 
 |  |  |                 //小车处于运行中,将标记置为true | 
 |  |  |                 if (shuttleProtocol.getDeviceStatus() == 1) { | 
 |  |  |                 if (shuttleProtocol.getDeviceStatus() == 0) { | 
 |  |  |                     shuttleProtocol.setPakMk(true); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 if (shuttleProtocol.getProtocolStatusType() == null && shuttleProtocol.getDeviceStatus().intValue() == 0) { | 
 |  |  |                 if (shuttleProtocol.getProtocolStatusType() == null && shuttleProtocol.getDeviceStatus().intValue() == 1) { | 
 |  |  |                     //小车空闲状态、小车任务状态为未知,认定曾离线过,需要复位成空闲 | 
 |  |  |                     shuttleProtocol.setProtocolStatusType(ShuttleProtocolStatusType.IDLE); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 if (shuttleProtocol.getProtocolStatusType().equals(ShuttleProtocolStatusType.OFFLINE) && shuttleProtocol.getDeviceStatus().intValue() == 1) { | 
 |  |  |                     this.shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 this.originDeviceData = data; | 
 |  |  | 
 |  |  |         return result;//返回Body结果集 | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void requestCommandAsync(NyShuttleHttpCommand httpCommand) throws IOException { | 
 |  |  |         if (this.socket == null) { | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //压缩数据包 | 
 |  |  |         JSONObject data = JSON.parseObject(JSON.toJSONString(httpCommand)); | 
 |  |  |         data.remove("nodes"); | 
 |  |  |  | 
 |  |  |         // 获取输出流 | 
 |  |  |         OutputStreamWriter writer = new OutputStreamWriter(this.socket.getOutputStream()); | 
 |  |  |         writer.write(JSON.toJSONString(data) + "\r\n"); | 
 |  |  |         writer.flush(); | 
 |  |  | //            System.out.println("Sent message to server: " + JSON.toJSONString(httpCommand)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private JSONObject filterBodyData(JSONObject data) { | 
 |  |  |         Object response = data.get("response"); | 
 |  |  |         if (response == null) { |