1
81041
2019-06-20 ab3c4acf83f54f8449ca8664c4a2bb79bd30f297
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
package com.fgkj.fbo;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
 
public class FboData {
    public FboDataType m_DataType = new FboDataType();
    public short CRC16;
    public FboTestTime m_TestTime = new FboTestTime();
    public int BattGroup;
    public int BattSum;
    public float OnlineVol;
    public float SumVoltage;
    public float SumCurrent;
    public float[] SubCurrent = new float[4];
    public float AllCap;
    public float[] SubCap = new float[4];
    public float[] SingleVol = new float[500];
    
    public void setData(byte[] buf)
    {
        ByteBuffer bf = ByteBuffer.allocate(2048);
        bf.order(ByteOrder.LITTLE_ENDIAN);
        bf.put(buf);
        bf.position(0);
        
        CRC16 = (short) (bf.getShort()&0xFFFF);
        m_TestTime.hour = (int) (bf.get()&0xFF);
        m_TestTime.minute = (int) (bf.get()&0xFF);
        m_TestTime.second = (int) (bf.get()&0xFF);
        BattGroup = (int) (bf.get()&0xFF);
        
        BattSum = (int) (bf.getShort()&0xFFFF);
        if(BattSum > 500)
            BattSum = 500;
        else if (BattSum < 0) {
            BattSum = 0;
        }
        
        OnlineVol = ((float) (bf.getShort()&0xFFFF)) / 10;
        SumVoltage = ((float) (bf.getShort()&0xFFFF)) / 10;
        
        SumCurrent = ((float) (bf.getShort()&0xFFFF)) / 10;
        if(0xFD == m_DataType.TypeTag0) {
            SumCurrent *= -1;
        }
        for(int n=0; n<4; n++)
        {
            SubCurrent[n] = ((float) (bf.getShort()&0xFFFF)) / 10;
            if(0xFD == m_DataType.TypeTag0) {
                SubCurrent[n] *= -1;
            }
        }
        
        AllCap = ((float) (bf.getShort()&0xFFFF));
        if(0xFD == m_DataType.TypeTag0) {
            AllCap *= -1;
        }
        for(int n=0; n<4; n++)
        {
            SubCap[n] = ((float) (bf.getShort()&0xFFFF));
            if(0xFD == m_DataType.TypeTag0) {
                SubCap[n] *= -1;
            }
        }
        
        for(int n=0; n<BattSum; n++)
        {
            SingleVol[n] = ((float) (bf.getShort()&0xFFFF)) / 1000;
        }
    }
    
    public static void checkFboFile(File file, FboDataInf data_inf, ArrayList<FboData> al_fbo_data)
    {
        File f = file;
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(f);
            byte[] buf = new byte[256];
            if(fis.read(buf, 0, buf.length) == 256)
            {
                data_inf.setDataInf(buf);
                while(true)
                {
                    FboDataType mType = new FboDataType();
                    int tag = mType.checkDataHead(fis);
                    if((0xFD == tag) || (0xFC == tag))
                    {
                        byte[] databuf = new byte[data_inf.BattSum*2 + 32];
                        if(fis.read(databuf) == databuf.length)
                        {
                            FboData m_FboData = new FboData();
                            m_FboData.m_DataType = mType;
                            m_FboData.setData(databuf);
                            al_fbo_data.add(m_FboData);
                        }
                    }
                    if(tag == 1)
                        break;
                }
            }
                
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(null != fis)
            {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    
    
    public void setData(IdcData i_data)
    {
        m_DataType.TypeTag0 = i_data.DataType;
        m_DataType.TypeTag1 = i_data.DataType;
        m_DataType.TypeTag2 = i_data.DataType;
        m_DataType.TypeTag3 = i_data.DataType;
        
        OnlineVol = 0;
        SumVoltage = i_data.SumVol;
        SumCurrent = i_data.SumCur;
        SubCurrent[0] = SumCurrent;
        
        AllCap = i_data.SumAH;
        SubCap[0] = AllCap;
        
        int param = (-1);
        if(0xFC == m_DataType.TypeTag0) {
            param = 1;
        }
        SumCurrent = Math.abs(SumCurrent) * param;
        SubCurrent[0] = Math.abs(SubCurrent[0]) * param;
        
        AllCap = Math.abs(AllCap) * param;
        SubCap[0] = Math.abs(SubCap[0]) * param;
        
        for(int n=0; n<400; n++)
        {
            SingleVol[n] = i_data.MonomerVol[n];
        }
    }
    
    public int getMinIndex()
    {
        int num = 0;
        float min = 800000;
        for(int n=0; n<SingleVol.length; n++)
        {
            if((SingleVol[n] > 0.1) && (SingleVol[n] < min))
            {
                min = SingleVol[n];
                num = n;
            }
        }
        
        return num;
    }
    
    public int getMaxIndex()
    {
        int num = 0;
        float max = 0;
        for(int n=0; n<SingleVol.length; n++)
        {
            if((SingleVol[n] > 0.1) && (max < SingleVol[n]))
            {
                max = SingleVol[n];
                num = n;
            }
        }
        
        return num;
    }
    
    public float getMinVol()
    {
        float min = 800000;
        for(int n=0; n<SingleVol.length; n++)
        {
            if((SingleVol[n] > 0.1) && (SingleVol[n] < min))
            {
                min = SingleVol[n];
            }
        }
        
        return min;
    }
    
    public float getMaxVol()
    {
        float max = 0;
        for(int n=0; n<SingleVol.length; n++)
        {
            if((SingleVol[n] > 0.1) && (max < SingleVol[n]))
            {
                max = SingleVol[n];
            }
        }
        
        return max;
    }
}