From 151ba81e92c3c60888cbc04b1a4f3276b8111ac6 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期六, 05 七月 2025 09:03:09 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/impl/NyShuttleThread.java | 85 ++++++++++++++++++++++++++++++++++++++++--
1 files changed, 81 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java b/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
index da2d8d9..5014298 100644
--- a/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
@@ -6,6 +6,8 @@
import com.core.common.SpringUtils;
import com.zy.common.utils.RedisUtil;
import com.zy.core.News;
+import com.zy.core.model.DeviceCommandMsgModel;
+import com.zy.core.model.DeviceMsgModel;
import com.zy.core.utils.DeviceMsgUtils;
import com.zy.core.cache.OutputQueue;
import com.zy.core.enums.SlaveType;
@@ -58,7 +60,7 @@
while (true) {
try {
DeviceMsgUtils deviceMsgUtils = SpringUtils.getBean(DeviceMsgUtils.class);
- Object deviceCommandMsg = deviceMsgUtils.getDeviceCommandMsg(SlaveType.Shuttle, slave.getId());
+ DeviceCommandMsgModel deviceCommandMsg = deviceMsgUtils.getDeviceCommandMsg(SlaveType.Shuttle, slave.getId());
if (deviceCommandMsg == null) {
continue;
}
@@ -73,15 +75,17 @@
executeThread.start();
}
- private void executeCommand(Object deviceCommandMsg) {
+ private void executeCommand(DeviceCommandMsgModel deviceCommandMsg) {
try {
if (this.socket == null) {
return;
}
+ Object command = deviceCommandMsg.getCommand();
+
// 鑾峰彇杈撳嚭娴�
OutputStreamWriter writer = new OutputStreamWriter(this.socket.getOutputStream());
- writer.write(JSON.toJSONString(deviceCommandMsg) + "\r\n");
+ writer.write(JSON.toJSONString(command) + "\r\n");
writer.flush();
// System.out.println("Sent message to server: " + JSON.toJSONString(httpCommand));
}catch (Exception e) {
@@ -115,7 +119,31 @@
}
JSONObject result = JSON.parseObject(sb.toString());//寰楀埌鍝嶅簲缁撴灉闆�
- deviceMsgUtils.sendDeviceMsg(SlaveType.Shuttle, slave.getId(), result);
+
+ String msgType = result.getString("msgType");
+ if ("responseMsg".equals(msgType)) {
+ JSONObject response = result.getJSONObject("response");
+ JSONObject body = response.getJSONObject("body");
+ if (body.containsKey("workingMode")) {
+ //read
+ JSONObject data = parseSocketResult(body);
+
+ DeviceMsgModel deviceMsgModel = new DeviceMsgModel();
+ deviceMsgModel.setDeviceId(slave.getId());
+ deviceMsgModel.setDeviceMsgType("status");
+ deviceMsgModel.setDeviceMsg(data);
+ deviceMsgModel.setDeviceOriginMsg(sb.toString());
+ deviceMsgUtils.sendDeviceMsg(SlaveType.Shuttle, slave.getId(), deviceMsgModel);
+ return;
+ }
+ }
+
+ DeviceMsgModel deviceMsgModel = new DeviceMsgModel();
+ deviceMsgModel.setDeviceId(slave.getId());
+ deviceMsgModel.setDeviceMsgType("command");
+ deviceMsgModel.setDeviceMsg(result);
+ deviceMsgModel.setDeviceOriginMsg(sb.toString());
+ deviceMsgUtils.sendDeviceMsg(SlaveType.Shuttle, slave.getId(), deviceMsgModel);
} catch (Exception e) {
e.printStackTrace();
}
@@ -144,4 +172,53 @@
public void close() {
}
+
+ public JSONObject parseSocketResult(JSONObject data) {
+ JSONObject device = new JSONObject();
+
+ //灏忚溅璁惧鐘舵��
+ device.put("deviceStatus", data.getInteger("free"));
+ //灏忚溅妯″紡
+ device.put("mode", data.getInteger("workingMode"));
+ //褰撳墠浜岀淮鐮�
+ device.put("currentCode", data.getString("point"));
+ //鐢垫睜鐢甸噺
+ device.put("batteryPower", data.getString("powerPercent"));
+ //鐢垫睜鐢靛帇
+ device.put("batteryVoltage", data.getInteger("voltage"));
+ //鏁呴殰
+ device.put("errorCode", data.getJSONArray("errCode").getString(0));
+
+ //鏄惁椤跺崌
+ device.put("hasLift", data.getInteger("liftPosition") == 2 ? true : false);
+ //鏄惁鏈夋墭鐩�
+ device.put("hasPallet", data.getInteger("loadState") == 1 ? true : false);
+ //琛岄┒鏂瑰悜
+ device.put("runDirection", data.getString("runDir") == null ? "none" : data.getString("runDir"));
+ //鏄惁涓哄厖鐢电姸鎬�
+ device.put("hasCharge", data.getInteger("chargState") == 1 ? true : false);
+ //杩愯閫熷害
+ device.put("speed", data.getInteger("speed"));
+
+ //*********璇诲彇鎵╁睍瀛楁**********
+
+ JSONObject extend = new JSONObject();
+ device.put("extend", extend);
+
+ //绠″埗鐘舵��
+ extend.put("suspendState", data.getInteger("suspendState"));
+ //鏈�楂樼數鑺數鍘�(mV)
+ extend.put("maxCellVoltage", data.getInteger("maxCellVoltage"));
+ //鏈�浣庣數鑺數鍘�(mV)
+ extend.put("minCellVoltage", data.getInteger("minCellVoltage"));
+ //鐢垫睜鐢靛帇
+ extend.put("voltage", data.getInteger("voltage"));
+ //鍏呮斁鐢靛惊鐜鏁�
+ extend.put("chargeCycleTimes", data.getInteger("chargeCycleTimes"));
+ //鍓╀綑鐢甸噺
+ extend.put("surplusQuantity", data.getInteger("surplusQuantity"));
+ //鎬荤數閲�
+ extend.put("countQuantity", data.getInteger("countQuantity"));
+ return device;
+ }
}
--
Gitblit v1.9.1