From af90f57201e2bd91342ec0a384517c4b6977f905 Mon Sep 17 00:00:00 2001
From: CZT <czt18638530771@163.com>
Date: 星期四, 14 九月 2023 15:44:07 +0800
Subject: [PATCH] 优化控制柜注册回复命令
---
igds-protocol-bhzn/src/main/java/com/ld/igds/protocol/bhzn/inout/BHZNWeightServiceImpl.java | 197 ++++++++++++++++++++++++++++++++++++------------
1 files changed, 146 insertions(+), 51 deletions(-)
diff --git a/igds-protocol-bhzn/src/main/java/com/ld/igds/protocol/bhzn/inout/BHZNWeightServiceImpl.java b/igds-protocol-bhzn/src/main/java/com/ld/igds/protocol/bhzn/inout/BHZNWeightServiceImpl.java
index 6ed27b6..bc8108e 100644
--- a/igds-protocol-bhzn/src/main/java/com/ld/igds/protocol/bhzn/inout/BHZNWeightServiceImpl.java
+++ b/igds-protocol-bhzn/src/main/java/com/ld/igds/protocol/bhzn/inout/BHZNWeightServiceImpl.java
@@ -2,19 +2,26 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
+import com.ld.igds.common.CoreCommonService;
+import com.ld.igds.constant.FoodVariety;
import com.ld.igds.inout.ApiInoutService;
import com.ld.igds.inout.InoutApiConstant;
import com.ld.igds.inout.InoutConstant;
import com.ld.igds.inout.dto.ApiInoutData;
import com.ld.igds.inout.dto.InoutData;
import com.ld.igds.io.constant.ProtocolEnum;
+import com.ld.igds.models.Depot;
import com.ld.igds.protocol.bhzn.inout.client.BHZNClientEngine;
import com.ld.igds.protocol.bhzn.utils.CRC16;
+import com.ld.igds.protocol.bhzn.verb.dto.IoMessage;
import com.ld.igds.util.BytesUtil;
import com.ld.io.api.InvokeResult;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import javax.xml.ws.soap.Addressing;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
@@ -28,7 +35,8 @@
// @Autowired
// private Inoutservice inoutservice;
-
+ @Autowired
+ private CoreCommonService coreCommonService;
@Override
public String getProtocol() {
return ProtocolEnum.TCP_BHZH_INOUT_V1.getCode();
@@ -120,30 +128,65 @@
@Override
public String noticeLed(ApiInoutData param, InoutData data) {
// todo
+ try{
+ log.info("BHZN鎺у埗LED寮�濮�");
+ BHZNClientEngine test = new BHZNClientEngine(
+ "192.168.0.210", 58258);
+ test.start();
+ Thread.sleep(3000L);
- return null;
- }
+ // 濮撳悕
+ String msg = getMsg(StringUtils.isEmpty(data.getUserName())?" ":data.getUserName(),"0B00");
+ log.info("msg=" + msg);
+ InvokeResult result = test.send(BytesUtil.hexStrToBytes(msg));
+ log.info("result=" +result.getMessage());
+ //杞︾墝
+ msg = getMsg(StringUtils.isEmpty(data.getPlateNum())?" ":data.getPlateNum(),"0C00");
+ log.info("msg=" + msg);
+ result = test.send(BytesUtil.hexStrToBytes(msg));
+ log.info("result=" +result.getMessage());
+ //浠撳簱
+ Depot depot =coreCommonService.getDepotById(data.getCompanyId(),data.getDepotId());
+ String depotName =" ";
+ if(depot != null)
+ {
+ depotName = depot.getName();
+ }
+ msg = getMsg(StringUtils.isEmpty(depotName)?" ":depotName,"0D00");
+ log.info("msg=" + msg);
+ result = test.send(BytesUtil.hexStrToBytes(msg));
+ log.info("result=" +result.getMessage());
- /**
- * 澧炲姞鐧藉悕鍗� --璋冪敤瀛愮嚎绋嬪疄鐜�
- *
- * @param param deviceId鍜宎ctionCode 涓嶅彲涓虹┖
- * @return
- */
- public String addWhitePlate(ApiInoutData param) {
+ //鍝佺
+ String foodvariety = FoodVariety.getMsg(data.getFoodVariety());
+ msg = getMsg(StringUtils.isEmpty(foodvariety)?" ":foodvariety,"0E00");
+ log.info("msg=" + msg);
+ result = test.send(BytesUtil.hexStrToBytes(msg));
+ log.info("result=" +result.getMessage());
+ //姣涢噸
+ msg = getMsg((data.getFullWeight() == null )?" ":data.getFullWeight().toString(),"0F00");
+ log.info("msg=" + msg);
+ result = test.send(BytesUtil.hexStrToBytes(msg));
+ log.info("result=" +result.getMessage());
+ //鐨噸
+ msg = getMsg((data.getEmptyWeight() == null )?" ":data.getEmptyWeight().toString(),"1000");
+ log.info("msg=" + msg);
+ result = test.send(BytesUtil.hexStrToBytes(msg));
+ log.info("result=" +result.getMessage());
+ //鍖栭獙缁撴灉
+ msg = getMsg("鍚堟牸","1100");
+ log.info("msg=" + msg);
+ result = test.send(BytesUtil.hexStrToBytes(msg));
+ log.info("result=" +result.getMessage());
- return "SUCCESS";
- }
+ log.info("BHZN鎺у埗LED缁撴潫");
- /**
- * 鍒犻櫎鐧藉悕鍗�---璋冪敤瀛愮嚎绋嬪疄鐜�
- *
- * @param param
- * @return
- */
- public String delWhitePlate(ApiInoutData param) {
+ return result.getMessage();
+ }catch (Exception e){
+ log.error(e.getMessage(),e);
+ return "ERROR";
+ }
- return "SUCCESS";
}
@@ -159,13 +202,14 @@
public static void main(String[] args) {
-// try{
+ try{
// String str1 = "璁稿浆",str2="绮123456",str3 = "3鍙蜂粨" ,str4 = "灏忛害",str5="286000",str6 = "30000",str7 ="鍚堟牸";
-// String test = "鎴戠埍涓埅杞欢";
-// //78340100290000000000000000 1400 0B00 01 02 00 01 0C 00
-// String start = "FFFFFFFFFF00000000";
+// String test = "120000.0";
+// //FF FF FF FF FF FF 00 00 00 00 78 34 01 00 29 BC FD 00 00 00 00 00 00 14 00 11 00 01 02 06 01 0C 00 CE D2 B0 AE D6 D0 BA BD C8 ED BC FE 87 1F A5
+// String start = "FFFFFFFFFFFF00000000";
// String lengh = BytesUtil.tran_LH(BytesUtil.intToHexStr(8+(test.length() * 2)));
-// String msg = "78340100290000000000000000" + lengh+ "0B00010201010C00";
+// String lengh2 = BytesUtil.tran_LH(BytesUtil.intToHexStr((test.length() * 2)));
+// String msg = "78340100290000000000000000" + lengh+ "100001020101" + lengh2;
// msg = msg + convertStr(test);
// msg = msg.toUpperCase();
//
@@ -178,26 +222,61 @@
// msg += "A5";
// msg = start +msg;
// System.out.println(msg);
-// }catch (Exception e){
-// e.printStackTrace();
-// }
+ }catch (Exception e){
+ e.printStackTrace();
+ }
- Map<String,Object> message = new HashMap<>();
- message.put("cmd",226);
- message.put("orderId","5009");
- message.put("result","0");
- message.put("sign","0000");
- message.put("stNum",100);
- message.put("version","V1.0000000");
- Map<String,Object> content = new HashMap<>();
- content.put("value",new Integer[]{0,1});
- content.put("LEDValue",new Integer[]{0,1});
- message.put("content", content);
- System.out.println(JSON.toJSONString(message));
+// Map<String,Object> message = new HashMap<>();
+// message.put("cmd",226);
+// message.put("orderId","5009");
+// message.put("result","0");
+// message.put("sign","0000");
+// message.put("stNum",100);
+// message.put("version","V1.0000000");
+// Map<String,Object> content = new HashMap<>();
+// content.put("value",new Integer[]{0,1});
+// content.put("LEDValue",new Integer[]{0,1});
+// message.put("content", content);
+// System.out.println(JSON.toJSONString(message));
+
+
+ IoMessage message = JSON.parseObject("{Cmd:120}",IoMessage.class);
+ System.out.println(message.getCmd());
}
+ /**
+ *
+ * @param s 瀛楃涓�
+ * @param id 0B00 瀛楃ID
+ * @return
+ */
+ public static String getMsg(String s ,String id){
+ try{
+ // String str1 = "璁稿浆",str2="绮123456",str3 = "3鍙蜂粨" ,str4 = "灏忛害",str5="286000",str6 = "30000",str7 ="鍚堟牸";
+ String test = s;
+ //FF FF FF FF FF FF 00 00 00 00 78 34 01 00 29 BC FD 00 00 00 00 00 00 14 00 11 00 01 02 06 01 0C 00 CE D2 B0 AE D6 D0 BA BD C8 ED BC FE 87 1F A5
+ String start = "FFFFFFFFFFFF00000000";
+ String lengh = BytesUtil.tran_LH(BytesUtil.intToHexStr(8+(test.length() * 2)));
+ String lengh2 = BytesUtil.tran_LH(BytesUtil.intToHexStr((test.length() * 2)));
+ String msg = "78340100290000000000000000" + lengh+ id+"01020101" + lengh2;
+ msg = msg + convertStr(test);
+ msg = msg.toUpperCase();
+// String t = "78 34 01 00 29 BC FD 00 00 00 00 00 00 14 00 01 00 01 02 06 01 0C 00 CE D2 B0 AE D6 D0 BA BD C8 ED BC FE";
+// t = t.replaceAll(" ","");
+ String check = BytesUtil.tran_LH(BytesUtil.intToHexStr(CRC16.calcCrc16(BytesUtil.hexStrToBytes(msg))));
+ System.out.println(check);
+ msg+=check;
+ msg += "A5";
+ msg = start +msg;
+ //log.info(msg);
+ return msg;
+ }catch (Exception e){
+ log.error(e.getMessage(),e);
+ return " ";
+ }
+ }
//hexToBytes鏂规硶锛氬崄鍏繘鍒跺瓧绗︿覆杞琤yte[]锛岀綉涓婂緢澶�
//getRepair0鏂规硶锛氳ˉ0鐨勶紝寰堢畝鍗曪紝鑷繁瀹炵幇鍚�
@@ -210,20 +289,36 @@
* @throws UnsupportedEncodingException
*/
public static String convertStr(String msg) throws Exception {
- //鍏堟妸瀛楃涓叉寜gb2312杞垚byte鏁扮粍
- byte[] bytes = msg.getBytes("gb2312");
StringBuilder gbString = new StringBuilder();
-
- for (byte b : bytes)
- {
- // 鍐嶇敤Integer涓殑鏂规硶锛屾妸姣忎釜byte杞崲鎴�16杩涘埗杈撳嚭
- String temp = Integer.toHexString(b);
- //鍒ゆ柇杩涜鎴彇
- if(temp.length()>=8){
- temp = temp.substring(6, 8);
+ String t = null;
+ char[] chars = msg.toCharArray();
+ String s= "";
+ for(int i=0;i<chars.length;i++){
+ t = "";
+ s = msg.substring(i,i+1);
+ //鍏堟妸瀛楃涓叉寜gb2312杞垚byte鏁扮粍
+ byte[] bytes = s.getBytes("gb2312");
+ for (byte b : bytes)
+ {
+ // 鍐嶇敤Integer涓殑鏂规硶锛屾妸姣忎釜byte杞崲鎴�16杩涘埗杈撳嚭
+ String temp = Integer.toHexString(b);
+ //鍒ゆ柇杩涜鎴彇
+ if(temp.length()>=8){
+ temp = temp.substring(6, 8);
+ }
+ t +=(temp);
}
- gbString.append(temp);
+ if(t.length()<4){
+ for (int k =0;k<4;k++){
+ if(t.length()<4){
+ t = "0"+t;
+ }
+ }
+ }
+ gbString.append(t);
}
+
return gbString.toString();
}
+
}
--
Gitblit v1.9.3