DELL
2024-12-18 4e6a319d3a023cd57b1bb3f5afd47df0763e57b7
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
package com.fgkj.bts;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
 
import com.fgkj.data.ComFn;
import com.fgkj.data.FboData;
import com.fgkj.data.FboData.DataType;
 
/**
 *     充电数据
 * @author DELL
 *
 */
public class BTS_ChargeData {
    
    public int parse_result = BTS_ComBase.PARSE_RESULT_NULL;
    
    
    public BTS_BattParam battParam;                    //电池参数
    public BTS_ChargeParam chargeParam;                //充电参数
    public BTS_ChargeState charState;                //充电状态
    
    public List<BTS_FbsData> fbsDatas;                //每次记录的单体数据
    
    public BTS_ChargeData() {
        battParam = new BTS_BattParam();
        chargeParam = new BTS_ChargeParam();
        charState = new BTS_ChargeState();
        fbsDatas = new ArrayList<BTS_FbsData>();
    }
    
    /**
     *     解析充电数据
     * @param filePath
     */
    public void readChrFile(String filePath)
    {
        FileInputStream fis = null;
        try {
            File f = new File(filePath);
            if(!filePath.endsWith(".CHR") || !filePath.toUpperCase().endsWith(".CHR")) {
                //文件格式错误
                parse_result = BTS_ComBase.PARSE_RESULT_FILETYPEERR;
                return;
            }
            if(!f.exists()) {
                //文件不存在
                parse_result = BTS_ComBase.PARSE_RESULT_NOTFOUNDFILE;
                return;
                //System.out.println("文件不存在..........");
            }
            fis = new FileInputStream(f);
            byte[] buf = new byte[2048];
            if(fis.read(buf, 0, buf.length) == 2048)
            {
                if(this.checkTestDataHead(buf)) {
                    parse_result = BTS_ComBase.PARSE_RESULT_SUCCESS;
                }else {
                    parse_result = BTS_ComBase.PARSE_RESULT_FILEERROR;
                }
                BTS_DataType dataType = new BTS_DataType();
                
                while(true)
                {                    
                    int tag = dataType.checkDataHead(fis);
                    if((0xFD == tag) || (0xFC == tag) || (0xFB == tag))
                    {
                        
                        System.out.println("#################");
                        byte[] databuf = new byte[BTS_FbsData.BASIC_LEN + (battParam.EachGroupBattCount*battParam.BattGroupCount)*2 -4];
                        if(fis.read(databuf) == databuf.length)
                        {
                            ByteBuffer bf = ByteBuffer.allocate(databuf.length + BTS_DataType.BYTE_LEN);
                            bf.order(ByteOrder.LITTLE_ENDIAN);
                            bf.put(dataType.getDataTypeByte());
                            bf.put(databuf);
                            bf.flip();
                            bf.position(0);
                            
                            System.out.println(ComFn.bytesToHexString(databuf, databuf.length));
                            BTS_FbsData fbsData = new BTS_FbsData();
                            if(fbsData.putByteBuffer(bf, 0, 0)) {
                                fbsDatas.add(fbsData);
                            }
                        }
                    }
                    if(tag == 1)
                        break;
                }
            }else {
                parse_result = BTS_ComBase.PARSE_RESULT_FILEERROR;
            }
                
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(null != fis)
            {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    
    /**
     *     解析文件头数据
     * @return
     */
    public boolean checkTestDataHead(byte[] buf) {
        boolean checkOk = true;
        ByteBuffer buffer = ByteBuffer.allocate(buf.length);
        buffer.order(ByteOrder.LITTLE_ENDIAN);
        buffer.put(buf);
        buffer.flip();
        buffer.position(0);
        checkOk = checkOk && battParam.putByteBuffer(buffer);
        System.out.println("checkTestDataHead:"+checkOk);
        
        checkOk = checkOk && chargeParam.putByteBuffer(buffer);
        System.out.println("checkTestDataHead:"+checkOk);
        
        charState.putByteBuffer(buffer);
        return checkOk;
    }
    
}