| | |
| | | import com.zy.core.dispatcher.ShuttleDispatchUtils; |
| | | import com.zy.core.enums.*; |
| | | import com.zy.core.model.CommandResponse; |
| | | import com.zy.core.model.TrafficControlDataModel; |
| | | import com.zy.core.model.command.ShuttleAssignCommand; |
| | | import com.zy.core.model.command.ShuttleCommand; |
| | | import com.zy.core.model.command.ShuttleRedisCommand; |
| | |
| | | return false; |
| | | } |
| | | |
| | | //清空下发索引 |
| | | Set<String> keys = redisUtil.searchKeys(RedisKeyType.SHUTTLE_SEND_COMMAND_INDEX.key + shuttleNo); |
| | | for (String key : keys) { |
| | | redisUtil.del(key); |
| | | } |
| | | //Clear Traffic Control |
| | | trafficControlThread.forceCancelTrafficControl(shuttleNo); |
| | | |
| | | ShuttleRedisCommand redisCommand = new ShuttleRedisCommand(); |
| | | |
| | |
| | | return false; |
| | | } |
| | | |
| | | public synchronized boolean executeWork(Integer shuttleNo, Integer taskNo) { |
| | | public boolean executeWork(Integer shuttleNo, Integer taskNo) { |
| | | Object obj = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + taskNo); |
| | | if (obj == null) { |
| | | return false; |
| | |
| | | return false; |
| | | } |
| | | |
| | | News.info("execute check command {},{}", shuttleNo, taskNo); |
| | | //检测命令 |
| | | int checked = checkCommand(redisCommand, shuttleNo); |
| | | News.info("execute check command complete {},{}", shuttleNo, taskNo); |
| | | if (checked == 0) { |
| | | return false; |
| | | } |
| | |
| | | |
| | | //移动命令,锁定路径 |
| | | if (command.getMode() == ShuttleCommandModeType.MOVE.id) { |
| | | TrafficControlThread trafficControlThread = (TrafficControlThread) SlaveConnection.get(SlaveType.TrafficControl, 1); |
| | | if (trafficControlThread == null) { |
| | | return false; |
| | | } |
| | | |
| | | List<NavigateNode> nodes = JSON.parseArray(JSON.toJSONString(command.getNodes()), NavigateNode.class); |
| | | //申请管制 |
| | | boolean apply = applyTrafficControl(commands, nodes, shuttleNo, taskNo); |
| | | |
| | | Object object = redisUtil.get(RedisKeyType.TRAFFIC_CONTROL_LOCK_APPLY.key + shuttleNo); |
| | | if (object == null) { |
| | | //申请管制 |
| | | News.info("execute apply control {},{}", shuttleNo, taskNo); |
| | | redisUtil.set(RedisKeyType.TRAFFIC_CONTROL_LOCK_APPLY.key + shuttleNo, "lock", 10); |
| | | applyTrafficControl(commands, nodes, shuttleNo, taskNo); |
| | | News.info("execute apply control complete {},{}", shuttleNo, taskNo); |
| | | } |
| | | |
| | | News.info("execute query control {},{}", shuttleNo, taskNo); |
| | | //查询管制 |
| | | boolean apply = queryTrafficControl(shuttleNo, taskNo); |
| | | News.info("execute query control complete {},{}", shuttleNo, taskNo); |
| | | if(!apply){ |
| | | return false;//申请失败 |
| | | } |
| | |
| | | if (!result) { |
| | | News.error("{} device can't lock path!", shuttleNo); |
| | | shuttleThread.offerSystemMsg("{} device can't lock path!", shuttleNo); |
| | | trafficControlThread.trafficReportError(shuttleNo, taskNo); |
| | | return false;//路径锁定失败 |
| | | } |
| | | } |
| | | |
| | | News.info("execute send command {},{}", shuttleNo, taskNo); |
| | | // 下发命令 |
| | | CommandResponse response = write(command, shuttleNo); |
| | | News.info("execute send command complete {},{}", shuttleNo, taskNo); |
| | | |
| | | //保存命令日志 |
| | | BasShuttleOpt basShuttleOpt = new BasShuttleOpt(); |
| | |
| | | } |
| | | |
| | | shuttleThread.setProtocolStatus(ShuttleProtocolStatusType.WORKING); |
| | | |
| | | //存储下发指令索引 |
| | | redisUtil.set(RedisKeyType.SHUTTLE_SEND_COMMAND_INDEX.key + shuttleNo + "_" + taskNo + "_" + commandStep, commandStep); |
| | | |
| | | commandStep += 1; |
| | | //更新redis数据 |
| | |
| | | return 0; |
| | | } |
| | | |
| | | //上一条指令 |
| | | String searchKey = RedisKeyType.SHUTTLE_SEND_COMMAND_INDEX.key + shuttleNo + "_" + redisCommand.getWrkNo() + "_"; |
| | | Set<String> keys = redisUtil.searchKeys(searchKey); |
| | | TreeSet<Integer> treeSet = new TreeSet<>(); |
| | | for (String key : keys) { |
| | | String[] split = key.split(searchKey); |
| | | treeSet.add(Integer.parseInt(split[1])); |
| | | boolean supportContinuously = false; |
| | | int checkIdx = commandStep - 2; |
| | | if (checkIdx < 0) { |
| | | checkIdx = commandStep - 1; |
| | | } |
| | | if (treeSet.isEmpty()) { |
| | | return 1; |
| | | ShuttleCommand last2Command = commands.get(checkIdx); |
| | | if(last2Command.getComplete()){ |
| | | supportContinuously = true; |
| | | checkIdx = commandStep - 1; |
| | | } |
| | | |
| | | String firstKey = searchKey + treeSet.first(); |
| | | Integer lastCommandIdx = (Integer) redisUtil.get(firstKey); |
| | | ShuttleCommand lastCommand = commands.get(lastCommandIdx); |
| | | ShuttleCommand lastCommand = commands.get(checkIdx); |
| | | if (!lastCommand.getComplete()) { |
| | | //检测更新命令完成 |
| | | boolean checked = updateCommandComplete(lastCommandIdx, commands, shuttleNo); |
| | | boolean checked = updateCommandComplete(checkIdx, commands, shuttleNo); |
| | | if (checked) { |
| | | //删除索引 |
| | | redisUtil.del(firstKey); |
| | | |
| | | // 更新redis数据 |
| | | redisUtil.set(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect)); |
| | | }else { |
| | | //小车移动连续下发指令 |
| | | if (assignCommand.getShuttleMoveCommandsContinuously()) { |
| | | if (treeSet.size() <= 1) { |
| | | if(commandStep >= commands.size()) { |
| | | return 0; |
| | | } |
| | | if (!supportContinuously) { |
| | | return 0; |
| | | } |
| | | |
| | | //移动指令 |
| | | if(lastCommand.getMode() != ShuttleCommandModeType.MOVE.id) { |
| | | return 0; |
| | | } |
| | | //移动指令 |
| | | if(lastCommand.getMode() != ShuttleCommandModeType.MOVE.id) { |
| | | return 0; |
| | | } |
| | | |
| | | List<NavigateNode> nodes = lastCommand.getNodes(); |
| | | NavigateNode startNode = nodes.get(0); |
| | | if (!startNode.getLinePartAllowGo()) {//直线段部分,允许直接行走 |
| | | return 0; |
| | | } |
| | | List<NavigateNode> nodes = lastCommand.getNodes(); |
| | | NavigateNode startNode = nodes.get(0); |
| | | if (!startNode.getLinePartAllowGo()) {//直线段部分,允许直接行走 |
| | | return 0; |
| | | } |
| | | |
| | | //直线段数据标识 |
| | | Long linePartFlag = startNode.getLinePartFlag(); |
| | | //直线段数据标识 |
| | | Long linePartFlag = startNode.getLinePartFlag(); |
| | | |
| | | if(commandStep < commands.size()){ |
| | | //取指令 |
| | | ShuttleCommand currentCommand = commands.get(commandStep); |
| | | if(currentCommand.getMode() != ShuttleCommandModeType.MOVE.id) { |
| | |
| | | //数据标识一致 |
| | | return 2;//允许小车移动连续下发指令 |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | //申请取消管制 |
| | | trafficControlThread.cancelTrafficControl(shuttleNo, shuttleProtocol.getTaskNo()); |
| | | cancelTrafficControl(shuttleNo, shuttleProtocol.getTaskNo()); |
| | | |
| | | //删除redis |
| | | redisUtil.del(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo()); |
| | | return 0;//禁止再下发命令 |
| | |
| | | return false; |
| | | } |
| | | //上报交管 |
| | | News.info("execute check command report traffic {},{}", shuttleNo, shuttleProtocol.getTaskNo()); |
| | | trafficControlThread.trafficReport(command.getNodesDeepCopy(), shuttleNo, shuttleProtocol.getTaskNo()); |
| | | News.info("execute check command report traffic complete {},{}", shuttleNo, shuttleProtocol.getTaskNo()); |
| | | |
| | | String currentLocNo = shuttleProtocol.getCurrentLocNo(); |
| | | if (currentLocNo == null) { |
| | | return false; |
| | | } |
| | | if (targetPoints.contains(Utils.getRow(currentLocNo) + "-" + Utils.getBay(currentLocNo))) { |
| | | command.setComplete(true); |
| | | boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(shuttleProtocol.getCurrentLocNo()), shuttleProtocol.getShuttleNo(), nodes, false);//解锁路径 |
| | | if (!result) { |
| | | return false;//解锁失败 |
| | | } |
| | | command.setComplete(true); |
| | | }else { |
| | | return false; |
| | | } |
| | |
| | | } |
| | | } |
| | | return trafficControlThread.applyTrafficControl(totalNodeList, nodeList, shuttleNo, taskNo); |
| | | } |
| | | |
| | | //查询是否申请管制成功 |
| | | public boolean queryTrafficControl(Integer shuttleNo, Integer taskNo) { |
| | | Object object = redisUtil.get(RedisKeyType.TRAFFIC_CONTROL_SUCCESS_APPLY.key + shuttleNo + "_" + taskNo); |
| | | if (object == null) { |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | public boolean cancelTrafficControl(Integer shuttleNo, Integer taskNo) { |
| | | TrafficControlDataModel model = new TrafficControlDataModel(); |
| | | model.setShuttleNo(shuttleNo); |
| | | model.setTaskNo(taskNo); |
| | | redisUtil.set(RedisKeyType.TRAFFIC_CONTROL_CANCEL_LIST.key + shuttleNo + "_" + taskNo, model); |
| | | return true; |
| | | } |
| | | |
| | | // /** |
| | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public synchronized boolean clearPath(Integer shuttleNo) { |
| | | return navigateMapUtils.clearPath(shuttleNo); |
| | | } |
| | | |
| | | // //跑库程序 |
| | |
| | | // } |
| | | // } |
| | | |
| | | private synchronized CommandResponse write(ShuttleCommand command, Integer shuttleNo) { |
| | | private CommandResponse write(ShuttleCommand command, Integer shuttleNo) { |
| | | CommandResponse response = new CommandResponse(false); |
| | | if (null == command) { |
| | | News.error("四向穿梭车写入命令为空"); |