From 09fcc4ec56a1ce6c0fcb308348d8dd5e2c08d336 Mon Sep 17 00:00:00 2001 From: fyxc <fyxc@qq.com> Date: 星期四, 22 五月 2025 14:33:06 +0800 Subject: [PATCH] server commit files --- src/main/java/com/zy/core/thread/ShuttleThread.java | 275 ++++++++----------------------------------------------- 1 files changed, 40 insertions(+), 235 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..993d0d1 100644 --- a/src/main/java/com/zy/core/thread/ShuttleThread.java +++ b/src/main/java/com/zy/core/thread/ShuttleThread.java @@ -1,275 +1,80 @@ package com.zy.core.thread; -import HslCommunication.Core.Transfer.DataFormat; -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.exception.CoolException; -import com.zy.core.News; + +import com.zy.common.ExecuteSupport; +import com.zy.common.model.NavigateNode; 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.model.ShuttleSlave; -import com.zy.core.model.SteSlave; -import com.zy.core.model.Task; +import com.zy.core.enums.ShuttleProtocolStatusType; +import com.zy.core.enums.ShuttleTaskNoType; +import com.zy.core.model.CommandResponse; import com.zy.core.model.command.ShuttleCommand; -import com.zy.core.model.command.SteCommand; +import com.zy.core.model.param.ShuttleMoveLocParam; import com.zy.core.model.protocol.ShuttleProtocol; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import java.text.MessageFormat; -import java.util.Date; +import java.util.List; -/** - * 鍥涘悜绌挎杞︾嚎绋� - */ -@Data -@Slf4j -public class ShuttleThread implements Runnable, ThreadHandler { +public interface ShuttleThread extends ThreadHandler { - private ModbusTcpNet modbusTcpNet; - private ShuttleSlave slave; - private ShuttleProtocol shuttleProtocol; - private SiemensS7Net siemensS7Net; + ShuttleProtocol getStatus(boolean clone);//鑾峰彇鍥涘悜绌挎杞︾姸鎬� - public ShuttleThread(ShuttleSlave slave) { - this.slave = slave; - } + ShuttleProtocol getStatus();//鑾峰彇鍥涘悜绌挎杞︾姸鎬�-榛樿clone - @Override - public void run() { - this.connect(); - while (true) { - try { - int step = 1; - Task task = MessageQueue.poll(SlaveType.Shuttle, slave.getId()); - if (task != null) { - step = task.getStep(); - } - switch (step) { - // 璇绘暟鎹� - case 1: - readStatus(); - break; - // 鍐欏叆鏁版嵁 - case 2: - write((ShuttleCommand) task.getData()); - break; - default: - break; - } - Thread.sleep(500); - } catch (Exception e) { - e.printStackTrace(); - } - } - } + CommandResponse movePath(List<NavigateNode> nodes, Integer taskNo);//璺緞涓嬪彂 - @Override - public boolean connect() { - boolean result = false; - //-------------------------鍥涘悜绌挎杞﹁繛鎺ユ柟娉�------------------------// - modbusTcpNet = new ModbusTcpNet(slave.getIp(), slave.getPort(), (byte) 0x01); - // 褰撲綘闇�瑕佹寚瀹氭牸寮忕殑鏁版嵁瑙f瀽鏃讹紝灏遍渶瑕佽缃笅闈㈢殑杩欎釜淇℃伅 - modbusTcpNet.setDataFormat(DataFormat.ABCD); - OperateResult connect = modbusTcpNet.ConnectServer(); - if(connect.IsSuccess){ - result = true; - OutputQueue.CRN.offer(MessageFormat.format( "銆恵0}銆戝洓鍚戠┛姊溅plc杩炴帴鎴愬姛 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); - log.info("鍥涘悜绌挎杞lc杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort()); - } else { - OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝洓鍚戠┛姊溅plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); - log.error("鍥涘悜绌挎杞lc杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}] ", slave.getId(), slave.getIp(), slave.getPort()); - } - modbusTcpNet.ConnectClose(); - //-------------------------鍥涘悜绌挎杞﹁繛鎺ユ柟娉�------------------------// - return result; - } + CommandResponse move(ShuttleCommand command);//绉诲姩 - @Override - public void close() { + CommandResponse lift(ShuttleCommand command);//椤跺崌 - } + CommandResponse charge(ShuttleCommand command);//鍏呯數寮�鍏� - private void readStatus() { - try { - OperateResultExOne<byte[]> result = modbusTcpNet.Read("0", (short) 17); - if (result.IsSuccess) { - if (null == shuttleProtocol) { - shuttleProtocol = new ShuttleProtocol(); - shuttleProtocol.setShuttleNo(slave.getId().shortValue()); - } + CommandResponse reset(ShuttleCommand command);//澶嶄綅寮�鍏� - //----------璁剧疆鍥涘悜绌挎杞︾姸鎬�----------- - //鑾峰彇鏁版嵁 - byte[] content = result.Content; + CommandResponse updateLocation(ShuttleCommand command);//鏇存柊鍧愭爣 - //--------鎺у埗瀛�-------- - //鎺у埗鎸囦护瀛� - 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)); + boolean isIdle(); + boolean isIdle(ExecuteSupport support);//鏄惁绌洪棽 - //---------鐘舵�佸瓧--------- -// shuttleProtocol.setBusyStatus(modbusTcpNet.getByteTransform().TransUInt16(content,32)); + boolean isDeviceIdle();//璁惧鏄惁绌洪棽 - ///璁剧疆鍥涘悜绌挎杞︾姸鎬�-end - OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId())); - //璇诲彇鍥涘悜绌挎杞﹁澶囦俊鎭紝鎻愪緵鏌ヨ - //..... + boolean isDeviceIdle(ExecuteSupport support);//璁惧鏄惁绌洪棽 + boolean isRequireCharge();//鏄惁婊¤冻鍏呯數鐘舵�� - // 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴� - //..... + boolean isCharging();//鏄惁鍏呯數涓� + boolean isChargingCompleted();//鏄惁鍏呯數瀹屾垚 - }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) { - OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆戝洓鍚戠┛姊溅plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); - initShuttle(); - } - } + boolean isFault();//鏄惁鏁呴殰 - private boolean write(ShuttleCommand command){ - if (null == command) { - News.error("鍥涘悜绌挎杞﹀啓鍏ュ懡浠や负绌�"); - return false; - } + List<NavigateNode> getMoveAdvancePath();//鑾峰彇绌挎杞︿换鍔¤矾寰� - //鍒ゆ柇灏忚溅鏄惁鍦ㄥ厖鐢� - SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1); - if (devpThread.charge1){ + int generateDeviceTaskNo(int taskNo, ShuttleTaskNoType type);//鐢熸垚纭欢璁惧宸ヤ綔鍙� - } + boolean setProtocolStatus(ShuttleProtocolStatusType status);//璁剧疆宸ヤ綔鐘舵�� - command.setShuttleNo(slave.getId()); - OperateResult result = null; - // 寮�濮嬩换鍔� - //... + boolean setTaskNo(Integer taskNo);//璁剧疆宸ヤ綔鍙� + boolean setSyncTaskNo(Integer taskNo);//璁剧疆宸ヤ綔鍙� - try { - // 鏃ュ織璁板綍 - if (!command.getComplete() && command.getTaskMode() != 0) { - //鏃ュ織璁板綍淇濆瓨鍒版暟鎹簱涓� - //..... - } - } catch (Exception ignore) {} + boolean setPakMk(boolean pakMk);//璁剧疆鏍囪 - 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()); -// } -// } + boolean enableMoveLoc(ShuttleMoveLocParam param, boolean enable); - 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; - } else { - OutputQueue.SHUTTLE.offer(MessageFormat.format("銆恵0}銆戝啓鍏ュ洓鍚戠┛姊溅plc鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort())); - News.error("鍐欏叆鍥涘悜绌挎杞lc鏁版嵁澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); - return false; - } - } + boolean requestWaiting(); - /** - * 鍒濆鍖栧洓鍚戠┛姊溅 - */ - private void initShuttle() { - if (null == shuttleProtocol) { - shuttleProtocol = new ShuttleProtocol(); - } - shuttleProtocol.setShuttleNo(slave.getId().shortValue()); - shuttleProtocol.setBusyStatus(ShuttleStatusType.BUSY); - shuttleProtocol.setCurrentCode("0"); - } + boolean enableDemo(boolean enable);//婕旂ず妯″紡 - /******************************************************************************************/ - /**************************************** 娴嬭瘯涓撶敤 *****************************************/ - /*****************************************************************************************/ - public static void main(String[] args) throws InterruptedException { - ShuttleSlave slave = new ShuttleSlave(); - 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)); + boolean offerSystemMsg(String format, Object... arguments); - // 浠诲姟浣滀笟 -// 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); + ShuttleCommand getMoveCommand(Integer taskNo, String startCodeNum, String distCodeNum, Integer allDistance, Integer runDirection, Integer runSpeed, List<NavigateNode> nodes);//鑾峰彇绉诲姩鍛戒护 - // 鎺у埗妯″紡 -// SteCommand command = new SteCommand(); -// command.setControlMode((short) 1); -// thread.write(command); + ShuttleCommand getLiftCommand(Integer taskNo, Boolean lift);//椤跺崌鍛戒护 true=>椤跺崌 false=>涓嬮檷 - // 澶嶄綅淇″彿 -// SteCommand command = new SteCommand(); -// command.setReset(Boolean.TRUE); -// thread.write(command); + ShuttleCommand getChargeCommand(Integer taskNo, Boolean charge);//鍏呯數寮�鍏冲懡浠� true=>寮� false=>鍏� - // 鍒犻櫎鎸囦护 -// SteCommand command = new SteCommand(); -// command.setDelete(Boolean.TRUE); -// thread.write(command); + ShuttleCommand getUpdateLocationCommand(Integer taskNo, String locNo);//鑾峰彇鏇存柊鍧愭爣鍛戒护 - // 绌挎杞﹁繍琛岀姝� -// SteCommand command = new SteCommand(); -// command.setRun((short)0); -// thread.write(command); - - } } -- Gitblit v1.9.1