lxw
2023-05-25 f3c27fb78447449a950ba73c5e72ceda64ad8a12
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
package com.whyc.abe;
 
import com.whyc.constant.ConstantDefined;
 
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;
 
public class ABEDataParase {
 
    public List<ABEFBSData> getFbsData() {
        return fbsData;
    }
 
    public void setFbsData(List<ABEFBSData> fbsData) {
        this.fbsData = fbsData;
    }
 
    public ABEDataHeadStart getFbsDataStart() {
        return fbsDataStart;
    }
 
    public void setFbsDataStart(ABEDataHeadStart fbsDataStart) {
        this.fbsDataStart = fbsDataStart;
    }
 
    public ABEDataHeadStop getFbsDataStop() {
        return fbsDataStop;
    }
 
    public void setFbsDataStop(ABEDataHeadStop fbsDataStop) {
        this.fbsDataStop = fbsDataStop;
    }
 
    public int getParse_result() {
        return parse_result;
    }
 
    public void setParse_result(int parse_result) {
        this.parse_result = parse_result;
    }
 
    public List<ABEFBSData> fbsData;
    public ABEDataHeadStart fbsDataStart;
    public ABEDataHeadStop fbsDataStop;
    
    public int parse_result = ConstantDefined.PARSE_RESULT_NULL;
    
    public void readFBSFile(String filePath)
    {
        //int Data_Type = -1;
        FileInputStream fis = null;
        try {
            File f = new File(filePath);
            if(filePath.toUpperCase().endsWith(".DDF")) {
                //放电数据文件
                fbsDataStart = new ABEDisDataHeadStart();
                fbsDataStop = new ABETestDataHeadStop();
                //Data_Type = ConstantDefined.DATA_TYPE_DIS;
            }else if(filePath.toUpperCase().endsWith(".CCF")) {
                //充电数据文件
                fbsDataStart = new ABEChrDataHeadStart();
                fbsDataStop = new ABETestDataHeadStop();
                //Data_Type = ConstantDefined.DATA_TYPE_DIS;
            }else {
                //非法文件
                parse_result = ConstantDefined.PARSE_RESULT_FILETYPEERR;
                return;                
            }
            if(!f.exists()) {
                //文件不存在
                parse_result = ConstantDefined.PARSE_RESULT_NOTFOUNDFILE;
                //System.out.println("文件不存在..........");
                return;
            }
            fis = new FileInputStream(f);
            
            /*if(ConstantDefined.DATA_TYPE_DIS == Data_Type) {
                
            }else if(ConstantDefined.DATA_TYPE_CHR == Data_Type) {
                fbsDataStart = new ABEChrDataHeadStart();
                fbsDataStop = new ABETestDataHeadStop();    
            }else if(ConstantDefined.DATA_TYPE_RULE == Data_Type){
                fbsDataStart = new ABECycleDataHeadStart();
                fbsDataStop = new ABECycleDataHeadStop();    
            }else {
                parse_result = ConstantDefined.PARSE_RESULT_FILETYPEERR;
                return;
            }*/
            byte[] buf = new byte[512];
            //解析文件头
            if(fis.read(buf, 0, buf.length) == 512)
            {
                ByteBuffer bf = ByteBuffer.allocate(buf.length);
                bf.order(ByteOrder.LITTLE_ENDIAN);
                bf.put(buf);
                bf.position(0);
                
                if(this.fbsDataStart.setDataInf(bf) && this.fbsDataStop.setDataInf(bf)) {
                    parse_result = ConstantDefined.PARSE_RESULT_SUCCESS;
                    
                } else {
                    parse_result = ConstantDefined.PARSE_RESULT_FILEERROR;
                    return;
                }
                
                fbsData = new ArrayList<>();
                ABEDataType mType = new ABEDataType();
                while(true)
                {                    
                    int tag = mType.checkDataHead(fis);
                    if((0xFD == tag) || (0xFC == tag) || (0xFB == tag))
                    {
                        //解析每一笔单体数据
                        byte[] databuf = new byte[8 + 80 + 2];
                        if(fis.read(databuf) == databuf.length)
                        {
                            ABEFBSData m_FbsData = new ABEFBSData();
                            m_FbsData.m_DataType = mType;
                            m_FbsData.setData(databuf);                            
                            fbsData.add(m_FbsData);
                        }
                    }
                    if(tag == 1) {
                        break;
                    }
                }
            }else {
                parse_result = ConstantDefined.PARSE_RESULT_FILEERROR;
            }
                
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(null != fis)
            {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    
    
    public static void main(String[] args) {
        ABEDataParase fbs = new ABEDataParase();
        //fbo.readFboFile("D:/test/F2022-03-09 11.26.12.FBX");
        //fbo.readFboFile("D:/test/F2022-03-09 16.22.37.FBX");
        //fbo.readFboFile("D:/test/F2022-03-10 11.12.30.FBX");
        fbs.readFBSFile("C:\\Users\\29550\\Documents\\WeChat Files\\wxid_uh2bej4ad4ya22\\FileStorage\\File\\2022-09\\F2022-08-02-094422-1.DDF");
        //fbs.readFBSFile("D:\\桌面文件备份\\公司各种设备资料\\硬件数据文件解析相关\\ABE文件解析相关\\数据文件\\F2022-08-02-094422-1.DDF");
        //fbs.readFBSFile("D:\\桌面文件备份\\公司各种设备资料\\硬件数据文件解析相关\\ABE文件解析相关\\数据文件\\F2022-08-02-094422-1.DDF");
        //fbs.readFBSFile("D:\\桌面文件备份\\公司各种设备资料\\硬件数据文件解析相关\\ABE文件解析相关\\数据文件\\F2022-08-03-165222-7.CCF");
        System.out.println(fbs);
    }
    
}