|
|
@@ -0,0 +1,176 @@
|
|
|
+package com.zd.laboratory.utils;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @time2022-10-28
|
|
|
+ * @author 董高升
|
|
|
+ * @descprition 该类用于通过传参获取动态指令,进行状态查询,当收到状态火警的时候给传感器信号
|
|
|
+ */
|
|
|
+public class FireLaborUtil {
|
|
|
+ //功能码
|
|
|
+ private static final String FUNCTION_CODE="03";
|
|
|
+ //起始地址高字节
|
|
|
+ private static final String START_HIGN_CODE="00";
|
|
|
+ //起始地址低字节
|
|
|
+ private static final String END_HIGN_CODE="00";
|
|
|
+ //36个寄存器查询地址
|
|
|
+ private static final String All_REGISTER="00 24";
|
|
|
+
|
|
|
+ //private static final String
|
|
|
+
|
|
|
+
|
|
|
+ public static final Map<String, String> statusMap = new HashMap<String, String>();
|
|
|
+ static {
|
|
|
+ statusMap.put("00","无事件");
|
|
|
+ statusMap.put("01","火警");
|
|
|
+ statusMap.put("02","故障");
|
|
|
+ statusMap.put("03","动作");
|
|
|
+ statusMap.put("05","启动");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 静态map,用于存储 寄存器状态说明
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public static final Map<Integer, String> myMap_0 = new HashMap<Integer, String>();
|
|
|
+ static {
|
|
|
+ myMap_0.put(1, "01 02");
|
|
|
+ myMap_0.put(2, "03 04");
|
|
|
+ myMap_0.put(3, "05 06");
|
|
|
+ myMap_0.put(4, "07 08");
|
|
|
+ myMap_0.put(5, "09 10");
|
|
|
+ myMap_0.put(6, "11 12");
|
|
|
+ myMap_0.put(7, "13 14");
|
|
|
+ myMap_0.put(8, "15 16");
|
|
|
+ myMap_0.put(9, "17 18");
|
|
|
+ myMap_0.put(10, "19 20");
|
|
|
+ myMap_0.put(11, "21 22");
|
|
|
+ myMap_0.put(12, "23 24");
|
|
|
+ myMap_0.put(13, "25 26");
|
|
|
+ myMap_0.put(14, "27 28");
|
|
|
+ myMap_0.put(15, "29 30");
|
|
|
+ myMap_0.put(16, "31 32");
|
|
|
+ myMap_0.put(17, "33 34");
|
|
|
+ myMap_0.put(18, "35 36");
|
|
|
+ myMap_0.put(19, "37 38");
|
|
|
+ myMap_0.put(20, "39 40");
|
|
|
+ myMap_0.put(21, "41 42");
|
|
|
+ myMap_0.put(22, "43 44");
|
|
|
+ myMap_0.put(23, "45 46");
|
|
|
+ myMap_0.put(24, "47 48");
|
|
|
+ myMap_0.put(25, "49 50");
|
|
|
+ myMap_0.put(26, "51 52");
|
|
|
+ myMap_0.put(27, "53 54");
|
|
|
+ myMap_0.put(28, "55 56");
|
|
|
+ myMap_0.put(29, "57 58");
|
|
|
+ myMap_0.put(30, "59 60");
|
|
|
+ myMap_0.put(31, "61 62");
|
|
|
+ myMap_0.put(32, "63 64");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 主机地址位
|
|
|
+ * @param addressBit
|
|
|
+ * @return
|
|
|
+ * 动态获取主机状态指令
|
|
|
+ * 寄存器地址
|
|
|
+ */
|
|
|
+ public static String getFireActiveOrder(Integer addressBit){
|
|
|
+ String activeCode="";
|
|
|
+ String coverCode=coverCode(addressBit);
|
|
|
+ activeCode=coverCode+" "+FUNCTION_CODE+" "+START_HIGN_CODE+" "+END_HIGN_CODE+" "+All_REGISTER+" ";
|
|
|
+ String disposeCode=activeCode.replace(" ","");
|
|
|
+ String crcCode=CRCCHECK.getCRC16Result(disposeCode);
|
|
|
+ activeCode+=crcCode;
|
|
|
+ return activeCode;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static JSONObject getFireStatus(String returnCode){
|
|
|
+ boolean fireStatus=false;
|
|
|
+ String msg="";
|
|
|
+ int fireNumber=0;
|
|
|
+ String returnCodes="02 03 48 00 00 00 00 02 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0A 00 00 00 40 3D ";
|
|
|
+ returnCodes=returnCodes.replace(" ","");
|
|
|
+ System.out.println("returnCodes length:"+returnCodes.length());
|
|
|
+ String registerCode=returnCodes.substring(6,returnCodes.length()-20);
|
|
|
+ System.out.println("registerCode:"+registerCode);
|
|
|
+ String mainCode=returnCodes.substring(134,returnCodes.length()-4);
|
|
|
+ System.out.println("mainCode:"+mainCode);
|
|
|
+ List<String> registerCodeList=parseArrayList(registerCode);
|
|
|
+ Set<String> statusSet=statusMap.keySet();
|
|
|
+ if(registerCodeList.contains("01")){
|
|
|
+ fireStatus=true;
|
|
|
+ }
|
|
|
+ for(int i=0;i<registerCodeList.size();i++){
|
|
|
+ String code=registerCodeList.get(i);
|
|
|
+ if(code.equals("01")){
|
|
|
+ fireNumber++;
|
|
|
+ }
|
|
|
+ for(String set:statusSet){
|
|
|
+ if(!registerCodeList.get(i).equals("00") && registerCodeList.get(i).equals(set)){
|
|
|
+ msg+="NO:"+(i+1)+"号设备"+statusMap.get(set)+" ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<String> mainCodeList=parseArrayList(mainCode);
|
|
|
+ JSONObject jsonObject=new JSONObject();
|
|
|
+ if(mainCodeList.get(0).equals("05")){
|
|
|
+ jsonObject.put("startSpray","1");
|
|
|
+ }else{
|
|
|
+ jsonObject.put("startSpray","0");
|
|
|
+ }
|
|
|
+ if(mainCodeList.get(1).equals("03")){
|
|
|
+ jsonObject.put("gasSpray","1");
|
|
|
+ }else{
|
|
|
+ jsonObject.put("gasSpray","0");
|
|
|
+ }
|
|
|
+ jsonObject.put("fireNumber",fireNumber);
|
|
|
+ jsonObject.put("fireStatus",fireStatus);
|
|
|
+ jsonObject.put("msg",msg);
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 主机地址位
|
|
|
+ * @param addressBit
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static String coverCode(Integer addressBit){
|
|
|
+ if(addressBit>=10){
|
|
|
+ return String.valueOf(addressBit);
|
|
|
+ }
|
|
|
+ return String.format("%0"+2+"x", Integer.valueOf(addressBit));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析数据为数组状态
|
|
|
+ * @return
|
|
|
+ * returnCode返回数据
|
|
|
+ */
|
|
|
+ /**
|
|
|
+ * 存放16进制字符串,字符串2为 2为存
|
|
|
+ * @param hexString
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<String> parseArrayList(String hexString){
|
|
|
+ List<String> strings = new ArrayList<>();
|
|
|
+ for (int i = 0; i < hexString.length()/2; i++){
|
|
|
+ int index = i * 2;
|
|
|
+ String var = hexString.substring(index,index+2);
|
|
|
+ strings.add(var);
|
|
|
+ }
|
|
|
+ return strings;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ boolean fireStatus=false;
|
|
|
+ String msg="";
|
|
|
+ System.out.println(getFireActiveOrder(2));
|
|
|
+ JSONObject jsonObject=getFireStatus("0");
|
|
|
+ System.out.println(jsonObject.toJSONString());
|
|
|
+ }
|
|
|
+}
|