From f3ec64035a323a6a31bf5e98401ea2dc342c8aa2 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 07 七月 2025 16:25:43 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java | 43 ++++++++++++++++++++++++++++++++-----------
1 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java b/src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java
index a879110..24732ea 100644
--- a/src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java
@@ -3,7 +3,6 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zy.common.SpringUtils;
-import com.zy.common.exception.CoolException;
import com.zy.common.utils.RedisUtil;
import com.zy.core.News;
import com.zy.core.ThreadHandler;
@@ -27,7 +26,7 @@
private RedisUtil redisUtil;
- private JSONObject fakeStatusDemo = JSONObject.parseObject("{\"mode\":1,\"extend\":{\"countQuantity\":400,\"suspendState\":0,\"minCellVoltage\":3279,\"chargeCycleTimes\":0,\"maxCellVoltage\":3281,\"surplusQuantity\":204,\"voltage\":5248},\"hasLift\":false,\"hasPallet\":false,\"batteryVoltage\":5248,\"runDirection\":\"2\",\"currentCode\":\"{\\\"x\\\":12,\\\"y\\\":37,\\\"z\\\":3}\",\"errorCode\":\"0\",\"hasCharge\":false,\"batteryPower\":\"51\",\"speed\":0,\"deviceStatus\":1}");
+ private JSONObject fakeStatusDemo = JSONObject.parseObject("{\"mode\":1,\"extend\":{\"countQuantity\":400,\"suspendState\":0,\"minCellVoltage\":3279,\"chargeCycleTimes\":0,\"maxCellVoltage\":3281,\"surplusQuantity\":204,\"voltage\":5248},\"hasLift\":false,\"hasPallet\":false,\"batteryVoltage\":5248,\"runDirection\":\"2\",\"currentCode\":\"{\\\"x\\\":19,\\\"y\\\":11,\\\"z\\\":2}\",\"errorCode\":\"0\",\"hasCharge\":false,\"batteryPower\":\"51\",\"speed\":0,\"deviceStatus\":1}");
private HashMap<String, Socket> fakeServerMap = new HashMap();
private HashMap<String, JSONObject> fakeStatusMap = new HashMap();
@@ -85,11 +84,6 @@
break;
}
- if(fakeSocket.isClosed()) {
- fakeSocket = null;
- continue;
- }
-
handleClient(fakeSocket, device);
}
}catch (Exception e){
@@ -126,9 +120,7 @@
log.info("鏀跺埌Client Data: {}", JSON.toJSONString(result));
processCommand(result, device);
} catch (Exception e) {
-// e.printStackTrace();
- socket.close();
- fakeServerMap.remove(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo());
+ e.printStackTrace();
}
}
@@ -137,22 +129,30 @@
JSONObject fakeStatus = fakeStatusMap.get(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo());
JSONObject request = result.getJSONObject("request");
+ JSONObject header = request.getJSONObject("header");
JSONObject body = request.getJSONObject("body");
+
+ Integer requestId = header.getInteger("requestId");
String requestType = body.getString("requestType");
Integer taskId = body.getInteger("taskId");
if (requestType.equals("liftUp")) {
fakeStatus.put("hasLift", true);
+ response = genereateFakeCommandResponse(requestId, taskId, requestType);
} else if (requestType.equals("liftDown")) {
fakeStatus.put("hasLift", false);
+ response = genereateFakeCommandResponse(requestId, taskId, requestType);
} else if (requestType.equals("charge")) {
fakeStatus.put("hasCharge", true);
+ response = genereateFakeCommandResponse(requestId, taskId, requestType);
} else if (requestType.equals("stopCharge")) {
fakeStatus.put("hasCharge", false);
+ response = genereateFakeCommandResponse(requestId, taskId, requestType);
} else if (requestType.equals("updateFloor")) {
String currentCode = fakeStatus.getString("currentCode");
JSONObject point = JSON.parseObject(currentCode);
point.put("z", body.getInteger("z"));
fakeStatus.put("currentCode", JSON.toJSONString(point));
+ response = genereateFakeCommandResponse(requestId, taskId, requestType);
} else if (requestType.equals("move")) {
String pathList = body.getString("path");
List<JSONObject> list = JSON.parseArray(pathList, JSONObject.class);
@@ -170,7 +170,7 @@
}
}
} else if (requestType.equals("readState")) {
- response = genereateFakeStatusResponse(taskId, fakeStatus);
+ response = genereateFakeStatusResponse(requestId, fakeStatus);
}
fakeStatusMap.put(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo(), fakeStatus);
@@ -221,6 +221,27 @@
return JSON.toJSONString(result);
}
+ public String genereateFakeCommandResponse(Integer responseId, Integer taskId, String commandType) {
+ JSONObject result = new JSONObject();
+ JSONObject response = new JSONObject();
+ result.put("msgType", "responseMsg");
+ result.put("robotId", 5001);
+ result.put("response", response);
+
+ JSONObject header = new JSONObject();
+ JSONObject body = new JSONObject();
+ response.put("header", header);
+ response.put("body", body);
+
+ header.put("responseId", responseId);
+ header.put("version", "GV-APP-F427-N24036-1112");
+
+ body.put("responseType", commandType);
+ body.put("result", "success");
+ body.put("taskId", taskId);
+ return JSON.toJSONString(result);
+ }
+
@Override
public boolean connect() {
return true;
--
Gitblit v1.9.1