bts
whyclxw
2024-12-18 783eb3cb284bce0ae7dfe57479550fce0591dcb2
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
package com.whyc.mcp;
 
import com.whyc.res.RES_Crc16;
import com.whyc.util.ComBase;
 
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public class FBSData {
 
    public static final int BYTE_LEN = 5 + TestTime.BYTE_LEN+VolCurrData.BYTE_LEN + MVolData.BYTE_LEN;
 
    public int dataType[] = new int[4];        //数据类型 见表1
    public int CRC16;
    public TestTime testTime;                //已测试时间(HMS)
    public int battGroup;                    //组数
    public int battSum;                        //单体个数
    public VolCurrData vcData;
    public MVolData mvol;
 
    public FBSData(int dataType) {
        testTime = new TestTime();
        vcData = new VolCurrData();
        for(int i=0;i<this.dataType.length;i++) {
            this.dataType[i] = dataType;
        }
    }
 
    public boolean setData(byte[] databuf) {
        boolean flag = true;
        ////System.out.println(databuf.length + "===" + BYTE_LEN);
        ////System.out.println(ComFn.bytesToHexString(databuf, databuf.length));
        ByteBuffer bf = ByteBuffer.allocate(databuf.length + dataType.length);
        bf.order(ByteOrder.LITTLE_ENDIAN);
        bf.position(0);
        if(databuf.length < (BYTE_LEN-MVolData.BYTE_LEN)) {
            return flag;
        }
        for(int i = 0;i<dataType.length;i++) {
            bf.put(ComBase.changeIntToByte(this.dataType[i]));
        }
        bf.put(databuf);
        ////System.out.println(ComFn.bytesToHexString(bf.array(), bf.array().length));
        bf.flip();
 
        CRC16 = ComBase.changeShortToInt(bf.getShort(4));
        bf.putShort(4, ComBase.changeIntToShort(0));
        int crc1 = RES_Crc16.CalCRC16(bf, bf.limit());
        if(CRC16 != crc1) {
            //System.err.println(CRC16 +"!="+ crc1);
            return false;
        }
        bf.position(6);
 
        testTime.setTestTime(bf);                            //已测试时间(HMS)
        battGroup = ComBase.changeByteToInt(bf.get());        //组数
        battSum = ComBase.changeShortToInt(bf.getShort());    //单体个数
 
        mvol = new MVolData(battGroup*battSum);
        bf.compact();
 
        flag &= vcData.puByteBuffer(bf);
        flag &= mvol.puByteBuffer(bf);
 
        return flag;
 
    }
 
    public int[] getDataType() {
        return dataType;
    }
 
    public void setDataType(int[] dataType) {
        this.dataType = dataType;
    }
 
    public int getCRC16() {
        return CRC16;
    }
 
    public void setCRC16(int CRC16) {
        this.CRC16 = CRC16;
    }
 
    public TestTime getTestTime() {
        return testTime;
    }
 
    public void setTestTime(TestTime testTime) {
        this.testTime = testTime;
    }
 
    public int getBattGroup() {
        return battGroup;
    }
 
    public void setBattGroup(int battGroup) {
        this.battGroup = battGroup;
    }
 
    public int getBattSum() {
        return battSum;
    }
 
    public void setBattSum(int battSum) {
        this.battSum = battSum;
    }
 
    public VolCurrData getVcData() {
        return vcData;
    }
 
    public void setVcData(VolCurrData vcData) {
        this.vcData = vcData;
    }
 
    public MVolData getMvol() {
        return mvol;
    }
 
    public void setMvol(MVolData mvol) {
        this.mvol = mvol;
    }
}