DELL
2024-04-01 3724852a7dd499f54740cd682aa7cfe89aea384d
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
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
package com.dev.dummyload;
import gnu.io.SerialPort;
import gnu.io.UnsupportedCommOperationException;
 
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.Date;
 
import javax.swing.JOptionPane;
import javax.swing.JTextField;
 
import org.apache.logging.log4j.Logger;
 
import sp_comm.CommSerialPort;
import sp_comm.Comm_Socket;
import main.page_debug_inf;
 
import com.Com;
import com.ComBase;
import com.ComFn;
import com.PlaySound;
import com.dev.bts.data.FBS9100_CapState;
import com.dev.bts.data.FBS9100_ChargeState;
import com.dev.bts.data.FBS9100_Cmd;
import com.dev.bts.data.FBS9100_ComBase;
import com.dev.bts.data.FBS9100_ComBuf;
import com.dev.bts.data.FBS9100_DeviceInf;
import com.dev.bts.data.FBS9100_ParamBatt;
import com.dev.bts.data.FBS9100_ParamCharge;
import com.dev.bts.data.FBS9100_ParamDischarge;
import com.dev.bts.data.FBS9100_ParamSystem;
import com.dev.bts.data.FBS9100_ResCapData;
import com.dev.bts.data.FBS9100_ResState;
import com.dev.bts.data.FBS9100_SysState;
import com.dev.bts.data.FBS9100_VCData;
import com.dev.bts4810.BTS_Ecb_Aes;
import com.dev.dummyload.data.DummyLoad_Cmd;
import com.dev.dummyload.data.DummyLoad_ComBase;
import com.dev.fbs9600_mon.SPCommMon;
import com.dev.switchdev.data.ModBus_RTU_Cmd;
import com.dev.switchdev.data.SwitchDevice_ComBase;
 
/**
 *     È«¹¦ÄÜÇл»×°ÖÃÉ豸ͨÐÅÏß³Ì
 * @author LiJun
 *
 */
public class CommDummyLoad implements Runnable/*, SerialPortEventListener*/ {
    
    public static final short CMD_TYPE_READ = 0x03;
    public static final short CMD_TYPE_WRITE = 0x05;
    public static final short CMD_TYPE_WRITE_MULTY = 0x10;
    
    public static final int DEV_PARAM_DATA_STATE_NULL         = 0;    //
    public static final int DEV_PARAM_DATA_STATE_DISQUERY     = 1;    //¶ÁÈ¡ºËÈݲÎÊý
    public static final int DEV_PARAM_DATA_STATE_BATTQUERY     = 2;    //¶ÁÈ¡µç³Ø²ÎÊý
    public static final int DEV_PARAM_DATA_STATE_SYSQUERY     = 3;    //¶Áȡϵͳ²ÎÊý
    public static final int DEV_PARAM_DATA_STATE_UPDATE        = 4;    //ÉèÖòÎÊý
    /*********************************************************************/
    public static final int DEV_DATA_AUTO_READ             = 0;        //×Ô¶¯¶ÁÈ¡
    public static final int DEV_DATA_MANUAL_SET         = 1;        //ÊÖ¶¯ÉèÖÃ
    public static final int DEV_DATA_AUTO_RANDOM         = 2;        //×Ô¶¯Ëæ»ú
    
    private boolean alearyMaxCurr = false;
    /*********************************************************************/
    public int dev_data_type = DEV_DATA_AUTO_READ;
    /*********************************************************************/
    public boolean DEV_DATA_ENCIPHER                    = true;        //ͨÐÅÊý¾ÝÊÇ·ñ¼ÓÃÜ
    /*********************************************************************/
    final public static String[] ZDHJ_OP_REST_INF_TEXT = new String[] {
            "ÎÞ²Ù×÷",
    };
    
    // ÊäÈëÊä³öÁ÷
    public static InputStream inputStream;
    public static OutputStream outputStream;
    // RS-232µÄ´®ÐпÚ
    public static SerialPort serialPort;
    
    private boolean CommThreadRunning = false;
    private boolean dt_dfu_en = false;
    BTS_Ecb_Aes my_aes = new BTS_Ecb_Aes();
    private ByteBuffer CommRxBuffer = ByteBuffer.allocate(1500); 
    private ByteBuffer CommTxBuffer = ByteBuffer.allocate(1048);
    
    public int comm_tx_cnt = 0;
    public int comm_rx_cnt = 0;
    
    private int comm_bautrate = 9600;
    public int dt_target_addr = 0;
    //--------------------------------------------------------//
    public int dev_param_data_state = DEV_PARAM_DATA_STATE_NULL;
    public int dev_param_addr = 0;
    public int[] dev_param_ch_mon_cnt = new int[5];
    public int dev_param_curr_range = 0;
    public double dev_param_wenbo_curr_lev = 0;
    public int dev_param_auto_restest_interval = 0;
    public int dev_param_res_test_type = 0;
    //--------------------------------------------------------//
    public String dev_stat_version_Str = "";
    
    public String dev_control_Str = "";
    public String dev_jiaozhun_Str = "";
    
    
    public int dev_stat_version = 0;
    public int dev_stat_state = 0;
    public double GroupVol = 0;
    public double BattCurr = 0;
    public int BattCurrDir = 0;
    public double AvgWenBoCurr = 0;
    public double PeakWenBoCurr = 0;
    //--------------------------------------------------------//
 
    public boolean m_discurr_jz_a = false;                        //È¡·ÅµçµçÁ÷A²ÉÑùÖÐ
    public boolean m_discurr_jz_b = false;                        //È¡·ÅµçµçÁ÷B²ÉÑùÖÐ
    public boolean m_chrcurr_jz_a = false;                        //È¡³äµçµçÁ÷A²ÉÑùÖÐ
    public boolean m_chrcurr_jz_b = false;                        //È¡³äµçµçÁ÷B²ÉÑùÖÐ
    //--------------------------------------------------------//
    @SuppressWarnings("unused")
    private JTextField dt_show_msg = new JTextField();
    private int dt_cmd = FBS9100_ComBase.CMD_GetVIData;
    private int dt_usr_cmd = FBS9100_ComBase.CMD_NULL;
    private ByteBuffer dt_datatofbs9100 = ByteBuffer.allocate(0);
    
    public int dt_cmd_ack = 0;
    public Date dt_cmd_ack_time = new Date();
    private int dt_cmd_cnt = 0;
    public int m_BTSDevSoftType = 0;
    //--------------------------------------------------------//
    private DummyLoad_Cmd m_Read_Cmd = new DummyLoad_Cmd();
    //--------------------------------------------------------//
    public FBS9100_Cmd m_FBS_Cmd = new FBS9100_Cmd();
    public FBS9100_VCData m_FBS_VCData = new FBS9100_VCData();
    public FBS9100_ParamBatt m_FBS_BattParam;
    public FBS9100_ParamSystem m_FBS_SystemParam;
    public FBS9100_ParamDischarge m_FBS_DiscParam = new FBS9100_ParamDischarge();            //ÉèÖõIJÎÊý
    public FBS9100_ParamDischarge m_FBS_DiscParamFromDev = new FBS9100_ParamDischarge();    //´ÓÉ豸¶ÁÈ¡µÄ²ÎÊý    
    public FBS9100_ParamCharge m_FBS_ChargeParam = new FBS9100_ParamCharge();
    public FBS9100_ResState m_ResTestState = new FBS9100_ResState();
    public FBS9100_CapState m_CapTestState = new FBS9100_CapState();
    public FBS9100_ChargeState m_ChrTestState = new FBS9100_ChargeState();
    public FBS9100_ResCapData m_FBS_ResCapData = new FBS9100_ResCapData();
    
    
    public ByteBuffer m_TaskList = ByteBuffer.allocate(1024); 
    //--------------------------------------------------------//
    private DummyLoad_Cmd m_DummyLoad_Cmd;
    
    public DummyLoad_Data m_DummyLoad_Data = new DummyLoad_Data();
 
    public DummyLoad_TemperData m_DummyLoad_TemperData = new DummyLoad_TemperData();
    
    public DummyLoad_Data m_AppDummyLoad = new DummyLoad_Data();            //appÉèÖõIJÎÊý[ÉèÖÃʱʹÓÃ]
    
    //--------------------------------------------------------//
    
    
    private page_debug_inf dt_debug_inf;
    private int m_COMM_PORT_TYPE = 0;
    private CommSerialPort m_SP_Comm = null;
    private Comm_Socket m_SocketComm = null;
    private Logger m_Log = null;
    //--------------------------------------------------------//
    
    public CommDummyLoad(int addr_t, int bitrate, page_debug_inf debug, Logger log) {
        dt_target_addr = addr_t & 0x00FF;
        comm_bautrate = bitrate;
        dt_debug_inf = debug;
        m_Log = log;
        
    }
    
    public void setCommBautrate(int bt_rate) {
        if(SPCommMon.COMM_PORT_TYPE_Serial != m_COMM_PORT_TYPE) {
            return;
        }
        
        try {
            comm_bautrate = bt_rate;
            serialPort.setSerialPortParams(comm_bautrate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
        } catch (UnsupportedCommOperationException e) {
            e.printStackTrace();
        }
    }
    
    //³õʼ»¯´®¿Ú
    public boolean OpenCommPort(int comm_port_type, String comm_name_or_ip, int bitrate_or_comm_port) {
        boolean res = false;
        m_COMM_PORT_TYPE = comm_port_type;
        if(SPCommMon.COMM_PORT_TYPE_Serial == m_COMM_PORT_TYPE) {
            m_SP_Comm = new CommSerialPort(bitrate_or_comm_port, m_Log);
            res = m_SP_Comm.OpenCommPort(comm_name_or_ip);
        } else {
            m_SocketComm = new Comm_Socket(comm_name_or_ip, bitrate_or_comm_port);
            res = true;
        }
        
        if(true == res) {
            CommTxBuffer.order(ByteOrder.BIG_ENDIAN);
            CommRxBuffer.order(ByteOrder.BIG_ENDIAN);
 
            comm_tx_cnt = 0;
            comm_rx_cnt = 0;
            CommThreadRunning = true;
        }
        
        return res;
    }
    
    private void makeCommTxData() {
        dt_cmd = SwitchDevice_ComBase.CMD_GetVIData;            //¶ÁȡʵʱÊý¾Ý
        
        m_DummyLoad_Cmd = new DummyLoad_Cmd();
        if(SwitchDevice_ComBase.CMD_NULL == dt_usr_cmd) {
            if(++dt_cmd_cnt  > 1000) {
                dt_cmd_cnt = 0;
            }
            if(dt_cmd_cnt%2 == 0) {
                m_DummyLoad_Cmd.makeCmd(dt_target_addr, DummyLoad_ComBase.CMD_GetLoaderState);
            }else if(dt_cmd_cnt%2 == 1) {
                m_DummyLoad_Cmd.makeCmd(dt_target_addr, DummyLoad_ComBase.CMD_GetTempData);
            }
            if(dt_cmd_cnt%10 == 0) {
                m_DummyLoad_Cmd.makeCmd(dt_target_addr, DummyLoad_ComBase.CMD_GetLoaderVersion);
            }
 
            dt_datatofbs9100 = ByteBuffer.allocate(0);
        } else {
            dt_cmd = dt_usr_cmd;
            dt_usr_cmd = SwitchDevice_ComBase.CMD_NULL;            
            
            /******************************* ¶àµãÉèÖà**************************************************/
            if(DummyLoad_ComBase.CMD_LoaderStop == dt_cmd) {
                //Í£Ö¹¼Ù¸ºÔع¤×÷
                m_DummyLoad_Cmd.makeCmd(dt_target_addr, DummyLoad_ComBase.CMD_LoaderStop);                
                
            }else if(DummyLoad_ComBase.CMD_StartDischarge == dt_cmd) {
                //Æô¶¯¼Ù¸ºÔطŵç²Ù×÷
                m_DummyLoad_Cmd.makeCmd(dt_target_addr, DummyLoad_ComBase.CMD_StartDischarge);                
                
            }else if(DummyLoad_ComBase.CMD_StartCharge == dt_cmd) {
                //Æô¶¯¼Ù¸ºÔسäµç²Ù×÷
                m_DummyLoad_Cmd.makeCmd(dt_target_addr, DummyLoad_ComBase.CMD_StartCharge);                
                
            }else if(DummyLoad_ComBase.CMD_LoaderControl == dt_cmd) {
                //ÉèÖüٸºÔص÷ÖÆ·ÅµçµçÁ÷
                m_DummyLoad_Cmd.makeCmd(dt_target_addr, DummyLoad_ComBase.CMD_LoaderControl);
                //dt_datatofbs9100 = m_DummyLoad_Cmd.makeByteBuffer(m_AppDummyLoad.SetCurrent*10);
            }else if(DummyLoad_ComBase.CMD_DisRlayControl == dt_cmd) {
                //¹Ø±Õ×ܵļ̵çÆ÷ºÍ·çÉȵŦÄÜ
                m_DummyLoad_Cmd.makeCmd(dt_target_addr, DummyLoad_ComBase.CMD_DisRlayControl);                
            }
        }
        
        ByteBuffer buf_t = m_DummyLoad_Cmd.makeFbs9100CommBuf(dt_datatofbs9100);        
        //System.err.println("@@@"+ComFn.bytesToHexString(buf_t.array(), buf_t.array().length));
        
        byte[] plain_tx_t = new byte[buf_t.limit()];
        buf_t.get(plain_tx_t);
        
        
        //System.err.println("@@@"+ComFn.bytesToHexString(plain_tx_t, plain_tx_t.length));
        CommTxBuffer = ByteBuffer.allocate(plain_tx_t.length);
        CommTxBuffer.put(plain_tx_t);
        CommTxBuffer.flip();
    }
    
 
    public void tr_Msg(ByteBuffer bbf_tx, ByteBuffer bbf_rx, boolean showdat) {
        if(++comm_tx_cnt > 32500) {
            comm_tx_cnt = 0;
        }
        if(SPCommMon.COMM_PORT_TYPE_Serial == m_COMM_PORT_TYPE) {
            m_SP_Comm.SP_Comm(bbf_tx, bbf_rx, CommSerialPort.mutycomm_Type_Samd09, dt_debug_inf, showdat);
        } else {
            m_SocketComm.SocketComm(bbf_tx, bbf_rx, dt_debug_inf, showdat);
        }
    }
    
    public void exitCommPortThread() {
        CommThreadRunning = false;
    }
    
    private void closeCommPort() {
        if(SPCommMon.COMM_PORT_TYPE_Serial == m_COMM_PORT_TYPE) {
            m_SP_Comm.serialPort.close();
        } else {
            m_SocketComm.socketClose();
        }
    }
    
    public void setCommCmd(int cmd, ByteBuffer data_buf) {
        dt_usr_cmd = cmd;
        dt_datatofbs9100 = data_buf;
    }
    
    public void setCommCmd_DFU(boolean dfu_en, String dfu_file, JTextField show_area) {
        dt_dfu_en = dfu_en;
        dt_show_msg = show_area;
    }
    
    public void setDataType(int datatype) {
        this.dev_data_type = datatype;
    }
    
    public void setCommCmdAck(int ack_t) {
        dt_cmd_ack = ack_t;
        dt_cmd_ack_time = new Date();
        String wav_f = "6133.wav";
        if(ack_t%2 == 0) {
            wav_f = "4577.wav";
        }
        if(ack_t > 0) {
            new PlaySound(wav_f);
        }
    }
    
    public void sendFBS9100Data(int cmd, ByteBuffer bbf_tx) throws IOException {
        ByteBuffer bf_t = FBS9100_ComBuf.makeFbs9100CommBuf(255, cmd, bbf_tx, true);
        byte[] cipher_tx_t = new byte[bf_t.limit()];
        bf_t.get(cipher_tx_t);
        //byte[] bt_t = FBS9100_ComBuf.makeFbs9100CommBuf(21, 0x15, ByteBuffer.allocate(0)).array();
        
        //byte[] cipher_tx_t = new byte[bf_t.limit()];
        //my_aes.ecb_encrypt(plain_tx_t, cipher_tx_t, plain_tx_t.length);
        
        //System.out.println(ComFn.bytesToHexString(plain_tx_t, plain_tx_t.length));
        outputStream.write(cipher_tx_t);
        if(++comm_tx_cnt > 1000000) {
            comm_tx_cnt = 0;
        }
    }
    
    public void run() {
        System.out.println("CommThreadRunning:"+CommThreadRunning);
        while(true == CommThreadRunning) {
            try {
                
                if(false == dt_dfu_en) {
                    //sendMsg(makeCommTxData());
                    //readMsg(CommRxBuffer);
                    makeCommTxData();
                    
                    tr_Msg(CommTxBuffer, CommRxBuffer, true);
                    
                    //System.out.println("·¢ËÍÊý¾Ý£º" + ComFn.bytesToHexString(CommTxBuffer.array(), CommTxBuffer.array().length));
                    
                    byte[] plain_buf = new byte[CommRxBuffer.limit()];
                    CommRxBuffer.get(plain_buf);
                    //System.out.println("½ÓÊÕÊý¾Ý£º" + ComFn.bytesToHexString(plain_buf, plain_buf.length));
                    getDataFromCommBuf(plain_buf);
                    
                    Thread.sleep(500);
                }            
            } catch (Exception e) {
                m_Log.error(e.toString(), e);
                exitCommPortThread();
                JOptionPane.showMessageDialog(null, "BTS ÉÏλ»ú´®¿ÚÒì³£: " + e.getMessage());
            }
        }
        /******************************************/
        closeCommPort();
        /******************************************/
        m_Log.error("SwitchDevice CommPort is quit!");
    }
    /*********************************************************************************************/
    /*********************************************************************************************/
    /*********************************************************************************************/
    /*********************************************************************************************/
    public String getDataFromCommBuf(final byte[] bytes)
      {
        boolean comm_res = false;
        ByteBuffer bf = ByteBuffer.allocate(bytes.length);
        bf.order(ByteOrder.BIG_ENDIAN);
        bf.put(bytes);
        bf.flip();
        //System.err.println(ComFn.bytesToHexString(bytes, bytes.length));
        String msg = "";
        if(true == m_Read_Cmd.putByteBuffer(bf))
        {
            //System.out.println(SwitchDevice_ComBase.CMD_GetVIData+"@@@@@@@@@@@@@@"+dt_cmd);
            //------------------- ¶ÁÈ¡FBS9100µçѹµçÁ÷Êý¾Ý --------------------
            if(DummyLoad_ComBase.CMD_GetLoaderState == dt_cmd)
            {
                if(true == m_DummyLoad_Data.putByteBuffer(bf))
                {
                    System.out.println("¶ÁÈ¡¸ºÔØ×´Ì¬³É¹¦");
                    comm_res = true;                
                }
            }
            else if(DummyLoad_ComBase.CMD_GetLoaderVersion == dt_cmd)
            {
                if(bf.capacity() >= 2) {
                    dev_stat_version = ComBase.changeShortToInt(bf.getShort());
                    dev_stat_version_Str = "V" + dev_stat_version;
                    
                    System.out.println("¶ÁÈ¡¸ºÔذ汾³É¹¦");
                    comm_res = true;                
                }
            }else if(DummyLoad_ComBase.CMD_GetTempData == dt_cmd)
                {    
                if(true == m_DummyLoad_TemperData.putByteBuffer(bf))
                {                    
                    System.out.println("¶ÁÈ¡¸ºÔØÎ¶ÈÐÅÏ¢³É¹¦");
                    comm_res = true;  
                }
            }else if(DummyLoad_ComBase.CMD_LoaderStop == dt_cmd) {
                if(DummyLoad_ComBase.CMD_Success == m_Read_Cmd.ResState) {    
                    
                    dt_cmd_ack = DummyLoad_ComBase.CMD_LoaderStop_Ack;
                    dev_control_Str = "Í£Ö¹¼Ù¸ºÔع¤×÷³É¹¦!"+Com.get_DTF(new Date(), Com.DTF_YMDhms);
                    comm_res = true;
                }
            }else if(DummyLoad_ComBase.CMD_StartDischarge == dt_cmd) {
                if(DummyLoad_ComBase.CMD_Success == m_Read_Cmd.ResState)
                {
                    dt_cmd_ack = DummyLoad_ComBase.CMD_StartDischarge_Ack;
                    dev_control_Str = "Æô¶¯¼Ù¸ºÔطŵç³É¹¦!"+Com.get_DTF(new Date(), Com.DTF_YMDhms);
                    comm_res = true;                
                }
            }else if(DummyLoad_ComBase.CMD_StartCharge == dt_cmd) {
                if(DummyLoad_ComBase.CMD_Success == m_Read_Cmd.ResState) {
                    dt_cmd_ack = DummyLoad_ComBase.CMD_StartCharge_Ack;
                    dev_control_Str = "Æô¶¯¼Ù¸ºÔسäµç³É¹¦!"+Com.get_DTF(new Date(), Com.DTF_YMDhms);
                    comm_res = true;
                }
            }else if(DummyLoad_ComBase.CMD_LoaderControl == dt_cmd) {
                if(DummyLoad_ComBase.CMD_Success == m_Read_Cmd.ResState) {
                    dt_cmd_ack = DummyLoad_ComBase.CMD_LoaderControl_Ack;
                    dev_control_Str = "ÉèÖüٸºÔزâÊÔµçÁ÷³É¹¦!"+Com.get_DTF(new Date(), Com.DTF_YMDhms);
                    comm_res = true;
                }
            }else if(DummyLoad_ComBase.CMD_DisRlayControl == dt_cmd) {
                if(DummyLoad_ComBase.CMD_Success == m_Read_Cmd.ResState) {
                    dt_cmd_ack = DummyLoad_ComBase.CMD_DisRlayControl_Ack;
                    dev_control_Str = "¹Ø±Õ×ܵļ̵çÆ÷ºÍ·çÉȳɹ¦!"+Com.get_DTF(new Date(), Com.DTF_YMDhms);
                    comm_res = true;
                }
            }
        }
        
        if(true == comm_res) {
            if(++comm_rx_cnt > 1000000) {
                comm_rx_cnt = 0;
            }
        }
        return msg;
    }
    /*********************************************************************************************/
    
    public void makeRandomData(int dt_cmd) {
        
        float targetCurr = 0;
        int testGroupNum = m_FBS_VCData.m_SysState.TestGroupNum;        //²âÊÔ×éºÅ
        int workState = m_FBS_VCData.m_SysState.WorkState;                //É豸¹¤×÷״̬
        float groupVolLimit = 0;                                        //×é¶Ëµçѹ
        int eveBattGroupNum = 0;                                        //ÿ×éµ¥Ìå¸öÊý
        eveBattGroupNum = m_FBS_VCData.battSum/m_FBS_VCData.battGroup;
        boolean isTest = false;
        
        if(m_FBS_VCData.m_SysState.WorkState == FBS9100_SysState.SYS_STATE_DISCHARGING) {
            //·Åµç²âÊÔ            
            targetCurr = m_FBS_DiscParamFromDev.DisCurr;
            groupVolLimit = 35f;
            isTest = true;
            alearyMaxCurr = false;
        }else if(m_FBS_VCData.m_SysState.WorkState == FBS9100_SysState.SYS_STATE_CHARGING){
            //³äµç²âÊÔ
            targetCurr = m_FBS_DiscParamFromDev.ChargeCurrSet;
            groupVolLimit = 53.5f;
            isTest = true;
            
            if(Math.abs(m_FBS_VCData.battcurr[testGroupNum-1] - targetCurr) <= 0.5) {
                alearyMaxCurr = true;
                targetCurr = 1;
            }
        }else if(m_FBS_VCData.m_SysState.WorkState == FBS9100_SysState.SYS_STATE_STOPPED){
            //¸¡³äʱ
            alearyMaxCurr = false;
        }
        
        System.err.println("Start:"+alearyMaxCurr);
        
//        System.err.println("ϵͳ¹¤×÷״̬£º"+m_FBS_VCData.m_SysState.WorkState + "\t±»²â×éºÅ£º" + m_FBS_VCData.m_SysState.TestGroupNum+
//                            "\n ·ÅµçµçÁ÷£º"+m_FBS_DiscParamFromDev.DisCurr + "\tÏÞÖÆµçÁ÷£º"+targetCurr) ;
        for(int i = 0 ; i< m_FBS_VCData.onlinevol.length;i++) {            
            if((i+1) == testGroupNum && (workState == FBS9100_SysState.SYS_STATE_CHARGING || workState == FBS9100_SysState.SYS_STATE_DISCHARGING)) {
                //²âÊÔʱ
                
                m_FBS_VCData.onlinevol[i] = (double)FBS9100_ComBase.CreateIntRanDom(5350,5360)/100;                
                m_FBS_VCData.batttemp[i] = (double)FBS9100_ComBase.CreateIntRanDom(200,400)/10;
 
                //m_FBS_VCData.groupvol[i] = (double)FBS9100_ComBase.CreateIntRanDom(5310,5690)/100;
                //m_FBS_VCData.battcurr[i] = (double)FBS9100_ComBase.CreateIntRanDom(0,30)/10;
                if(workState == FBS9100_SysState.SYS_STATE_CHARGING && alearyMaxCurr) {
                    
                    //³äµçʱ£¬ÈôÔÚÏßµçѹºÍ×é¶Ëµçѹѹ²îСÓÚµÈÓÚ4V,Ä£ÄâµçÁ÷ϽµÖÁ1A×óÓÒ
                    float testCurr = 0;    
                    double test_curr = m_FBS_VCData.battcurr[testGroupNum-1];
                    if(test_curr > (testCurr+1)) {                        
                        m_FBS_VCData.battcurr[testGroupNum-1] = m_FBS_VCData.battcurr[testGroupNum-1] - (double)FBS9100_ComBase.CreateIntRanDom(0,5)/10;
                    }else {                        
                        m_FBS_VCData.battcurr[testGroupNum-1] = testCurr + (double)FBS9100_ComBase.CreateIntRanDom(0,10)/10;
                    }
                    
                    
                }else {                    
                    m_FBS_VCData.setRandomTestCurr(testGroupNum, targetCurr);
                }
                
            }else {
                
                
                m_FBS_VCData.onlinevol[i] = (double)FBS9100_ComBase.CreateIntRanDom(5350,5360)/100;
                //m_FBS_VCData.groupvol[i] = (double)FBS9100_ComBase.CreateIntRanDom(5310,5690)/100;
                m_FBS_VCData.battcurr[i] = (double)FBS9100_ComBase.CreateIntRanDom(0,30)/10;
                m_FBS_VCData.batttemp[i] = (double)FBS9100_ComBase.CreateIntRanDom(200,400)/10;
            
            }        
        }
        if(FBS9100_ComBase.CMD_SetVIData == dt_cmd) {            
            for(int i = 0 ;i<m_FBS_VCData.vol.length;i++) {
                if(isTest && (i >= (testGroupNum-1)*eveBattGroupNum) && (i<(testGroupNum)*eveBattGroupNum)) {
                    if(m_FBS_VCData.m_SysState.WorkState == FBS9100_SysState.SYS_STATE_DISCHARGING) {
                        //·Åµçʱµ¥Ìåµçѹ
                        m_FBS_VCData.vol[i] = RandomDisMonVol(m_FBS_VCData.vol[i]);
                        //System.out.println("·Åµç²âÊÔÖÐ#"+(i+1)+":"+m_FBS_VCData.vol[i]);
                    }else{            
                        //³äµçʱµ¥Ìåµçѹ
                        m_FBS_VCData.vol[i] = RandomChrMonVol(m_FBS_VCData.vol[i]);    
                        //System.out.println("³äµç²âÊÔÖÐ#"+(i+1)+":"+m_FBS_VCData.vol[i]);
                    }
                }else {
                    m_FBS_VCData.vol[i] = (double)FBS9100_ComBase.CreateIntRanDom(2229,2231)/1000;
                }
                
            }
            
            for(int n = 0;n<m_FBS_VCData.groupvol.length;n++) {
                double sumVol = 0;
                for(int k = (n*eveBattGroupNum);k<((n+1)*eveBattGroupNum);k++) {
                    sumVol += m_FBS_VCData.vol[k];
                }        
                m_FBS_VCData.groupvol[n] = sumVol;
            }
        }
        if(FBS9100_ComBase.CMD_SetMonomerRes == dt_cmd) {            
            for(int i = 0 ;i<m_FBS_ResCapData.m_res.length;i++) {
                m_FBS_ResCapData.m_res[i] = (double)FBS9100_ComBase.CreateIntRanDom(99,1000)/1000;
            }
        }
        if(FBS9100_ComBase.CMD_SetMonomerTMP == dt_cmd) {            
            for(int i = 0 ;i<m_FBS_ResCapData.m_tmp.length;i++) {
                m_FBS_ResCapData.m_tmp[i] = (double)FBS9100_ComBase.CreateIntRanDom(200,400)/10;
            }
        }
        
        
        
        System.err.println("End:"+alearyMaxCurr);
        //System.out.println("m_res[i]:" + Arrays.toString(m_FBS_ResCapData.m_res));
        //System.out.println("m_tmp[i]:" + Arrays.toString(m_FBS_ResCapData.m_tmp));
    }
    
    //Ä£Äâ·Åµçʱµ¥Ìåµçѹ
    public static double RandomDisMonVol(double monvol) {        
        if(monvol <= 1.7) {
            return (double)FBS9100_ComBase.CreateIntRanDom(1690,1710)/1000;
        }else {
            return monvol - (double)FBS9100_ComBase.CreateIntRanDom(0,2)/10000;
        }
    }
    
    //Ä£Äâ³äµçʱµ¥Ìåµçѹ
    public static double RandomChrMonVol(double monvol) {
        if(monvol >= 2.230) {
            return (double)FBS9100_ComBase.CreateIntRanDom(2229,2231)/1000;
        }else {
            return monvol + (double)FBS9100_ComBase.CreateIntRanDom(0,10)/10000;
        }    
    }
    
    public static void main(String[] args) {
        for(int i  =0 ;i<100;i++) {
            System.out.println(RandomDisMonVol(2.16));
            
        }
    }
}