zsh_root
2024-01-02 7b595546af704983dbafcd0d385c8768ddacefc2
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
package BaoWen;
import java.math.BigInteger;
import java.util.Vector;
import Frame.TcpIpManage;
import Judge.JugeNumber;
import Method.GetNowTime;
import Method.StringToHex;
import PbuliClass.ShowMessage;
import Tag_Ceju.Ceju;
import Tag_Ceju.Dell_Ceju;
import anchor.Anchor;
import anchor.Anchor_Dell;
import buju.dell_buju;
import jiekou.Warnig;
import person.Person;
import person.person_Dell;
import tag.Tag;
import tag.Tag_Dell;
import tbDataModel_Dell.Dell_tb_suanfa2;
 
public class DellMessage {
 
    static Vector<String> vector=new Vector<>();
 
    private static String hexStr =  "0123456789ABCDEF";  
    private static String[] binaryArray =   
        {"0000","0001","0010","0011",  
                "0100","0101","0110","0111",  
                "1000","1001","1010","1011",  
                "1100","1101","1110","1111"}; 
 
 
    @SuppressWarnings("unused")
    /**´¦Àíԭʼ²â¾àÐÅÏ¢*/
    public static  void dell_info(String ip,String infom,String addtime,int timestamp,int port) {
 
        if(infom.startsWith("55AA01")) {            
            String[] hex=StringToHex.hex(infom);//ԭʼÊý¾Ý            
            String zhilingtype=hex[2] ;//Ö¸ÁîÀàÐÍ            
            String lenth= String.valueOf(decodeHEX(hex[3]));//Êý¾Ý³¤¶È            
            String receive_baoxu=String.valueOf(decodeHEX(hex[4]));//°üÐò            
            String receive_tagid=hex[6]+hex[5];//Ä£¿éID receive_tagid            
            String receive_anchorid=hex[8]+hex[7];//Ä£¿éID receive_anchorid            
            Anchor ac=Anchor_Dell.get_anchor(receive_anchorid);            
            int receive_distance=decodeHEX(hex[12]+hex[11]+hex[10]+hex[9]);
            String distance=String.valueOf(receive_distance);//¾àÀë            
            String battery=String.valueOf(decodeHEX(hex[13]));//µçÁ¿
            int batteryint=decodeHEX(hex[13]);
 
            //°´¼ü
            String button=bytes2BinaryStr(HexStringToBinary(hex[14])).substring(7, 8);
 
            //±êÇ©¾²Ö¹
            String jingzhi=bytes2BinaryStr(HexStringToBinary(infom.substring(28, 30))).substring(6, 7);
 
            //±êÇ©ÐÝÃß
            String xiumian=bytes2BinaryStr(HexStringToBinary(infom.substring(28, 30))).substring(5, 6);
 
 
            //ÐźÅÇ¿¶È1
            String Strong1="-"+decodeHEX(hex[15]);
 
            //ÐźÅÇ¿¶È²î
            String Strong2="-"+decodeHEX(hex[16]);
 
            //±êǩƵÂÊ
            String taghz=String.valueOf(decodeHEX(hex[17]));
 
            int int_taghz=decodeHEX(hex[17]);
 
            //±êǩʱ¼äƬ
            String time_pian=String.valueOf(decodeHEX(hex[18]));
 
            //ÏÔʾ°´¼ü°´ÏµÄÐÅÏ¢
            if(button.toString().equals("1")) {
                ShowMessage.zidingyi(GetNowTime.now2()+": "+receive_tagid+" °´¼ü°´ÏÂ"+button);
            }
            Tag tag=Tag_Dell.get_tag(receive_tagid);
 
            //µÍµçÁ¿¸æ¾¯
            //    Tag_Dell.alert_tag_low_power(receive_tagid.toString(), batteryint);
 
            //±êÇ©±»²ð³ý
            String tagoff="0";
 
            if(TcpIpManage.getStar()) {
                StringBuffer data=new StringBuffer(GetNowTime.now()+":"+"ÊÕ:"+ip+":"+port+",°üÐò:"+receive_baoxu+",±êÇ©:"
                        +receive_tagid+",»ùÕ¾:"+receive_anchorid
                        +",¾àÀë:"+receive_distance+",µçÁ¿:"+battery+"%"+",°´¼ü:"+button+",¾²Ö¹:"
                        +jingzhi+",ÐÝÃß:"+xiumian+",ÐźÅÇ¿¶È1:"+Strong1+",ÐźÅÇ¿¶È2:"+Strong2+",ƵÂÊ:"+taghz+",ʱ¼äƬ:"+time_pian);
                if(TcpIpManage.getDatatypeis().equals("±¨ÎÄÊý¾Ý")) {//ÏÔʾ×Ö·û´®¸ñʽ
                    if(TcpIpManage.getNeed_guo_lv_tag().equals("Ñ¡Ôñ±êÇ©")) {
                        TcpIpManage.get_text_area().append(data+"\n");
                    }else  if(receive_tagid.toString().equals(TcpIpManage.getNeed_guo_lv_tag())){
                        TcpIpManage.get_text_area().append(data+"\n");
                    }
                }else if(TcpIpManage.getDatatypeis().equals("HEXÏÔʾ")) {
                    TcpIpManage.get_text_area().append("ÊÕ:"+ip+":"+port+","+infom+","+addtime+"\n");
                }
                TcpIpManage.get_text_area().setCaretPosition(TcpIpManage.get_text_area().getText().length());
                data.setLength(0);
            }
 
            Person person=person_Dell.get_Person(receive_tagid);
            if(person==null || ac==null) {
                return;    
            }
            /**SOS¸æ¾¯**/
            Warnig.sos(tag,tagoff,button, jingzhi, xiumian, receive_tagid, addtime, receive_baoxu,person);
 
            //¸üлùվ״̬ΪÔÚÏß
            Anchor_Dell.set_anchor_mode(ac,receive_anchorid,ip,port);
 
            //¸ü¸Ä±êÇ©µÄ״̬ºÍµçÁ¿ÐÅÏ¢
            Tag_Dell.set_tagpower(receive_tagid, battery);
 
            //Ð޸ıêÇ©µÄÈËÔ±µÄSOS״̬
            person_Dell.alert_sos(receive_tagid, button);
 
            //ÐÞ¸ÄÈËÔ±µÄµçÁ¿ÐÅÏ¢,
            person_Dell.alert_person_power(receive_tagid, battery,receive_anchorid);
 
            //Ð޸IJ½¾àÐÅÏ¢
            if(dell_buju.getBuju_vector().size() !=0) {
                dell_buju.alert(receive_anchorid, receive_tagid, receive_distance);
            };
            person.setHave_uwbxinhao(1);//2023.07.12 zsh
            //½«Êý¾Ý¸øµ½JNA¶¯Ì¬¿â´¦Àí    
            dellforJNA(
                    ip,//ip
                    receive_baoxu, //°üÐò
                    receive_tagid, //±êÇ©ID
                    receive_anchorid, //»ùÕ¾ID
                    distance,//²â¾à¾àÀë
                    jingzhi,//¾²Ö¹×´Ì¬
                    "0",//ÐźÅÇ¿¶È
                    timestamp,//ʱ¼ä´Á
                    button,//SOSÇé¿ö
                    battery,//µçÁ¿
                    ac.getAnc_floor(),//²ã
                    Strong1,//µÚ1·ÐźÅÇ¿¶È
                    Strong2,//µÚ2·ÐźÅÇ¿¶È
                    int_taghz//±êÇ©µÄƵÂÊ
                    );
        }
 
 
    }
 
 
 
 
 
    /**Êý¾Ý¸øµ½JNA´¦Àí
     * @param receive_baoxu½ÓÊÕµ½µÄ°üÐò
     * @param receive_tagid½ÓÊÕµ½µÄ±êÇ©id
     * @param receive_anchorid½ÓÊÕµ½µÄ»ùÕ¾id¼¯ºÏ
     * @param receive_distance½ÓÊÕµ½µÄ¾àÀ뼯ºÏ
     * @param stationary_flag ¾²Ö¹×´Ì¬
     * @param signal_powerÐźÅÇ¿¶È
     * @param timestampʱ¼ä´Á
     * @param int_taghz±êÇ©µÄƵÂÊ
     * @param button SOS״̬*/
    public static  void dellforJNA(
            String ip,
            String receive_baoxu,
            String receive_tagid,
            String receive_anchorid,
            String receive_distance,
            String stationary_flag,
            String signal_power,
            int timestamp,
            String sos,
            String battery,
            String layer,
            String power,
            String power_diff,
            int int_taghz
            ) {
 
        Ceju cej=new Ceju();        
        cej.setCe_baoxu(receive_baoxu);        
        cej.setCe_ip(ip);
        cej.setCe_tagid(receive_tagid);
        cej.setCe_timestamp(timestamp);
        cej.setCe_anchorid(receive_anchorid);
        cej.setCe_distance(receive_distance);
        cej.setCe_battery(battery);//µçÁ¿
        cej.setCe_power(power);
        cej.setCe_power_diff(power_diff);
        cej.setCe_taghz(int_taghz);
        cej.setCe_jingzhi(stationary_flag);    
        cej.setCe_button(sos);
        Dell_Ceju.dell_ceju(ip,receive_tagid,cej,Integer.parseInt(receive_baoxu),receive_anchorid);
 
    }
 
 
    /**16½øÖÆ×ªÎª10½øÖÆ*/
    public static int decodeHEX(String hexs){
        String hex=hexs.trim();
        boolean a=JugeNumber.isLetterDigit(hex);
        int numb=0;
        if(a) {
            BigInteger bigint=new BigInteger(hex,16);
            numb=bigint.intValue();
        }else {
            ShowMessage.zidingyi("16½øÖÆ×ª10½øÖƳö´í,ÊÕµ½£º"+hex);
        }
        return numb;
 
    }
 
    /**32½øÖÆ×ªÎª10½øÖÆ*/
    public static String change32To10(String num) {
        int f=32;
        int t=10;
        return new 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;
    }
 
 
    /** 
     *  
     * @param hexString 
     * @return ½«Ê®Áù½øÖÆ×ª»»Îª×Ö½ÚÊý×é 
     */  
    public static byte[] HexStringToBinary(String hexString){  
        //hexStringµÄ³¤¶È¶Ô2È¡Õû£¬×÷ΪbytesµÄ³¤¶È  
        int len = hexString.length()/2;  
        byte[] bytes = new byte[len];  
        byte high = 0;//×Ö½Ú¸ßËÄλ  
        byte low = 0;//×Ö½ÚµÍËÄλ  
 
        for(int i=0;i<len;i++){  
            //ÓÒÒÆËÄλµÃµ½¸ßλ  
            high = (byte)((hexStr.indexOf(hexString.charAt(2*i)))<<4);  
            low = (byte)hexStr.indexOf(hexString.charAt(2*i+1));  
            bytes[i] = (byte) (high|low);//¸ßµØÎ»×ö»òÔËËã  
        }  
        return bytes;  
    }  
 
    /** 
     *  
     * @param str 
     * @return ×ª»»Îª¶þ½øÖÆ×Ö·û´® 
     */  
    public static String bytes2BinaryStr(byte[] bArray){  
 
        String outStr = "";  
        int pos = 0;  
        for(byte b:bArray){  
            //¸ßËÄλ  
            pos = (b&0xF0)>>4;  
            outStr+=binaryArray[pos];  
            //µÍËÄλ  
            pos=b&0x0F;  
            outStr+=binaryArray[pos];  
        }  
        return outStr;  
 
    }
 
 
 
    public static Vector<String> getVector() {
        return vector;
    }
 
    /**±£´æ±¨ÎÄyang20230725±¨Îı¨ÎÄÊý¾Ý*/
    public static void save_log(String message) {
        if(Dell_tb_suanfa2.isJnalog_open()){
        vector.add(message);//yang20230725±¨Îı¨ÎÄÊý¾Ý
        }
    }
    
}