From d3417407db947cf6f10c163d75325fd7df408eab Mon Sep 17 00:00:00 2001
From: zy <zy@123>
Date: 星期日, 03 八月 2025 15:19:12 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/LiftThread.java | 10
src/main/java/com/zy/core/controller/OpenController.java | 17 +
src/main/java/com/zy/core/utils/DeviceMsgUtils.java | 4
src/main/java/com/zy/core/thread/fake/FakeNyLiftThread.java | 402 ++++++++++++++++++++++++++++++
src/main/java/com/zy/core/thread/fake/FakeZyForkLiftThread.java | 2
src/main/java/com/zy/core/enums/RedisKeyType.java | 3
src/main/java/com/zy/core/thread/impl/NyLiftThread.java | 308 +++++++++++++++++++++++
src/main/java/com/zy/core/ServerBootstrap.java | 20 +
8 files changed, 763 insertions(+), 3 deletions(-)
diff --git a/src/main/java/com/zy/core/ServerBootstrap.java b/src/main/java/com/zy/core/ServerBootstrap.java
index 1b617d9..08bdeb2 100644
--- a/src/main/java/com/zy/core/ServerBootstrap.java
+++ b/src/main/java/com/zy/core/ServerBootstrap.java
@@ -6,9 +6,11 @@
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
import com.zy.core.properties.DeviceConfig;
+import com.zy.core.thread.fake.FakeNyLiftThread;
import com.zy.core.thread.fake.FakeNyShuttleThread;
import com.zy.core.thread.fake.FakeZyForkLiftThread;
import com.zy.core.thread.impl.LfdZyForkLiftMasterThread;
+import com.zy.core.thread.impl.NyLiftThread;
import com.zy.core.thread.impl.NyShuttleThread;
import com.zy.core.utils.DeviceMsgUtils;
import lombok.extern.slf4j.Slf4j;
@@ -71,6 +73,8 @@
for (DeviceConfig device : deviceConfigs) {
if (device.getDeviceType().equals(String.valueOf(SlaveType.ForkLift))) {
initForkLiftThread(device);
+ } else if (device.getDeviceType().equals(String.valueOf(SlaveType.Lift))) {
+ initLiftThread(device);
} else if (device.getDeviceType().equals(String.valueOf(SlaveType.Shuttle))) {
initShuttleThread(device);
}
@@ -85,6 +89,10 @@
ThreadHandler thread2 = new FakeZyForkLiftThread(redisUtil);
new Thread(thread2).start();
SlaveConnection.put(SlaveType.FakeThread, 2, thread2);
+
+ ThreadHandler thread3 = new FakeNyLiftThread(redisUtil);
+ new Thread(thread3).start();
+ SlaveConnection.put(SlaveType.FakeThread, 3, thread3);
}
@@ -104,6 +112,18 @@
SlaveConnection.put(SlaveType.ForkLiftMaster, deviceConfig.getDeviceNo(), thread);
}
+ private void initLiftThread(DeviceConfig deviceConfig) {
+ ThreadHandler thread = null;
+ if (deviceConfig.getThreadImpl().equals("NyLiftThread")) {
+ thread = new NyLiftThread(deviceConfig, redisUtil);
+ } else {
+ throw new CoolException("鏈煡鐨勭嚎绋嬪疄鐜�");
+ }
+
+ new Thread(thread).start();
+ SlaveConnection.put(SlaveType.Lift, deviceConfig.getDeviceNo(), thread);
+ }
+
private void initShuttleThread(DeviceConfig deviceConfig) {
ThreadHandler thread = null;
if (deviceConfig.getThreadImpl().equals("NyShuttleThread")) {
diff --git a/src/main/java/com/zy/core/controller/OpenController.java b/src/main/java/com/zy/core/controller/OpenController.java
index f948742..7b23c25 100644
--- a/src/main/java/com/zy/core/controller/OpenController.java
+++ b/src/main/java/com/zy/core/controller/OpenController.java
@@ -12,6 +12,7 @@
import com.zy.core.properties.DeviceConfig;
import com.zy.core.thread.FakeThread;
import com.zy.core.thread.ForkLiftThread;
+import com.zy.core.thread.LiftThread;
import com.zy.core.thread.ShuttleThread;
import com.zy.core.utils.DeviceMsgUtils;
import com.zy.core.utils.FakeDeviceUtils;
@@ -52,7 +53,9 @@
if (param.getDeviceType().equals(String.valueOf(SlaveType.Shuttle))) {
fakeThread = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 1);
} else if (param.getDeviceType().equals(String.valueOf(SlaveType.ForkLift))) {
- fakeThread = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 1);
+ fakeThread = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 2);
+ } else if (param.getDeviceType().equals(String.valueOf(SlaveType.Lift))) {
+ fakeThread = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 3);
}
if (fakeThread == null) {
@@ -72,7 +75,9 @@
if (param.getDeviceType().equals(String.valueOf(SlaveType.Shuttle))) {
fakeThread = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 1);
} else if (param.getDeviceType().equals(String.valueOf(SlaveType.ForkLift))) {
- fakeThread = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 1);
+ fakeThread = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 2);
+ } else if (param.getDeviceType().equals(String.valueOf(SlaveType.Lift))) {
+ fakeThread = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 3);
}
if (fakeThread == null) {
@@ -93,10 +98,12 @@
public R getFakeThreadStatusList() {
FakeThread fakeThread1 = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 1);
FakeThread fakeThread2 = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 2);
+ FakeThread fakeThread3 = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 3);
HashMap<String, Object> map = new HashMap<>();
map.put("fakeNyShuttleStatusMap", fakeThread1.getFakeStatusMap());
map.put("fakeZyForkLiftStatusMap", fakeThread2.getFakeStatusMap());
+ map.put("fakeNyLiftStatusMap", fakeThread3.getFakeStatusMap());
return R.ok().add(map);
}
@@ -130,6 +137,12 @@
continue;
}
deviceList.add(forkLiftThread.getDeviceConfig());
+ } else if (slaveType.equals(SlaveType.Lift)) {
+ LiftThread liftThread = (LiftThread) SlaveConnection.get(slaveType, config.getDeviceNo());
+ if(liftThread == null){
+ continue;
+ }
+ deviceList.add(liftThread.getDeviceConfig());
}
}
diff --git a/src/main/java/com/zy/core/enums/RedisKeyType.java b/src/main/java/com/zy/core/enums/RedisKeyType.java
index 8c3a76b..63a2fc8 100644
--- a/src/main/java/com/zy/core/enums/RedisKeyType.java
+++ b/src/main/java/com/zy/core/enums/RedisKeyType.java
@@ -5,13 +5,16 @@
//璁惧娑堟伅KEY
DEVICE_SHUTTLE_MSG_KEY_("deviceShuttleMsgKey_"),
DEVICE_FORK_LIFT_MSG_KEY_("deviceForkLiftMsgKey_"),
+ DEVICE_LIFT_MSG_KEY_("deviceLiftMsgKey_"),
//璁惧鎸囦护娑堟伅KEY
DEVICE_SHUTTLE_COMMAND_MSG_KEY("deviceShuttleCommandMsgKey_"),
DEVICE_FORK_LIFT_COMMAND_MSG_KEY("deviceForkLiftCommandMsgKey_"),
+ DEVICE_LIFT_COMMAND_MSG_KEY("deviceLiftCommandMsgKey_"),
//铏氭嫙璁惧鎸囦护娑堟伅KEY
FAKE_DEVICE_FORK_LIFT_COMMAND_MSG_KEY("fakeDeviceForkLiftCommandMsgKey_"),
+ FAKE_DEVICE_LIFT_COMMAND_MSG_KEY("fakeDeviceLiftCommandMsgKey_"),
//璁惧閰嶇疆鏂囦欢
DEVICE_CONFIG("deviceConfig"),
diff --git a/src/main/java/com/zy/core/thread/LiftThread.java b/src/main/java/com/zy/core/thread/LiftThread.java
new file mode 100644
index 0000000..d42ce73
--- /dev/null
+++ b/src/main/java/com/zy/core/thread/LiftThread.java
@@ -0,0 +1,10 @@
+package com.zy.core.thread;
+
+import com.zy.core.ThreadHandler;
+import com.zy.core.properties.DeviceConfig;
+
+public interface LiftThread extends ThreadHandler {
+
+ DeviceConfig getDeviceConfig();
+
+}
diff --git a/src/main/java/com/zy/core/thread/fake/FakeNyLiftThread.java b/src/main/java/com/zy/core/thread/fake/FakeNyLiftThread.java
new file mode 100644
index 0000000..f09a59e
--- /dev/null
+++ b/src/main/java/com/zy/core/thread/fake/FakeNyLiftThread.java
@@ -0,0 +1,402 @@
+package com.zy.core.thread.fake;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.zy.common.Cools;
+import com.zy.common.SpringUtils;
+import com.zy.common.utils.RedisUtil;
+import com.zy.core.News;
+import com.zy.core.cache.SlaveConnection;
+import com.zy.core.enums.RedisKeyType;
+import com.zy.core.enums.SlaveType;
+import com.zy.core.model.DeviceCommandMsgModel;
+import com.zy.core.model.DeviceMsgModel;
+import com.zy.core.model.param.UpdateFakeThreadStatusParam;
+import com.zy.core.properties.DeviceConfig;
+import com.zy.core.thread.FakeThread;
+import com.zy.core.thread.impl.NyLiftThread;
+import com.zy.core.utils.DeviceMsgUtils;
+import com.zy.core.utils.FakeDeviceUtils;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+@Slf4j
+@SuppressWarnings("all")
+public class FakeNyLiftThread implements FakeThread {
+
+ private RedisUtil redisUtil;
+ private JSONObject fakeStatusDemo = JSONObject.parseObject("{\"model\":2,\"plcTaskNo\":0,\"lev\":1,\"protocolStatus\":0,\"taskMode\":0,\"pick\":0,\"put\":0,\"iOMode\":0,\"errorCode\":0,\"hasTray\":0,\"hasCar\":0,\"trayList\":[0,0,0,0],\"carList\":[0,0,0,0],\"extend\":{\"frontOverrun\":false,\"backOverrun\":false,\"leftOverrun\":false,\"rightOverrun\":false,\"overHeight\":false,\"overWeight\":false}}");
+ private ConcurrentHashMap<String, Thread> fakeThreadMap = new ConcurrentHashMap();
+ private ConcurrentHashMap<String, JSONObject> fakeStatusMap = new ConcurrentHashMap();
+ private ConcurrentHashMap<String, JSONObject> fakeCommandMap = new ConcurrentHashMap();
+
+ private boolean fake = false;
+
+ public FakeNyLiftThread(RedisUtil redisUtil) {
+ this.redisUtil = redisUtil;
+ }
+
+ @Override
+ public void run() {
+ News.info("Fake Server is Started");
+
+ Thread fakeCommandThread = new Thread(() -> {
+ while (true) {
+ try {
+ FakeDeviceUtils fakeDeviceUtils = null;
+ try {
+ fakeDeviceUtils = SpringUtils.getBean(FakeDeviceUtils.class);
+ }catch (Exception e){}
+ if(fakeDeviceUtils == null){
+ continue;
+ }
+ List<DeviceConfig> deviceConfigs = fakeDeviceUtils.getFakeDeviceConfig();
+ for (DeviceConfig device : deviceConfigs) {
+ excuteFakeCommand(String.valueOf(SlaveType.Lift) + device.getDeviceNo());
+ }
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+ });
+ fakeCommandThread.start();
+
+ while (true) {
+ try {
+ initFakeDeviceServer();
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private synchronized void initFakeDeviceServer() {
+ FakeDeviceUtils fakeDeviceUtils = null;
+ try {
+ fakeDeviceUtils = SpringUtils.getBean(FakeDeviceUtils.class);
+ }catch (Exception e){}
+ if(fakeDeviceUtils == null){
+ return;
+ }
+ List<DeviceConfig> deviceConfigs = fakeDeviceUtils.getFakeDeviceConfig();
+ for (DeviceConfig device : deviceConfigs) {
+ if (!device.getDeviceType().equals(String.valueOf(SlaveType.Lift))) {
+ continue;
+ }
+
+ if (!device.getThreadImpl().equals("NyLiftThread")) {
+ continue;
+ }
+
+ if (fakeThreadMap.containsKey(String.valueOf(SlaveType.Lift) + device.getDeviceNo())) {
+ continue;
+ }
+
+ Thread fakeThread = new Thread(() -> {
+ log.info("{}:device is start handle client", device.getDeviceNo());
+ try {
+ while (true) {
+ handleClient(device);
+ }
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ });
+ fakeThread.start();
+
+ String fakeStatus = JSON.toJSONString(fakeStatusDemo);
+ if (!Cools.isEmpty(device.getFakeInitStatus())) {
+ fakeStatus = device.getFakeInitStatus();
+ }
+ fakeThreadMap.put(String.valueOf(SlaveType.Lift) + device.getDeviceNo(), fakeThread);
+ fakeStatusMap.put(String.valueOf(SlaveType.Lift) + device.getDeviceNo(), JSON.parseObject(fakeStatus));
+
+
+ // init
+ NyLiftThread thread = new NyLiftThread(device, redisUtil);;
+ new Thread(thread).start();
+ SlaveConnection.put(SlaveType.Lift, device.getDeviceNo(), thread);
+ }
+ }
+
+ private void excuteFakeCommand(String key) {
+ if (!fakeCommandMap.containsKey(key)) {
+ return;
+ }
+ JSONObject command = fakeCommandMap.get(key);
+ JSONObject commandBody = command.getJSONObject("commandBody");
+ fakeCommandMap.remove(key);
+ new Thread(() -> {
+ try {
+ JSONObject fakeStatus = fakeStatusMap.get(key);
+ Integer commandType = command.getInteger("commandType");
+ if (commandType == null) {
+ return;
+ }
+
+ if (commandType == 1) {
+ //鍙栨斁璐�
+ fakeStatus.put("plcTaskNo", commandBody.getInteger("taskNo"));//浠诲姟鍙�
+ fakeStatus.put("protocolStatus", 1);//鍙栬揣涓�
+ fakeStatus.put("taskMode", commandType);//浠诲姟绫诲瀷
+ fakeStatus.put("pick", commandBody.getInteger("pick"));//鍙栬揣鏁版嵁
+ fakeStatus.put("put", commandBody.getInteger("put"));//鏀捐揣鏁版嵁
+ fakeStatusMap.put(key, fakeStatus);
+
+ //delay
+ Thread.sleep(5000);
+
+ fakeStatus.put("protocolStatus", 0);
+ fakeStatus.put("taskMode", 0);//浠诲姟绫诲瀷
+ fakeStatus.put("pick", 0);//鍙栬揣鏁版嵁
+ fakeStatus.put("put", 0);//鏀捐揣鏁版嵁
+ fakeStatus.put("lev", commandBody.getInteger("put"));
+ fakeStatusMap.put(key, fakeStatus);
+ } else if (commandType == 2) {
+ //灏忚溅鎹㈠眰
+ fakeStatus.put("plcTaskNo", commandBody.getInteger("taskNo"));//浠诲姟鍙�
+ fakeStatus.put("protocolStatus", 1);//鍙栬揣涓�
+ fakeStatus.put("taskMode", commandType);//浠诲姟绫诲瀷
+ fakeStatus.put("pick", commandBody.getInteger("pick"));//鍙栬揣鏁版嵁
+ fakeStatus.put("put", commandBody.getInteger("put"));//鏀捐揣鏁版嵁
+ fakeStatusMap.put(key, fakeStatus);
+
+ //delay
+ Thread.sleep(5000);
+
+ fakeStatus.put("protocolStatus", 0);
+ fakeStatus.put("taskMode", 0);//浠诲姟绫诲瀷
+ fakeStatus.put("pick", 0);//鍙栬揣鏁版嵁
+ fakeStatus.put("put", 0);//鏀捐揣鏁版嵁
+ fakeStatus.put("lev", commandBody.getInteger("put"));
+ fakeStatusMap.put(key, fakeStatus);
+ } else if (commandType == 3) {
+ //鎻愬崌鏈虹Щ鍔�
+ fakeStatus.put("plcTaskNo", commandBody.getInteger("taskNo"));//浠诲姟鍙�
+ fakeStatus.put("protocolStatus", 1);//绉诲姩涓�
+ fakeStatus.put("taskMode", commandType);//浠诲姟绫诲瀷
+ fakeStatus.put("pick", commandBody.getInteger("pick"));//鍙栬揣鏁版嵁
+ fakeStatus.put("put", commandBody.getInteger("put"));//鏀捐揣鏁版嵁
+ fakeStatusMap.put(key, fakeStatus);
+
+ //delay
+ Thread.sleep(5000);
+
+ fakeStatus.put("protocolStatus", 0);
+ fakeStatus.put("taskMode", 0);//浠诲姟绫诲瀷
+ fakeStatus.put("pick", 0);//鍙栬揣鏁版嵁
+ fakeStatus.put("put", 0);//鏀捐揣鏁版嵁
+ fakeStatus.put("lev", commandBody.getInteger("put"));
+ fakeStatusMap.put(key, fakeStatus);
+ } else if (commandType == 9996) {
+ //澶嶄綅
+ fakeStatus.put("plcTaskNo", 0);//浠诲姟鍙�
+ fakeStatus.put("protocolStatus", 0);
+ fakeStatus.put("taskMode", 0);//浠诲姟绫诲瀷
+ fakeStatus.put("pick", 0);//鍙栬揣鏁版嵁
+ fakeStatus.put("put", 0);//鏀捐揣鏁版嵁
+ fakeStatusMap.put(key, fakeStatus);
+ } else if (commandType == 9997) {
+ //鍒囨崲鍏ュ簱妯″紡
+ fakeStatus.put("iOMode", 1);//鍑哄叆搴撴ā寮�
+ fakeStatusMap.put(key, fakeStatus);
+ } else if (commandType == 9998) {
+ //鍒囨崲鍑哄簱妯″紡
+ fakeStatus.put("iOMode", 2);//鍑哄叆搴撴ā寮�
+ fakeStatusMap.put(key, fakeStatus);
+ }
+
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }).start();
+ }
+
+ private void handleClient(DeviceConfig device) throws IOException {
+ try {
+ Set<String> keys = redisUtil.searchKeys(RedisKeyType.FAKE_DEVICE_LIFT_COMMAND_MSG_KEY.key + device.getDeviceNo());
+ if (keys.isEmpty()) {
+ return;
+ }
+
+ TreeSet<String> treeSet = new TreeSet<>();
+ for (String key : keys) {
+ treeSet.add(key);
+ }
+
+ String first = treeSet.first();
+ DeviceCommandMsgModel deviceCommandMsgModel = (DeviceCommandMsgModel) redisUtil.get(first);
+ redisUtil.del(first);
+
+// log.info("鏀跺埌Client Data: {}", JSON.toJSONString(result));
+ processCommand(deviceCommandMsgModel, device);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void removeFake(DeviceConfig device) {
+ Thread thread = fakeThreadMap.get(String.valueOf(SlaveType.Lift) + device.getDeviceNo());
+ if (thread != null) {
+ thread.interrupt();
+ }
+
+ fakeThreadMap.remove(String.valueOf(SlaveType.Lift) + device.getDeviceNo());
+ fakeStatusMap.remove(String.valueOf(SlaveType.Lift) + device.getDeviceNo());
+ fakeCommandMap.remove(String.valueOf(SlaveType.Lift) + device.getDeviceNo());
+ }
+
+ public void processCommand(DeviceCommandMsgModel deviceCommandMsgModel, DeviceConfig device) throws IOException {
+ DeviceMsgUtils deviceMsgUtils = SpringUtils.getBean(DeviceMsgUtils.class);
+ if (deviceMsgUtils == null) {
+ return;
+ }
+
+ HashMap<String, Object> response = null;
+ JSONObject fakeStatus = fakeStatusMap.get(String.valueOf(SlaveType.Lift) + device.getDeviceNo());
+
+ String command = JSON.toJSONString(deviceCommandMsgModel.getCommand());
+ JSONObject commandObj = JSON.parseObject(command);
+ Integer mode = commandObj.getInteger("mode");
+
+ String deviceMsgType = "command";
+ JSONObject fakeCommand = new JSONObject();
+ fakeCommand.put("deviceNo", device.getDeviceNo());
+ fakeCommand.put("deviceType", device.getDeviceType());
+ fakeCommand.put("commandType", commandObj.getInteger("mode"));
+ fakeCommand.put("commandBody", command);
+ if (mode == 1) {
+ //鍙栨斁璐�
+ fakeCommandMap.put(String.valueOf(SlaveType.Lift) + device.getDeviceNo(), fakeCommand);
+ response = genereateFakeCommandResponse();
+ } else if (mode == 2) {
+ //灏忚溅鎹㈠眰
+ fakeCommandMap.put(String.valueOf(SlaveType.Lift) + device.getDeviceNo(), fakeCommand);
+ response = genereateFakeCommandResponse();
+ } else if (mode == 3) {
+ //鎻愬崌鏈虹Щ鍔�
+ fakeCommandMap.put(String.valueOf(SlaveType.Lift) + device.getDeviceNo(), fakeCommand);
+ response = genereateFakeCommandResponse();
+ } else if (mode == 9996) {
+ //澶嶄綅
+ fakeCommandMap.put(String.valueOf(SlaveType.Lift) + device.getDeviceNo(), fakeCommand);
+ response = genereateFakeCommandResponse();
+ } else if (mode == 9997) {
+ //鍒囨崲鍏ュ簱妯″紡
+ fakeCommandMap.put(String.valueOf(SlaveType.Lift) + device.getDeviceNo(), fakeCommand);
+ response = genereateFakeCommandResponse();
+ } else if (mode == 9998) {
+ //鍒囨崲鍑哄簱妯″紡
+ fakeCommandMap.put(String.valueOf(SlaveType.Lift) + device.getDeviceNo(), fakeCommand);
+ response = genereateFakeCommandResponse();
+ } else if (mode == 9999) {
+ //璇诲彇鐘舵��
+ response = genereateFakeStatusResponse(fakeStatus);
+ deviceMsgType = "status";
+ }
+
+ fakeStatusMap.put(String.valueOf(SlaveType.Lift) + device.getDeviceNo(), fakeStatus);
+
+ if (deviceMsgType.equals("command")) {
+ log.info("鏀跺埌Rcs Lift Command Data: {}", JSON.toJSONString(deviceCommandMsgModel));
+ }
+ DeviceMsgModel deviceMsgModel = new DeviceMsgModel();
+ deviceMsgModel.setDeviceId(device.getDeviceNo());
+ deviceMsgModel.setDeviceMsgType(deviceMsgType);
+ deviceMsgModel.setDeviceMsg(response);
+ deviceMsgModel.setDeviceOriginMsg(JSON.toJSONString(response));
+ deviceMsgModel.setResultKey(deviceCommandMsgModel.getResultKey());
+ deviceMsgUtils.sendDeviceMsg(SlaveType.Lift, device.getDeviceNo(), deviceMsgModel);
+ }
+
+ public HashMap<String, Object> genereateFakeStatusResponse(JSONObject fakeStatus) {
+ JSONObject device = new JSONObject();
+ HashMap<String, Object> resultData = new HashMap<>();
+ resultData.put("result", "success");
+ resultData.put("deviceStatus", device);
+
+
+ device.put("model", fakeStatus.getInteger("model"));
+ device.put("plcTaskNo", fakeStatus.getInteger("plcTaskNo"));
+ device.put("protocolStatus", fakeStatus.getInteger("protocolStatus"));
+ device.put("taskMode", fakeStatus.getInteger("taskMode"));
+ device.put("pick", fakeStatus.getInteger("pick"));
+ device.put("put", fakeStatus.getInteger("put"));
+ device.put("iOMode", fakeStatus.getInteger("iOMode"));
+ device.put("errorCode", fakeStatus.getInteger("errorCode"));
+ device.put("hasTray", fakeStatus.getInteger("hasTray"));
+ device.put("hasCar", fakeStatus.getInteger("hasCar"));
+ device.put("lev", fakeStatus.getInteger("lev"));
+
+ Object trayListObj = fakeStatus.get("trayList");
+ List<Integer> trayList = new ArrayList<>();
+ if (trayListObj != null) {
+ trayList = JSON.parseArray(JSON.toJSONString(trayListObj), Integer.class);
+ }
+
+ Object carListObj = fakeStatus.get("carList");
+ List<Integer> carList = new ArrayList<>();
+ if (carListObj != null) {
+ carList = JSON.parseArray(JSON.toJSONString(carListObj), Integer.class);
+ }
+
+ device.put("trayList", trayList);
+ device.put("carList", carList);
+
+ JSONObject extend = fakeStatus.getJSONObject("extend");
+ device.put("frontOverrun", extend.getBoolean("frontOverrun"));
+ device.put("backOverrun", extend.getInteger("backOverrun"));
+ device.put("leftOverrun", extend.getInteger("leftOverrun"));
+ device.put("rightOverrun", extend.getInteger("rightOverrun"));
+ device.put("overHeight", extend.getInteger("overHeight"));
+ device.put("overWeight", extend.getInteger("overWeight"));
+ return resultData;
+ }
+
+ public HashMap<String, Object> genereateFakeCommandResponse() {
+ HashMap<String, Object> resultData = new HashMap<>();
+ resultData.put("result", "success");
+ return resultData;
+ }
+
+ @Override
+ public boolean connect() {
+ return true;
+ }
+
+ @Override
+ public void close() {
+
+ }
+
+ @Override
+ public ConcurrentHashMap<String, Thread> getFakeThreadMap() {
+ return this.fakeThreadMap;
+ }
+
+ @Override
+ public ConcurrentHashMap<String, JSONObject> getFakeStatusMap() {
+ return this.fakeStatusMap;
+ }
+
+ @Override
+ public ConcurrentHashMap<String, JSONObject> getFakeCommandMap() {
+ return this.fakeCommandMap;
+ }
+
+ @Override
+ public boolean updateFakeStatus(UpdateFakeThreadStatusParam param) {
+ String key = param.getDeviceType() + param.getDeviceNo();
+ JSONObject result = fakeStatusMap.get(key);
+ if (result == null) {
+ return false;
+ }
+
+ JSONObject newData = JSON.parseObject(param.getData());
+ this.fakeStatusMap.put(key, newData);
+ return true;
+ }
+}
diff --git a/src/main/java/com/zy/core/thread/fake/FakeZyForkLiftThread.java b/src/main/java/com/zy/core/thread/fake/FakeZyForkLiftThread.java
index 1e08662..52a85d0 100644
--- a/src/main/java/com/zy/core/thread/fake/FakeZyForkLiftThread.java
+++ b/src/main/java/com/zy/core/thread/fake/FakeZyForkLiftThread.java
@@ -155,7 +155,7 @@
Thread.sleep(5000);
fakeStatus.put("protocolStatus", 98);//绛夊緟纭
- fakeStatus.put("lev", command.getInteger("put"));
+ fakeStatus.put("lev", commandBody.getInteger("put"));
fakeStatusMap.put(key, fakeStatus);
} else if (commandType == 4) {
//灏忚溅鎹㈠眰
diff --git a/src/main/java/com/zy/core/thread/impl/NyLiftThread.java b/src/main/java/com/zy/core/thread/impl/NyLiftThread.java
new file mode 100644
index 0000000..f047f5a
--- /dev/null
+++ b/src/main/java/com/zy/core/thread/impl/NyLiftThread.java
@@ -0,0 +1,308 @@
+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.alibaba.fastjson.JSONObject;
+import com.zy.common.SpringUtils;
+import com.zy.common.utils.DateUtils;
+import com.zy.common.utils.RedisUtil;
+import com.zy.core.News;
+import com.zy.core.cache.OutputQueue;
+import com.zy.core.enums.RedisKeyType;
+import com.zy.core.enums.SlaveType;
+import com.zy.core.model.DeviceCommandMsgModel;
+import com.zy.core.model.DeviceMsgModel;
+import com.zy.core.properties.DeviceConfig;
+import com.zy.core.thread.LiftThread;
+import com.zy.core.utils.DeviceMsgUtils;
+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;
+
+@Slf4j
+@SuppressWarnings("all")
+public class NyLiftThread implements LiftThread {
+
+ private DeviceConfig deviceConfig;
+ private RedisUtil redisUtil;
+ private SiemensS7Net siemensS7Net;
+ private boolean connect = false;
+
+ public NyLiftThread(DeviceConfig deviceConfig, RedisUtil redisUtil) {
+ this.deviceConfig = deviceConfig;
+ this.redisUtil = redisUtil;
+ }
+
+ @Override
+ public boolean connect() {
+ if (deviceConfig.getFake()) {
+ this.connect = true;
+ OutputQueue.LIFT.offer(MessageFormat.format( "銆恵0}銆戞彁鍗囨満杩炴帴鎴愬姛 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort(), 0, 0));
+ News.info("銆恵}銆戞彁鍗囨満杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort());
+ return true;
+ }
+
+ boolean result = false;
+ siemensS7Net = new SiemensS7Net(SiemensPLCS.S1200, deviceConfig.getIp());
+ siemensS7Net.setRack(Integer.valueOf(0).byteValue());
+ siemensS7Net.setSlot(Integer.valueOf(0).byteValue());
+ OperateResult connect = siemensS7Net.ConnectServer();
+ if(connect.IsSuccess){
+ result = true;
+ OutputQueue.LIFT.offer(MessageFormat.format( "銆恵0}銆戞彁鍗囨満杩炴帴鎴愬姛 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort(), 0, 0));
+ News.info("銆恵}銆戞彁鍗囨満杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort());
+ } else {
+ OutputQueue.LIFT.offer(MessageFormat.format( "銆恵0}銆戞彁鍗囨満杩炴帴澶辫触锛侊紒锛� ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort(), 0, 0));
+ News.error("銆恵}銆戞彁鍗囨満杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort());
+ }
+ // siemensS7Net.ConnectClose();
+ this.connect = result;
+ return result;
+ }
+
+ @Override
+ public void close() {
+
+ }
+
+ @Override
+ public void run() {
+ News.info("{}鍙锋彁鍗囨満绾跨▼鍚姩", deviceConfig.getDeviceNo());
+ this.connect();
+ while (true) {
+ try {
+ DeviceMsgUtils deviceMsgUtils = null;
+ try {
+ deviceMsgUtils = SpringUtils.getBean(DeviceMsgUtils.class);
+ }catch (Exception e){}
+ if (deviceMsgUtils == null) {
+ continue;
+ }
+ DeviceCommandMsgModel deviceCommandMsg = deviceMsgUtils.getDeviceCommandMsg(SlaveType.Lift, deviceConfig.getDeviceNo());
+ if (deviceCommandMsg == null) {
+ continue;
+ }
+ executeCommand(deviceCommandMsg, deviceMsgUtils);
+
+ Thread.sleep(200);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void executeCommand(DeviceCommandMsgModel deviceCommandMsg, DeviceMsgUtils deviceMsgUtils) {
+ if (deviceConfig.getFake()) {
+ redisUtil.set(RedisKeyType.FAKE_DEVICE_LIFT_COMMAND_MSG_KEY.key + deviceConfig.getDeviceNo(), deviceCommandMsg, 60 * 60);
+ return;
+ }
+
+ String command = JSON.toJSONString(deviceCommandMsg.getCommand());
+ JSONObject commandObj = JSON.parseObject(command);
+
+ HashMap<String, Object> resultData = new HashMap<>();
+ resultData.put("result", "false");
+
+ String deviceMsgType = "command";
+ OperateResult result = null;
+ OperateResult result2 = null;
+ if (commandObj.getInteger("mode") == 3) {
+ //鍙栨斁璐�
+ short[] array = new short[4];
+ array[0] = commandObj.getShort("taskNO");//浠诲姟鍙�
+ array[1] = commandObj.getShort("mode");//浠诲姟妯″紡
+ array[2] = commandObj.getShort("pick");//鍙栬揣鏁版嵁
+ array[3] = commandObj.getShort("put");//鏀捐揣鏁版嵁
+ resultData.put("commandData", array);
+
+ result = siemensS7Net.Write("DB103.0", array);
+ if (result.IsSuccess) {
+ result2 = siemensS7Net.Write("DB103.8", (short) 1);
+ if (result2.IsSuccess) {
+ resultData.put("result", "success");
+ }
+ }
+ } else if (commandObj.getInteger("mode") == 4) {
+ //灏忚溅鎹㈠眰
+ short[] array = new short[4];
+ array[0] = commandObj.getShort("taskNO");//浠诲姟鍙�
+ array[1] = commandObj.getShort("mode");//浠诲姟妯″紡
+ array[2] = commandObj.getShort("pick");//鍙栬揣鏁版嵁
+ array[3] = commandObj.getShort("put");//鏀捐揣鏁版嵁
+ resultData.put("commandData", array);
+
+ result = siemensS7Net.Write("DB103.0", array);
+ if (result.IsSuccess) {
+ result2 = siemensS7Net.Write("DB103.8", (short) 1);
+ if (result2.IsSuccess) {
+ resultData.put("result", "success");
+ }
+ }
+ } else if (commandObj.getInteger("mode") == 5) {
+ //鎻愬崌鏈虹Щ鍔�
+ short[] array = new short[4];
+ array[0] = commandObj.getShort("taskNO");//浠诲姟鍙�
+ array[1] = commandObj.getShort("mode");//浠诲姟妯″紡
+ array[2] = commandObj.getShort("pick");//鍙栬揣鏁版嵁
+ array[3] = commandObj.getShort("put");//鏀捐揣鏁版嵁
+ resultData.put("commandData", array);
+
+ result = siemensS7Net.Write("DB103.0", array);
+ if (result.IsSuccess) {
+ result2 = siemensS7Net.Write("DB103.8", (short) 1);
+ if (result2.IsSuccess) {
+ resultData.put("result", "success");
+ }
+ }
+ } else if (commandObj.getInteger("mode") == 9996) {
+ //澶嶄綅
+ short[] array = new short[1];
+ array[0] = 1;
+ resultData.put("commandData", array);
+
+ result = siemensS7Net.Write("DB103.10", array);
+ if (result.IsSuccess) {
+ resultData.put("result", "success");
+ }
+ } else if (commandObj.getInteger("mode") == 9997) {
+ //鍒囨崲鍏ュ簱妯″紡
+ short[] array = new short[1];
+ array[0] = 1;
+ resultData.put("commandData", array);
+
+ result = siemensS7Net.Write("DB103.12", array);
+ if (result.IsSuccess) {
+ resultData.put("result", "success");
+ }
+ } else if (commandObj.getInteger("mode") == 9998) {
+ //鍒囨崲鍑哄簱妯″紡
+ short[] array = new short[1];
+ array[0] = 2;
+ resultData.put("commandData", array);
+
+ result = siemensS7Net.Write("DB103.12", array);
+ if (result.IsSuccess) {
+ resultData.put("result", "success");
+ }
+ } else if (commandObj.getInteger("mode") == 9999) {
+ //璇诲彇鐘舵��
+ JSONObject device = new JSONObject();
+
+ OperateResultExOne<byte[]> readResult1 = siemensS7Net.Read("DB101.0", (short) 18);
+ if (readResult1.IsSuccess) {
+ //妯″紡
+ device.put("model", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 0));
+ //PLC浠诲姟鍙�
+ device.put("wrkNo", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 2));
+ //浠诲姟鐘舵��
+ device.put("protocolStatus", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 4));
+ //浠诲姟妯″紡
+ device.put("taskMode", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 6));
+ //鍙栬揣鏁版嵁
+ device.put("pick", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 8));
+ //鏀捐揣鏁版嵁
+ device.put("put", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 10));
+ //鍑哄叆搴撴ā寮�
+ device.put("iOMode", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 12));
+ //鏁呴殰鐮�
+ device.put("errorCode", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 14));
+ //灞�
+ device.put("lev", (int) siemensS7Net.getByteTransform().TransInt16(readResult1.Content, 16));
+
+ resultData.put("deviceStatus", device);
+ }
+
+ //绔欑偣涓暟
+ int staCount = 4;
+ //璇诲彇鎵樼洏鏁版嵁
+ List<Integer> trayList = new ArrayList<>();
+ OperateResultExOne<byte[]> readResult2 = siemensS7Net.Read("DB102.0", (short) (staCount * 2));
+ if(readResult2.IsSuccess) {
+ for (int i = 0; i < staCount; i++) {
+ short val = siemensS7Net.getByteTransform().TransInt16(readResult2.Content, i * 2);
+ trayList.add((int) val);
+ }
+ }
+
+ //璇诲彇灏忚溅鏁版嵁
+ OperateResultExOne<byte[]> readResult3 = siemensS7Net.Read("DB102.50", (short) (staCount * 2));
+ List<Integer> carList = new ArrayList<>();
+ if(readResult3.IsSuccess) {
+ for (int i = 0; i < staCount; i++) {
+ short val = siemensS7Net.getByteTransform().TransInt16(readResult3.Content, i * 2);
+ carList.add((int) val);
+ }
+ }
+
+ device.put("trayList", trayList);
+ device.put("carList", carList);
+
+ deviceMsgType = "status";
+ }
+
+ resultData.put("commandResult1", JSON.toJSONString(result));
+ resultData.put("commandResult2", JSON.toJSONString(result2));
+
+ if (deviceMsgType.equals("command")) {
+ log.info("鏀跺埌Rcs Lift Command Data: {}", JSON.toJSONString(deviceCommandMsg));
+ }
+ DeviceMsgModel deviceMsgModel = new DeviceMsgModel();
+ deviceMsgModel.setDeviceId(deviceConfig.getDeviceNo());
+ deviceMsgModel.setDeviceMsgType(deviceMsgType);
+ deviceMsgModel.setDeviceMsg(JSON.toJSONString(resultData));
+ deviceMsgModel.setDeviceOriginMsg(JSON.toJSONString(resultData));
+ deviceMsgModel.setResultKey(deviceCommandMsg.getResultKey());
+ deviceMsgUtils.sendDeviceMsg(SlaveType.Lift, deviceConfig.getDeviceNo(), deviceMsgModel);
+ }
+
+ @Override
+ public DeviceConfig getDeviceConfig() {
+ return this.deviceConfig;
+ }
+
+ /**
+ * 鎵╁睍瀛楁
+ */
+ @Data
+ private class InnerLiftExtend {
+
+ /**
+ * 鍓嶈秴闄�
+ */
+ private Boolean frontOverrun;
+
+ /**
+ * 鍚庤秴闄�
+ */
+ private Boolean backOverrun;
+
+ /**
+ * 宸﹁秴闄�
+ */
+ private Boolean leftOverrun;
+
+ /**
+ * 鍙宠秴闄�
+ */
+ private Boolean rightOverrun;
+
+ /**
+ * 瓒呴珮
+ */
+ private Boolean overHeight;
+
+ /**
+ * 瓒呴噸
+ */
+ private Boolean overWeight;
+
+ }
+}
diff --git a/src/main/java/com/zy/core/utils/DeviceMsgUtils.java b/src/main/java/com/zy/core/utils/DeviceMsgUtils.java
index 79cb35f..6b0ed43 100644
--- a/src/main/java/com/zy/core/utils/DeviceMsgUtils.java
+++ b/src/main/java/com/zy/core/utils/DeviceMsgUtils.java
@@ -137,6 +137,8 @@
return RedisKeyType.DEVICE_SHUTTLE_MSG_KEY_.key + deviceId + "_";
} else if (deviceType.equals(SlaveType.ForkLift)) {
return RedisKeyType.DEVICE_FORK_LIFT_MSG_KEY_.key + deviceId + "_";
+ } else if (deviceType.equals(SlaveType.Lift)) {
+ return RedisKeyType.DEVICE_LIFT_MSG_KEY_.key + deviceId + "_";
}else {
throw new CoolException("璁惧绫诲瀷鏈畾涔�");
}
@@ -151,6 +153,8 @@
return RedisKeyType.DEVICE_SHUTTLE_COMMAND_MSG_KEY.key + deviceId + "_";
} else if (deviceType.equals(SlaveType.ForkLift)) {
return RedisKeyType.DEVICE_FORK_LIFT_COMMAND_MSG_KEY.key + deviceId + "_";
+ } else if (deviceType.equals(SlaveType.Lift)) {
+ return RedisKeyType.DEVICE_LIFT_COMMAND_MSG_KEY.key + deviceId + "_";
}else {
throw new CoolException("璁惧绫诲瀷鏈畾涔�");
}
--
Gitblit v1.9.1