From 24393cdbdcc3f3e921050e733bd6a27208d4ea55 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 09 五月 2023 12:48:54 +0800
Subject: [PATCH] console.html fixed
---
src/main/java/com/zy/core/thread/ShuttleThread.java | 1028 ++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 917 insertions(+), 111 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/ShuttleThread.java b/src/main/java/com/zy/core/thread/ShuttleThread.java
index 224377b..b3d8b2e 100644
--- a/src/main/java/com/zy/core/thread/ShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/ShuttleThread.java
@@ -4,30 +4,45 @@
import HslCommunication.Core.Types.OperateResult;
import HslCommunication.Core.Types.OperateResultExOne;
import HslCommunication.ModBus.ModbusTcpNet;
-import HslCommunication.Profinet.Siemens.SiemensPLCS;
-import HslCommunication.Profinet.Siemens.SiemensS7Net;
import com.alibaba.fastjson.JSON;
import com.core.common.DateUtils;
-import com.core.common.RadixTools;
+import com.core.common.SpringUtils;
import com.core.exception.CoolException;
+import com.zy.asrs.entity.BasDevp;
+import com.zy.asrs.entity.BasShuttle;
+import com.zy.asrs.entity.BasShuttleOpt;
+import com.zy.asrs.entity.LocMast;
+import com.zy.asrs.service.BasDevpService;
+import com.zy.asrs.service.BasShuttleOptService;
+import com.zy.asrs.service.BasShuttleService;
+import com.zy.asrs.service.LocMastService;
+import com.zy.common.model.NavigateNode;
+import com.zy.common.utils.CommonUtils;
+import com.zy.common.utils.NavigatePositionConvert;
+import com.zy.common.utils.NavigateUtils;
+import com.zy.common.utils.RedisUtil;
import com.zy.core.News;
import com.zy.core.ThreadHandler;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
import com.zy.core.cache.SlaveConnection;
-import com.zy.core.enums.ShuttleStatusType;
-import com.zy.core.enums.SlaveType;
+import com.zy.core.enums.*;
import com.zy.core.model.ShuttleSlave;
-import com.zy.core.model.SteSlave;
import com.zy.core.model.Task;
+import com.zy.core.model.command.LiftAssignCommand;
+import com.zy.core.model.command.LiftCommand;
+import com.zy.core.model.command.ShuttleAssignCommand;
import com.zy.core.model.command.ShuttleCommand;
-import com.zy.core.model.command.SteCommand;
+import com.zy.core.model.protocol.LiftProtocol;
import com.zy.core.model.protocol.ShuttleProtocol;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.text.MessageFormat;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
/**
* 鍥涘悜绌挎杞︾嚎绋�
@@ -39,10 +54,11 @@
private ModbusTcpNet modbusTcpNet;
private ShuttleSlave slave;
private ShuttleProtocol shuttleProtocol;
- private SiemensS7Net siemensS7Net;
+ private RedisUtil redisUtil;
- public ShuttleThread(ShuttleSlave slave) {
+ public ShuttleThread(ShuttleSlave slave,RedisUtil redisUtil) {
this.slave = slave;
+ this.redisUtil = redisUtil;
}
@Override
@@ -63,6 +79,10 @@
// 鍐欏叆鏁版嵁
case 2:
write((ShuttleCommand) task.getData());
+ break;
+ //涓嬪彂浠诲姟
+ case 3:
+ assignWork((ShuttleAssignCommand) task.getData());
break;
default:
break;
@@ -97,71 +117,168 @@
@Override
public void close() {
-
+ modbusTcpNet.ConnectClose();
}
private void readStatus() {
try {
- OperateResultExOne<byte[]> result = modbusTcpNet.Read("0", (short) 17);
+ OperateResultExOne<byte[]> result = modbusTcpNet.Read("200", (short) 17);
if (result.IsSuccess) {
if (null == shuttleProtocol) {
shuttleProtocol = new ShuttleProtocol();
shuttleProtocol.setShuttleNo(slave.getId().shortValue());
+ shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
}
- //----------璁剧疆鍥涘悜绌挎杞︾姸鎬�-----------
+ //----------璇诲彇鍥涘悜绌挎杞︾姸鎬�-----------
//鑾峰彇鏁版嵁
byte[] content = result.Content;
+ //灏忚溅蹇欑姸鎬佷綅
+ shuttleProtocol.setBusyStatus(modbusTcpNet.getByteTransform().TransInt16(content,0));
+ //褰撳墠浜岀淮鐮�
+ shuttleProtocol.setCurrentCode(modbusTcpNet.getByteTransform().TransInt16(content,2));
+ //鐢垫睜鐢甸噺鐧惧垎姣�
+ shuttleProtocol.setBatteryPower(modbusTcpNet.getByteTransform().TransInt16(content,4));
+ //鐢垫睜娓╁害
+ shuttleProtocol.setBatteryTemp(modbusTcpNet.getByteTransform().TransInt16(content,6));
+ //閿欒缂栧彿
+ shuttleProtocol.setErrorCode(modbusTcpNet.getByteTransform().TransInt16(content,8));
+ //Plc杈撳嚭鐘舵�両O
+ boolean[] booleans = modbusTcpNet.getByteTransform().TransBool(content, 10, 2);
+ shuttleProtocol.setPlcOutputLift(booleans[1]);
+ shuttleProtocol.setPlcOutputTransfer(booleans[2]);
+ shuttleProtocol.setPlcOutputBrake(booleans[3]);
+ shuttleProtocol.setPlcOutputCharge(booleans[4]);
+ shuttleProtocol.setPlcOutputStatusIO(modbusTcpNet.getByteTransform().TransInt16(content, 10));
+ //閿欒淇℃伅鐮�
+ shuttleProtocol.setStatusErrorCode(modbusTcpNet.getByteTransform().TransInt16(content,12));
+ //PLC杈撳叆鐘舵��
+ shuttleProtocol.setPlcInputStatus(modbusTcpNet.getByteTransform().TransInt16(content,14));
+ //褰撳墠鎴栬�呬箣鍓嶈鍒扮殑浜岀淮鐮佸��
+ shuttleProtocol.setCurrentOrBeforeCode(modbusTcpNet.getByteTransform().TransInt16(content,16));
+ //璇诲埌鐨勪簩缁寸爜X鏂瑰悜鍋忕Щ閲�
+ shuttleProtocol.setCodeOffsetX(modbusTcpNet.getByteTransform().TransInt16(content,18));
+ //璇诲埌鐨勪簩缁寸爜Y鏂瑰悜鍋忕Щ閲�
+ shuttleProtocol.setCodeOffsetY(modbusTcpNet.getByteTransform().TransInt16(content,20));
+ //褰撳墠鐨勭數鍘嬪��
+ shuttleProtocol.setCurrentVoltage(modbusTcpNet.getByteTransform().TransInt16(content,22));
+ //褰撳墠鐨勬ā鎷熼噺鍊�
+ shuttleProtocol.setCurrentAnalogValue(modbusTcpNet.getByteTransform().TransInt16(content,24));
+ //褰撳墠鐨勫崌闄嶄己鏈嶉�熷害
+ shuttleProtocol.setCurrentLiftServoSpeed(modbusTcpNet.getByteTransform().TransInt16(content,26));
+ //褰撳墠鐨勮璧颁己鏈嶉�熷害
+ shuttleProtocol.setCurrentMoveServoSpeed(modbusTcpNet.getByteTransform().TransInt16(content,28));
+ //褰撳墠鐨勫崌闄嶄己鏈嶈礋杞界巼
+ shuttleProtocol.setCurrentLiftServoLoad(modbusTcpNet.getByteTransform().TransInt16(content,30));
+ //褰撳墠鐨勮璧颁己鏈嶈礋杞界巼
+ shuttleProtocol.setCurrentMoveServoLoad(modbusTcpNet.getByteTransform().TransInt16(content,32));
- //--------鎺у埗瀛�--------
- //鎺у埗鎸囦护瀛�
- shuttleProtocol.setCommandWord(modbusTcpNet.getByteTransform().TransUInt16(content, 0));
- //鍚浜岀淮缂栧彿
- shuttleProtocol.setStartCodeNum(modbusTcpNet.getByteTransform().TransUInt16(content, 2));
- //涓棿浜岀淮缂栧彿
- shuttleProtocol.setMiddleCodeNum(modbusTcpNet.getByteTransform().TransUInt16(content, 4));
- //鐩爣浜岀淮缂栧彿
- shuttleProtocol.setDistCodeNum(modbusTcpNet.getByteTransform().TransUInt16(content, 6));
- //璧风偣鍒扮洰鏍囩偣鐨勮窛绂婚暱搴�
- shuttleProtocol.setStartToDistDistance(modbusTcpNet.getByteTransform().TransInt32(content, 8));
- //涓棿鐐瑰埌鐩爣鐐圭殑璺濈闀垮害
- shuttleProtocol.setMiddleToDistDistance(modbusTcpNet.getByteTransform().TransInt32(content, 12));
- //灏忚溅杩愯鏂瑰悜
- shuttleProtocol.setRunDirection(modbusTcpNet.getByteTransform().TransUInt16(content, 16));
- //鎵樼洏椤跺崌
- shuttleProtocol.setPalletLift(modbusTcpNet.getByteTransform().TransUInt16(content,18));
- //灏忚溅寮哄埗绉诲姩璺濈
- shuttleProtocol.setForceMoveDistance(modbusTcpNet.getByteTransform().TransInt32(content, 20));
- //鍏呯數寮�鍏�
- shuttleProtocol.setChargeSwitch(modbusTcpNet.getByteTransform().TransUInt16(content,24));
- //灏忚溅IO鎺у埗
- shuttleProtocol.setIOControl(modbusTcpNet.getByteTransform().TransUInt16(content,26));
- //灏忚溅杩愯閫熷害
- shuttleProtocol.setRunSpeed(modbusTcpNet.getByteTransform().TransUInt16(content,28));
- //灏忚溅闆疯揪澶囩敤
- shuttleProtocol.setRadarTmp(modbusTcpNet.getByteTransform().TransUInt16(content,30));
- //鎸囦护缁撴潫浣�
- shuttleProtocol.setCommandEnd(modbusTcpNet.getByteTransform().TransUInt16(content,32));
+ ///璇诲彇鍥涘悜绌挎杞︾姸鎬�-end
+ //灏忚溅澶勪簬蹇欑鐘舵�侊紝灏嗘爣璁扮疆涓簍rue
+ if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.BUSY) {
+ shuttleProtocol.setPakMk(true);
+ }
- //---------鐘舵�佸瓧---------
-// shuttleProtocol.setBusyStatus(modbusTcpNet.getByteTransform().TransUInt16(content,32));
+ if (shuttleProtocol.getErrorCode() != 0 && shuttleProtocol.getProtocolStatusType() == ShuttleProtocolStatusType.WORKING) {
+ //鍑虹幇閿欒
+ reset(shuttleProtocol.getAssignCommand());
+ }
- ///璁剧疆鍥涘悜绌挎杞︾姸鎬�-end
- OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
- //璇诲彇鍥涘悜绌挎杞﹁澶囦俊鎭紝鎻愪緵鏌ヨ
- //.....
+ if(shuttleProtocol.getProtocolStatusType() == ShuttleProtocolStatusType.FIXING
+ && shuttleProtocol.getTaskNo() != 0
+ && shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE
+ && shuttleProtocol.getAssignCommand() != null){
+ //澶勪簬鏁呴殰淇鐘舵��
+ //鎵ц涓嬩竴姝ユ寚浠�
+ executeWork(shuttleProtocol.getAssignCommand());
+ }
+ //鍥涘悜绌挎杞︾┖闂层�佹湁浠诲姟銆佹爣璁颁负true銆佸瓨鍦ㄤ换鍔℃寚浠わ紝闇�瑕佹墽琛屼换鍔$殑涓嬩竴鏉℃寚浠�
+ if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE
+ && shuttleProtocol.getTaskNo() != 0
+ && shuttleProtocol.getPakMk()
+ && shuttleProtocol.getAssignCommand() != null) {
+ //鎵ц涓嬩竴姝ユ寚浠�
+ executeWork(shuttleProtocol.getAssignCommand());
+ }
- // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴�
- //.....
+ //妫�娴嬫槸鍚︽湁鎻愬崌鏈洪攣瀹氭爣璁帮紝鏈夊垯妫�娴嬫彁鍗囨満鏄惁鍒颁綅锛屾槸鍚﹁兘璧颁笅涓�姝ュ懡浠�
+ if (shuttleProtocol.getBusyStatusType() == ShuttleStatusType.IDLE
+ && shuttleProtocol.getTaskNo() != 0
+ && shuttleProtocol.getAssignCommand() != null) {
+ Object o = redisUtil.get("wrk_no_" + shuttleProtocol.getAssignCommand().getTaskNo());
+ if (o != null) {
+ HashMap map = JSON.parseObject(o.toString(), HashMap.class);
+ if (map.containsKey("liftSecurityMk") && Boolean.parseBoolean(map.get("liftSecurityMk").toString())) {
+ //鎵ц涓嬩竴姝ユ寚浠�
+ executeWork(shuttleProtocol.getAssignCommand());
+ }
+ }
+ }
+ //灏嗗洓鍚戠┛姊溅鐘舵�佷繚瀛樿嚦鏁版嵁搴�
+ BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class);
+ BasShuttle basShuttle = shuttleService.selectById(shuttleProtocol.getShuttleNo());
+ if (basShuttle == null) {
+ basShuttle = new BasShuttle();
+ //鍥涘悜绌挎杞﹀彿
+ basShuttle.setShuttleNo(slave.getId());
+ shuttleService.insert(basShuttle);
+ }
+ //灏忚溅蹇欑姸鎬佷綅
+ basShuttle.setBusyStatus(shuttleProtocol.getBusyStatus().intValue());
+ //褰撳墠浜岀淮鐮�
+ basShuttle.setCurrentCode(shuttleProtocol.getCurrentCode().intValue());
+ //鐢垫睜鐢甸噺鐧惧垎姣�
+ basShuttle.setBatteryPower(shuttleProtocol.getBatteryPower().intValue());
+ //鐢垫睜娓╁害
+ basShuttle.setBatteryTemp(shuttleProtocol.getBatteryTemp().intValue());
+ //閿欒缂栧彿
+ basShuttle.setErrorCode(shuttleProtocol.getErrorCode().intValue());
+ //Plc杈撳嚭鐘舵�両O
+ basShuttle.setPlcOutputStatusIo(shuttleProtocol.getPlcOutputStatusIO().intValue());
+ //閿欒淇℃伅鐮�
+ basShuttle.setStatusErrorCode(shuttleProtocol.getStatusErrorCode().intValue());
+ //PLC杈撳叆鐘舵��
+ basShuttle.setPlcInputStatus(shuttleProtocol.getPlcInputStatus().intValue());
+ //褰撳墠鎴栬�呬箣鍓嶈鍒扮殑浜岀淮鐮佸��
+ basShuttle.setCurrentOrBeforeCode(shuttleProtocol.getCurrentOrBeforeCode().intValue());
+ //璇诲埌鐨勪簩缁寸爜X鏂瑰悜鍋忕Щ閲�
+ basShuttle.setCodeOffsetX(shuttleProtocol.getCodeOffsetX().intValue());
+ //璇诲埌鐨勪簩缁寸爜Y鏂瑰悜鍋忕Щ閲�
+ basShuttle.setCodeOffsetY(shuttleProtocol.getCodeOffsetY().intValue());
+ //褰撳墠鐨勭數鍘嬪��
+ basShuttle.setCurrentVoltage(shuttleProtocol.getCurrentVoltage().intValue());
+ //褰撳墠鐨勬ā鎷熼噺鍊�
+ basShuttle.setCurrentAnalogValue(shuttleProtocol.getCurrentAnalogValue().intValue());
+ //褰撳墠鐨勫崌闄嶄己鏈嶉�熷害
+ basShuttle.setCurrentLiftServoSpeed(shuttleProtocol.getCurrentLiftServoSpeed().intValue());
+ //褰撳墠鐨勮璧颁己鏈嶉�熷害
+ basShuttle.setCurrentMoveServoSpeed(shuttleProtocol.getCurrentMoveServoSpeed().intValue());
+ //褰撳墠鐨勫崌闄嶄己鏈嶈礋杞界巼
+ basShuttle.setCurrentLiftServoLoad(shuttleProtocol.getCurrentLiftServoLoad().intValue());
+ //褰撳墠鐨勮璧颁己鏈嶈礋杞界巼
+ basShuttle.setCurrentMoveServoLoad(shuttleProtocol.getCurrentMoveServoLoad().intValue());
+ //褰撳墠灏忚溅鐘舵�侊紙鍐呴儴鑷垜缁存姢锛�
+ basShuttle.setShuttleStatus(shuttleProtocol.getProtocolStatus());
+ //浠诲姟鍙�
+ basShuttle.setWrkNo(shuttleProtocol.getTaskNo().intValue());
+ //淇敼鏃堕棿
+ basShuttle.setUpdateTime(new Date());
+ //浣滀笟鏍囪
+ basShuttle.setPakMk(shuttleProtocol.getPakMk());
+ if (shuttleService.updateById(basShuttle)) {
+ OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
+// log.info(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
+ }
}else {
OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆憑1}鍥涘悜绌挎杞lc鐘舵�佷俊鎭け璐�", DateUtils.convert(new Date()), slave.getId()));
throw new CoolException(MessageFormat.format( "鍥涘悜绌挎杞lc鐘舵�佷俊鎭け璐� ===>> [id:{0}] [ip:{1}] [port:{2}]", slave.getId(), slave.getIp(), slave.getPort()));
}
} catch (Exception e) {
+ e.printStackTrace();
OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆戝洓鍚戠┛姊溅plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
initShuttle();
}
@@ -173,34 +290,95 @@
return false;
}
- //鍒ゆ柇灏忚溅鏄惁鍦ㄥ厖鐢�
- SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
- if (devpThread.charge1){
-
+ BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class);
+ if (shuttleService == null) {
+ News.error("绯荤粺閿欒");
+ return false;
}
- command.setShuttleNo(slave.getId());
- OperateResult result = null;
+ BasShuttle basShuttle = shuttleService.selectById(slave.getId().shortValue());
+ if (basShuttle == null) {
+ News.error("鍥涘悜绌挎杞︿笉瀛樺湪");
+ return false;
+ }
+
+ command.setShuttleNo(slave.getId().shortValue());
// 寮�濮嬩换鍔�
- //...
+ short[] array = new short[17];
+ //鎺у埗鎸囦护瀛�
+ array[0] = command.getCommandWord();
+ if (command.getStartCodeNum() != null) {
+ //鍚浜岀淮缂栧彿
+ array[1] = command.getStartCodeNum();
+ }
+ if (command.getMiddleCodeNum() != null) {
+ //涓棿浜岀淮缂栧彿
+ array[2] = command.getMiddleCodeNum();
+ }
- try {
- // 鏃ュ織璁板綍
- if (!command.getComplete() && command.getTaskMode() != 0) {
- //鏃ュ織璁板綍淇濆瓨鍒版暟鎹簱涓�
- //.....
- }
- } catch (Exception ignore) {}
+ if (command.getDistCodeNum() != null) {
+ //鐩爣浜岀淮缂栧彿
+ array[3] = command.getDistCodeNum();
+ }
+ if (command.getStartToDistDistance() != null) {
+ //璧风偣鍒扮洰鏍囩偣鐨勮窛绂婚暱搴︼紝鍏堝皢int杞负byte鏁扮粍锛屽啀灏哹yte鏁扮粍杞垚涓や釜short锛屽垎鍒崰鐢�4鍜�5绌洪棿
+ short[] startToDistDistances = CommonUtils.intToShorts(command.getStartToDistDistance());
+ array[4] = startToDistDistances[0];
+ array[5] = startToDistDistances[1];
+ }
+
+ if (command.getMiddleToDistDistance() != null) {
+ //涓棿鐐瑰埌鐩爣鐐圭殑璺濈闀垮害锛屽厛灏唅nt杞负byte鏁扮粍锛屽啀灏哹yte鏁扮粍杞垚涓や釜short锛屽垎鍒崰鐢�4鍜�5绌洪棿
+ short[] middleToDistDistances = CommonUtils.intToShorts(command.getMiddleToDistDistance());
+ array[6] = middleToDistDistances[0];
+ array[7] = middleToDistDistances[1];
+ }
+
+ array[8] = basShuttle.getRunSpeed().shortValue();//鍥涘悜绌挎杞﹁繍琛岄�熷害锛屼粠绯荤粺鏁版嵁搴撹鍑�
+ if (command.getRunDirection() != null) {
+ //灏忚溅杩愯鏂瑰悜
+ array[8] = command.getRunDirection();
+ }
+
+ if (command.getPalletLift() != null) {
+ //鎵樼洏椤跺崌
+ array[9] = command.getPalletLift();
+ }
+
+ if (command.getForceMoveDistance() != null) {
+ //灏忚溅寮哄埗绉诲姩璺濈锛屽厛灏唅nt杞负byte鏁扮粍锛屽啀灏哹yte鏁扮粍杞垚涓や釜short锛屽垎鍒崰鐢�4鍜�5绌洪棿
+ short[] forceMoveDistances = CommonUtils.intToShorts(command.getForceMoveDistance());
+ array[10] = forceMoveDistances[0];
+ array[11] = forceMoveDistances[1];
+ }
+
+ if (command.getChargeSwitch() != null) {
+ //鍏呯數寮�鍏�
+ array[12] = command.getChargeSwitch();
+ }
+
+ if (command.getIOControl() != null) {
+ //灏忚溅IO鎺у埗
+ array[13] = command.getIOControl();
+ }
+
+ if (command.getRunSpeed() != null) {
+ //灏忚溅杩愯閫熷害
+ array[14] = command.getRunSpeed();
+ }
+
+ if (command.getRadarTmp() != null) {
+ //灏忚溅闆疯揪澶囩敤
+ array[15] = command.getRadarTmp();
+ }
+
+ //鎸囦护缁撴潫浣�
+ array[16] = command.getCommandEnd();
+
+ OperateResult result = modbusTcpNet.Write("0", array);;
if (result != null && result.IsSuccess) {
- // 缁存姢鏁版嵁搴撴帓鍒楀眰
-// if (!steProtocol.getWaiting()) {
-// if (!Cools.isEmpty(command.getRow(), command.getBay(), command.getLev())) {
-// this.modifyPos(command.getRow().intValue(), command.getBay().intValue(), command.getLev().intValue());
-// }
-// }
-
News.info("鍥涘悜绌挎杞﹀懡浠や笅鍙慬id:{}] >>>>> {}", slave.getId(), JSON.toJSON(command));
OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
return true;
@@ -218,9 +396,656 @@
if (null == shuttleProtocol) {
shuttleProtocol = new ShuttleProtocol();
}
- shuttleProtocol.setShuttleNo(slave.getId().shortValue());
- shuttleProtocol.setBusyStatus(ShuttleStatusType.BUSY);
- shuttleProtocol.setCurrentCode("0");
+ }
+
+ //鍒嗛厤浠诲姟
+ private void assignWork(ShuttleAssignCommand assignCommand) {
+ //灏嗘map瀛樺叆redis涓�
+ HashMap<String, Object> map = new HashMap<>();
+ if (!assignCommand.getAuto()) {
+ List<ShuttleCommand> commands = new ArrayList<>();
+ ShuttleCommand command = new ShuttleCommand();
+ LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
+ switch (assignCommand.getTaskMode()) {
+ case 1://鍏ュ簱
+ case 2://鍑哄簱
+ //灏忚溅绉诲姩鍒版彁鍗囨満鍙o紝璁$畻璺緞
+ //璁$畻灏忚溅璧风偣鍒颁腑鐐规墍闇�鍛戒护
+ LocMast currentLocMast = locMastService.queryByQrCode(shuttleProtocol.getCurrentCode().toString());
+ List<NavigateNode> firstMastResult = NavigateUtils.calc(currentLocMast.getLocNo(), assignCommand.getSourceLocNo(), ShuttleTaskModeType.PAK_IN.id);
+ if (firstMastResult != null) {
+ //鑾峰彇鍒嗘璺緞
+ ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(firstMastResult);
+ //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
+ for (ArrayList<NavigateNode> nodes : data) {
+ //寮�濮嬭矾寰�
+ NavigateNode startPath = nodes.get(0);
+ //鐩爣璺緞
+ NavigateNode endPath = nodes.get(nodes.size() - 1);
+ Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+
+ ShuttleCommand command1 = new ShuttleCommand();
+ command1.setCommandWord((short) 1);
+ command1.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), 1));
+ command1.setMiddleCodeNum((short) 1);
+ command1.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), 1));
+ command1.setStartToDistDistance(allDistance);
+ command1.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
+ command1.setForceMoveDistance(0);
+ command1.setIOControl((short) 0);
+ command1.setRunSpeed((short) 1000);
+ command1.setCommandEnd((short) 1);
+ commands.add(command1);
+ }
+
+ //鎵樼洏椤跺崌
+ ShuttleCommand command2 = new ShuttleCommand();
+ command2.setCommandWord((short) 2);
+ command2.setStartCodeNum((short) 0);
+ command2.setMiddleCodeNum((short) 0);
+ command2.setDistCodeNum((short) 0);
+ command2.setStartToDistDistance(0);
+ command2.setMiddleToDistDistance(0);
+ command2.setRunDirection((short) 0);
+ command2.setForceMoveDistance(0);
+ command2.setPalletLift((short) 1);
+ command2.setRunSpeed((short) 0);
+ command2.setCommandEnd((short) 1);
+ commands.add(command2);
+ }else {
+ //娌℃湁璁$畻鍒拌矾寰勶紝鍙兘瀛樺湪灏忚溅浣嶇疆灏辨槸璧风偣浣嶇疆
+ if (currentLocMast.getLocNo().equals(assignCommand.getSourceLocNo())) {
+ //灏忚溅浣嶇疆灏辨槸璧风偣浣嶇疆锛屾棤闇�绉诲姩锛岀洿鎺ラ《鍗�
+ //鎵樼洏椤跺崌
+ ShuttleCommand command2 = new ShuttleCommand();
+ command2.setCommandWord((short) 2);
+ command2.setStartCodeNum((short) 0);
+ command2.setMiddleCodeNum((short) 0);
+ command2.setDistCodeNum((short) 0);
+ command2.setStartToDistDistance(0);
+ command2.setMiddleToDistDistance(0);
+ command2.setRunDirection((short) 0);
+ command2.setForceMoveDistance(0);
+ command2.setPalletLift((short) 1);
+ command2.setRunSpeed((short) 0);
+ command2.setCommandEnd((short) 1);
+ commands.add(command2);
+ }
+ }
+
+ //璁$畻涓偣鍒扮粓鐐硅矾寰�
+ List<NavigateNode> secMastResult = NavigateUtils.calc(assignCommand.getSourceLocNo(), assignCommand.getLocNo(), ShuttleTaskModeType.PAK_IN.id);
+ if (secMastResult != null) {
+ //鑾峰彇鍒嗘璺緞
+ ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(secMastResult);
+ //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
+ for (ArrayList<NavigateNode> nodes : data) {
+ //寮�濮嬭矾寰�
+ NavigateNode startPath = nodes.get(0);
+ //鐩爣璺緞
+ NavigateNode endPath = nodes.get(nodes.size() - 1);
+ Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+
+ ShuttleCommand command1 = new ShuttleCommand();
+ command1.setCommandWord((short) 1);
+ command1.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), 1));
+ command1.setMiddleCodeNum((short) 1);
+ command1.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), 1));
+ command1.setStartToDistDistance(allDistance);
+ command1.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
+ command1.setForceMoveDistance(0);
+ command1.setIOControl((short) 0);
+ command1.setRunSpeed((short) 1000);
+ command1.setCommandEnd((short) 1);
+ commands.add(command1);
+ }
+
+ //鎵樼洏涓嬮檷
+ ShuttleCommand command2 = new ShuttleCommand();
+ command2.setCommandWord((short) 2);
+ command2.setStartCodeNum((short) 0);
+ command2.setMiddleCodeNum((short) 0);
+ command2.setDistCodeNum((short) 0);
+ command2.setStartToDistDistance(0);
+ command2.setMiddleToDistDistance(0);
+ command2.setRunDirection((short) 0);
+ command2.setForceMoveDistance(0);
+ command2.setPalletLift((short) 2);
+ command2.setRunSpeed((short) 0);
+ command2.setCommandEnd((short) 1);
+ commands.add(command2);
+ }
+ break;
+ case 3://鎵樼洏椤跺崌
+ case 4://鎵樼洏涓嬮檷
+ command.setCommandWord((short) 2);
+ command.setStartCodeNum((short) 0);
+ command.setMiddleCodeNum((short) 0);
+ command.setDistCodeNum((short) 0);
+ command.setStartToDistDistance(0);
+ command.setMiddleToDistDistance(0);
+ command.setRunDirection((short) 0);
+ command.setForceMoveDistance(0);
+ command.setPalletLift(assignCommand.getTaskMode() == 3 ? (short)1 : (short)2);
+ command.setRunSpeed((short) 0);
+ command.setCommandEnd((short) 1);
+ commands.add(command);
+ break;
+ case 5://寮哄埗宸︾Щ
+ case 6://寮哄埗鍙崇Щ
+ case 7://寮哄埗涓婄Щ
+ case 8://寮哄埗涓嬬Щ
+ command.setCommandWord((short) 3);
+ command.setStartCodeNum((short) 0);
+ command.setMiddleCodeNum((short) 0);
+ command.setDistCodeNum((short) 0);
+ command.setStartToDistDistance(600);
+ command.setRunDirection((short) (assignCommand.getTaskMode() - 4));
+ command.setForceMoveDistance(600);
+ command.setIOControl((short) 0);
+ command.setCommandEnd((short) 1);
+ command.setRunSpeed((short) 1000);
+ commands.add(command);
+ break;
+ case 9://鐘舵�佸浣�
+ command.setCommandWord((short) 6);
+ command.setStartCodeNum((short) 0);
+ command.setMiddleCodeNum((short) 0);
+ command.setDistCodeNum((short) 0);
+ command.setStartToDistDistance(0);
+ command.setMiddleToDistDistance(0);
+ command.setRunDirection((short) 0);
+ command.setPalletLift((short) 0);
+ command.setPalletLift((short) 0);
+ command.setForceMoveDistance(0);
+ command.setChargeSwitch((short) 0);
+ command.setIOControl((short) 0);
+ command.setRunSpeed((short) 0);
+ command.setCommandEnd((short) 1);
+ commands.add(command);
+ break;
+ case 10://鍚戞鏂瑰悜(宸�)瀵诲簱浣�
+ command.setCommandWord((short) 4);
+ command.setRunDirection((short) 1);
+ command.setStartToDistDistance(3000);
+ command.setRunSpeed((short) 1000);
+ command.setCommandEnd((short) 1);
+ commands.add(command);
+ break;
+ case 11://鍚戣礋鏂瑰悜(鍙�)瀵诲簱浣�
+ command.setCommandWord((short) 4);
+ command.setRunDirection((short) 2);
+ command.setStartToDistDistance(3000);
+ command.setRunSpeed((short) 1000);
+ command.setCommandEnd((short) 1);
+ commands.add(command);
+ break;
+ case 12://鍚戞鏂瑰悜(鍓�)瀵诲簱浣�
+ command.setCommandWord((short) 4);
+ command.setRunDirection((short) 4);
+ command.setStartToDistDistance(3000);
+ command.setRunSpeed((short) 1000);
+ command.setCommandEnd((short) 1);
+ commands.add(command);
+ break;
+ case 13://鍚戣礋鏂瑰悜(鍚�)瀵诲簱浣�
+ command.setCommandWord((short) 4);
+ command.setRunDirection((short) 3);
+ command.setStartToDistDistance(3000);
+ command.setRunSpeed((short) 1000);
+ command.setCommandEnd((short) 1);
+ commands.add(command);
+ break;
+ case 14://绉诲姩鍒扮洰鏍囧簱浣�
+ LocMast locMast = locMastService.queryByQrCode(shuttleProtocol.getCurrentCode().toString());
+ List<NavigateNode> result = NavigateUtils.calc(locMast.getLocNo(), assignCommand.getLocNo(), ShuttleTaskModeType.PAK_IN.id);
+ if (result != null) {
+ //鑾峰彇鍒嗘璺緞
+ ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(result);
+ //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
+ for (ArrayList<NavigateNode> nodes : data) {
+ //寮�濮嬭矾寰�
+ NavigateNode startPath = nodes.get(0);
+ //鐩爣璺緞
+ NavigateNode endPath = nodes.get(nodes.size() - 1);
+ Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+
+ LocMast distLocMast = locMastService.queryByLoc(assignCommand.getLocNo());
+ String qrCodeValue = distLocMast.getQrCodeValue();
+ command.setCommandWord((short) 1);
+ command.setStartCodeNum(shuttleProtocol.getCurrentCode());
+ command.setMiddleCodeNum((short) 1);
+ command.setDistCodeNum((short) Integer.parseInt(qrCodeValue));
+ command.setStartToDistDistance(allDistance);
+ command.setRunSpeed((short) 1000);
+ command.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
+ command.setForceMoveDistance(0);
+ command.setIOControl((short) 0);
+ command.setCommandEnd((short) 1);
+ commands.add(command);
+ }
+ }
+ break;
+ case 15://鍏呯數寮�鍏�
+ command.setCommandWord((short) 8);
+ command.setIOControl((short) 4);
+ command.setCommandEnd((short) 1);
+ commands.add(command);
+ break;
+ default:
+ }
+ assignCommand.setCommands(commands);
+ }
+
+ //鍥涘悜绌挎杞﹀彿
+ map.put("shuttle_no", assignCommand.getShuttleNo());
+ //宸ヤ綔鍙�
+ map.put("wrk_no", assignCommand.getTaskNo());
+ //鍛戒护鎵ц姝ュ簭
+ map.put("commandStep", 0);
+ //鍛戒护
+ map.put("assignCommand", assignCommand);
+ //鍙戠敓閿欒鏃跺皾璇曟墽琛岀殑鎸囦护锛屼紭鍏堢骇鏈�楂�
+ map.put("errorCommands", new ArrayList<ShuttleCommand>());
+ shuttleProtocol.setTaskNo(assignCommand.getTaskNo());
+ shuttleProtocol.setAssignCommand(assignCommand);
+ shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
+ //浠诲姟鏁版嵁淇濆瓨鍒皉edis
+ redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map));
+ //鎵ц涓嬪彂浠诲姟
+ executeWork(assignCommand);
+ }
+
+ //鎵ц涓嬪彂鐨勬寚浠�
+ private boolean executeWork(ShuttleAssignCommand assignCommand) {
+ //璇诲彇redis鏁版嵁
+ if (assignCommand == null) {
+ return false;
+ }
+
+ Object o = redisUtil.get("wrk_no_" + assignCommand.getTaskNo());
+ if (o == null) {
+ return false;
+ }
+ HashMap map = JSON.parseObject(o.toString(), HashMap.class);
+
+ if (!checkLiftStation(assignCommand)) {//妫�娴嬫槸鍚︽湁鎻愬崌鏈虹珯鐐癸紝鏈夊垯璋冨害鎻愬崌鏈�
+ return false;
+ }
+
+ //灏嗘爣璁扮疆涓篺alse(闃叉閲嶅彂)
+ shuttleProtocol.setPakMk(false);
+
+ List<ShuttleCommand> errorCommands = JSON.parseArray(map.get("errorCommands").toString(),ShuttleCommand.class);
+ if (errorCommands.size() > 0) {
+ //浼樺厛鎵ц璇ユ寚浠�
+ ShuttleCommand errorCommand = errorCommands.get(0);//鍙栧嚭鎸囦护
+
+ if(errorCommand.getCommandWord() == 1){//姝e父琛岃蛋鍛戒护锛岄渶瑕佸厛鎵ц瀹屾壘搴撲綅鍛戒护鍚庯紝鍐嶆墽琛�
+ LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
+ LocMast locMast = locMastService.queryByQrCode(shuttleProtocol.getCurrentCode().toString());
+ LocMast distLocMast = locMastService.queryByQrCode(errorCommand.getStartCodeNum().toString());
+ if (shuttleProtocol.getCurrentCode().equals(errorCommand.getStartCodeNum())) {
+ //璧风偣鍜岀粓鐐瑰睘浜庡悓涓�搴撲綅锛屾棤闇�鍐嶆墽琛岀Щ鍔ㄦ搷浣�
+ errorCommands.remove(0);//绉婚櫎璇ュ懡浠�
+ map.put("errorCommands", new ArrayList<ShuttleCommand>());
+ shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
+ //褰撳墠姝ュ簭
+ int commandStep = Integer.parseInt(map.get("commandStep").toString());
+ //姝ュ簭鍥為��
+ commandStep--;
+ map.put("commandStep", commandStep);
+ //浠诲姟鏁版嵁淇濆瓨鍒皉edis
+ redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map));
+ shuttleProtocol.setPakMk(true);
+ return true;
+ }else {
+ List<NavigateNode> result = NavigateUtils.calc(locMast.getLocNo(), distLocMast.getLocNo(), ShuttleTaskModeType.PAK_IN.id);
+ if (result != null) {
+ //鑾峰彇鍒嗘璺緞
+ ArrayList<ArrayList<NavigateNode>> data = NavigateUtils.getSectionPath(result);
+ //灏嗘瘡涓�娈佃矾寰勫垎鎴恈ommand鎸囦护
+ for (ArrayList<NavigateNode> nodes : data) {
+ //寮�濮嬭矾寰�
+ NavigateNode startPath = nodes.get(0);
+ //鐩爣璺緞
+ NavigateNode endPath = nodes.get(nodes.size() - 1);
+ Integer allDistance = NavigateUtils.getCurrentPathAllDistance(nodes);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂�
+
+ String qrCodeValue = distLocMast.getQrCodeValue();
+ errorCommand.setCommandWord((short) 1);
+ errorCommand.setStartCodeNum(shuttleProtocol.getCurrentCode());
+ errorCommand.setMiddleCodeNum((short) 1);
+ errorCommand.setDistCodeNum((short) Integer.parseInt(qrCodeValue));
+ errorCommand.setStartToDistDistance(allDistance);
+ errorCommand.setRunSpeed((short) 1000);
+ errorCommand.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
+ errorCommand.setForceMoveDistance(0);
+ errorCommand.setIOControl((short) 0);
+ errorCommand.setCommandEnd((short) 1);
+ break;
+ }
+ }
+ }
+
+ shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);
+ //褰撳墠姝ュ簭
+ int commandStep = Integer.parseInt(map.get("commandStep").toString());
+ //姝ュ簭鍥為��
+ commandStep--;
+ map.put("commandStep", commandStep);
+ }
+
+ if (!write(errorCommand)) {
+ News.error("鍥涘悜绌挎杞﹀懡浠や笅鍙戝け璐ワ紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(errorCommand));
+ return false;
+ } else {
+ News.info("鍥涘悜绌挎杞﹀懡浠や笅鍙戞垚鍔燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(errorCommand));
+ errorCommands.remove(0);
+ map.put("errorCommands", errorCommands);
+ //浠诲姟鏁版嵁淇濆瓨鍒皉edis
+ redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map));
+ return true;
+ }
+ }
+
+ List<ShuttleCommand> commands = assignCommand.getCommands();
+ //褰撳墠姝ュ簭
+ int commandStep = Integer.parseInt(map.get("commandStep").toString());
+ //path璺緞鏁扮洰
+ int size = commands.size();
+
+ //鍙栧嚭鍛戒护
+ ShuttleCommand command = commands.get(commandStep);
+
+ if (assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_IN.id.shortValue()
+ || assignCommand.getTaskMode() == ShuttleTaskModeType.PAK_OUT.id.shortValue()
+ ) {
+ //灏忚溅澶卞幓鍧愭爣锛岀姝笅鍙戝懡浠�
+ if (shuttleProtocol.getCurrentCode() == 0) {
+ return false;
+ }
+ }
+
+ //涓嬪彂鍛戒护
+ if (!write(command)) {
+ News.error("鍥涘悜绌挎杞﹀懡浠や笅鍙戝け璐ワ紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
+ return false;
+ } else {
+ News.info("鍥涘悜绌挎杞﹀懡浠や笅鍙戞垚鍔燂紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
+
+ //鍒ゆ柇鏁版嵁鏄惁鎵ц瀹屾垚
+ if (commandStep < size - 1) {
+ //鏇存柊redis鏁版嵁
+ //姝ュ簭澧炲姞
+ commandStep++;
+ map.put("commandStep", commandStep);
+ //浠诲姟鏁版嵁淇濆瓨鍒皉edis
+ redisUtil.set("wrk_no_" + map.get("wrk_no").toString(), JSON.toJSONString(map));
+ }else {
+ //宸叉墽琛屽畬鎴�
+ //淇濆瓨鏁版嵁鍒版暟鎹簱鍋氭祦姘�
+ BasShuttleOptService shuttleOptService = SpringUtils.getBean(BasShuttleOptService.class);
+ if (shuttleOptService != null) {
+ BasShuttleOpt opt = new BasShuttleOpt(
+ assignCommand.getTaskNo().intValue(),
+ assignCommand.getShuttleNo().intValue(),
+ new Date(),
+ ShuttleTaskModeType.get(assignCommand.getTaskMode()).desc,
+ assignCommand.getSourceLocNo(),
+ assignCommand.getLocNo(),
+ null,
+ null,
+ null,
+ JSON.toJSONString(assignCommand)
+ );
+ shuttleOptService.insert(opt);
+ }
+
+ if (map.containsKey("liftSecurityMk") && Boolean.parseBoolean(map.get("liftSecurityMk").toString())) {
+ //鏇鹃攣瀹氳繃鎻愬崌鏈猴紝闇�瑕佽繘琛岃В閿�
+ LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1);
+ LiftProtocol liftProtocol = liftThread.getLiftProtocol();
+ if (liftProtocol != null) {
+ liftProtocol.setSecurityMk(false);
+ }
+ }
+
+ //鍒犻櫎redis
+ redisUtil.del("wrk_no_" + map.get("wrk_no").toString());
+
+ if (!assignCommand.getAuto()) {
+ //鎵嬪姩妯″紡涓嶆姏鍑虹瓑寰呯姸鎬侊紝鐩存帴澶嶄綅
+ if (assignCommand.getTaskMode() == 9) {
+ //璁剧疆鍥涘悜绌挎杞︿负绌洪棽鐘舵��
+ shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
+ //浠诲姟鍙锋竻闆�
+ shuttleProtocol.setTaskNo((short) 0);
+ //鏍囪澶嶄綅
+ shuttleProtocol.setPakMk(true);
+ //浠诲姟鎸囦护娓呴浂
+ shuttleProtocol.setAssignCommand(null);
+ }
+ News.info("鍥涘悜绌挎杞︽墜鍔ㄤ换鍔℃墽琛屽畬鎴愶紝绌挎杞﹀彿={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
+ }else {
+ if (!assignCommand.getCharge()) {
+ //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting
+ shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WAITING);
+ }else {
+ shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING);
+ }
+ News.info("鍥涘悜绌挎杞︿换鍔℃墽琛屽畬鎴愮瓑寰呯‘璁や腑锛岀┛姊溅鍙�={}锛屼换鍔℃暟鎹�={}", shuttleProtocol.getShuttleNo(), JSON.toJSON(command));
+ }
+
+ }
+
+ }
+ return true;
+ }
+
+ /**
+ * 妫�娴嬫槸鍚︽湁鎻愬崌鏈虹珯鐐癸紝鏈夊垯璋冨害鎻愬崌鏈�
+ */
+ private boolean checkLiftStation(ShuttleAssignCommand assignCommand) {
+ //璇诲彇redis鏁版嵁
+ if (assignCommand == null) {
+ return false;
+ }
+
+ Object o = redisUtil.get("wrk_no_" + assignCommand.getTaskNo());
+ if (o == null) {
+ return false;
+ }
+ HashMap map = JSON.parseObject(o.toString(), HashMap.class);
+ //褰撳墠姝ュ簭
+ int commandStep = Integer.parseInt(map.get("commandStep").toString());
+
+ //妫�娴嬫槸鍚﹀瓨鍦ㄦ彁鍗囨満鍙g殑鎸囦护
+ List<ShuttleCommand> commands = assignCommand.getCommands();
+ BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
+ ArrayList<Short> qrCodeValues = new ArrayList<>();
+ for (BasDevp basDevp : basDevpService.selectList(null)) {
+ //灏嗘墍鏈夋彁鍗囨満鍙d簩缁寸爜瀛樺叆list
+ qrCodeValues.add(Short.parseShort(basDevp.getQrCodeValue()));
+ }
+
+ //閬嶅巻鎵�鏈夋寚浠わ紝鍒ゆ柇鏄惁鏈夊埌鎻愬崌鏈哄彛鐨勬寚浠わ紝骞惰幏鍙栧埌杈捐鎻愬崌鏈哄彛鎵�闇�姝ュ簭
+ int step = 0;
+ ShuttleCommand command = null;
+ for (int i = 1; i < commands.size(); i++) {
+ command = commands.get(i);
+ if (qrCodeValues.contains(command.getDistCodeNum())) {
+ //瀛樺湪
+ step = i + 1;
+ break;
+ }
+ }
+
+ if (step == 0) {
+ //鏃犻渶鍚庣画妫�娴嬶紝鐩存帴鏀捐
+ return true;
+ }
+
+ //鍒ゆ柇涓嬩竴姝ユ槸鍚︿负鎻愬崌鏈哄彛
+ if (commandStep + 1 != step) {
+ //涓嬩竴姝ヤ笉鏄彁鍗囨満鍙o紝璺宠繃鍚庣画娴佺▼
+ return true;
+ }
+
+ //鎷垮埌鎻愬崌鏈虹嚎绋�
+ LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1);
+ if (liftThread == null) {
+ return false;
+ }
+ LiftProtocol liftProtocol = liftThread.getLiftProtocol();
+ if (liftProtocol == null) {
+ return false;
+ }
+
+ //鑾峰彇鍥涘悜绌挎杞﹀綋鍓嶆ゼ灞�
+ String shuttleLocNo = shuttleProtocol.getCurrentLocNo();//浜岀淮鐮佸搴斿簱浣嶅彿
+ Integer shuttleLocNoLev = Integer.parseInt(shuttleLocNo.substring(shuttleLocNo.length() - 2, shuttleLocNo.length()));//搴撲綅鍙峰搴斿眰楂�
+
+ //绋嬪簭璧板埌杩欙紝琛ㄧず鎻愬崌鏈哄彲鑳戒竴鐩村氨鍦ㄥ綋鍓嶅眰锛屽彲鑳界粡杩囦簡绉诲姩鍒拌揪浜嗚灞�
+ if (liftProtocol.getProtocolStatusType() == LiftProtocolStatusType.WAITING) {
+ //鎻愬崌鏈虹瓑寰呯‘璁�
+ //璁剧疆鎻愬崌鏈轰负绌洪棽鐘舵��
+ liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE);
+ //浠诲姟鍙锋竻闆�
+ liftProtocol.setTaskNo((short) 0);
+ //鏍囪澶嶄綅
+ liftProtocol.setPakMk(true);
+ //浠诲姟鎸囦护娓呴浂
+ liftProtocol.setAssignCommand(null);
+ //鎻愬崌鏈鸿В閿�
+ liftProtocol.setLiftLock(false);
+ }
+
+ //鍒ゆ柇鎻愬崌鏈烘槸鍚﹀湪鐩爣妤煎眰
+ if (liftProtocol.getLev().intValue() == shuttleLocNoLev) {
+ //鍚屼竴灞傦紝鐩存帴鏀捐
+ return true;
+ }
+
+ //鎻愬崌鏈哄拰绌挎杞﹀浜庝笉鍚屾ゼ灞傦紝闇�瑕佽繘琛岃皟搴�
+ if (!liftProtocol.isIdle()) {
+ //鎻愬崌鏈轰笉鏄┖闂�
+ return false;
+ }
+
+ //缁欐彁鍗囨満鍒嗛厤浠诲姟
+ liftProtocol.setLiftLock(true);//閿佸畾鎻愬崌鏈�
+ liftProtocol.setTaskNo(shuttleProtocol.getTaskNo());//璁剧疆浠诲姟鍙�
+ liftProtocol.setShuttleNo(shuttleProtocol.getShuttleNo());//璁剧疆鍥涘悜绌挎杞﹀彿
+ liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//璁剧疆鎻愬崌鏈虹姸鎬佷负宸ヤ綔涓�
+ liftProtocol.setSecurityMk(true);//鏍囪缃负true锛岄槻姝㈠叾浠栦换鍔″崰鐢ㄥ綋鍓嶆彁鍗囨満
+ map.put("liftSecurityMk", true);//鏍囪缃负true锛岄槻姝㈠叾浠栦换鍔″崰鐢ㄥ綋鍓嶆彁鍗囨満
+ //浠诲姟鏁版嵁淇濆瓨鍒皉edis
+ redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map));
+
+ //鍛戒护list
+ ArrayList<LiftCommand> liftCommands = new ArrayList<>();
+ LiftCommand liftCommand = new LiftCommand();
+ liftCommand.setLiftNo(liftProtocol.getLiftNo());//鎻愬崌鏈哄彿
+ liftCommand.setTaskNo(liftProtocol.getTaskNo());//浠诲姟鍙�
+ liftCommand.setRun((short) 1);//鍗囬檷
+ liftCommand.setDistPosition(shuttleLocNoLev.shortValue());//鐩爣妤煎眰(绌挎杞︽墍鍦ㄦゼ灞�)
+ liftCommand.setLiftLock(true);//閿佸畾鎻愬崌鏈�
+ liftCommands.add(liftCommand);//灏嗗懡浠ゆ坊鍔犺繘list
+
+ LiftAssignCommand liftAssignCommand = new LiftAssignCommand();
+ liftAssignCommand.setCommands(liftCommands);
+ liftAssignCommand.setLiftNo(liftProtocol.getLiftNo());
+ liftAssignCommand.setTaskNo(liftProtocol.getTaskNo());
+ //涓嬪彂浠诲姟
+ MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, liftAssignCommand));
+
+ return false;
+ }
+
+ /**
+ * 澶嶄綅骞跺皾璇曚慨澶嶉敊璇�
+ */
+ private boolean reset(ShuttleAssignCommand assignCommand) {
+ //璇诲彇redis鏁版嵁
+ if (assignCommand == null) {
+ return false;
+ }
+
+ Object o = redisUtil.get("wrk_no_" + assignCommand.getTaskNo());
+ if (o == null) {
+ return false;
+ }
+
+ HashMap map = JSON.parseObject(o.toString(), HashMap.class);
+ List<ShuttleCommand> commands = assignCommand.getCommands();
+ //褰撳墠姝ュ簭
+ int commandStep = Integer.parseInt(map.get("commandStep").toString());
+ //path璺緞鏁扮洰
+ int size = commands.size();
+
+ ArrayList<ShuttleCommand> list = new ArrayList<>();
+
+ //鍙栧嚭鍛戒护
+ ShuttleCommand command = commands.get(commandStep - 1);
+
+ //澶嶄綅鍛戒护
+ ShuttleCommand resetCommand = new ShuttleCommand();
+ resetCommand.setCommandWord((short) 6);
+ resetCommand.setStartCodeNum((short) 0);
+ resetCommand.setMiddleCodeNum((short) 0);
+ resetCommand.setDistCodeNum((short) 0);
+ resetCommand.setStartToDistDistance(0);
+ resetCommand.setMiddleToDistDistance(0);
+ resetCommand.setRunDirection((short) 0);
+ resetCommand.setPalletLift((short) 0);
+ resetCommand.setPalletLift((short) 0);
+ resetCommand.setForceMoveDistance(0);
+ resetCommand.setChargeSwitch((short) 0);
+ resetCommand.setIOControl((short) 0);
+ resetCommand.setRunSpeed((short) 0);
+ resetCommand.setCommandEnd((short) 1);
+ list.add(resetCommand);
+
+ //杞﹁締绌洪棽锛岀瓑寰呭啓鍏ユ壘搴撲綅鍛戒护
+ //鎵惧簱浣嶅懡浠�
+ ShuttleCommand searchCommand = new ShuttleCommand();
+ searchCommand.setCommandWord((short) 4);
+ short direction = 1;
+ switch (command.getRunDirection()) {
+ case 1:
+ direction = 2;
+ break;
+ case 2:
+ direction = 1;
+ break;
+ case 3:
+ direction = 4;
+ break;
+ case 4:
+ direction = 3;
+ break;
+ default:
+ direction = 1;
+ }
+
+ searchCommand.setRunDirection(direction);//杩愯鏂瑰悜
+ searchCommand.setStartToDistDistance(1200);
+ searchCommand.setRunSpeed((short) 1000);
+ searchCommand.setCommandEnd((short) 1);
+ list.add(searchCommand);
+
+ //绉诲姩杞﹁締锛岄渶瑕佸湪鎵ц瀹屽鎵惧畾浣嶇偣鍚庡啀鎵ц
+ ShuttleCommand moveCommand = new ShuttleCommand();
+ moveCommand.setCommandWord((short) 1);
+ moveCommand.setStartCodeNum(command.getStartCodeNum());//瀛樺叆鐩爣搴撲綅鍙�
+ list.add(moveCommand);
+
+ map.put("errorCommands", list);
+ //浠诲姟鏁版嵁淇濆瓨鍒皉edis
+ redisUtil.set("wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(map));
+ shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.FIXING);
+ return true;
}
/******************************************************************************************/
@@ -231,44 +1056,25 @@
slave.setId(1);
slave.setIp("192.168.4.24");
slave.setPort(502);
- ShuttleThread thread = new ShuttleThread(slave);
- thread.connect();
- thread.readStatus();
- System.out.println(JSON.toJSONString(thread.shuttleProtocol));
-
- // 浠诲姟浣滀笟
-// SteCommand command = new SteCommand();
-// command.setSteNo(1); // 鍫嗗灈鏈虹紪鍙�
-// Random random = new Random();
-// int taskNo = random.nextInt(9090);
-// command.setTaskNo(taskNo); // 宸ヤ綔鍙�
-// command.setTaskMode(SteTaskModeType.MOVE_LEFT); // 浠诲姟妯″紡
-// thread.write(command);
-
- // 浠诲姟瀹屾垚
-// SteCommand command = new SteCommand();
-// command.setSteNo(1); // 鍫嗗灈鏈虹紪鍙�
-// command.setComplete(Boolean.TRUE); // 浠诲姟妯″紡
-// thread.write(command);
-
- // 鎺у埗妯″紡
-// SteCommand command = new SteCommand();
-// command.setControlMode((short) 1);
-// thread.write(command);
-
- // 澶嶄綅淇″彿
-// SteCommand command = new SteCommand();
-// command.setReset(Boolean.TRUE);
-// thread.write(command);
-
- // 鍒犻櫎鎸囦护
-// SteCommand command = new SteCommand();
-// command.setDelete(Boolean.TRUE);
-// thread.write(command);
-
- // 绌挎杞﹁繍琛岀姝�
-// SteCommand command = new SteCommand();
-// command.setRun((short)0);
+// ShuttleThread thread = new ShuttleThread(slave);
+// thread.connect();
+// thread.readStatus();
+//
+// ShuttleCommand command = new ShuttleCommand();
+// command.setCommandWord((short) 0);
+// command.setStartCodeNum((short) 12323);
+// command.setMiddleCodeNum((short) 22323);
+// command.setDistCodeNum((short) 29999);
+// command.setStartToDistDistance(109999);
+// command.setMiddleToDistDistance(5000);
+// command.setRunDirection((short) 1);
+// command.setPalletLift((short) 2);
+// command.setForceMoveDistance(3000);
+// command.setChargeSwitch((short) 2);
+// command.setIOControl((short) 0);
+// command.setRunSpeed((short) 0);
+// command.setRadarTmp((short) 0);
+// command.setCommandEnd((short) 1);
// thread.write(command);
}
--
Gitblit v1.9.1