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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
package tbDataModel_Dell;
import java.math.BigInteger;
import java.util.LinkedHashMap;
import BaoWen.Dell_55AA03;
import Frame.AnchorSet;
import Method.GetNowTime;
public class ReadPeizhiMessage {
 
    /**±£´æÅäÖÃÐÅÏ¢
     * @param anchorid»ùÕ¾id
     * @param gonglv»ùÕ¾¹¦ÂÊ
     * @param wucha»ùÕ¾Îó²î
     * @param lvboÂ˲¨²ÎÊý
     * @param zu×é
     * @param hzƵÂÊ
     * @param shangxianͨѶÊýÁ¿ÉÏÏÞ
     * @param rootanchorͬ²½»ùÕ¾
     * @param xuhaoͬ²½»ùÕ¾ÀàÐÍ0ÆÕͨ»ùÕ¾£¬1Ö÷»úÕ¾£¬2ÊÇ´Ó»ùÕ¾*/
    public static byte[] save(
            String anchorid,
            String gonglv,
            String wucha,
            String lvbo,
            String zu,
            String hz,
            String shangxian,
            String type,            
            String nearnum,
            String near1,
            String near2,
            String near3,
            String near4,
            String near5,
            String near6,
            String near7,
            String near8,
            String near9,
            String near10,
            String qiehuan,
            String initiative,
            String heart,
            String rootanchor,
            String xuhao,
            String jiaozhungao
            ) {
        byte[] data=null;        
        if(Dell_55AA03.isReadpeizhi_succ()) {
 
            int[] value=new int[36];
 
            //É豸id 0x4
            value[0]=covert(anchorid);
 
            //±êǩͨѶ¼ä¸ô 0x6
            value[1]=Integer.parseInt(hz);
 
            //µ¥´ÎͨѶ»ùÕ¾ÊýÁ¿ÉÏÏÞ
            value[2]=Integer.parseInt(shangxian);
 
            //0xA    Í¨Ñ¶×éID£¨2Byte£© 
            value[3]=Integer.parseInt(zu);
 
            //0xC    ¾àÀëУ׼ֵ£¨2Byte£©
            value[4]=Integer.parseInt(wucha);
 
            //0xE    Ä£¿éÀàÐÍ£¨2Byte£©
            value[5]=1;
            if(type.equals("0")) {
                value[5]=0;
            }
 
            //0x10    »ùÕ¾Ö÷¶¯²â¾à£¨2Byte£©
            value[6]=0;
            if(initiative.equals("1")) {
                value[6]=1;    
            }
 
 
            //0x12    ±¨¾¯É豸£¨2Byte£© 
            value[7]=0;
 
            //0x14    ±¨¾¯¾àÀë1£¨2Byte£© 
            value[8]=Integer.parseInt(qiehuan);;
 
            //0x16    ±¨¾¯¾àÀë2£¨2Byte£© 
            value[9]=0;
 
            //0x18    ±¨¾¯¾àÀë3£¨2Byte£© 
            value[10]=0;
 
            //0x1A    Åä¶ÔIDÎÞ×÷Óã¨2Byte£© 
            value[11]=0;
 
            //0x1C    ÐÄÌø°ü£¨2Byte£© 
            value[12]=0;
            if(heart.equals("1")) {
                value[12]=1;    
            }
 
            //0x1E    Modbusģʽ£¨2Byte£©
            value[13]=0;
 
            value[14]=Integer.parseInt(nearnum);
            value[15]=covert(near1);
            value[16]=covert(near2);
            value[17]=covert(near3);
            value[18]=covert(near4);
            value[19]=covert(near5);
            value[20]=covert(near6);
            value[21]=covert(near7);
            value[22]=covert(near8);
            value[23]=covert(near9);
            value[24]=covert(near10);
 
            //·¢É书ÂÊ
            value[25]=Integer.parseInt(gonglv);
 
            //¼ÓËÙ¶ÈÁéÃô¶È
            value[26]=2;
 
            //ÐÝÃßʱ¼ä
            value[27]=120;
 
            //Õñ¶¯Ê¹ÄÜ
            value[28]=0;
 
 
            //¼ÓËÙ¶ÈʹÄÜ
            value[29]=0;
 
            
            //±êǩϷ¢ÅäÖÃ״̬
            value[30]=Integer.parseInt(lvbo);
            
            //±êǩϷ¢ÅäÖÃID 0x42
            value[31]=0;
            
            //ͬ²½»ùÕ¾µØÖ· 0x44
            value[32]=covert(rootanchor);
            
            //ͬ²½ÀàÐÍ0/1/2(0ÆÕͨ»ùÕ¾£¬1Ö÷»úÕ¾£¬2ÊÇ´Ó»ùÕ¾)46
            value[33]=Integer.parseInt(xuhao);
            
            //µØÖ·48
            value[34]=0;
            
            //µØÖ·50,ÆøÑ¹¼Æ¸ß¶ÈУ׼ֵ
            value[35]=Integer.parseInt(jiaozhungao);
 
            //±£´æÅäÖÃÐÅÏ¢
            data=WriteDatapeiz((byte)0x4,(byte)0x48, value);
            AnchorSet.jt_area.setText(GetNowTime.now2()+":±£´æÅäÖóɹ¦...");
 
        }else {
            AnchorSet.jt_area.setText(GetNowTime.now2()+": \n±£´æÅäÖÃʧ°Ü,ÇëÏȶÁÈ¡É豸ÅäÖÃÐÅÏ¢...");
        }
        return data;        
    }
 
 
    /**ÐÞ¸ÄËùÓлùÕ¾*/
    public static byte[] alert_all_anchor(
            String gonglv,
            String wucha,
            String lvbo,
            String zu,
            String hz,
            String shangxian,
            String rootanc,
            String xuhao
            ) {
 
        int[] value=new int[30];
        //±êǩͨѶ¼ä¸ô 0x6
        value[0]=Integer.parseInt(hz);
 
        //µ¥´ÎͨѶ»ùÕ¾ÊýÁ¿ÉÏÏÞ
        value[1]=Integer.parseInt(shangxian);
 
        //0xA    Í¨Ñ¶×éID£¨2Byte£© 
        value[2]=Integer.parseInt(zu);
 
        //0xC    ¾àÀëУ׼ֵ£¨2Byte£©
        value[3]=Integer.parseInt(wucha);
 
        //0xE    Ä£¿éÀàÐÍ£¨2Byte£©
        value[4]=0;
 
        //0x10    »ùÕ¾Ö÷¶¯²â¾à£¨2Byte£© 
        value[5]=0;
 
        //0x12    ±¨¾¯É豸£¨2Byte£© 
        value[6]=0;
 
        //0x14    ±¨¾¯¾àÀë1£¨2Byte£© 
        value[7]=0;
 
        //0x16    ±¨¾¯¾àÀë2£¨2Byte£© 
        value[8]=0;
 
        //0x18    ±¨¾¯¾àÀë3£¨2Byte£© 
        value[9]=0;
 
        //0x1A    Åä¶ÔIDÎÞ×÷Óã¨2Byte£© 
        value[10]=0;
 
        //0x1C    ÐÄÌø°ü£¨2Byte£© 
        value[11]=1;
 
        //0x1E    Modbusģʽ£¨2Byte£©
        value[12]=0;
 
        value[13]=0;
        value[14]=0;
        value[15]=0;
        value[16]=0;
        value[17]=0;
        value[18]=0;
        value[19]=0;
        value[20]=0;
        value[21]=0;
        value[22]=0;
        value[23]=0;
 
        //·¢É书ÂÊ
        value[24]=Integer.parseInt(gonglv);
 
        //¼ÓËÙ¶ÈÁéÃô¶È
        value[25]=2;
 
        //ÐÝÃßʱ¼ä
        value[26]=120;
 
        //Õñ¶¯Ê¹ÄÜ
        value[27]=0;
 
 
        //¼ÓËÙ¶ÈʹÄÜ
        value[28]=0;
 
        //Â˲¨²ÎÊý
        value[29]=Integer.parseInt(lvbo);
        
        //±êǩϷ¢ÅäÖÃID
        value[30]=0;
        
        //ͬ²½»ùÕ¾ID
        value[31]=covert(rootanc);
        
        //ͬ²½»ùÕ¾½ÇÉ«
        value[32]=Integer.parseInt(xuhao);
        
        byte[] data=WriteDatapeiz((byte)0x6,(byte)0x3F, value);
        AnchorSet.jt_area.setText(GetNowTime.now2()+":Ð޸ijÉ...");
 
 
        return data;        
    }
 
    /**д±£´æÅäÖÃ
     * @param ref ÆðʼµØÖ·
     * @param lenth Êý¾Ý³¤¶È
     * @param value Ð´ÈëÖµ*/
    public static byte[] WriteDatapeiz(byte ref ,byte lenth,int[] value) {
        byte[] buf =new byte[9+lenth];
        byte[] buf1 =new byte[5+lenth];
        //°üÍ·
        buf[0]=(byte) 0x55;
        //°üÍ·
        buf[1]=(byte) 0xAA;
        //Ö¸ÁîÀàÐÍ
        buf1[0]=(byte) 0x03;
        //Êý¾Ý³¤¶È
        buf1[1]=(byte) ((byte) 5+lenth);
        //¶Áģʽ
        buf1[2]=(byte) 0x02;
        //ÆðʼµØÖ·
        buf1[3]=(byte) ref; 
 
        //¶Áд³¤¶È
        buf1[4]=(byte) lenth;
 
        for(int i=0;i<value.length;i++) {
            buf1[5+2*i]=intToRegisters(value[i])[3];
            buf1[6+2*i]=intToRegisters(value[i])[2];
        }
 
        for(int i=0;i<buf1.length;i++) {
            buf[i+2]=buf1[i];
        }
        //УÑéÂë
        buf[buf.length-2]=Jiaoyan.check(buf1)[1];
        buf[buf.length-1]=Jiaoyan.check(buf1)[0];
        
        return buf; 
    }
    
    /**±£´æÁÙ½ü»ùÕ¾ÅäÖÃ*/
    public static byte[] save_nerby(String[] anchornearid,int distance,int baoliu1,int baoliu2 ) {    
        int size=anchornearid.length+2;
        int lenth=size*2;
        byte[] buf =new byte[19+lenth];
        byte[] buf1 =new byte[15+lenth];
        //°üÍ·
        buf[0]=(byte) 0x55;
        //°üÍ·
        buf[1]=(byte) 0xAA;
        //Ö¸ÁîÀàÐÍ
        buf1[0]=(byte) 0x03;
        //Êý¾Ý³¤¶È
        buf1[1]=(byte) (15+lenth);
        //¶Áģʽ
        buf1[2]=(byte) 0x02;
        //ÆðʼµØÖ·
        buf1[3]=(byte) 0x14; 
 
        //¶Áд³¤¶È
        buf1[4]=(byte) (lenth+10);
        
        //Çл»¾àÀë        
        buf1[5]=intToRegisters(distance)[3];  
        buf1[6]=intToRegisters(distance)[2];
        
 
        //»ùÕ¾×îÔ¶²âÁ¿·¶Î§
        buf1[7]=intToRegisters(baoliu1)[3];
        buf1[8]=intToRegisters(baoliu1)[2];
        
        //Ö»Êä³ö±¾»ùվΪÖ÷»ùÕ¾µÄÊý¾Ý
        buf1[9]=intToRegisters(baoliu2)[3];
        buf1[10]=intToRegisters(baoliu2)[2];
        
        //Åä¶ÔID
        buf1[11]= (byte)0x0;
        buf1[12]= (byte)0x0;
        
        //ÐÄÌø°ü,¿ªÆôÐÄÌø°ü
        buf1[13]= (byte)0x01;
        buf1[14]= (byte)0x0;
        
        //MODBUSģʽ
        buf1[15]= (byte)0x0;
        buf1[16]= (byte)0x0;
        
        //ÁÙ½ü»ùÕ¾ÊýÁ¿
        int nearnum=anchornearid.length;
        buf1[17]=int_to_Byt(nearnum)[1]; 
        buf1[18]=int_to_Byt(nearnum)[0];
        
 
        for(int i=0;i<nearnum;i++) {
            buf1[19+i*2]=toByteArray(anchornearid[i])[1];
            buf1[20+i*2]=toByteArray(anchornearid[i])[0];
        }
 
        for(int i=0;i<buf1.length;i++) {
            buf[i+2]=buf1[i];
        }
        //УÑéÂë
        buf[buf.length-2]=Jiaoyan.check(buf1)[1];
        buf[buf.length-1]=Jiaoyan.check(buf1)[0];
 
 
        return buf;
 
    }
    
    /**д±£´æÇл»¾àÀë
      * @param ref ÆðʼµØÖ·
      * @param lenth Êý¾Ý³¤¶È
      * @param value Ð´ÈëÖµ*/
     public static byte[] Write(byte ref ,byte lenth,int[] value) {
            byte[] buf =new byte[9+lenth];
            byte[] buf1 =new byte[5+lenth];
            //°üÍ·
            buf[0]=(byte) 0x55;
            //°üÍ·
            buf[1]=(byte) 0xAA;
            //Ö¸ÁîÀàÐÍ
            buf1[0]=(byte) 0x03;
            //Êý¾Ý³¤¶È
            buf1[1]=(byte) ((byte) 5+lenth);
            //¶Áģʽ
            buf1[2]=(byte) 0x02;
            //ÆðʼµØÖ·
            buf1[3]=(byte) ref; 
            
            //¶Áд³¤¶È
            buf1[4]=(byte) lenth;
            
            
            for(int i=0;i<value.length;i++) {
                //Çл»¾àÀë        
                buf1[5+2*i]=intToRegisters(value[i])[3];  
                buf1[6+2*i]=intToRegisters(value[i])[2];
            }
            
            
            for(int i=0;i<buf1.length;i++) {
                buf[i+2]=buf1[i];
            }
            //УÑéÂë
            buf[buf.length-2]=Jiaoyan.check(buf1)[1];
            buf[buf.length-1]=Jiaoyan.check(buf1)[0];
            return buf; 
       }
    
    /**ÅäÖÃдÈë»ùÕ¾£¬Ö÷ÒªÓÃÓÚдÈëÁÙ½üºÍºÍͬ²½
     * @param ÆðʼµØÖ·
     * @param Êý¾Ý³¤¶È
     * @param Ð´ÈëµÄ¾ßÌåÖµ16½øÖÆ×Ö·û´®*/
    public static byte[] Write_in_anchor(byte ref,byte lenth,String[] hex) {
        byte[] buf =new byte[9+lenth];
        byte[] buf1 =new byte[5+lenth];
        //°üÍ·
        buf[0]=(byte) 0x55;
        //°üÍ·
        buf[1]=(byte) 0xAA;
        //Ö¸ÁîÀàÐÍ
        buf1[0]=(byte) 0x03;
        //Êý¾Ý³¤¶È
        buf1[1]=(byte) ((byte)5+lenth);
        //¶Áģʽ
        buf1[2]=(byte) 0x02;
        //ÆðʼµØÖ·
        buf1[3]=(byte) ref; 
        
        //¶Áд³¤¶È
        buf1[4]=(byte) lenth;
        
        
        for(int i=0;i<hex.length;i++) {
            buf1[5+i*2]=toByteArray(hex[i])[1];  
            buf1[6+i*2]=toByteArray(hex[i])[0];
        }
        
        
        for(int i=0;i<buf1.length;i++) {
            buf[i+2]=buf1[i];
        }
        //УÑéÂë
        buf[buf.length-2]=Jiaoyan.check(buf1)[1];
        buf[buf.length-1]=Jiaoyan.check(buf1)[0];
        return buf; 
   }
    
 
 
    public static  byte[] intToRegisters(int v) {
        byte[] registers = new byte[4];
        registers[0] = (byte) (0xff & (v >> 24));
        registers[1] = (byte) (0xff & (v >> 16));
        registers[2] = (byte) (0xff & (v >> 8));
        registers[3] = (byte) (0xff & v);
        return registers;
    }
 
 
    /**
     * @param: [content]
     * @return: int
     * @description: Ê®Áù½øÖÆ×ªÊ®½øÖÆ
     */
    public static int covert(String content){
        int number=0;
        String [] HighLetter = {"A","B","C","D","E","F"};
        LinkedHashMap<String,Integer> map = new LinkedHashMap<>();
        for(int i = 0;i <= 9;i++){
            map.put(i+"",i);
        }
        for(int j= 10;j<HighLetter.length+10;j++){
            map.put(HighLetter[j-10],j);
        }
        String[] str = new String[content.length()];
        for(int i = 0; i < str.length; i++){
            str[i] = content.substring(i,i+1);
        }
        for(int i = 0; i < str.length; i++){
            number += map.get(str[i])*Math.pow(16,str.length-1-i);
        }
        return number;
    }
 
 
    /**½ØÈ¡Ö¸¶¨³¤¶ÈµÄ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;
    }
 
    /** 
     * ½«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();
    }
 
    /**16½øÖÆ×ªÎª10½øÖÆ*/
    public static int decodeHEX(String hexs){
        BigInteger bigint=new BigInteger(hexs, 16);
        int numb=bigint.intValue();
        return numb;
 
    }
    
    /**½«10½øÖÆÊý×éתΪ2×Ö½ÚµÄ16½øÖÆÔÚתΪbytÊý×éÊä³ö*/
    public static byte[] int_to_Byt(int b) {
        String a=String.format("%04x", b);
        final byte[] byteArray = new byte[a.length() / 2];
        int k = 0;
        for (int i = 0; i < byteArray.length; i++) {//ÒòΪÊÇ16½øÖÆ£¬×î¶àÖ»»áÕ¼ÓÃ4λ£¬×ª»»³É×Ö½ÚÐèÒªÁ½¸ö16½øÖƵÄ×Ö·û£¬¸ßλÔÚÏÈ
            byte high = (byte) (Character.digit(a.charAt(k), 16) & 0xff);
            byte low = (byte) (Character.digit(a.charAt(k + 1), 16) & 0xff);
            byteArray[i] = (byte) (high << 4 | low);
            k += 2;
        }
        return byteArray;
    }
    /**
     * 16½øÖƵÄ×Ö·û´®±íʾת³É×Ö½ÚÊý×é
     *
     * @param hexString 16½øÖƸñʽµÄ×Ö·û´®            
     * @return ×ª»»ºóµÄ×Ö½ÚÊý×é
     **/
    public static byte[] toByteArray(String hexString) {
        hexString = hexString.replaceAll(" ", "");
        final byte[] byteArray = new byte[hexString.length() / 2];
        int k = 0;
        for (int i = 0; i < byteArray.length; i++) {//ÒòΪÊÇ16½øÖÆ£¬×î¶àÖ»»áÕ¼ÓÃ4λ£¬×ª»»³É×Ö½ÚÐèÒªÁ½¸ö16½øÖƵÄ×Ö·û£¬¸ßλÔÚÏÈ
            byte high = (byte) (Character.digit(hexString.charAt(k), 16) & 0xff);
            byte low = (byte) (Character.digit(hexString.charAt(k + 1), 16) & 0xff);
            byteArray[i] = (byte) (high << 4 | low);
            k += 2;
        }
        return byteArray;
    }
 
 
 
}