From 8c7b4949dfcf875cc537304d34a7f6960cbb0c10 Mon Sep 17 00:00:00 2001
From: qlsxk <qlsxk@qq.com>
Date: 星期四, 16 十月 2025 14:57:12 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/impl/LfdZyForkLiftSlaveThread.java | 919 +++++++++++++++++++++++++++++---------------------------
1 files changed, 475 insertions(+), 444 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/impl/LfdZyForkLiftSlaveThread.java b/src/main/java/com/zy/core/thread/impl/LfdZyForkLiftSlaveThread.java
index dfd1074..ae2b966 100644
--- a/src/main/java/com/zy/core/thread/impl/LfdZyForkLiftSlaveThread.java
+++ b/src/main/java/com/zy/core/thread/impl/LfdZyForkLiftSlaveThread.java
@@ -1,444 +1,475 @@
-package com.zy.core.thread.impl;
-
-import HslCommunication.Core.Types.OperateResult;
-import HslCommunication.Core.Types.OperateResultExOne;
-import HslCommunication.Profinet.Siemens.SiemensPLCS;
-import HslCommunication.Profinet.Siemens.SiemensS7Net;
-import com.alibaba.fastjson.JSON;
-import com.baomidou.mybatisplus.mapper.EntityWrapper;
-import com.core.common.DateUtils;
-import com.core.common.SpringUtils;
-import com.zy.asrs.entity.BasLift;
-import com.zy.asrs.entity.DeviceDataLog;
-import com.zy.asrs.service.BasLiftService;
-import com.zy.asrs.service.DeviceDataLogService;
-import com.zy.asrs.utils.Utils;
-import com.zy.common.ExecuteSupport;
-import com.zy.common.utils.RedisUtil;
-import com.zy.core.News;
-import com.zy.core.action.ForkLiftAction;
-import com.zy.core.cache.OutputQueue;
-import com.zy.core.cache.SlaveConnection;
-import com.zy.core.enums.*;
-import com.zy.core.model.CommandResponse;
-import com.zy.core.model.ForkLiftSlave;
-import com.zy.core.model.command.ForkLiftCommand;
-import com.zy.core.model.protocol.ForkLiftProtocol;
-import com.zy.core.model.protocol.ForkLiftStaProtocol;
-import com.zy.core.thread.ForkLiftThread;
-import lombok.Data;
-import lombok.extern.slf4j.Slf4j;
-
-import java.text.MessageFormat;
-import java.util.*;
-
-@Slf4j
-@SuppressWarnings("all")
-public class LfdZyForkLiftSlaveThread implements ForkLiftThread {
-
- private Integer masterId;
- private ForkLiftSlave slave;
- private ForkLiftProtocol forkLiftProtocol;
- private RedisUtil redisUtil;
- private List<ForkLiftStaProtocol> forkLiftStaProtocols = new ArrayList<>();
- private LfdZyForkLiftMasterThread masterThread;
-
- public LfdZyForkLiftSlaveThread(ForkLiftSlave slave, RedisUtil redisUtil, Integer masterId) {
- this.slave = slave;
- this.redisUtil = redisUtil;
- this.masterId = masterId;
- //鍒濆鍖栫珯鐐�
- for (ForkLiftSlave.Sta sta : this.slave.getSta()) {
- ForkLiftStaProtocol forkLiftStaProtocol = new ForkLiftStaProtocol();
- forkLiftStaProtocol.setStaNo(sta.getStaNo());//绔欑偣鍙�
- forkLiftStaProtocol.setLev(sta.getLev());//绔欑偣妤煎眰
- String locNo = Utils.getLocNo(this.slave.getStaRow(), this.slave.getStaBay(), sta.getLev());
- forkLiftStaProtocol.setLocNo(locNo);//绔欑偣搴撲綅鍙�
- forkLiftStaProtocol.setLiftNo(sta.getLiftNo());//鎻愬崌鏈哄彿
- forkLiftStaProtocols.add(forkLiftStaProtocol);
- }
- }
-
- @Override
- public boolean connect() {
- boolean result = false;
- LfdZyForkLiftMasterThread masterThread = (LfdZyForkLiftMasterThread) SlaveConnection.get(SlaveType.ForkLiftMaster, masterId);
- if(masterThread != null) {
- result = true;
- this.masterThread = masterThread;
- }
- return result;
- }
-
- @Override
- public void close() {
-
- }
-
- @Override
- public void run() {
- News.info("{}鍙疯揣鍙夋彁鍗囨満绾跨▼鍚姩", slave.getId());
- this.connect();
- while (true) {
- try {
- if (this.masterThread == null) {
- this.connect();
- continue;
- }
-
- read();
- Thread.sleep(200);
- execute();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- private void execute() {
- ForkLiftAction forkLiftAction = SpringUtils.getBean(ForkLiftAction.class);
- if (forkLiftAction == null) {
- return;
- }
-
- Object object = redisUtil.get(RedisKeyType.FORK_LIFT_FLAG.key + slave.getId());
- if (object == null) {
- return;
- }
-
- Integer taskNo = Integer.valueOf(String.valueOf(object));
- if (taskNo != 0) {
- //瀛樺湪浠诲姟闇�瑕佹墽琛�
- boolean result = forkLiftAction.executeWork(slave.getId(), taskNo);
- }
- }
-
- private void read() {
- try {
- readStatus();
-
- //鎻愬崌鏈哄浜庤繍琛岀姸鎬侊紝灏嗘爣璁扮疆涓簍rue
- if (forkLiftProtocol.getProtocolStatusType().equals(ForkLiftProtocolStatusType.PICK_UP)
- || forkLiftProtocol.getProtocolStatusType().equals(ForkLiftProtocolStatusType.PUT_DOWN)
- || forkLiftProtocol.getProtocolStatusType().equals(ForkLiftProtocolStatusType.WAITING)) {
- forkLiftProtocol.setPakMk(true);
- }
- } catch (Exception e) {
- OutputQueue.FORKLIFT.offer(MessageFormat.format("銆恵0}銆戣鍙栨彁鍗囨満鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
- }
- }
-
- private void readStatus() {
- try {
- //鑾峰彇鎻愬崌鏈烘暟鎹�
- HashMap<String, Object> resultData = this.masterThread.read(this.slave.getId(), "status");
- if (resultData == null) {
- OutputQueue.FORKLIFT.offer(MessageFormat.format("銆恵0}銆憑1}璇诲彇璐у弶鎻愬崌鏈虹姸鎬佷俊鎭け璐�", DateUtils.convert(new Date()), slave.getId()));
- return;
- }
- if (Integer.parseInt(resultData.get("slaveId").toString()) != this.slave.getId()) {
- return;
- }
- if (!resultData.get("dbTag").toString().equals("status")) {
- return;
- }
-
- OperateResultExOne<byte[]> result1 = (OperateResultExOne<byte[]>) resultData.get("data");
- SiemensS7Net siemensS7Net = this.masterThread.getSiemensS7Net();
- if (result1.IsSuccess) {
- if (null == forkLiftProtocol) {
- forkLiftProtocol = new ForkLiftProtocol();
- forkLiftProtocol.setLiftNo(slave.getId());
- forkLiftProtocol.setProtocolStatus(ForkLiftProtocolStatusType.NONE);
-
- InnerForkLiftExtend innerForkLiftExtend = new InnerForkLiftExtend();
- }
-
- //----------璇诲彇鎻愬崌鏈虹姸鎬�-----------
- //妯″紡
- forkLiftProtocol.setModel((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 0));
- //PLC浠诲姟鍙�
- forkLiftProtocol.setWrkNo((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 2));
- //浠诲姟鐘舵��
- forkLiftProtocol.setProtocolStatus((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 4));
- //浠诲姟妯″紡
- forkLiftProtocol.setTaskMode((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 6));
- //鍙栬揣鏁版嵁
- forkLiftProtocol.setPick((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 8));
- //鏀捐揣鏁版嵁
- forkLiftProtocol.setPut((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 10));
- //鍑哄叆搴撴ā寮�
- forkLiftProtocol.setIOMode((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 12));
- //鏁呴殰鐮�
- forkLiftProtocol.setErrorCode((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 14));
-
- //************琛ュ厖鎵╁睍瀛楁*************
- InnerForkLiftExtend forkLiftExtend = (InnerForkLiftExtend) forkLiftProtocol.getExtend();
- forkLiftProtocol.setExtend(forkLiftExtend);
-
- }else {
- OutputQueue.FORKLIFT.offer(MessageFormat.format("銆恵0}銆憑1}璇诲彇璐у弶鎻愬崌鏈虹姸鎬佷俊鎭け璐�", DateUtils.convert(new Date()), slave.getId()));
- }
-
- //鑾峰彇鎻愬崌鏈烘暟鎹�
- HashMap<String, Object> resultData2 = this.masterThread.read(this.slave.getId(), "staStatus");
- if (resultData2 == null) {
- OutputQueue.FORKLIFT.offer(MessageFormat.format("銆恵0}銆憑1}璇诲彇璐у弶鎻愬崌鏈虹姸鎬佷俊鎭け璐�", DateUtils.convert(new Date()), slave.getId()));
- }
- if (Integer.parseInt(resultData2.get("slaveId").toString()) != this.slave.getId()) {
- return;
- }
- if (!resultData2.get("dbTag").toString().equals("staStatus")) {
- return;
- }
- OperateResultExOne<byte[]> result2 = (OperateResultExOne<byte[]>) resultData2.get("data");
- if (result2.IsSuccess) {
- for (int i = 0; i < this.slave.getSta().size(); i++) {
- ForkLiftSlave.Sta sta = this.slave.getSta().get(i);
- if (forkLiftStaProtocols.isEmpty()) {
- continue;
- }
-
- ForkLiftStaProtocol forkLiftStaProtocol = forkLiftStaProtocols.get(i);
- boolean[] status1 = siemensS7Net.getByteTransform().TransBool(result2.Content, i * 2, 2);
- forkLiftStaProtocol.setHasTray(status1[0]);
- forkLiftStaProtocol.setHasCar(status1[1]);
- }
- }
-
- if (System.currentTimeMillis() - forkLiftProtocol.getDeviceDataLog() > 1000 * 5) {
- //閲囬泦鏃堕棿瓒呰繃5s锛屼繚瀛樹竴娆℃暟鎹褰�
- //淇濆瓨鏁版嵁璁板綍
- DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class);
- DeviceDataLog deviceDataLog = new DeviceDataLog();
- deviceDataLog.setOriginData(Base64.getEncoder().encodeToString(result1.Content));
- deviceDataLog.setWcsData(JSON.toJSONString(forkLiftProtocol));
- deviceDataLog.setType("forkLift");
- deviceDataLog.setDeviceNo(forkLiftProtocol.getLiftNo());
- deviceDataLog.setCreateTime(new Date());
- deviceDataLogService.insert(deviceDataLog);
-
- //淇濆瓨鏁版嵁璁板綍
- DeviceDataLog deviceDataLog2 = new DeviceDataLog();
- deviceDataLog2.setOriginData(Base64.getEncoder().encodeToString(result2.Content));
- deviceDataLog2.setWcsData(JSON.toJSONString(forkLiftStaProtocols));
- deviceDataLog2.setType("forkLiftStaProtocols");
- deviceDataLog2.setDeviceNo(forkLiftProtocol.getLiftNo());
- deviceDataLog2.setCreateTime(new Date());
- deviceDataLogService.insert(deviceDataLog2);
-
- //鏇存柊閲囬泦鏃堕棿
- forkLiftProtocol.setDeviceDataLog(System.currentTimeMillis());
- }
-
- //灏嗘彁鍗囨満鐘舵�佷繚瀛樿嚦鏁版嵁搴�
- BasLiftService basLiftService = SpringUtils.getBean(BasLiftService.class);
- BasLift basLift = basLiftService.selectOne(new EntityWrapper<BasLift>()
- .eq("lift_no", slave.getId()));
- if (basLift == null) {
- basLift = new BasLift();
- //鎻愬崌鏈哄彿
- basLift.setLiftNo(forkLiftProtocol.getLiftNo());
- basLift.setStatus(1);
- basLiftService.insert(basLift);
- }
- //浠诲姟鍙�
- basLift.setWrkNo(forkLiftProtocol.getTaskNo());
- //淇敼鏃堕棿
- basLift.setUpdateTime(new Date());
- //璁惧鐘舵��
- basLift.setDeviceStatus(JSON.toJSONString(forkLiftProtocol));
- if (basLiftService.updateById(basLift)) {
- OutputQueue.FORKLIFT.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), forkLiftProtocol.getLiftNo()));
- }
-
- } catch (Exception e) {
- OutputQueue.FORKLIFT.offer(MessageFormat.format("銆恵0}銆戣鍙栬揣鍙夋彁鍗囨満鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
- }
- }
-
- @Override
- public ForkLiftProtocol getStatus(boolean clone) {
- if (this.forkLiftProtocol == null) {
- return null;
- }
- return clone ? this.forkLiftProtocol.clone() : this.forkLiftProtocol;
- }
-
- @Override
- public List<ForkLiftStaProtocol> getForkLiftStaProtocols() {
- return this.forkLiftStaProtocols;
- }
-
- @Override
- public ForkLiftProtocol getStatus() {
- return getStatus(true);
- }
-
- @Override
- public CommandResponse pickAndPut(ForkLiftCommand command) {
- CommandResponse response = new CommandResponse(false);
-
- short[] array = new short[4];
- array[0] = command.getTaskNo();//浠诲姟鍙�
- array[1] = command.getMode();//浠诲姟妯″紡
- array[2] = command.getPick();//鍙栬揣鏁版嵁
- array[3] = command.getPut();//鏀捐揣鏁版嵁
- OperateResult result = this.masterThread.write(this.slave.getId(), "write", array);
- if (result.IsSuccess) {
- OperateResult result2 = this.masterThread.write(this.slave.getId(), "writeConfirm", command.getConfirm());
- if (result2.IsSuccess) {
- response.setResult(true);
- }
- }
- return response;
- }
-
- @Override
- public CommandResponse shuttleSwitch(ForkLiftCommand command) {
- CommandResponse response = new CommandResponse(false);
-
- short[] array = new short[4];
- array[0] = command.getTaskNo();//浠诲姟鍙�
- array[1] = command.getMode();//浠诲姟妯″紡
- array[2] = command.getPick();//鍙栬揣鏁版嵁
- array[3] = command.getPut();//鏀捐揣鏁版嵁
- OperateResult result = this.masterThread.write(this.slave.getId(), "write", array);
- if (result.IsSuccess) {
- OperateResult result2 = this.masterThread.write(this.slave.getId(), "writeConfirm", command.getConfirm());
- if (result2.IsSuccess) {
- response.setResult(true);
- }
- }
- return response;
- }
-
- @Override
- public CommandResponse reset() {
- CommandResponse response = new CommandResponse(false);
- OperateResult result = this.masterThread.write(this.slave.getId(), "confirm", (short) 1);
- if (result.IsSuccess) {
- News.info("璐у弶鎻愬崌鏈虹‘璁ゅ懡浠や笅鍙戞垚鍔燂紝鎻愬崌鏈哄彿={}", forkLiftProtocol.getLiftNo());
- response.setResult(true);
- }
- return response;
- }
-
- @Override
- public boolean isIdle() {
- if (this.forkLiftProtocol.getTaskNo() == null
- || this.forkLiftProtocol.getProtocolStatus() == null
- || this.forkLiftProtocol.getModel() == null
- || this.forkLiftProtocol.getErrorCode() == null
- ) {
- return false;
- }
-
- boolean res = this.forkLiftProtocol.getProtocolStatus() == ForkLiftProtocolStatusType.IDLE.id
- && this.forkLiftProtocol.getWrkNo() == 0
- && this.forkLiftProtocol.getTaskNo() == 0
- && this.forkLiftProtocol.getModel() == 2
- && this.forkLiftProtocol.getErrorCode() == 0
- ;
- return res;
- }
-
- @Override
- public boolean isDeviceIdle() {
- return isDeviceIdle(null);
- }
-
- @Override
- public boolean isDeviceIdle(ExecuteSupport support) {
- if (null != support) {
- Boolean judgement = support.judgement();
- if (judgement != null && !judgement) {
- return true;
- }
- }
-
- if (this.forkLiftProtocol.getTaskNo() == null
- || this.forkLiftProtocol.getProtocolStatus() == null
- || this.forkLiftProtocol.getModel() == null
- || this.forkLiftProtocol.getErrorCode() == null
- ) {
- return false;
- }
-
- boolean res = this.forkLiftProtocol.getProtocolStatus() == ForkLiftProtocolStatusType.IDLE.id
- && this.forkLiftProtocol.getWrkNo() == 0
- && this.forkLiftProtocol.getModel() == 2
- && this.forkLiftProtocol.getErrorCode() == 0
- ;
- return res;
- }
-
- @Override
- public boolean setProtocolStatus(ForkLiftProtocolStatusType status) {
- return false;
- }
-
- @Override
- public boolean setSyncTaskNo(Integer taskNo) {
- this.forkLiftProtocol.setSyncTaskNo(taskNo);
- return true;
- }
-
- @Override
- public boolean switchIOMode(ForkLiftIoModeType type) {
- OperateResult result = this.masterThread.write(this.slave.getId(), "switchIOMode", type.id.shortValue());
- if (result.IsSuccess) {
- return true;
- }
- return false;
- }
-
- @Override
- public int generateDeviceTaskNo(int taskNo, ForkLiftTaskModeType type) {
- return taskNo;
- }
-
- @Override
- public List<ForkLiftCommand> getPickAndPutCommand(Integer taskNo, Integer pick, Integer put) {
- Integer realPick = pick % 1000;
- Integer realPut = put % 1000;
-
- List<ForkLiftCommand> commands = new ArrayList<>();
- ForkLiftCommand command = new ForkLiftCommand();
- command.setLiftNo(slave.getId());
- command.setTaskNo(taskNo.shortValue());
- command.setMode(ForkLiftTaskModeType.PICK_PUT.id.shortValue());
- command.setPick(realPick.shortValue());
- command.setPut(realPut.shortValue());
- command.setConfirm((short) 1);
-
- commands.add(command);
- return commands;
- }
-
- @Override
- public List<ForkLiftCommand> getShuttleSwitchCommand(Integer taskNo, Integer pick, Integer put) {
- Integer realPick = pick % 1000;
- Integer realPut = put % 1000;
-
- List<ForkLiftCommand> commands = new ArrayList<>();
- ForkLiftCommand command = new ForkLiftCommand();
- command.setLiftNo(slave.getId());
- command.setTaskNo(taskNo.shortValue());
- command.setMode(ForkLiftTaskModeType.SHUTTLE_SWITCH.id.shortValue());
- command.setPick(realPick.shortValue());
- command.setPut(realPut.shortValue());
- command.setConfirm((short) 1);
-
- commands.add(command);
- return commands;
- }
-
- /**
- * 鎵╁睍瀛楁
- */
- @Data
- private class InnerForkLiftExtend {
-
- }
-}
+//package com.zy.core.thread.impl;
+//
+//import HslCommunication.Core.Types.OperateResult;
+//import HslCommunication.Core.Types.OperateResultExOne;
+//import HslCommunication.Profinet.Siemens.SiemensPLCS;
+//import HslCommunication.Profinet.Siemens.SiemensS7Net;
+//import com.alibaba.fastjson.JSON;
+//import com.baomidou.mybatisplus.mapper.EntityWrapper;
+//import com.core.common.DateUtils;
+//import com.core.common.SpringUtils;
+//import com.zy.asrs.entity.BasLift;
+//import com.zy.asrs.entity.DeviceDataLog;
+//import com.zy.asrs.service.BasLiftService;
+//import com.zy.asrs.service.DeviceDataLogService;
+//import com.zy.asrs.utils.Utils;
+//import com.zy.common.ExecuteSupport;
+//import com.zy.common.utils.RedisUtil;
+//import com.zy.core.News;
+//import com.zy.core.action.ForkLiftAction;
+//import com.zy.core.cache.OutputQueue;
+//import com.zy.core.cache.SlaveConnection;
+//import com.zy.core.enums.*;
+//import com.zy.core.model.CommandResponse;
+//import com.zy.core.model.ForkLiftSlave;
+//import com.zy.core.model.command.ForkLiftCommand;
+//import com.zy.core.model.protocol.ForkLiftProtocol;
+//import com.zy.core.model.protocol.ForkLiftStaProtocol;
+//import com.zy.core.thread.ForkLiftThread;
+//import lombok.Data;
+//import lombok.extern.slf4j.Slf4j;
+//
+//import java.text.MessageFormat;
+//import java.util.*;
+//
+//@Slf4j
+//@SuppressWarnings("all")
+//public class LfdZyForkLiftSlaveThread implements ForkLiftThread {
+//
+// private Integer masterId;
+// private ForkLiftSlave slave;
+// private ForkLiftProtocol forkLiftProtocol;
+// private RedisUtil redisUtil;
+// private List<ForkLiftStaProtocol> forkLiftStaProtocols = new ArrayList<>();
+// private LfdZyForkLiftMasterThread masterThread;
+//
+// public LfdZyForkLiftSlaveThread(ForkLiftSlave slave, RedisUtil redisUtil, Integer masterId) {
+// this.slave = slave;
+// this.redisUtil = redisUtil;
+// this.masterId = masterId;
+// //鍒濆鍖栫珯鐐�
+// for (ForkLiftSlave.Sta sta : this.slave.getSta()) {
+// ForkLiftStaProtocol forkLiftStaProtocol = new ForkLiftStaProtocol();
+// forkLiftStaProtocol.setStaNo(sta.getStaNo());//绔欑偣鍙�
+// forkLiftStaProtocol.setLev(sta.getLev());//绔欑偣妤煎眰
+// String locNo = Utils.getLocNo(this.slave.getStaRow(), this.slave.getStaBay(), sta.getLev());
+// forkLiftStaProtocol.setLocNo(locNo);//绔欑偣搴撲綅鍙�
+// forkLiftStaProtocol.setLiftNo(sta.getLiftNo());//鎻愬崌鏈哄彿
+// forkLiftStaProtocols.add(forkLiftStaProtocol);
+// }
+// }
+//
+// @Override
+// public boolean connect() {
+// boolean result = false;
+// LfdZyForkLiftMasterThread masterThread = (LfdZyForkLiftMasterThread) SlaveConnection.get(SlaveType.ForkLiftMaster, masterId);
+// if(masterThread != null) {
+// result = true;
+// this.masterThread = masterThread;
+// }
+// return result;
+// }
+//
+// @Override
+// public void close() {
+//
+// }
+//
+// @Override
+// public void run() {
+// News.info("{}鍙疯揣鍙夋彁鍗囨満绾跨▼鍚姩", slave.getId());
+// this.connect();
+// while (true) {
+// try {
+// if (this.masterThread == null) {
+// this.connect();
+// continue;
+// }
+//
+// read();
+// Thread.sleep(300);
+// execute();
+// } catch (Exception e) {
+// e.printStackTrace();
+// }
+// }
+// }
+//
+// private void execute() {
+// ForkLiftAction forkLiftAction = null;
+// try {
+// forkLiftAction = SpringUtils.getBean(ForkLiftAction.class);
+// }catch (Exception e){}
+// if (forkLiftAction == null) {
+// return;
+// }
+//
+// Object object = redisUtil.get(RedisKeyType.FORK_LIFT_FLAG.key + slave.getId());
+// if (object == null) {
+// return;
+// }
+//
+// Integer taskNo = Integer.valueOf(String.valueOf(object));
+// if (taskNo != 0) {
+// //瀛樺湪浠诲姟闇�瑕佹墽琛�
+// boolean result = forkLiftAction.executeWork(slave.getId(), taskNo);
+// }
+// }
+//
+// private void read() {
+// try {
+// readStatus();
+//
+// //鎻愬崌鏈哄浜庤繍琛岀姸鎬侊紝灏嗘爣璁扮疆涓簍rue
+// if (forkLiftProtocol.getProtocolStatusType().equals(ForkLiftProtocolStatusType.PICK_UP)
+// || forkLiftProtocol.getProtocolStatusType().equals(ForkLiftProtocolStatusType.PUT_DOWN)
+// || forkLiftProtocol.getProtocolStatusType().equals(ForkLiftProtocolStatusType.WAITING)) {
+// forkLiftProtocol.setPakMk(true);
+// }
+// } catch (Exception e) {
+// OutputQueue.FORKLIFT.offer(MessageFormat.format("銆恵0}銆戣鍙栨彁鍗囨満鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
+// }
+// }
+//
+// private void readStatus() {
+// try {
+// //鑾峰彇鎻愬崌鏈烘暟鎹�
+// OperateResultExOne<byte[]> result1 = this.masterThread.read(this.slave.getId(), "status");
+// SiemensS7Net siemensS7Net = this.masterThread.getSiemensS7Net();
+// if (result1.IsSuccess) {
+// if (null == forkLiftProtocol) {
+// forkLiftProtocol = new ForkLiftProtocol();
+// forkLiftProtocol.setLiftNo(slave.getId());
+// forkLiftProtocol.setProtocolStatus(ForkLiftProtocolStatusType.NONE);
+//
+// InnerForkLiftExtend innerForkLiftExtend = new InnerForkLiftExtend();
+// }
+//
+// //----------璇诲彇鎻愬崌鏈虹姸鎬�-----------
+// //妯″紡
+// forkLiftProtocol.setModel((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 0));
+// //PLC浠诲姟鍙�
+// forkLiftProtocol.setWrkNo((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 2));
+// //浠诲姟鐘舵��
+// forkLiftProtocol.setProtocolStatus((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 4));
+// //浠诲姟妯″紡
+// forkLiftProtocol.setTaskMode((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 6));
+// //鍙栬揣鏁版嵁
+// forkLiftProtocol.setPick((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 8));
+// //鏀捐揣鏁版嵁
+// forkLiftProtocol.setPut((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 10));
+// //鍑哄叆搴撴ā寮�
+// forkLiftProtocol.setIOMode((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 12));
+// //鏁呴殰鐮�
+// forkLiftProtocol.setErrorCode((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 14));
+// //褰撳墠灞�
+// forkLiftProtocol.setLev((int) siemensS7Net.getByteTransform().TransInt16(result1.Content, 16));
+//
+// //************琛ュ厖鎵╁睍瀛楁*************
+// InnerForkLiftExtend forkLiftExtend = (InnerForkLiftExtend) forkLiftProtocol.getExtend();
+// forkLiftProtocol.setExtend(forkLiftExtend);
+//
+// }else {
+// OutputQueue.FORKLIFT.offer(MessageFormat.format("銆恵0}銆憑1}璇诲彇璐у弶鎻愬崌鏈虹姸鎬佷俊鎭け璐�", DateUtils.convert(new Date()), slave.getId()));
+// }
+//
+// OperateResultExOne<byte[]> result2 = this.masterThread.read(this.slave.getId(), "staStatusTray");
+// if (result2.IsSuccess) {
+// for (int i = 0; i < this.slave.getSta().size(); i++) {
+// ForkLiftSlave.Sta sta = this.slave.getSta().get(i);
+// if (forkLiftStaProtocols.isEmpty()) {
+// continue;
+// }
+//
+// short val = siemensS7Net.getByteTransform().TransInt16(result2.Content, i * 2);
+// ForkLiftStaProtocol forkLiftStaProtocol = forkLiftStaProtocols.get(i);
+// forkLiftStaProtocol.setHasTray(val == 1);
+// }
+// }
+//
+// OperateResultExOne<byte[]> result3 = this.masterThread.read(this.slave.getId(), "staStatusCar");
+// if (result3.IsSuccess) {
+// for (int i = 0; i < this.slave.getSta().size(); i++) {
+// ForkLiftSlave.Sta sta = this.slave.getSta().get(i);
+// if (forkLiftStaProtocols.isEmpty()) {
+// continue;
+// }
+//
+// short val = siemensS7Net.getByteTransform().TransInt16(result3.Content, i * 2);
+// ForkLiftStaProtocol forkLiftStaProtocol = forkLiftStaProtocols.get(i);
+// forkLiftStaProtocol.setHasCar(val == 1);
+// }
+// }
+//
+// if (System.currentTimeMillis() - forkLiftProtocol.getDeviceDataLog() > 1000 * 5) {
+// //閲囬泦鏃堕棿瓒呰繃5s锛屼繚瀛樹竴娆℃暟鎹褰�
+// //淇濆瓨鏁版嵁璁板綍
+// DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class);
+// DeviceDataLog deviceDataLog = new DeviceDataLog();
+// deviceDataLog.setOriginData(Base64.getEncoder().encodeToString(result1.Content));
+// deviceDataLog.setWcsData(JSON.toJSONString(forkLiftProtocol));
+// deviceDataLog.setType("forkLift");
+// deviceDataLog.setDeviceNo(forkLiftProtocol.getLiftNo());
+// deviceDataLog.setCreateTime(new Date());
+// deviceDataLogService.insert(deviceDataLog);
+//
+// //淇濆瓨鏁版嵁璁板綍
+// DeviceDataLog deviceDataLog2 = new DeviceDataLog();
+// deviceDataLog2.setOriginData(Base64.getEncoder().encodeToString(result2.Content));
+// deviceDataLog2.setWcsData(JSON.toJSONString(forkLiftStaProtocols));
+// deviceDataLog2.setType("forkLiftStaProtocols");
+// deviceDataLog2.setDeviceNo(forkLiftProtocol.getLiftNo());
+// deviceDataLog2.setCreateTime(new Date());
+// deviceDataLogService.insert(deviceDataLog2);
+//
+// //鏇存柊閲囬泦鏃堕棿
+// forkLiftProtocol.setDeviceDataLog(System.currentTimeMillis());
+// }
+//
+// //灏嗘彁鍗囨満鐘舵�佷繚瀛樿嚦鏁版嵁搴�
+// BasLiftService basLiftService = SpringUtils.getBean(BasLiftService.class);
+// BasLift basLift = basLiftService.selectOne(new EntityWrapper<BasLift>()
+// .eq("lift_no", slave.getId()));
+// if (basLift == null) {
+// basLift = new BasLift();
+// //鎻愬崌鏈哄彿
+// basLift.setLiftNo(forkLiftProtocol.getLiftNo());
+// basLift.setStatus(1);
+// basLiftService.insert(basLift);
+// }
+// //浠诲姟鍙�
+// basLift.setWrkNo(forkLiftProtocol.getTaskNo());
+// //淇敼鏃堕棿
+// basLift.setUpdateTime(new Date());
+// //璁惧鐘舵��
+// basLift.setDeviceStatus(JSON.toJSONString(forkLiftProtocol));
+// if (basLiftService.updateById(basLift)) {
+// OutputQueue.FORKLIFT.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), forkLiftProtocol.getLiftNo()));
+// }
+//
+// } catch (Exception e) {
+// OutputQueue.FORKLIFT.offer(MessageFormat.format("銆恵0}銆戣鍙栬揣鍙夋彁鍗囨満鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort()));
+// }
+// }
+//
+// @Override
+// public ForkLiftProtocol getStatus(boolean clone) {
+// if (this.forkLiftProtocol == null) {
+// return null;
+// }
+// return clone ? this.forkLiftProtocol.clone() : this.forkLiftProtocol;
+// }
+//
+// @Override
+// public List<ForkLiftStaProtocol> getForkLiftStaProtocols() {
+// return this.forkLiftStaProtocols;
+// }
+//
+// @Override
+// public ForkLiftProtocol getStatus() {
+// return getStatus(true);
+// }
+//
+// @Override
+// public CommandResponse pickAndPut(ForkLiftCommand command) {
+// CommandResponse response = new CommandResponse(false);
+//
+// short[] array = new short[4];
+// array[0] = command.getTaskNo();//浠诲姟鍙�
+// array[1] = command.getMode();//浠诲姟妯″紡
+// array[2] = command.getPick();//鍙栬揣鏁版嵁
+// array[3] = command.getPut();//鏀捐揣鏁版嵁
+// OperateResult result = this.masterThread.write(this.slave.getId(), "write", array);
+// if (result.IsSuccess) {
+// OperateResult result2 = this.masterThread.write(this.slave.getId(), "writeConfirm", command.getConfirm());
+// if (result2.IsSuccess) {
+// response.setResult(true);
+// }
+// }
+// return response;
+// }
+//
+// @Override
+// public CommandResponse shuttleSwitch(ForkLiftCommand command) {
+// CommandResponse response = new CommandResponse(false);
+//
+// short[] array = new short[4];
+// array[0] = command.getTaskNo();//浠诲姟鍙�
+// array[1] = command.getMode();//浠诲姟妯″紡
+// array[2] = command.getPick();//鍙栬揣鏁版嵁
+// array[3] = command.getPut();//鏀捐揣鏁版嵁
+// OperateResult result = this.masterThread.write(this.slave.getId(), "write", array);
+// if (result.IsSuccess) {
+// OperateResult result2 = this.masterThread.write(this.slave.getId(), "writeConfirm", command.getConfirm());
+// if (result2.IsSuccess) {
+// response.setResult(true);
+// }
+// }
+// return response;
+// }
+//
+// @Override
+// public CommandResponse move(ForkLiftCommand command) {
+// CommandResponse response = new CommandResponse(false);
+//
+// short[] array = new short[4];
+// array[0] = command.getTaskNo();//浠诲姟鍙�
+// array[1] = command.getMode();//浠诲姟妯″紡
+// array[2] = command.getPut();//鏀捐揣鏁版嵁
+// OperateResult result = this.masterThread.write(this.slave.getId(), "write", array);
+// if (result.IsSuccess) {
+// OperateResult result2 = this.masterThread.write(this.slave.getId(), "writeConfirm", command.getConfirm());
+// if (result2.IsSuccess) {
+// response.setResult(true);
+// }
+// }
+// return response;
+// }
+//
+// @Override
+// public CommandResponse reset() {
+// CommandResponse response = new CommandResponse(false);
+// OperateResult result = this.masterThread.write(this.slave.getId(), "confirm", (short) 1);
+// if (result.IsSuccess) {
+// News.info("璐у弶鎻愬崌鏈虹‘璁ゅ懡浠や笅鍙戞垚鍔燂紝鎻愬崌鏈哄彿={}", forkLiftProtocol.getLiftNo());
+// response.setResult(true);
+// }
+// return response;
+// }
+//
+// @Override
+// public boolean isIdle() {
+// if (this.forkLiftProtocol.getTaskNo() == null
+// || this.forkLiftProtocol.getProtocolStatus() == null
+// || this.forkLiftProtocol.getModel() == null
+// || this.forkLiftProtocol.getErrorCode() == null
+// ) {
+// return false;
+// }
+//
+// boolean res = this.forkLiftProtocol.getProtocolStatus() == ForkLiftProtocolStatusType.IDLE.id
+// && this.forkLiftProtocol.getWrkNo() == 0
+// && this.forkLiftProtocol.getTaskNo() == 0
+// && this.forkLiftProtocol.getModel() == 2
+// && this.forkLiftProtocol.getErrorCode() == 0
+// ;
+// return res;
+// }
+//
+// @Override
+// public boolean isDeviceIdle() {
+// return isDeviceIdle(null);
+// }
+//
+// @Override
+// public boolean isDeviceIdle(ExecuteSupport support) {
+// if (null != support) {
+// Boolean judgement = support.judgement();
+// if (judgement != null && !judgement) {
+// return true;
+// }
+// }
+//
+// if (this.forkLiftProtocol.getTaskNo() == null
+// || this.forkLiftProtocol.getProtocolStatus() == null
+// || this.forkLiftProtocol.getModel() == null
+// || this.forkLiftProtocol.getErrorCode() == null
+// ) {
+// return false;
+// }
+//
+// boolean res = this.forkLiftProtocol.getProtocolStatus() == ForkLiftProtocolStatusType.IDLE.id
+// && this.forkLiftProtocol.getWrkNo() == 0
+// && this.forkLiftProtocol.getModel() == 2
+// && this.forkLiftProtocol.getErrorCode() == 0
+// ;
+// return res;
+// }
+//
+// @Override
+// public boolean setProtocolStatus(ForkLiftProtocolStatusType status) {
+// return false;
+// }
+//
+// @Override
+// public boolean setSyncTaskNo(Integer taskNo) {
+// this.forkLiftProtocol.setSyncTaskNo(taskNo);
+// return true;
+// }
+//
+// @Override
+// public boolean switchIOMode(ForkLiftIoModeType type) {
+// OperateResult result = this.masterThread.write(this.slave.getId(), "switchIOMode", type.id.shortValue());
+// if (result.IsSuccess) {
+// return true;
+// }
+// return false;
+// }
+//
+// @Override
+// public int generateDeviceTaskNo(int taskNo, ForkLiftTaskModeType type) {
+// return taskNo;
+// }
+//
+// @Override
+// public List<ForkLiftCommand> getPickAndPutCommand(Integer taskNo, Integer pick, Integer put) {
+// Integer realPick = pick % 1000;
+// Integer realPut = put % 1000;
+//
+// List<ForkLiftCommand> commands = new ArrayList<>();
+// ForkLiftCommand command = new ForkLiftCommand();
+// command.setLiftNo(slave.getId());
+// command.setTaskNo(taskNo.shortValue());
+// command.setMode(ForkLiftTaskModeType.PICK_PUT.id.shortValue());
+// command.setPick(realPick.shortValue());
+// command.setPut(realPut.shortValue());
+// command.setConfirm((short) 1);
+//
+// commands.add(command);
+// return commands;
+// }
+//
+// @Override
+// public List<ForkLiftCommand> getShuttleSwitchCommand(Integer taskNo, Integer pick, Integer put) {
+// Integer realPick = pick % 1000;
+// Integer realPut = put % 1000;
+//
+// List<ForkLiftCommand> commands = new ArrayList<>();
+// ForkLiftCommand command = new ForkLiftCommand();
+// command.setLiftNo(slave.getId());
+// command.setTaskNo(taskNo.shortValue());
+// command.setMode(ForkLiftTaskModeType.SHUTTLE_SWITCH.id.shortValue());
+// command.setPick(realPick.shortValue());
+// command.setPut(realPut.shortValue());
+// command.setConfirm((short) 1);
+//
+// commands.add(command);
+// return commands;
+// }
+//
+// @Override
+// public List<ForkLiftCommand> getMoveCommand(Integer taskNo, Integer pick, Integer put) {
+// Integer realPick = pick % 1000;
+// Integer realPut = put % 1000;
+//
+// List<ForkLiftCommand> commands = new ArrayList<>();
+// ForkLiftCommand command = new ForkLiftCommand();
+// command.setLiftNo(slave.getId());
+// command.setTaskNo(taskNo.shortValue());
+// command.setMode(ForkLiftTaskModeType.MOVE.id.shortValue());
+// command.setPick(realPick.shortValue());
+// command.setPut(realPut.shortValue());
+// command.setConfirm((short) 1);
+//
+// commands.add(command);
+// return commands;
+// }
+//
+// /**
+// * 鎵╁睍瀛楁
+// */
+// @Data
+// private class InnerForkLiftExtend {
+//
+// }
+//}
--
Gitblit v1.9.1