充放电一体机FGCD通信程序【二期初版】
Administrator
2021-09-03 f615ba8a90438b91ddb7f2df8bd94fd9b7020d0a
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
package com.dev.fgcd.data;
 
import java.nio.ByteBuffer;
 
import com.battmonitor.base.ComBase;
import com.dev.fgcd.comm.FGCD_TestDataDownLoad;
import com.mchange.v3.hocon.HoconUtils;
 
public class FGCD_TestFBOFile {
    public static int BYTE_LEN = 28;            //µ¥¸öÊý¾ÝÎļþ´óС
    public int dev_id;
    public int op_cmd;
    
    public int battgroupid;                        //µç³Ø×éid
    public int file_index;                        //ÏÂÔØÎļþË÷Òý
    public int file_count;                        //µ±Ç°ÎļþÊý
    public int file_total;                        //Êý¾ÝÎļþ×ÜÊý
    
    public int file_downloadNum;               //µ±Ç°ÏÂÔØÎļþ±àºÅË÷Òý
    
    private int stop_reason;                    //½áÊøÔ­Òò
            
    public FBOFile[] files = new FBOFile[8];    //¶ÁÈ¡µÄÀúÊ·Îļþ
    
    public FGCD_TestFBOFile(int dev_id) {
        this.dev_id = dev_id;
        for(int i=0;i<files.length;i++) {
            files[i] = new FBOFile();
        }
    }
    
    
    public FGCD_Cmd createCmd(int cmd) {
        FGCD_Cmd m_Cmd = new FGCD_Cmd();
        m_Cmd.CMD = cmd;
        m_Cmd.Db1 = file_index;                    //±¾Ò³ÐòºÅ
        return m_Cmd;
    }
    
    
    
    
 
    public int getStop_reason() {
        return stop_reason;
    }
 
 
    public void setStop_reason(int stop_reason) {
        this.stop_reason = stop_reason;
    }
 
    public boolean putByteBuffer(ByteBuffer bf,int file_count) {
        this.file_count = (int)Math.floor((double)bf.limit()/BYTE_LEN);
        if(bf.limit() < BYTE_LEN) {
            return false;
        }
        ByteBuffer tmpbuf = bf;
        tmpbuf.position(0);        
        for(int i=0;i<files.length;i++) {
            if(i< this.file_count) {
                FBOFile fbo = files[i];
                fbo.file_count = ComBase.changeByteToInt(bf.get());
                this.file_total = fbo.file_count;
                fbo.file_index = ComBase.changeByteToInt(bf.get());
                fbo.year = ComBase.changeByteToInt(bf.get());                            //Äê
                fbo.month = ComBase.changeByteToInt(bf.get());                            //ÔÂ
                fbo.day = ComBase.changeByteToInt(bf.get());                            //Ìì
                fbo.hour = ComBase.changeByteToInt(bf.get());                            //ʱ    
                fbo.minte = ComBase.changeByteToInt(bf.get());                            //·Ö
                fbo.second = ComBase.changeByteToInt(bf.get());                            //Ãë
                //System.out.println(fbo.year+"-"+fbo.month+"-"+fbo.day+" "+fbo.hour+":"+fbo.minte+":"+fbo.second);
                fbo.setFileName();
                //System.out.println(fbo.filename);
                //fbo.filename;        //ÎļþÃû
                int hour =  ComBase.changeByteToInt(bf.get());
                int minte =  ComBase.changeByteToInt(bf.get());
                int second =  ComBase.changeByteToInt(bf.get());
                fbo.test_timelong = hour*60*60+minte*60+second;                            //²âÊÔʱ³¤
                fbo.data_type = getFBSDevType(ComBase.changeByteToInt(bf.get()));        //Êý¾ÝÀàÐÍ
                fbo.test_curr = (float)ComBase.changeShortToInt(bf.getShort())/10;        //²âÊÔµçÁ÷(0.1A)
                fbo.test_cap = ComBase.changeShortToInt(bf.getShort());                    //²âÊÔÈÝÁ¿(1AH)
                fbo.cap_std = ComBase.changeShortToInt(bf.getShort());                    //±ê³ÆÈÝÁ¿(1AH)
                fbo.monvol_low = ComBase.changeShortToInt(bf.getShort())/100;            //µ¥ÌåÏÂÏÞ(0.01V)
                fbo.groupvol_low = ComBase.changeShortToInt(bf.getShort());                //×é¶ËÏÂÏÞ
                fbo.mon_count = ComBase.changeShortToInt(bf.getShort());                //µ¥Ìå¸öÊý
                fbo.testgroup_count = ComBase.changeShortToInt(bf.getShort());            //²âÊÔµÚ¼¸×éµÃµ½µÄÊý¾Ý
                fbo.teststop_reason = ComBase.changeByteToInt(bf.get());                //Í£Ö¹Ô­Òò
                fbo.monvol_type = getMonVolType(ComBase.changeByteToInt(bf.get()));                //µ¥ÌåµçѹÀàÐÍ
            
                fbo.download_state = 0;
                fbo.download_flag = 0;
                fbo.now_data_block = 0;        //µ±Ç°Êý¾Ý¿éÊýÄ¿
                fbo.total_data_block=0;     //µ±Ç°ÏÂÔØ×´Ì¬
            }else {
                files[i].clear();
            }
        }
        return true;
    }
    
    /**
     *     ×ª»¯µ±Ç°²âÊÔÀàÐÍ
     * @param dev_type
     * @return
     */
    public static int getFBSDevType(int dev_type) {
        switch(dev_type) {
            case 0xFD:dev_type = 3;break;            //·Åµç
            case 0xFC:dev_type = 2;break;            //³äµç
            case 0xFE:dev_type = 4;break;            //»î»¯
        }
        return dev_type;
    }
    
    /**
     *     »ñÈ¡µ±Ç°µ¥Ìåµçѹ
     * @param testtype
     * @return
     */
    public float getMonVolType(int testtype) {
        float mon_vol = 0;
        switch(testtype) {
            case 0x14:mon_vol = 2.0f;break;
            case 0x28:mon_vol = 4.0f;break;
            case 0x3C:mon_vol = 6.0f;break;
            case 0x50:mon_vol = 8.0f;break;
            case 0x64:mon_vol = 10.0f;break;
            case 0x78:mon_vol = 12.0f;break;
            case 0x20:mon_vol = 3.2f;break;
            case 0x25:mon_vol = 3.7f;break;
        }
        return mon_vol;
    }
    
    public class FBOFile{
        public int file_count;            //Êý¾ÝÎļþ×ÜÊý
        public int file_index;            //µ±Ç°ÎļþË÷Òý
        public int year;                //Äê
        public int month;                //ÔÂ
        public int day;                    //Ìì
        public int hour;                //ʱ    
        public int minte;                //·Ö
        public int second;                //Ãë
        public String filename;            //ÎļþÃû
        public int test_timelong;        //²âÊÔʱ³¤
        public int data_type;            //Êý¾ÝÀàÐÍ
        public float test_curr;            //²âÊÔµçÁ÷(0.1A)
        public int test_cap;            //²âÊÔÈÝÁ¿(1AH)
        public int cap_std;                //±ê³ÆÈÝÁ¿(1AH)
        public float monvol_low;        //µ¥ÌåÏÂÏÞ(0.01V)
        public float groupvol_low;        //×é¶ËÏÂÏÞ
        public int mon_count;            //µ¥Ìå¸öÊý
        public int testgroup_count;        //²âÊÔµÚ¼¸×éµÃµ½µÄÊý¾Ý
        public int teststop_reason;        //Í£Ö¹Ô­Òò
        public float monvol_type;        //µ¥ÌåµçѹÀàÐÍ
        public int download_flag;        //ÏÂÔØ±êʶ
        public int download_state;        //ÏÂÔØ×´Ì¬
        public int now_data_block;        //µ±Ç°Êý¾Ý¿éÊýÄ¿
        public int total_data_block;     //µ±Ç°ÏÂÔØ×´Ì¬
        
        
        
        public void clear() {
            file_count = 0;            //Êý¾ÝÎļþ×ÜÊý
            file_index = 0;            //µ±Ç°ÎļþË÷Òý
            filename = "";            //ÎļþÃû
            test_timelong = 0;        //²âÊÔʱ³¤
            data_type = 0;            //Êý¾ÝÀàÐÍ
            test_curr = 0;            //²âÊÔµçÁ÷(0.1A)
            test_cap = 0;            //²âÊÔÈÝÁ¿(1AH)
            cap_std = 0;            //±ê³ÆÈÝÁ¿(1AH)
            monvol_low = 0;            //µ¥ÌåÏÂÏÞ(0.01V)
            groupvol_low = 0;        //×é¶ËÏÂÏÞ
            mon_count = 0;            //µ¥Ìå¸öÊý
            testgroup_count = 0;    //²âÊÔµÚ¼¸×éµÃµ½µÄÊý¾Ý
            teststop_reason = 0;    //Í£Ö¹Ô­Òò
            monvol_type = 0;        //µ¥ÌåµçѹÀàÐÍ
            download_flag = 0;        //ÏÂÔØ±êʶ
            download_state = 0;        //ÏÂÔØ×´Ì¬
            
            now_data_block = 0;        //µ±Ç°Êý¾Ý¿éÊýÄ¿
            total_data_block = 0;     //µ±Ç°ÏÂÔØ×´Ì¬
        }
        
        public FBOFile clone() {
            FBOFile tmpFile = new FBOFile();
            tmpFile.file_count = file_count;            //Êý¾ÝÎļþ×ÜÊý
            tmpFile.file_index = file_index;            //µ±Ç°ÎļþË÷Òý
            tmpFile.filename = filename;            //ÎļþÃû
            tmpFile.test_timelong = test_timelong;        //²âÊÔʱ³¤
            tmpFile.data_type =data_type;            //Êý¾ÝÀàÐÍ
            tmpFile.test_curr =test_curr;            //²âÊÔµçÁ÷(0.1A)
            tmpFile.test_cap =test_cap;            //²âÊÔÈÝÁ¿(1AH)
            tmpFile.cap_std =cap_std;            //±ê³ÆÈÝÁ¿(1AH)
            tmpFile.monvol_low = monvol_low;            //µ¥ÌåÏÂÏÞ(0.01V)
            tmpFile.groupvol_low = groupvol_low;        //×é¶ËÏÂÏÞ
            tmpFile.mon_count = mon_count;            //µ¥Ìå¸öÊý
            tmpFile.testgroup_count = testgroup_count;    //²âÊÔµÚ¼¸×éµÃµ½µÄÊý¾Ý
            tmpFile.teststop_reason = teststop_reason;    //Í£Ö¹Ô­Òò
            tmpFile.monvol_type = monvol_type;        //µ¥ÌåµçѹÀàÐÍ
            tmpFile.download_flag = download_flag;        //ÏÂÔØ±êʶ
            tmpFile.download_state = download_state;        //ÏÂÔØ×´Ì¬
            
            tmpFile.now_data_block = now_data_block;        //µ±Ç°Êý¾Ý¿éÊýÄ¿
            tmpFile.total_data_block = total_data_block;     //µ±Ç°ÏÂÔØ×´Ì¬
            return tmpFile;
        }
        
        public int getFile_count() {
            return file_count;
        }
        public int getFile_index() {
            return file_index;
        }
        public int getYear() {
            return year;
        }
        public int getMonth() {
            return month;
        }
        public int getDay() {
            return day;
        }
        public int getHour() {
            return hour;
        }
        public int getMinte() {
            return minte;
        }
        public int getSecond() {
            return second;
        }
        public String getFilename() {
            return filename;
        }
        public int getTest_timelong() {
            return test_timelong;
        }
        public int getData_type() {
            return data_type;
        }
        public float getTest_curr() {
            return test_curr;
        }
        public int getTest_cap() {
            return test_cap;
        }
        public int getCap_std() {
            return cap_std;
        }
        public float getMonvol_low() {
            return monvol_low;
        }
        public float getGroupvol_low() {
            return groupvol_low;
        }
        public int getMon_count() {
            return mon_count;
        }
        public int getTestgroup_count() {
            return testgroup_count;
        }
        public int getTeststop_reason() {
            return teststop_reason;
        }
        public void setFile_count(int file_count) {
            this.file_count = file_count;
        }
        public void setFile_index(int file_index) {
            this.file_index = file_index;
        }
        public void setYear(int year) {
            this.year = year;
        }
        public void setMonth(int month) {
            this.month = month;
        }
        public void setDay(int day) {
            this.day = day;
        }
        public void setHour(int hour) {
            this.hour = hour;
        }
        public void setMinte(int minte) {
            this.minte = minte;
        }
        public void setSecond(int second) {
            this.second = second;
        }
        public void setFilename(String filename) {
            this.filename = filename;
        }
        public void setTest_timelong(int test_timelong) {
            this.test_timelong = test_timelong;
        }
        public void setData_type(int data_type) {
            this.data_type = data_type;
        }
        public void setTest_curr(float test_curr) {
            this.test_curr = test_curr;
        }
        public void setTest_cap(int test_cap) {
            this.test_cap = test_cap;
        }
        public void setCap_std(int cap_std) {
            this.cap_std = cap_std;
        }
        public int getDownload_flag() {
            return download_flag;
        }
        public int getDownload_state() {
            return download_state;
        }
        public void setDownload_flag(int download_flag) {
            this.download_flag = download_flag;
        }
        
        public int getNow_data_block() {
            return now_data_block;
        }
 
        public int getTotal_data_block() {
            return total_data_block;
        }
 
        public void setNow_data_block(int now_data_block) {
            this.now_data_block = now_data_block;
        }
 
        public void setTotal_data_block(int total_data_block) {
            this.total_data_block = total_data_block;
        }
 
        public void setDownload_state(int download_state) {
            this.download_state = download_state;
        }
        public void setMonvol_low(float monvol_low) {
            this.monvol_low = monvol_low;
        }
        public void setGroupvol_low(float groupvol_low) {
            this.groupvol_low = groupvol_low;
        }
        public void setMon_count(int mon_count) {
            this.mon_count = mon_count;
        }
        public void setTestgroup_count(int testgroup_count) {
            this.testgroup_count = testgroup_count;
        }
        public void setTeststop_reason(int teststop_reason) {
            this.teststop_reason = teststop_reason;
        }
        public float getMonvol_type() {
            return monvol_type;
        }
        public void setMonvol_type(float monvol_type) {
            this.monvol_type = monvol_type;
        }
        
 
        public void setFileName() {
            filename = "F"+(2000+year);
            if(month>=10) {
                filename += "-"+month;
            }else {
                filename += "-0"+month;                
            }
            if(day>=10) {
                filename += "-"+day;
            }else {
                filename += "-0"+day;    
            }
            if(hour>=10) {
                filename += " "+hour;
            }else {
                filename += " 0"+hour;
            }
            if(minte >= 10) {
                filename += ":"+minte;
            }else {
                filename += ":0"+minte;
            }
            if(second >= 10) {
                filename += ":"+second;
            }else {
                filename += ":0"+second;
            }
            filename += ".FBO";
        }
 
        @Override
        public String toString() {
            return "FBOFile [file_count=" + file_count + ", file_index=" + file_index + ", year=" + year + ", month="
                    + month + ", day=" + day + ", hour=" + hour + ", minte=" + minte + ", second=" + second
                    + ", filename=" + filename + ", test_timelong=" + test_timelong + ", data_type=" + data_type
                    + ", test_curr=" + test_curr + ", test_cap=" + test_cap + ", cap_std=" + cap_std + ", monvol_low="
                    + monvol_low + ", groupvol_low=" + groupvol_low + ", mon_count=" + mon_count + ", testgroup_count="
                    + testgroup_count + ", teststop_reason=" + teststop_reason + ", monvol_type=" + monvol_type
                    + ", download_flag=" + download_flag + ", download_state=" + download_state + ", now_data_block="
                    + now_data_block + ", total_data_block=" + total_data_block + "]";
        }
        
    }
 
    public void initDownLoadState() {
        for(int i=0;i<files.length;i++) {
            FBOFile fbo = files[i];
            if(fbo.download_flag == 1) {
                fbo.setDownload_state(FGCD_TestDataDownLoad.DownLoadState_ReadData);
                fbo.total_data_block = 0;
                fbo.now_data_block = 0;
            }
            
        }
        
    }
 
 
    public void clearState() {
        for(int i=0;i<files.length;i++) {
            this.files[i].download_flag = 0;
            this.files[i].download_state = 0;
            this.files[i].now_data_block = 0;
            this.files[i].total_data_block = 0;
        }    
    }
 
 
    @Override
    public String toString() {
        return "FGCD_TestFBOFile [dev_id=" + dev_id + ", op_cmd=" + op_cmd + ", battgroupid=" + battgroupid
                + ", file_index=" + file_index + ", file_count=" + file_count + ", file_total=" + file_total + "]";
    }
 
    
    
}