From 8e19e67d1178e834a868f4a820d827ddf64c6e01 Mon Sep 17 00:00:00 2001 From: 野心家 <1051256694@qq.com> Date: 星期三, 28 五月 2025 12:46:08 +0800 Subject: [PATCH] #ZH --- src/main/java/com/zy/core/thread/RgvThread.java | 121 ++++++++++++++++++++++++++++++++-------- 1 files changed, 96 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/zy/core/thread/RgvThread.java b/src/main/java/com/zy/core/thread/RgvThread.java index 3c70e71..c823915 100644 --- a/src/main/java/com/zy/core/thread/RgvThread.java +++ b/src/main/java/com/zy/core/thread/RgvThread.java @@ -53,6 +53,7 @@ private Long trackBenchmark = 1L; // # 閬胯璺濈 private Long avoidDistance = 5000L; + private String errorRgv = "-"; /** * 宸ヤ綅1澶嶄綅淇″彿 @@ -103,6 +104,7 @@ private void rgvConnect() { while (true) { try { + Thread.sleep(1000); if(!connectRgv){ try { connectRgv = this.connect(); @@ -117,7 +119,7 @@ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "rgv杩炴帴澶辫触"+e.getMessage()); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } initRgv(); // e.printStackTrace(); @@ -129,7 +131,7 @@ while (true) { try { Thread.sleep(20); - System.out.println("璇荤嚎绋�"+ slave.getId()); +// System.out.println("璇荤嚎绋�"+ slave.getId()); readStatus(); @@ -139,7 +141,7 @@ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV鏁版嵁璇诲彇绾跨▼寮傚父"+e.getMessage()); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } initRgv(); // e.printStackTrace(); @@ -172,7 +174,7 @@ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV鏁版嵁浠诲姟涓嬪彂澶嶄綅绾跨▼寮傚父"+e.getMessage()); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } initRgv(); // e.printStackTrace(); @@ -295,10 +297,10 @@ try { Thread.sleep(50); rgvRun = RgvRunCache.getRgvRun(); - System.out.println(JSON.toJSON(rgvRun)); +// System.out.println(JSON.toJSON(rgvRun)); // 浼戠湢 1 绉� - if (System.currentTimeMillis() - rgvRun.currentTimeMilliOld > 1500) { + if (System.currentTimeMillis() - rgvRun.currentTimeMilliOld > 1000) { rgvRun.currentTimeMilliOld = System.currentTimeMillis()+50; } else { continue; @@ -307,6 +309,9 @@ rgvRun.currentTimeMilliOld = System.currentTimeMillis()+50; rgvRun.setRgvNo(slave.getOtherId()); RgvRunCache.updateRgvStatus(rgvRun); + if (!errorRgv.equals("鏃�")){ + RgvErrCache.updateRgvErr(slave.getId(),errorRgv); + } continue; } @@ -327,6 +332,7 @@ rgvRun.currentTimeMilliOld = System.currentTimeMillis()+50; rgvRun.setRgvNo(slave.getOtherId()); RgvRunCache.updateRgvStatus(rgvRun); + RgvErrCache.updateRgvErr(slave.getId(),"灏忚溅鎺㈢墿鐗╃姸鎬佸紓甯�"); continue; } if (rgvTaskProtocol.getAvoid() != 0) { @@ -337,6 +343,7 @@ issued.setTaskStatus(1); issued.setDirection(true); write(issued); + RgvErrCache.updateRgvErr(slave.getId()); rgvTaskProtocol.setAvoid(0); // try{Thread.sleep(50L);} catch (Exception e){} @@ -358,21 +365,25 @@ if (rgvOtherStatusEnable()) { //鍙︿竴鍙拌溅鏄惁鍏佽姝ゅ彴杞︽墽琛� if (!otherRgvAvoid(taskProtocol.getTargetPosition())) { + RgvErrCache.updateRgvErr(slave.getId(),errorRgv); break; } } if (taskProtocol.getTargetPosition()<=rgvProtocol.getRgvPos()+50 && taskProtocol.getTargetPosition()>=rgvProtocol.getRgvPos()-50){ taskProtocolCache.removeTaskProtocol(taskProtocol.getTaskNoDirection()); + RgvErrCache.updateRgvErr(slave.getId()); break; } else { TaskProtocol issued = new TaskProtocol(taskProtocol,true); write(issued); + RgvErrCache.updateRgvErr(slave.getId()); taskProtocolCache.removeTaskProtocol(taskProtocol.getTaskNoDirection()); break; } } } + RgvErrCache.updateRgvErr(slave.getId()); } else { for (TaskProtocol taskProtocol : allTakeTaskProtocol) { if (taskProtocol.getIsRunning() == 1) {//鍑嗗涓嬪彂 @@ -380,6 +391,7 @@ if (rgvOtherStatusEnable()) { //鍙︿竴鍙拌溅鏄惁鍏佽姝ゅ彴杞︽墽琛� if (!otherRgvAvoid(taskProtocol.getTargetPosition())) { + RgvErrCache.updateRgvErr(slave.getId(),errorRgv); break; } } @@ -389,21 +401,38 @@ DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, taskProtocol.getTargetPositionStaNoPlcId()); StaProtocol staProtocol = devpThread.getStation().get(taskProtocol.getTargetPositionStaNo()); if (staProtocol == null ) { + RgvErrCache.updateRgvErr(slave.getId(),"鏈煡鍒板皬杞︿綔涓氱珯"+staProtocol.getStaNo()+"绔欑偣"); break; } // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢 if (!staProtocol.isAutoing() || staProtocol.isLoading() ){ + RgvErrCache.updateRgvErr(slave.getId(),"灏忚溅绛夊緟"+staProtocol.getStaNo()+"绔欑偣灏辩华"); + break; + } + } else if (taskProtocol.getTaskStatus()==2){ + DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, taskProtocol.getTargetPositionStaNoPlcId()); + StaProtocol staProtocol = devpThread.getStation().get(taskProtocol.getTargetPositionStaNo()); + if (staProtocol == null ) { + RgvErrCache.updateRgvErr(slave.getId(),"鏈煡鍒板皬杞︿綔涓氱珯"+staProtocol.getStaNo()+"绔欑偣"); + break; + } + // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢 + if (!staProtocol.isAutoing() || !staProtocol.isLoading() || staProtocol.getWorkNo()==0 + ){ + RgvErrCache.updateRgvErr(slave.getId(),"灏忚溅绛夊緟"+staProtocol.getStaNo()+"绔欑偣灏辩华"); break; } } TaskProtocol issued = new TaskProtocol(taskProtocol); write(issued); + RgvErrCache.updateRgvErr(slave.getId()); taskProtocolCache.removeTaskProtocol(taskProtocol.getTaskNoDirection()); break; } else { TaskProtocol issued = new TaskProtocol(taskProtocol,true); write(issued); + RgvErrCache.updateRgvErr(slave.getId()); break; } } @@ -418,7 +447,7 @@ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV浠诲姟涓嬪彂绾跨▼寮傚父"+e.getMessage()); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } rgvRun = RgvRunCache.getRgvRun(); rgvRun.currentTimeMilliOld = System.currentTimeMillis()+50; @@ -454,10 +483,25 @@ RgvTaskProtocol rgvTaskProtocol = RgvTaskCache.getRgvStatus(slave.getId()); if (rgvProtocol == null || rgvTaskProtocol == null) { + errorRgv = slave.getId()+"鍙峰皬杞﹁繛鎺ュけ璐�"; return false; } - if (!rgvProtocol.getModeType().equals(RgvModeType.AUTO) || rgvProtocol.getRgvPos().equals(0L) || rgvTaskProtocol.getAvoid() == -1 || rgvProtocol.getRgvPosDestination() == 0L - || ((!rgvProtocol.getStatusType().equals(RgvStatusType.IDLE) || (Math.abs(rgvProtocol.getRgvPos() - rgvProtocol.getRgvPosDestination())>100)) && !rgvProtocol.getStatusType().equals(RgvStatusType.ROAM))) { + if (!rgvProtocol.getModeType().equals(RgvModeType.AUTO)) { + errorRgv = slave.getId()+"鍙峰皬杞﹂潪鑷姩"; + return false; + } + if (rgvProtocol.getRgvPos().equals(0L) + || rgvTaskProtocol.getAvoid() == -1 + || rgvProtocol.getRgvPosDestination() == 0L) { + errorRgv = slave.getId()+"鍙峰皬杞︾姸鎬佸紓甯�"; + return false; + } + if (!rgvProtocol.getStatusType().equals(RgvStatusType.IDLE) && !rgvProtocol.getStatusType().equals(RgvStatusType.ROAM)) { + errorRgv = "鏃�"; + return false; + } + if ( (Math.abs(rgvProtocol.getRgvPos() - rgvProtocol.getRgvPosDestination())>100) && !rgvProtocol.getStatusType().equals(RgvStatusType.ROAM)) { + errorRgv = slave.getId()+"鍙峰皬杞﹀瓨鍦ㄨ繍琛岀洰鏍囧�硷紝闇�瑕佸浣嶏紒锛侊紒"; return false; } RgvProtocol rgvProtocolOther = RgvStatusCache.getRgvStatus(slave.getOtherId()); @@ -466,10 +510,12 @@ // "rgvTaskProtocolOther:"+slave.getOtherId()+"sign:"+rgvTaskProtocolOther.isSignRun()+"/n"); if (rgvProtocolOther == null) { + errorRgv = slave.getOtherId()+"鍙峰皬杞﹁繛鎺ュけ璐�"; return false; } if (rgvProtocolOther.statusEnable) { if (!rgvProtocolOther.getModeType().equals(RgvModeType.AUTO) || rgvProtocolOther.getRgvPos().equals(0L) || rgvTaskProtocolOther.getAvoid() == -1 || rgvProtocolOther.getRgvPosDestination() == 0L) { + errorRgv = slave.getOtherId()+"鍙峰皬杞︾姸鎬佸紓甯�"; return false; } } @@ -525,11 +571,12 @@ long avoid = rgvProtocolOther.getRgvPos() - rgvProtocolOther.getCarBodyJiaoMing() - avoidDistance - rgvProtocol.getCarBodyKunPeng(); if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[1])) { log.error("RGV琛岃蛋瓒呭嚭鑼冨洿锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + errorRgv = "RGV琛岃蛋鐩爣瓒呭嚭鑼冨洿"; try{ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV琛岃蛋瓒呭嚭鑼冨洿"); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } return false; } @@ -548,17 +595,20 @@ } } if (signNowPosRun){ + errorRgv = slave.getOtherId()+"鍙稲GV绛夊緟浣滀笟..."; return false; } } long avoid = targetPosition + rgvProtocol.getCarBodyKunPeng() + avoidDistance + rgvProtocolOther.getCarBodyJiaoMing(); if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[0])) { log.error("RGV琛岃蛋瓒呭嚭鑼冨洿锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + errorRgv = "RGV琛岃蛋鐩爣瓒呭嚭鑼冨洿"; + try{ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV琛岃蛋瓒呭嚭鑼冨洿"); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } return false; } @@ -580,11 +630,13 @@ long avoid = targetPosition + rgvProtocol.getCarBodyKunPeng() + avoidDistance + rgvProtocolOther.getCarBodyJiaoMing(); if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[0])) { log.error("RGV琛岃蛋瓒呭嚭鑼冨洿锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + errorRgv = "RGV琛岃蛋鐩爣瓒呭嚭鑼冨洿"; + try{ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV琛岃蛋瓒呭嚭鑼冨洿"); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } return false; } @@ -607,11 +659,13 @@ long avoid = rgvProtocolOther.getRgvPos() - rgvProtocolOther.getCarBodyJiaoMing() - avoidDistance - rgvProtocol.getCarBodyKunPeng(); if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[1])) { log.error("RGV琛岃蛋瓒呭嚭鑼冨洿锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + errorRgv = "RGV琛岃蛋鐩爣瓒呭嚭鑼冨洿"; + try{ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV琛岃蛋瓒呭嚭鑼冨洿"); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } return false; } @@ -624,6 +678,8 @@ RgvTaskCache.updateRgvStatus(rgvTaskProtocol); return false; } + errorRgv = slave.getOtherId()+"鍙稲GV褰卞搷锛岀瓑寰呬腑..."; + return false; } } else { @@ -660,11 +716,13 @@ long avoid = rgvProtocolOther.getRgvPos() + rgvProtocolOther.getCarBodyKunPeng() + avoidDistance + rgvProtocol.getCarBodyJiaoMing(); if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[0])) { log.error("RGV琛岃蛋瓒呭嚭鑼冨洿锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + errorRgv = "RGV琛岃蛋鐩爣瓒呭嚭鑼冨洿"; + try{ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV琛岃蛋瓒呭嚭鑼冨洿"); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } return false; } @@ -683,17 +741,20 @@ } } if (signNowPosRun){ + errorRgv = slave.getOtherId()+"鍙稲GV绛夊緟浣滀笟..."; return false; } } long avoid = targetPosition - rgvProtocol.getCarBodyJiaoMing() - avoidDistance - rgvProtocolOther.getCarBodyKunPeng(); if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[1])) { log.error("RGV琛岃蛋瓒呭嚭鑼冨洿锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + errorRgv = "RGV琛岃蛋鐩爣瓒呭嚭鑼冨洿"; + try{ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV琛岃蛋瓒呭嚭鑼冨洿"); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } return false; } @@ -715,11 +776,13 @@ long avoid = targetPosition - rgvProtocol.getCarBodyJiaoMing() - avoidDistance - rgvProtocolOther.getCarBodyKunPeng(); if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[1])) { log.error("RGV琛岃蛋瓒呭嚭鑼冨洿锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + errorRgv = "RGV琛岃蛋鐩爣瓒呭嚭鑼冨洿"; + try{ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV琛岃蛋瓒呭嚭鑼冨洿"); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } return false; } @@ -743,11 +806,13 @@ long avoid = rgvProtocolOther.getRgvPos() + rgvProtocolOther.getCarBodyKunPeng() + avoidDistance + rgvProtocol.getCarBodyJiaoMing(); if (!new TrackRangeUtils().avoidRange(avoid, avoidRange[0])) { log.error("RGV琛岃蛋瓒呭嚭鑼冨洿锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); + errorRgv = "RGV琛岃蛋鐩爣瓒呭嚭鑼冨洿"; + try{ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV琛岃蛋瓒呭嚭鑼冨洿"); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } return false; } @@ -760,6 +825,7 @@ RgvTaskCache.updateRgvStatus(rgvTaskProtocol); return false; } + errorRgv = slave.getOtherId()+"鍙稲GV绛夊緟涓�..."; return false; } } else { @@ -770,6 +836,8 @@ } } } + + errorRgv = slave.getOtherId()+"鍙稲GV褰卞搷锛岀瓑寰呬腑..."; return false; } @@ -806,7 +874,7 @@ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV寮傚父"+e.getMessage()); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } rgvProtocol.setStatusEnable(true); } @@ -844,7 +912,7 @@ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "RGVplc杩炴帴澶辫触"); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } } initRgv(); @@ -893,7 +961,7 @@ rgvProtocol.setErr4(status[11]); rgvProtocol.setErr5(status[12]); rgvProtocol.setErr6(status[13]); - System.out.println("璇荤嚎绋�"+ slave.getId()+"---"+JSON.toJSONString(rgvProtocol)); +// System.out.println("璇荤嚎绋�"+ slave.getId()+"---"+JSON.toJSONString(rgvProtocol)); OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛", DateUtils.convert(new Date()), slave.getId())); // // 宸ヤ綅1澶嶄綅淇″彿 @@ -907,6 +975,9 @@ // } // } // } + if (rgvProtocol.getAlarm$()!=0){ + RgvErrCache.updateRgvErr(slave.getId(),rgvProtocol.getAlarmM()); + } try { // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴� @@ -927,7 +998,7 @@ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV plc鏁版嵁搴撴洿鏂板け璐�"); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } } } catch (Exception ignore) { @@ -948,7 +1019,7 @@ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "璇诲彇RGV plc鐘舵�佷俊鎭け璐�"); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } } } catch (Exception e) { @@ -960,7 +1031,7 @@ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "璇诲彇RGV plc鐘舵�佷俊鎭け璐�"); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } initRgv(); } @@ -977,7 +1048,7 @@ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV鍐欏叆鍛戒护涓虹┖"); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } return false; } @@ -1036,7 +1107,7 @@ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class); deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV 鍛戒护涓嬪彂"+JSON.toJSON(taskProtocol)); } catch (Exception e2){ - log.error("e2:"+e2.getMessage()); +// log.error("e2:"+e2.getMessage()); } OutputQueue.RGV.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(taskProtocol))); return true; -- Gitblit v1.9.1