FBS9600通信程序,带了均衡电压版本
Administrator
2021-08-12 8467d3be4ce3be340d36f45c83d370def9e7e50f
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
574
package com.dev.fbs9009;
 
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.Date;
 
import com.base.ComBase;
import com.dev.fbs9100.ComFn;
import com.mysql.fabric.xmlrpc.base.Array;
 
public class MyModBusData {
    public static final int[] SYS_STATE_ADDR_INDEX = new int[]{0x2000,0x2020,0x2040,0x2060};                    //¶Áȡϵͳ״̬µÄ¼Ä´æÆ÷µØÖ·
    public static final int[] BATT_STATE_ADDR_INDEX = new int[] {0x2100,0x2200,0x2300,0x2400};                    //¶ÁÈ¡µç³Ø×´Ì¬µÄ¼Ä´æÆ÷µØÖ·
    public static final int[] BATT_MON_DATA_ADDR_INDEX = new int[]{0x5000,0x5030,0x5060,0x5090};                //¶ÁÈ¡ÄÚ×èζȵļĴæÆ÷µØÖ·
    
    private int cmd_addr;                                            //·¢ËÍÊý¾ÝÃüÁîµÄÆðʼµØÖ·
    
    private int cmd;                                                    //·¢ËÍÊý¾ÝµÄÃüÁî
    private int dev_addr;                                            //É豸µØÖ·            
    
    private int dev_id;                                                //É豸id 
    private String dev_ip;                                            //É豸ip
    
    private int dev_count = 1;                                            //´®ÁªÉ豸ÊýÁ¿    
    private int battgroupid;                                        //µ±Ç°µÄµç³Ø×é
    private int test_record_count = 1;                                //µ±Ç°µç³Ø×éµÄ·Åµç²âÊÔ´ÎÊý
    
    private Date threadRunTime;                                        //µ±Ç°Ï̵߳ÄÔËÐÐʱ¼ä
    
    
    private Date recordhistorytime = new Date(2000,0,1);            //¼Ç¼ÀúÊ·Êý¾ÝµÄʱ¼ä
    
    private LD_sys_state[] ld_sys;
    private LD_param  ld_param;
    private LD_date_time ld_date;
    private LD_sys_version ld_version;
    private LD_batt_states[] ld_batt_states;
    
    private ConcentratorState concenState;                            //»ã¼¯Æ÷״̬±í
    private ConcentratorParam concenParam;                            //»ã¼¯Æ÷²ÎÊý±í
    
    private String err_logo = "";
    
    private int Coment_errorcount = 0;                                //ͨÐÅ´íÎó¼ÆÊý
    private int coment_totalcount = 0;                               //ͨÐżÆÊý
    
    public MyModBusData() {
        super();
        //this.ld_sys = new LD_sys_state();
        this.ld_param = new LD_param();
        this.ld_date = new LD_date_time();
        this.ld_version = new LD_sys_version();
        //this.ld_batt_states = new LD_batt_states();
        this.threadRunTime = new Date();
        this.concenState = new ConcentratorState();
        this.concenParam = new ConcentratorParam();
        this.ld_sys = new LD_sys_state[1];
        this.ld_sys[0] = new LD_sys_state();
        this.ld_batt_states = new LD_batt_states[1];
        this.ld_batt_states[0] = new LD_batt_states();
    }
    
    //³õʼ»¯É豸µÄ½ÚÊý(¼æÈݶą̀LD9¶ÈÉ豸´®Áª)
    public void init(int moncount) {
        int device_count = (int) Math.ceil((double)moncount/9);
        if(device_count > 4) {
            device_count =4;                    //×î¶à´®ÁªËĄ̈LD9¶ÈÉ豸
        }else if(device_count <= 0){
            device_count = 1;
        }
        if(this.ld_sys == null) {
            this.ld_sys = new LD_sys_state[device_count];
            for(int i=0;i<device_count;i++) {
                this.ld_sys[i] = new LD_sys_state();
            }
        }else if(this.ld_sys.length < device_count){
            LD_sys_state[] states = new LD_sys_state[device_count];
            for(int i = 0 ;i<device_count;i++) {
                if(i< this.ld_sys.length) {
                    states[i] = this.ld_sys[i];
                }else {
                    states[i] = new LD_sys_state();
                }
            }
            this.ld_sys = states;
        }else if(this.ld_sys.length > device_count){
            LD_sys_state[] states = new LD_sys_state[device_count];
            for(int i = 0 ;i<device_count;i++) {
                states[i] = this.ld_sys[i];
            }
            this.ld_sys = states;
            
        }
        if(this.ld_batt_states == null) {
            this.ld_batt_states = new LD_batt_states[device_count];
            for(int i=0;i<device_count;i++) {
                this.ld_batt_states[i] = new LD_batt_states();
            }
        }else if(this.ld_batt_states.length < device_count) {
            LD_batt_states[] battstates = new LD_batt_states[device_count];
            for(int i=0;i<device_count;i++) {
                if(i<this.ld_batt_states.length) {
                    battstates[i] = this.ld_batt_states[i];
                }else {
                    battstates[i] = new LD_batt_states();
                }                
            }
            this.ld_batt_states = battstates;
        }else if(this.ld_batt_states.length > device_count) {
            LD_batt_states[] battstates = new LD_batt_states[device_count];
            for(int i=0;i<device_count;i++) {
                battstates[i] = this.ld_batt_states[i];
            }
            this.ld_batt_states = battstates;
        }
        this.dev_count = device_count;
        //System.err.println(this.ld_sys.length);
        //System.err.println(this.ld_batt_states.length);
    }
 
    /**
     *     »ñÈ¡µ±Ç°É豸µÄ×é¶ËµçѹÀÛ¼ÓºÍ
     * @return
     */
    public double getTotalGroupVol() {
        double group_vols = 0;
        for(int i=0;i<dev_count && i<ld_sys.length;i++) {
            group_vols += this.ld_sys[i].getSys_group_vol();
        }
        return group_vols;
    }
 
 
    /*private int cmd;                //·¢ËÍÊý¾ÝµÄÃüÁî
    
    
    private int dataCount;            //Êý¾ÝµÄ³¤¶È
    
    private int dev_addr;            //É豸µØÖ·
    private int first_num;            //µÚһ·µ¥ÌåÊýÄ¿
    private int second_num;            //µÚ¶þ·µ¥ÌåÊýÄ¿
    private int thrid_num;            //µÚÈý·µ¥ÌåÊýÄ¿
    private int forth_num;            //µÚËÄ·µ¥ÌåÊýÄ¿
    private int fifth_num;            //µÚÎå·µ¥ÌåÊýÄ¿
    
    private float curr_range;        //µçÁ÷ǯÁ¿³Ì    
    private float float_curr_limit;    //¸¡³äµçÁ÷ÃÅÏÞ(0.1)
    private float Curr_threshold;    //ÎÆ²¨µçÁ÷·§Öµ (×Ô¶¯·¨²âÄÚ×èʱ,ÅжÏÎÆ²¨µçÁ÷´óСµÄ·§Öµ  0.01)
    private float res_testcycle;    //ÄÚ×è×Ô¶¯²âÊÔÖÜÆÚ(Сʱ)
    private int res_testmethod;        //ÄÚ×è²âÊÔ·½·¨
    private int dischage_model;        //·Åµçģʽ    (·Åµç·¨²âÄÚ×èʱ,²ÉÓõķŵçģʽ     0-µ¥½Ú·Åµç   1-¹ã²¥·Åµç )
    private double MonStdCap;        //±ê³ÆÈÝÁ¿
    
    
    
    private float system_version;    //ϵͳ°æ±¾
    private int system_state;        //ϵͳ״̬            0-³£¹æÄ£Ê½      1-ÄÚ×èģʽ    2-±àַģʽ
    private double group_vol;        //×é¶Ëµçѹ
    private double group_curr;        //×é¶ËµçÁ÷
    
    private int battstate;            //µç³Ø×´Ì¬            0-¸¡³ä    1-·Åµç   2-³äµç
    private int curr_direction;        //µçÁ÷·½Ïò            0-³äµç     1-·Åµç
    
    private double curr_avg;        //ÎÆ²¨µçÁ÷¾ùÖµ    (0.01)
    private double curr_peak;        //ÎÆ²¨µçÁ÷·åÖµ    (0.01) 
    
    private double reser1;            //±£Áôλ1
    private double reser2;            //±£Áôλ1
    private double reser3;            //±£Áôλ1
    private double reser4;            //±£Áôλ1
    private double reser5;            //±£Áôλ1
    private double reser6;            //±£Áôλ1
    
    private int res_testcount;        //ÄÚ×è²âÊÔ´ÎÊý
    private int monres_testmethod;    //µ¥ÌåÄÚ×è²âÊÔ·½·¨
    
    private double[] mon_vols;        //µ¥Ìåµçѹ(0.01  V)
    private double[] mon_tmps;        //µ¥ÌåζÈ(ϵÊý0.1 ¡æ    ÐèÒª¼õÈ¥10.0¡æ)
    private double[] mon_ress;        //µ¥ÌåÄÚ×è(ϵÊý0.001  m¦¸)
    private double[] mon_currs;        //µ¥Ìå¾ùºâµçÁ÷(     µ¥Î»mA)
    
    public int TOTAL_READ_MESSAGE = 126;                            //×î´ó¼Ä´æÆ÷ÊýÁ¿
    
    public int mon_vol_start_index=0;                                //µ¥ÌåµçѹÆðʼλÖÃ
    public int mon_vol_end_index=TOTAL_READ_MESSAGE;                //µ¥Ìåµçѹ½áÊøÎ»ÖÃ
    
    public int mon_tmp_start_index=0;                                //µ¥ÌåÎÂ¶ÈÆðʼλÖÃ
    public int mon_tmp_end_index=TOTAL_READ_MESSAGE;                //µ±ÌåζȽáÊøÎ»ÖÃ
    
    public int mon_res_start_index=0;                                //µ¥ÌåÄÚ×èÆðʼλÖÃ
    public int mon_res_end_index=TOTAL_READ_MESSAGE;                //µ¥ÌåÄÚ×è½áÊøÎ»ÖÃ
    
    public int mon_curr_start_index=0;                                //µ¥Ìå¾ùºâµçÁ÷ÆðʼλÖÃ
    public int mon_curr_end_index=TOTAL_READ_MESSAGE;                //µ¥Ìå¾ùºâµçÁ÷½áÊøÎ»ÖÃ
    */
    public void setCmd(int cmd_addr) {
        this.cmd_addr = cmd_addr;
    }
    
    /**
     * Ð´ÈëÉ豸µÄ·µ»ØÊý¾Ý
     * @param bf
     * @return
     */
    public boolean getDataFromTcp(ByteBuffer bf,int byteCount){
        boolean flag = false;
        //System.err.println("½ÓÊÕµ½Êý¾Ý"+ComFn.bytesToHexString(bf.array(), bf.array().length));
        bf.position(0);
        bf.order(ByteOrder.BIG_ENDIAN);
        this.dev_addr = ComBase.changeByteToInt(bf.get());
        this.cmd = ComBase.changeByteToInt(bf.get());        
        this.cmd_addr = ComBase.changeShortToInt(bf.getShort());
        int code = ComBase.changeShortToInt(bf.getShort());
        //System.err.println("code:"+code +"\t bytecount:"+byteCount);
        if(code == byteCount){
            //²Ù×÷½á¹ûµÈÓڼĴæÆ÷¸öÊýÊDzÙ×÷³É¹¦
            err_logo = "²Ù×÷³É¹¦";
            flag = true;
        }else if(code != byteCount){
            System.out.println(code +" == "+ byteCount);
            
            err_logo = "²Ù×÷ʧ°Ü";
        }
        System.err.println(err_logo+"@@@@@@@@@@@@");
        return flag;        
    }
    
    /**
     *     Åж϶ÁÈ¡µÄÊý¾Ý
     * @param bf
     * @return
     */
    public boolean checkData(ByteBuffer bf){
        boolean flag = false;
        //System.out.println("cmd_addr = " + cmd_addr);
        bf.order(ByteOrder.BIG_ENDIAN);
        int index = -1;
        if((index = getDev_indexBySysReg_index(this.cmd_addr, BATT_STATE_ADDR_INDEX))> -1) {
            return ld_batt_states[index].setLD_batt_state(bf);                                    //¶ÁÈ¡µ¥ÌåÐÅÏ¢
        }else if((index = getDev_indexBySysReg_index(this.cmd_addr, BATT_MON_DATA_ADDR_INDEX))>-1) {
            return ld_batt_states[index].setLD_battmon_state(bf);            //¶ÁÈ¡µç³Ø×éµ¥ÌåµçѹζÈÄÚ×èÊý¾Ý
        }else if(MyModBusCom.LD_CMD_SYS_VERSION_ADDR == this.cmd_addr) {
            return ld_version.setLD_sys_tem_version(bf);            //¶ÁÈ¡É豸µÄ°æ±¾ÐÅÏ¢
        }else if(MyModBusCom.LD_PARM_ADDR == this.cmd_addr) {
            return ld_param.setLD_param(bf);                        //¶ÁÈ¡É豸²ÎÊýÐÅÏ¢
        }else if(MyModBusCom.LD_DATE_TIME_ADDR == this.cmd_addr) {
            return ld_date.setLD_param(bf);                            //¶ÁÈ¡É豸ʱ¼ä
        }else if((index = getDev_indexBySysReg_index(this.cmd_addr, SYS_STATE_ADDR_INDEX))>-1) {
            return ld_sys[index].setLD_sys_state(bf);                    //¶ÁÈ¡É豸״̬
        }else if(MyModBusCom.LD_BATT_COLLECTIO_DATA_ADDR == this.cmd_addr) {
            return concenState.setConcenState(bf);                    //¶ÁÈ¡»ã¼¯Æ÷״̬
        }else if(MyModBusCom.LD_BATT_COLLECTIO_PARAM_ADDR == this.cmd_addr) {
            return concenParam.setConcenParam(bf);                    //¶ÁÈ¡»ã¼¯Æ÷²ÎÊý
        }
        //System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@");
        return flag;
    }
 
    public int getCmd_addr() {
        return cmd_addr;
    }
 
    public void setCmd_addr(int cmd_addr) {
        this.cmd_addr = cmd_addr;
    }
 
    public LD_param getLd_param() {
        return ld_param;
    }
 
    public void setLd_param(LD_param ld_param) {
        this.ld_param = ld_param;
    }
 
    public LD_date_time getLd_date() {
        return ld_date;
    }
 
    public void setLd_date(LD_date_time ld_date) {
        this.ld_date = ld_date;
    }
 
    public LD_sys_version getLd_version() {
        return ld_version;
    }
 
    public void setLd_version(LD_sys_version ld_version) {
        this.ld_version = ld_version;
    }
 
    public int getBattgroupid() {
        return battgroupid;
    }
 
 
 
    public void setBattgroupid(int battgroupid) {
        this.battgroupid = battgroupid;
    }
 
 
 
    public int getTest_record_count() {
        return test_record_count;
    }
 
 
 
    public void setTest_record_count(int test_record_count) {
        this.test_record_count = test_record_count;
    }
    
    public Date getThreadRunTime() {
        return threadRunTime;
    }
 
 
 
    public void setThreadRunTime(Date threadRunTime) {
        this.threadRunTime = threadRunTime;
    }
 
 
 
    public int getDev_id() {
        return dev_id;
    }
 
 
 
    public void setDev_id(int dev_id) {
        this.dev_id = dev_id;
    }
    
    public Date getRecordhistorytime() {
        return recordhistorytime;
    }
 
    public String getDev_ip() {
        return dev_ip;
    }
 
 
 
    public void setDev_ip(String dev_ip) {
        this.dev_ip = dev_ip;
    }
    
    public ConcentratorState getConcenState() {
        return concenState;
    }
    public ConcentratorParam getConcenParam() {
        return concenParam;
    }
    public void setConcenState(ConcentratorState concenState) {
        this.concenState = concenState;
    }
    public void setConcenParam(ConcentratorParam concenParam) {
        this.concenParam = concenParam;
    }
 
    public LD_sys_state[] getLd_sys() {
        return ld_sys;
    }
 
    public LD_batt_states[] getLd_batt_states() {
        return ld_batt_states;
    }
 
    public void setLd_sys(LD_sys_state[] ld_sys) {
        this.ld_sys = ld_sys;
    }
 
    public void setLd_batt_states(LD_batt_states[] ld_batt_states) {
        this.ld_batt_states = ld_batt_states;
    }
    
    //Èç¹ûÉ豸ÕýÔڷŵçÔò·µ»Øµ±Ç°É豸״̬, ÕýÔڷŵçµÄÉ豸µÄ״̬,Èç¹ûÉ豸δ·ÅµçÔòÏÔʾµÚÒ»×éÉ豸µÄ״̬
    public LD_sys_state getDischageSysState() {
        for(int i = 0 ; i < this.dev_count ; i++) {
            LD_sys_state sys_state = this.getLd_sys()[i];
            //System.out.println(sys_state);
            //Åжϵ±Ç°É豸ÊÇ·ñÕýÔڷŵç
            if(sys_state.getSys_state() ==  MyModBusCom.SYS_STATE_HRTEST && 
                    ((sys_state.getSys_now_battstate() == MyModBusCom.BATT_DISCHARGE)|| 
                    (sys_state.getSys_next_battstate() == MyModBusCom.BATT_DISCHARGE))) {
                return sys_state;
            }
        }    
        return this.getLd_sys()[0];
    }
 
    /*//ÉèÖõ¥ÌåµçѹµÄÊý¾ÝÐÅÏ¢
    private boolean setMon_vols(ByteBuffer bf) {
        boolean flag = false;
        ByteBuffer tmpbuf = bf;    
        System.out.println("pos:"+bf.position()+"\tlimit:"+bf.limit()+"\tcap"+bf.capacity());
        tmpbuf.position(0);
        try {
            for(int i=mon_vol_start_index;i<mon_vol_end_index;i++){
                mon_vols[i] = ComBase.changeShortToDouble(tmpbuf.getShort());
            }
            if(mon_vol_end_index<299){
                if((mon_vol_end_index +TOTAL_READ_MESSAGE)>299){
                    mon_vol_end_index = 299;
                    mon_vol_start_index = mon_vol_end_index + 1;
                    
                    System.out.println(mon_vol_start_index + "~" +mon_vol_end_index);
                }else{
                    mon_vol_start_index = mon_vol_end_index;
                    mon_vol_end_index =  mon_vol_end_index + TOTAL_READ_MESSAGE;
                    
                    System.out.println(mon_vol_start_index + "~" +mon_vol_end_index);
                }
            }else{
                mon_vol_start_index = 0;
                mon_vol_end_index = TOTAL_READ_MESSAGE; 
                
                System.out.println(mon_vol_start_index + "~" +mon_vol_end_index);
            }
            
        } catch (Exception e) {
            flag = false;
            e.printStackTrace();
        }        
        return flag;
    }
 
    //»ñÈ¡É豸ÉϵIJÎÊýÉèÖÃÐÅÏ¢
    public boolean setDev_Param(ByteBuffer bf){    
        boolean flag = false;
        ByteBuffer tmpbuf = bf;    
        System.out.println("pos:"+bf.position()+"\tlimit:"+bf.limit()+"\tcap"+bf.capacity());
        tmpbuf.position(0);        
        try {
            this.dev_addr = ComBase.changeByteToInt(tmpbuf.get());                    //»ñÈ¡É豸µØÖ·
            this.cmd = ComBase.changeByteToInt(tmpbuf.get());
            //this.dataCount = ComBase.changeByteToInt(tmpbuf.get());                //Êý¾ÝÇø×Ö½ÚÊý        
            this.dataCount = ComBase.changeByteToInt(tmpbuf.get());
            this.dev_addr = ComBase.changeShortToInt(tmpbuf.getShort());            //»ñÈ¡É豸µØÖ·    
            
            System.out.println("Êý¾ÝÇø×Ö½ÚÊýµÄ³¤¶È:"+this.dataCount);
            
            this.first_num = ComBase.changeShortToInt(tmpbuf.getShort());            //µÚһ·µ¥ÌåÊýÄ¿
            this.second_num = ComBase.changeShortToInt(tmpbuf.getShort());            //µÚ¶þ·µ¥ÌåÊýÄ¿
            this.thrid_num = ComBase.changeShortToInt(tmpbuf.getShort());            //µÚÈý·µ¥ÌåÊýÄ¿
            this.forth_num = ComBase.changeShortToInt(tmpbuf.getShort());            //µÚËÄ·µ¥ÌåÊýÄ¿
            this.fifth_num = ComBase.changeShortToInt(tmpbuf.getShort());            //µÚÎå·µ¥ÌåÊýÄ¿
            this.curr_range = ComBase.changeShortToInt(tmpbuf.getShort());            //µçÁ÷ǯÁ¿³Ì
            this.float_curr_limit = ComBase.changeShortToByte(tmpbuf.getShort());    //¸¡³äµçÁ÷ÃÅÏÞ
            this.Curr_threshold = ComBase.changeShortToInt(tmpbuf.getShort());        //ÎÆ²¨µçÁ÷·§Öµ
            this.res_testcycle = ComBase.changeShortToInt(tmpbuf.getShort());        //ÄÚ×è×Ô¶¯²âÊÔÖÜÆÚ
            this.res_testmethod = ComBase.changeShortToInt(tmpbuf.getShort());        //ÄÚ×è²âÊÔ·½·¨
            this.dischage_model = ComBase.changeShortToInt(tmpbuf.getShort());        //·Åµçģʽ
            this.MonStdCap = ComBase.changeShortToDouble(tmpbuf.getShort());        //±ê³ÆÈÝÁ¿    
        } catch (Exception e) {
            e.printStackTrace();
        }                
        flag = true;
        return flag;
    }
    
    //¶ÁÈ¡²âÊÔÊý¾Ý´Óϵͳ°æ±¾
    public boolean readTestData(ByteBuffer bf){
        boolean flag = false;
        ByteBuffer tmpbuf = bf;        
        tmpbuf.position(0);        
        this.dev_addr = ComBase.changeByteToInt(tmpbuf.get());                    //»ñÈ¡É豸µØÖ·
        this.cmd = ComBase.changeByteToInt(tmpbuf.get());                        //ÃüÁîµØÖ·
        //this.dataCount = ComBase.changeByteToInt(tmpbuf.get());                //Êý¾ÝÇø×Ö½ÚÊý                
        this.dataCount = ComBase.changeByteToInt(tmpbuf.get());
        
        System.out.println("Êý¾ÝÇø×Ö½ÚÊýµÄ³¤¶È:"+this.dataCount);                        
        this.system_version = ComBase.changeShortToInt(tmpbuf.getShort());        //°æ±¾ºÅ
        this.system_state = ComBase.changeShortToInt(tmpbuf.getShort());        //ϵͳ״̬
        this.group_vol = ComBase.changeShortToInt(tmpbuf.getShort());            //×é¶Ëµçѹ
        this.group_curr = ComBase.changeShortToByte(tmpbuf.getShort());            //×é¶ËµçÁ÷
        this.battstate = ComBase.changeShortToInt(tmpbuf.getShort());            //µç³Ø×´Ì¬
        this.curr_direction = ComBase.changeShortToInt(tmpbuf.getShort());        //µçÁ÷·½Ïò
        this.curr_avg = ComBase.changeShortToDouble(tmpbuf.getShort());            //ÎÆ²¨µçÁ÷¾ùÖµ    (0.01)
        this.curr_peak = ComBase.changeShortToDouble(tmpbuf.getShort());        //ÎÆ²¨µçÁ÷·åÖµ    (0.01)
        
        this.reser1 = ComBase.changeShortToDouble(tmpbuf.getShort());            //±£Áôλ1
        this.reser2 = ComBase.changeShortToDouble(tmpbuf.getShort());            //±£Áôλ2
        this.reser3 = ComBase.changeShortToDouble(tmpbuf.getShort());            //±£Áôλ3
        this.reser4 = ComBase.changeShortToDouble(tmpbuf.getShort());            //±£Áôλ4
        this.reser5 = ComBase.changeShortToDouble(tmpbuf.getShort());            //±£Áôλ5
        this.reser6 = ComBase.changeShortToDouble(tmpbuf.getShort());            //±£Áôλ6
        
        this.res_testcount =ComBase.changeShortToInt(tmpbuf.getShort());        //ÄÚ×è²âÊÔ´ÎÊý
        this.monres_testmethod = ComBase.changeShortToInt(tmpbuf.getShort());    //µç³Øµ¥ÌåÄÚ×è²âÊÔ·½·¨
        return flag;
        
    }
 
    @Override
    public String toString() {
        return "MyModBusData [cmd=" + cmd + ", dataCount=" + dataCount + ", dev_addr=" + dev_addr + ", first_num="
                + first_num + ", second_num=" + second_num + ", thrid_num=" + thrid_num + ", forth_num=" + forth_num
                + ", fifth_num=" + fifth_num + ", curr_range=" + curr_range + ", float_curr_limit=" + float_curr_limit
                + ", Curr_threshold=" + Curr_threshold + ", res_testcycle=" + res_testcycle + ", res_testmethod="
                + res_testmethod + ", dischage_model=" + dischage_model + ", MonStdCap=" + MonStdCap
                + ", system_version=" + system_version + ", system_state=" + system_state + ", group_vol=" + group_vol
                + ", group_curr=" + group_curr + ", battstate=" + battstate + ", curr_direction=" + curr_direction
                + ", curr_avg=" + curr_avg + ", curr_peak=" + curr_peak + ", res_testcount=" + res_testcount
                + ", monres_testmethod=" + monres_testmethod + ", mon_vols=" + Arrays.toString(mon_vols) + ", mon_tmps="
                + Arrays.toString(mon_tmps) + ", mon_ress=" + Arrays.toString(mon_ress) + ", mon_currs="
                + Arrays.toString(mon_currs) + "]";
    }
    */
    
    
    /**
     *     »ñÈ¡µ±Ç°É豸µÄË÷ÒýºÅ
     * @param reg_index
     * @return
     */
    public static int getDev_indexBySysReg_index(int reg_index,int[] arr) {
        for(int i = 0;i<arr.length;i++) {
            if(reg_index == arr[i]) {
                return i;
            }
        }
        return -1;
    }
    
    public int getComent_errorcount() {
        return Coment_errorcount;
    }
 
    public void setComent_errorcountIncrease(){
        this.Coment_errorcount ++;
        if(this.Coment_errorcount >= 90000000){
            this.Coment_errorcount = 1;
        }
    }
    
    public void setComent_errorcount(int coment_errorcount) {
        Coment_errorcount = coment_errorcount;
    }
 
    public int getComent_totalcount() {
        return coment_totalcount;
    }
    
    public void setComent_totalcountIncrease() {
        this.coment_totalcount += 1;
        if(this.coment_totalcount >= 90000000 ){
            this.coment_totalcount = 1;
        }
    }
 
    
    public int getDev_count() {
        return dev_count;
    }
 
    public void setDev_count(int dev_count) {
        this.dev_count = dev_count;
    }
 
    public void setComent_totalcount(int coment_totalcount) {
        this.coment_totalcount = coment_totalcount;
    }
    
    public static void main(String[] args) {
        int[] a = new int[]{1,2,3};
        for(int i = 0;i<20;i++) {
            System.out.println(i+"=="+(int)Math.ceil((double)i/9));
        }
    }
}