| | |
| | | import com.zy.asrs.wcs.common.ExecuteSupport; |
| | | import com.zy.asrs.wcs.core.entity.BasShuttle; |
| | | import com.zy.asrs.wcs.core.entity.Loc; |
| | | import com.zy.asrs.wcs.core.model.MapNode; |
| | | import com.zy.asrs.wcs.core.model.NavigateNode; |
| | | import com.zy.asrs.wcs.core.model.command.ShuttleCommand; |
| | | import com.zy.asrs.wcs.core.model.command.ShuttleRedisCommand; |
| | | import com.zy.asrs.wcs.core.model.enums.MotionCtgType; |
| | | import com.zy.asrs.wcs.core.model.enums.NavigationMapType; |
| | | import com.zy.asrs.wcs.core.model.enums.ShuttleCommandModeType; |
| | | import com.zy.asrs.wcs.core.model.enums.ShuttleRunDirection; |
| | | import com.zy.asrs.wcs.core.service.BasShuttleService; |
| | | import com.zy.asrs.wcs.core.service.LocService; |
| | | import com.zy.asrs.wcs.core.utils.NavigateMapData; |
| | | import com.zy.asrs.wcs.core.utils.NavigatePositionConvert; |
| | | import com.zy.asrs.wcs.core.utils.RedisUtil; |
| | | import com.zy.asrs.wcs.rcs.News; |
| | |
| | | this.connect(); |
| | | } |
| | | readStatus(); |
| | | listenInit(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】读取四向穿梭车状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), device.getId(), device.getIp(), device.getPort())); |
| | |
| | | } catch (IOException | InterruptedException exception) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 监听小车复位初始化信号 |
| | | */ |
| | | public void listenInit() { |
| | | try { |
| | | // 获取输入流 |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(this.socket.getInputStream())); |
| | | |
| | | // 读取服务器的响应 |
| | | StringBuffer sb = new StringBuffer(); |
| | | String response = null; |
| | | char[] chars = new char[2048];//缓冲区 |
| | | do { |
| | | reader.read(chars); |
| | | String trim = new String(chars).trim(); |
| | | sb.append(trim); |
| | | if (sb.lastIndexOf("\r\n") != -1) { |
| | | break; |
| | | } |
| | | } while (response != null); |
| | | // System.out.println("Received response from server: " + sb); |
| | | |
| | | JSONObject result = JSON.parseObject(sb.toString());//得到请求结果集 |
| | | if (!result.get("msgType").equals("requestMsg")) {//不是请求内容 |
| | | return; |
| | | } |
| | | |
| | | JSONObject resultResponse = JSON.parseObject(result.get("request").toString()); |
| | | JSONObject resultHeader = JSON.parseObject(resultResponse.get("header").toString()); |
| | | JSONObject resultBody = JSON.parseObject(resultResponse.get("body").toString()); |
| | | String requestType = resultBody.getString("requestType"); |
| | | Integer requestId = resultHeader.getInteger("requestId"); |
| | | if (requestType.equals("init")) { |
| | | //小车复位请求 |
| | | ShuttleCommand initCommand = getInitCommand(requestId); |
| | | //发出请求 |
| | | NyShuttleHttpCommand httpCommand = JSON.parseObject(initCommand.getBody(), NyShuttleHttpCommand.class); |
| | | JSONObject requestResult = requestCommand(httpCommand); |
| | | if (requestResult == null) { |
| | | return;//请求失败 |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ShuttleCommand getMoveCommand(Integer taskNo, String startCodeNum, String distCodeNum, Integer allDistance, Integer runDirection, Integer runSpeed) { |
| | | public ShuttleCommand getMoveCommand(Integer taskNo, String startCodeNum, String distCodeNum, Integer allDistance, Integer runDirection, Integer runSpeed, List<NavigateNode> nodes) { |
| | | NavigateMapData navigateMapData = SpringUtils.getBean(NavigateMapData.class); |
| | | NyShuttleHttpCommand httpStandard = getHttpStandard(Integer.parseInt(device.getDeviceNo()), taskNo); |
| | | NyShuttleHttpCommand.NyRequest request = httpStandard.getRequest(); |
| | | |
| | | ArrayList<HashMap<String, Object>> path = new ArrayList<>(); |
| | | |
| | | HashMap<String, Object> body = new HashMap<>(); |
| | | body.put("requestType", "move");//移动命令 |
| | | body.put("taskId", getTaskId());//TaskID需要随机 |
| | | body.put("start", navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(startCodeNum, device.getHostId())));//起点 |
| | | body.put("target", navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(distCodeNum, device.getHostId())));//终点 |
| | | // body.put("start", navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(startCodeNum, device.getHostId())));//起点 |
| | | // body.put("target", navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(distCodeNum, device.getHostId())));//终点 |
| | | body.put("path", path); |
| | | request.setBody(body); |
| | | |
| | | NavigateNode startNode = nodes.get(0); |
| | | navigateMapData.setLev(startNode.getZ()); |
| | | for (NavigateNode node : nodes) { |
| | | HashMap<String, Object> data = new HashMap<>(); |
| | | String codeNum = NavigatePositionConvert.xyToPosition(node.getX(), node.getY(), node.getZ(), device.getHostId()); |
| | | Map<String, Object> nyNode = navigateNodeToNyPointNode(NavigatePositionConvert.codeToNode(codeNum, device.getHostId())); |
| | | int xp = Integer.parseInt(String.valueOf(nyNode.get("x"))); |
| | | int yp = Integer.parseInt(String.valueOf(nyNode.get("y"))); |
| | | int z = Integer.parseInt(String.valueOf(nyNode.get("z"))); |
| | | |
| | | List<List<MapNode>> mapData = navigateMapData.getJsonData(NavigationMapType.NONE.id, null, null); |
| | | List<MapNode> mapNodes = mapData.get(node.getX()); |
| | | MapNode mapNode = mapNodes.get(node.getY()); |
| | | |
| | | data.put("xp", xp); |
| | | data.put("yp", yp); |
| | | data.put("z", z); |
| | | data.put("x", mapNode.getXBase()); |
| | | data.put("y", mapNode.getYBase()); |
| | | } |
| | | |
| | | |
| | | httpStandard.setRequest(request); |
| | | |
| | |
| | | return command; |
| | | } |
| | | |
| | | //获取小车复位响应命令 |
| | | public ShuttleCommand getInitCommand(Integer taskNo) { |
| | | NyShuttleHttpCommand httpStandard = getHttpStandard(Integer.parseInt(device.getDeviceNo()), taskNo); |
| | | NyShuttleHttpCommand.NyRequest request = httpStandard.getRequest(); |
| | | |
| | | HashMap<String, Object> body = new HashMap<>(); |
| | | body.put("responseType", "init");//复位 |
| | | body.put("location", new ArrayList<>());//初始化坐标 |
| | | body.put("devicePoints", new ArrayList<>());//提升机点位 |
| | | body.put("specialPoints", new ArrayList<>());//特殊条码坐标 |
| | | request.setBody(body); |
| | | |
| | | httpStandard.setRequest(request); |
| | | |
| | | ShuttleCommand command = new ShuttleCommand(); |
| | | command.setShuttleNo(Integer.parseInt(this.device.getDeviceNo())); |
| | | command.setBody(JSON.toJSONString(httpStandard)); |
| | | command.setMode(ShuttleCommandModeType.RESET.id); |
| | | return command; |
| | | } |
| | | |
| | | @Override |
| | | public boolean connect() { |
| | | try { |