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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
package BaoWen;
import java.util.Vector;
import Frame.SystemSet;
import Frame.TagReaLocation;
import Frame.Tagstate;
import Frame.TcpIpManage;
import JNADell.DellJAN;
import Method.BaoWenShow;
import Method.ControTag;
import Method.GetNowTime;
import Method.JugeHaveZimu;
import Method.StringToHex;
import PbuliClass.Shi_jian_cha_sss;
import PbuliClass.ShowMessage;
import PbuliClass.Systems;
import ToolBarS.ToolBarModel;
import anchor.Anchor;
import anchor.Anchor_Dell;
import home.ChuShiHua;
import person.Person;
import person.person_Dell;
import tag.Tag;
import tag.Tag_Dell;
import tbDataModel_Dell.ReadPeizhiMessage;
import tbDataModel_Dell.Read_Write_Anchor_Message;
/**´¦Àí±êÇ©µÄ×¢²áÐÅÏ¢¼¯ºÏ*/
public class Dell_55AA0A  {
    //±êǩע²á¶ÔÏóµÄ¼¯ºÏ
    static int zhiding=SystemSet.getZhuceanchor().length();
    static boolean busy=false;
    static int bj=0;
    static Vector<Person> shijianpianvc=new Vector<Person>();//ʱ¼äƬµÄ¼¯ºÏ
    static Person person;
    static String tagid;
    static String anchorid;
    static int hz;
    static int power;//ÐźÅÇ¿¶È
    static String tagstate;        
    static String move_open;//¿ªÆôÕñ¶¯01        
    static String sleep_open;//¿ªÆôÐÝÃß01        
    static String button;//°´¼ü״̬01±íʾ°´Ï        
    static String version;//±êÇ©°æ±¾ºÅ
    static int gonglv;//±êÇ©µÄ¹¦ÂÊ            
    static int speed;//±êÇ©µÄ¼ÓËÙ¼ÆãÐÖµ            
    static int sleep_time;//±êÇ©¾²Ö¹ÐÝÃßʱ¼ä
    static int gas;
    /**´¦Àí×¢²áÐÅÏ¢
     * Ö¸ÁîÀàÐÍ0x0A
     * Êý¾Ý¶Î³¤¶È20
     * »ùÕ¾ID£¨2BYTE£©    
     * ±êÇ©ID£¨2BYTE£©;6,7    
     * ±êǩ״̬£¨1BYTE£©;8
     * µÚһλ£ºÕð¶¯Ê¹ÄÜ;
     * µÚ¶þλ£ºÐÝÃßʹÄÜ;
     * µÚÈýλ£º°´¼ü״̬;
     * ±êÇ©°æ±¾ºÅ£¨2BYTE£©;9,10
     * ±êǩƵÂÊ£¨1BYTE£©;    11
     * ±êÇ©¹¦ÂÊ£¨1BYTE£©;    12
     * ±êÇ©¼ÓËÙ¼ÆãÐÖµ£¨2BYTE£©;13,14    
     * ±êÇ©¾²Ö¹ÐÝÃßʱ¼ä£¨2BYTE£©    ;15,16
     * ÐźÅÇ¿¶È£¨1BYTE£©;    17
     * ÆøÑ¹²Î¿¼»ùÕ¾ID£¨2BYTE£©;18,19
     * */
    public static void dellrgs(String infom,String ip,int port) {
        BaoWenShow.show(infom, "55AA0A","");
        String[] hex=StringToHex.hex(infom);
        anchorid=hex[5]+hex[4];
        tagid=hex[7]+hex[6];
        hz=get_value(hex[11]);//±êÇ©µÄƵÂÊ
        tagstate=DellMessage.bytes2BinaryStr(DellMessage.HexStringToBinary(hex[8]));        
        move_open=tagstate.substring(7,8);//¿ªÆôÕñ¶¯01        
        sleep_open=tagstate.substring(6,7);//¿ªÆôÐÝÃß01        
        button=tagstate.substring(5,6);//°´¼ü״̬01±íʾ°´Ï        
        version=get_versoin(hex[10],hex[9]);//±êÇ©°æ±¾ºÅ
        gonglv=get_value(hex[12]);//±êÇ©µÄ¹¦ÂÊ            
        speed=get_value((hex[14]+hex[13]));//±êÇ©µÄ¼ÓËÙ¼ÆãÐÖµ            
        sleep_time=get_value((hex[16]+hex[15]));//±êÇ©¾²Ö¹ÐÝÃßʱ¼ä            
        power=get_value((hex[17]));//±êÇ©ÐźÅÇ¿¶È    
        gas= Integer.valueOf(hex[19]+hex[18], 16).shortValue();//ÆøÑ¹¼ÆÖµ
        show_baowen(tagstate,move_open,sleep_open,version,gonglv,speed,sleep_time);//ÏÔʾ±¨ÎÄ
        Tag_Dell.alert_tag(tagid,version, move_open, sleep_open, button,gonglv,speed,sleep_time,power,gas);
        have_person_do();
        have_anchor_do(ip,port);
        get_dell_hz();//´¦ÀíÆµÂÊ´óÓÚ20HzµÄÎÊÌâ
        have_tag_do();    
    }
 
 
    /**ѰÕÒÓÐЧµÄ×¢²áÐÅÏ¢¸øµ½JNA´¦Àí*/
    public static void  get_ok_regs() {    
        if (Systems.isZidongshijianpian()) {//Èç¹û¿ªÆô×Ô¶¯Ê±¼äƬģʽ
            return;
        }
        Vector<Person> needpianvc=person_Dell.needpianvc();
        int size=needpianvc.size();
        if(size!=0) {
            for(int i=0;i<size;i++) {
                Person  person=needpianvc.get(i);
                String tagid=person.getP_tagid();
                int  tagidint=Integer.parseInt(tagid,16);
                int timestamp=person.getAskpiantime();
                int tag_freq=person.getRealhz();                            
                String anchorid=person.getZhuceanchor();
                Anchor anchor=Anchor_Dell.get_anchor(anchorid);    
                int shijianpian=DellJAN.get_slotted_aloha(timestamp, tagidint, tag_freq);//Ë÷ȡʱ¼äƬ
                String a="·ÖƬ£º"+tagid+"£¬ÆµÂÊ"+tag_freq+"£¬¸ø»ùÕ¾"+anchorid+",Ƭ"+shijianpian;                
                boolean b1=false;
                if(shijianpian>-1) {
                    getShijianpianvc().add(person);
                    person.setPian(shijianpian);
                    byte[] byt=Read_Write_Anchor_Message.write_timestamp(tagid, tag_freq, shijianpian);//¼ÆËã³öʱ¼äƬºó½«Êý¾Ý¸øµ½»ùÕ¾                    
                    if(anchor !=null) {//Èç¹ûÖ¸¶¨Á˸øÄ³¸ö»ùվϷ¢×¢²áÐÅÏ¢
                        if(zhiding>3) {
                            anchorid=SystemSet.getZhuceanchor();
                            Anchor acr=Anchor_Dell.get_anchor(anchorid);
                            if(acr !=null) {
                                Udp_Receive.out(byt,byt.length,acr,"´¦Àí×¢²áÐÅÏ¢");
                                b1=true;
                            }
 
                        }else {
                            Udp_Receive.out(byt,byt.length,anchor,"´¦Àí×¢²áÐÅÏ¢");
                            b1=true;
                        }
                        if(TcpIpManage.getStar() && b1) {
                            BaoWenShow.show(a, "×¢²á±¨ÎÄ",tagid);
                        }                        
                    }else {
                        if(bj==0) {
                            a=anchorid+"·ÖƬʧ°Ü£¡";
                            BaoWenShow.show(a, "×¢²á±¨ÎÄ",tagid);
                            bj=1;
                        }
                    }
                }else {    
                    person.setPian(-1);
                    a="·ÖƬerr£º"+shijianpian;
                    BaoWenShow.show(a, "×¢²á±¨ÎÄ",tagid);
                }
            }
        }else {
            ChuShiHua.setPiannedd(50);
        }
 
    }
 
 
    /**Ï·¢Ê±¼äƬ¸øµ½»ùÕ¾*/
    public static void  fenpian(String tagid,int tag_freq,int shijianpian) {
        if (Systems.isZidongshijianpian()) {//Èç¹û¿ªÆô×Ô¶¯Ê±¼äƬģʽ
            return;
        }
        Tag tag=Tag_Dell.get_tag(tagid);
        byte[] byt=Read_Write_Anchor_Message.write_timestamp(tagid, tag_freq, shijianpian);
        String anchorid=tag.getNowzhuceanchor();        
        String timez=tag.getZhucetime();//±êÇ©×î½üÏ·¢Ê±¼äƬʱ¼ä
        if(timez !=null) {
            int shicha=Shi_jian_cha_sss.get_time_cha_s(GetNowTime.now(), timez);
            if(shicha<2) {//Èç¹û×îÐÂ×¢²áµÄʱ¼ä²îСÓÚ2Ãë¾Í²»×¢²á
                return;
            }
        }    
        String a=anchorid+"·Ö·¢Æ¬Ê§°Ü£¡";
        if(!anchorid.equals("0")) {
            Anchor anchor=Anchor_Dell.get_anchor(anchorid);
            if(anchor !=null) {    
                Udp_Receive.out(byt,byt.length,anchor,"´¦Àí×¢²áÐÅÏ¢");
                tag.setZhucetime(GetNowTime.now());
                if(TcpIpManage.getStar()) {
                    a="·ÖƬ2£º"+tagid+"£¬ÆµÂÊ"+tag_freq+"£¬¸ø»ùÕ¾"+anchorid+",ʱ¼äƬ"+shijianpian;
                    BaoWenShow.show(a, "×¢²á±¨ÎÄ",tagid);
                }
            }
        }else {
            BaoWenShow.show(a, "×¢²á±¨ÎÄ",tagid);
        }
    }
 
 
    /**ÐÞ¸Äijע²á»ùÕ¾¶ÔÏóÐÅÏ¢
     *@param  tagid±êÇ©id
     *@param  anchor»ùÕ¾ID
     *@param  powerÐźÅÇ¿¶È
     *@param  timestampʱ¼ä´Á*/
    public static void alert_xinhaoqiangdu(Tag tag,String anchorid,int newpower) {
        int oldpower=tag.getXinhaoqingdu();
        if(newpower-oldpower<0) {
            person_Dell.get_Person(tag.getTag_id()).setZhuceanchor(anchorid);
            tag.setXinhaoqingdu(newpower);
        }
    }
 
 
    /**ɾ³ýʱ¼äƬµÄ·½·¨*/
    public static void delete_pian(String tagid,int hz,String biaozhi) {
        Person psrson=person_Dell.get_Person(tagid);
        int pian=psrson.getPian();
        if(hz !=0 ) {
            if(pian<0 ) {
                return;
            }
            String time=psrson.getXinhaotime();            
            int tagidint=0;
            if(JugeHaveZimu.haszimu(tagid)) {
                tagidint=ReadPeizhiMessage.decodeHEX(tagid);
            }else {                
                tagidint=Integer.parseInt(tagid,16);//½«str ×ª»»³É 16½øÖÆÊýÖµ
            }    
            int succ=DellJAN.delete_tag_from_slotted_aloha(tagid,tagidint, hz);            
            String time1=GetNowTime.timestamp2();//ÏÔʾUDPת·¢µÄÊý¾Ý
            String a=biaozhi+"ɾ³ýƬ£º"+tagidint+","+tagid+",lastontime:"+time+",return:"+succ+","+time1;            
            BaoWenShow.show(a,"×¢²á±¨ÎÄ",tagid);            
            Person person=person_Dell.get_Person(tagid);
            person.setPian(-2);
            getShijianpianvc().removeElement(person);
        }
    }
 
 
    /**Ð޸ıêǩƵÂÊ*/
    public static void alert_tag_hz(Tag tag,String tagid,int hz) {
        if(hz>20) {
            ControTag.set_tag_hz("1",tagid);
        }
 
        if(TagReaLocation.isAlerttaghz()) {
            String p=tag.getTag_pinglv();
            int pinlv=Integer.parseInt(p);
            if(hz !=pinlv) {
                ControTag.set_tag_hz(p,tagid);
            }
        }
    }
 
    /**δÌí¼Ó±êÇ©·Öʱ¼äƬ*/
    public static void noinfenpian(String anchorid,String tagid,int tag_freq) {
        if (Systems.isZidongshijianpian()) {//Èç¹û¿ªÆô×Ô¶¯Ê±¼äƬģʽ
            return;
        }
        Anchor anchor=Anchor_Dell.get_anchor(anchorid);
        //¼ÆËã³öʱ¼äƬºó½«Êý¾Ý¸øµ½»ùÕ¾
        byte[] byt=Read_Write_Anchor_Message.write_timestamp(tagid, tag_freq, 0);
        //ÏÔʾע²á±¨ÎÄÐÅÏ¢
        if(anchor !=null) {    
            Anchor acr=Anchor_Dell.get_anchor(anchorid);
            if(acr !=null) {
                Udp_Receive.out(byt,byt.length,acr,"δÌí¼Ó±êÇ©·ÖÅäʱ¼äƬ");
            }
        }
    }
 
 
    /**½«Ê±¼äƬÉèÖÃÔÚͬ²½·½·¨ÖÐ*/
    public static  synchronized Vector<Person> getShijianpianvc() {
        return shijianpianvc;
    }
 
 
    public static void setShijianpianvc(Vector<Person> shijianpianvc) {
        Dell_55AA0A.shijianpianvc = shijianpianvc;
    }
 
    /**ͨ¹ýʱ¼äƬÕÒµ½Ä³¸ö±êÇ©ID*/
    public static Person  getpersonpian(String tagid,int pian) {
        Person pers=null;
        for(int i=0;i<getShijianpianvc().size();i++) {
            Person pr=getShijianpianvc().get(i);
            String tagid1=pr.getP_tagid();
            int pian1=pr.getPian();
            if(pian==pian1 && tagid.equals(tagid1)) {
                pers=pr;
                break;
            }
        }
        return pers;        
    }
 
    /**ͨ¹ýʱ¼äƬÕÒµ½Ä³¸ö±êÇ©ID*/
    public static Person  getpersonpian(int pian) {
        Person pers=null;
        int size=getShijianpianvc().size();
        for(int i=0;i<size;i++) {
            Person pr=getShijianpianvc().get(i);
            int pian0=pr.getPian();
            if( pian==pian0) {
                pers=pr;
                break;
            }
        }
        return pers;        
    }
 
    /**Éý¼¶µÄʱºò´¦Àí55AA0AµÄÊý¾Ý*/
    public static void dell55aa0a(String infom,String ip,int port) {
        String[] hex=StringToHex.hex(infom);
        if(hex.length>6) {
            String anchorid=hex[5]+hex[4];
            Anchor a=Anchor_Dell.get_anchor(anchorid);
            if(a !=null) {
                a.setAnc_ip(ip);
                a.setPort(port);
            }
        }
    }
 
    /**yang20230723 */
    public static void have_person_do() {
        person=person_Dell.get_Person(tagid);
        if(person !=null) {
            person.setNow_ceju_anchorid(anchorid);
            person.setXinhaotime(GetNowTime.now());
            person.setHavexinhao(true);
            person.setHz(hz);            
        }
    }
    /**yang20230723 */
    public static void have_anchor_do(String ip,int port) {
        Anchor a2=Anchor_Dell.get_anchor(anchorid);
        if(a2 !=null) {
            Anchor_Dell.set_anchor_mode(a2,anchorid,ip,port);//Ð޸ĻùÕ¾µÄÔÚÏß״̬¼°IP
        }
    }
    
    /**yang20230723 */
    public static void have_tag_do() {
       Tag tag=Tag_Dell.get_tag(tagid);
       if(tag==null ) {
          if (ToolBarModel.isAddtagzidong()) {//×Ô¶¯Ìí¼Ó±êÇ©
             Tag_Dell.add_tag(tagid, "δ°ó¶¨", "150", "500", "1", 0, "", 2);
             ShowMessage.zidingyi("×Ô¶¯Ìí¼Ó±êÇ©" + tagid);
          }
       }else {
          if (!Systems.isZidongshijianpian()) {//Èç¹ûûÓпªÆô×Ô¶¯Ê±¼äƬģʽ
             if (Tagstate.isFanjihuo()) {
                noinfenpian(anchorid, tagid, hz);//ûÓÐÌí¼ÓµÄ±êÇ©¸ø·ÖÅäʱ¼äƬ
             }
            
             if (hz != 0) {
                if (person == null) {
                   return;
                }
                int pian = person.getPian();
                alert_xinhaoqiangdu(tag, anchorid, power);//Ð޸ıêÇ©ÐźÅÇ¿¶È
                if (pian == (-2)) {//Èç¹û±êÇ©²»´¦Óڵȴý×¢²áģʽ£¬Òâ˼¾ÍÊDZêÇ©ÒѾ­·ÖÅäµ½ÁËʱ¼äƬ
                   person.setPian(-1);
                   person.setZhuceanchor(anchorid);
                   person.setAskpiantime(GetNowTime.timestamp());
                   person.setRealhz(hz);
                }
                int lasthz = person.getRealhz();
                if (lasthz != hz) {
                   delete_pian(tagid, hz, "×¢²á");
                } else {
                   if (pian > (-1)) {
                      fenpian(tagid, hz, pian);
                   }
                }
                person.setRealhz(hz);
             }
          }
          alert_tag_hz(tag, tagid, hz);//Èç¹û¿ªÆô×Ô¶¯Ð޸ıêǩƵÂÊ
          tag.setNowzhuceanchor(anchorid);
       }
    }
    
    
    /**yang20230723 */
    public static int get_value(String hex) {
        return Integer.parseInt(hex,16);
    }
 
    /**yang20230723 */
    public static void get_dell_hz() {
        if(hz>20) {
            hz=1;
        }
    }
 
    /**yang20230723 */
    public static void show_baowen(String tagstate,String move_open,String sleep_open,
            String version,int gonglv,int speed,int sleep_time) {
        if(TcpIpManage.getStar()) {//ÏÔʾ±êǩע²áÐÅÏ¢
            String tagid0=tagid;
            Tag tag=Tag_Dell.get_tag(tagid);
            if(tag==null) {
                tagid0=tagid+"δÌí¼Ó±êÇ©";
            }
            String a=tagid0+"×¢²á"+
                    ", À´×Ô:"+anchorid+
                    ", ×´Ì¬:"+tagstate+
                    ", Õñ¶¯:"+move_open+
                    ", ÐÝÃß:"+sleep_open+
                    ", °æ±¾:"+version+
                    ", ÆµÂÊ:"+hz+
                    ", ¹¦ÂÊ:"+gonglv+
                    ", IMU:"+speed+
                    ", ÐÝÃßʱ¼ä:"+sleep_time+
                    ", Ç¿¶È£º"+power+
                    ","+GetNowTime.timestamp2();
            BaoWenShow.show(a, "×¢²á±¨ÎÄ",tagid);
        }
    }
    
    /**yang20230723 */
    public static String get_versoin(String hex1,String hex2) {
        String vers="V"+Integer.parseInt(hex1,16)+"."+Integer.parseInt(hex2,16);
        return vers;
    }
}