wenzheng.yang
2023-06-19 8d3a46d346ef028acc16e267fe5c812c76a754e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package baowen;
import java.math.BigInteger;
import frame.Index1;
import publicclass.GetNowTime;
public class Dell_55AA01 {
    static String baotou;//°üÍ· 0x55AA 
    static String zhilingtype;//Ö¸ÁîÀàÐÍ0x01Õý³£Ä£Ê½£»0x02ÐÄÌø°ü
    static String lenth;//Êý¾Ý³¤¶È17 1BYTE
    static String xuhao;//ÐòºÅ 1BYTE
    static String tagid;//±êÇ©id 2BYTE
    static String anchorid;//»ùÕ¾id
    static String distance10;//10½øÖƾàÀë
    static String power;//µçÁ¿
    static String button;//°´¼ü
    static String baoliu;//±£Áô
    static String distanceMessage;//ʵʱ¾àÀëÐÅÏ¢
    static String zhiling01="01";//Ö¸ÁîÀàÐÍ01´ú±íÕý³£Ä£Ê½
    static String zhiling02="02";//Ö¸ÁîÀàÐÍ02´ú±íÐÄÌø°ü
    static String zhiling03="03";//Ö¸ÁîÀàÐÍ03´ú±í²ÎÊý¶Áдģʽ
    static String zhiling="";
    static String  hexshow="";
    static String sudu="";
    static String baistart;//°×Ãûµ¥ÆðʼID
    static String baistop;//°×Ãûµ¥ÖÕÖ¹ID
    static String gujiantype;//¹Ì¼þÀàÐÍ
    static int f4gj=0;//¹Ì¼þÀàÐÍ
    static String tag_state;//±êÇ©¼¤»î״̬
    static StringBuffer data=new StringBuffer();
 
 
    static int info_lenth=0;
 
    static boolean succpeizhi=false;
 
 
    public static void dell55aa01_start(String message,String ip,int port) {
        if(!message.startsWith("55AA01")) {
            return;
        }
        message=message.replaceAll("\r\n|\r|\n", "");//È¡³öËùÓГQÐкͻسµ
        String[] aa0=message.split("55AA");
        int size=aa0.length;
        for(int i=0;i<size;i++) {
            String info="55AA"+aa0[i];
            dell55AA01(info,ip,port);
        }
    }
 
    /**´¦Àí55AA01¿ªÍ·µÄ²â¾àÐÅÏ¢
     * 55 AA 01 11 AF 01 00 05 00 10 02 00 00 64 00 00 00 00 00 C2 FE
     */
    public static void dell55AA01(String infom,String ip,int port) {
        int timestamp=GetNowTime.timestamp();
        String intime=GetNowTime.timestamp2();
        int lenth1=infom.length()/2;
        if(lenth1>10) {
            int size=lenth1;
            //½«ÐÅÏ¢2¸ö×Ö·û1λ±£´æÔÚÊý×éÖÐ
            String[] hex=new String[size];
            for(int i=0;i<size;i++) {
                hex[i]=infom.substring(i*2, 2+i*2);
            }
            //Ö¸ÁîÀàÐÍ
            zhilingtype=hex[2];
            if(!zhilingtype.equals("01")) {
                return;
            }
            //Êý¾Ý³¤¶È
            int datalen=decodeHEX(hex[3])+4;
            lenth= String.valueOf(decodeHEX(hex[3]));
            if(datalen==lenth1) {        
                //°üÐò
                xuhao=String.valueOf(decodeHEX(hex[4]));
                //Ä£¿éID tagid
                tagid=hex[6]+hex[5];    
                //Ä£¿éID anchorid
                anchorid=hex[8]+hex[7];
                /**²â¾à¾àÀë*/
                int dis=decodeHEX(hex[12]+hex[11]+hex[10]+hex[9]);
                distance10=String.valueOf(dis);
 
                /**µçÁ¿*/
                power=String.valueOf(decodeHEX(hex[13]));
 
                /**°´¼ü*/
                button=String.valueOf(decodeHEX(hex[14]));
 
                /**±£Áôλ*/
                baoliu=String.valueOf(decodeHEX(hex[15]));
                showdata();        
            }else {
                Dell_uanshi_byt.intsert(ip,infom,intime, timestamp,port);
            }
            hex=null;
        }else {
            Dell_uanshi_byt.intsert(ip,infom,intime, timestamp,port);
        }
        
 
    }
 
 
    /**±¨ÎÄÏÔʾµ÷ÓÃ*/
    public static void showdata() {
        if(Index1.getTagid().equals("ԭʼÊý¾Ý")) {
            return;
        }
        if(Index1.isShoware()) {
            data.append("ID:"+tagid+",");
            data.append("°üÐò:"+xuhao+",");
            data.append("µçÁ¿:"+power+",");
            data.append("±àºÅ:"+anchorid+",");
            data.append("¾àÀë:"+distance10);            
            String as=data.toString();    
            if(Index1.getTagid().equals("0")) {
                Index1.ara_show(as);
            }else {
                if(Index1.getTagid().equals(tagid)) {
                    Index1.ara_show(as);
                }
            }            
            data.setLength(0);
        }
 
    }
 
    public static String get_realldistance() {
        return distanceMessage;
    }
 
    /**16½øÖÆ×ªÎª10½øÖÆ*/
    public static int decodeHEX(String hexs){
        BigInteger bigint=new BigInteger(hexs, 16);
        int numb=bigint.intValue();
        return numb;
 
    }
 
    /**32½øÖÆ×ªÎª10½øÖÆ*/
    public static String change32To10(String num) {
        int f=32;
        int t=10;
        return new java.math.BigInteger(num, f).toString(t);
    }
 
 
    /** 
     * ½«byte[]תΪ¸÷ÖÖ½øÖƵÄ×Ö·û´® 
     * @param bytes byte[] 
     * @param radix »ùÊý¿ÉÒÔת»»½øÖƵķ¶Î§£¬´ÓCharacter.MIN_RADIXµ½Character.MAX_RADIX£¬³¬³ö·¶Î§ºó±äΪ10½øÖÆ 
     * @return ×ª»»ºóµÄ×Ö·û´® 
     */ 
    public static String binary(byte[] bytes, int radix){  
        return new BigInteger(1, bytes).toString(radix);// ÕâÀïµÄ1´ú±íÕýÊý  
    } 
 
 
    private static final char[] HEXES = {
            '0', '1', '2', '3',
            '4', '5', '6', '7',
            '8', '9', 'a', 'b',
            'c', 'd', 'e', 'f'
    };
 
    /**
     * byteÊý×é ×ª»»³É 16½øÖÆÐ¡Ð´×Ö·û´®
     */
    public static String bytes2Hex(byte[] bytes) {
        if (bytes == null || bytes.length == 0) {
            return null;
        }
 
        StringBuilder hex = new StringBuilder();
 
        for (byte b : bytes) {
            hex.append(HEXES[(b >> 4) & 0x0F]);
            hex.append(HEXES[b & 0x0F]);
        }
 
        return hex.toString();
    }
 
 
 
 
 
    /**½ØÈ¡Ö¸¶¨³¤¶ÈµÄBYTEÊý×é
     * @param srcÔ­×Ö½ÚÊý×é
     * @param ¿ªÊ¼Î»ÖÃ
     * @param ½ØÈ¡³¤¶È*/
    public static byte[] subBytes(byte[] src, int begin, int count) {
        byte[] bs = new byte[count];
        System.arraycopy(src, begin, bs, 0, count);
        return bs;
    }
 
    
    public static String[] hex(String message) {
        int size=message.length()/2;        
        String[] hex=new String[size];
        for(int i=0;i<size;i++) {
            hex[i]=message.substring(i*2, 2+i*2);
        }
 
        return hex;
    }
 
}