lxw
2023-02-10 f978d4ecdf83cbf7c8b778f1362b86be5aa510bd
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
package com.whyc.mcp;
 
import com.whyc.util.ComBase;
 
import java.nio.ByteBuffer;
import java.util.Arrays;
 
public class VolCurrData {
    public static final int BYTE_LEN = 80;
 
    public static final int GROUP_COUNT_MAX = 4;
    public float onlinevol[]  = new float[GROUP_COUNT_MAX];//在线电压    分辨率0.1V
    public float groupvol[]   = new float[GROUP_COUNT_MAX];//组端电压 分辨率0.1V
    public int battstate[]    = new int[GROUP_COUNT_MAX];//电池状态,见表2
    public float  battcurr[]  = new float[GROUP_COUNT_MAX];//电流 分辨率0.1A
    public int battcap[]      = new int[GROUP_COUNT_MAX];//已测容量 AH
    public float  batttemp[]  = new float[GROUP_COUNT_MAX];//温度,预留,没使用
    public int monMAX_num[]   = new int[GROUP_COUNT_MAX];//最高单体索引号
    public int monMIN_num[]   = new int[GROUP_COUNT_MAX];//最低单体索引号
    public float  monvolMAX[] = new float[GROUP_COUNT_MAX];//最高单体电压 0.001V
    public float  monvolMIN[] = new float[GROUP_COUNT_MAX];//最低单体电压 0.001V
 
    public boolean puByteBuffer(ByteBuffer bf) {
        //System.err.println(ComFn.bytesToHexString(bf.array(), bf.array().length));
        bf.position(0);
        if(bf.remaining() < BYTE_LEN) {
            return false;
        }
        for(int i=0;i<onlinevol.length;i++) {
            onlinevol[i]  = ComBase.changeShortToFloat(bf.getShort())*0.1f;    //在线电压    分辨率0.1V
        }
        for(int i=0;i<groupvol.length;i++) {
            groupvol[i]   = ComBase.changeShortToFloat(bf.getShort())*0.1f;    //组端电压 分辨率0.1V
        }
        for(int i =0;i<battstate.length;i++) {
            battstate[i] = ComBase.changeShortToInt(bf.getShort());            //电池状态,见表2
        }
        for(int i = 0;i<battcurr.length;i++) {
            battcurr[i]  = ComBase.changeShortToFloat(bf.getShort())*0.1f;    //电流 分辨率0.1A
        }
        for(int i=0;i<battcap.length;i++) {
            battcap[i] = ComBase.changeShortToInt(bf.getShort());            //已测容量 AH
        }
        for(int i=0;i<batttemp.length;i++) {
            batttemp[i]  = ComBase.changeShortToFloat(bf.getShort());        //温度,预留,没使用
        }
        for(int i=0;i<monMAX_num.length;i++) {
            monMAX_num[i]   = ComBase.changeShortToInt(bf.getShort());        //最高单体索引号
        }
        for(int i=0;i<monMIN_num.length;i++) {
            monMIN_num[i]   = ComBase.changeShortToInt(bf.getShort());//最低单体索引号
        }
        for(int i=0;i<monvolMAX.length;i++) {
            monvolMAX[i] = ComBase.changeShortToFloat(bf.getShort())*0.001f;//最高单体电压 0.001V
        }
        for(int i=0;i<monvolMIN.length;i++) {
            monvolMIN[i] = ComBase.changeShortToFloat(bf.getShort())*0.001f;//最低单体电压 0.001V
        }
        bf.compact();
        //System.out.println(this);
        return true;
    }
 
    @Override
    public String toString() {
        return "VolCurrData [onlinevol=" + Arrays.toString(onlinevol) + ", groupvol=" + Arrays.toString(groupvol)
                + ", battstate=" + Arrays.toString(battstate) + ", battcurr=" + Arrays.toString(battcurr)
                + ", battcap=" + Arrays.toString(battcap) + ", batttemp=" + Arrays.toString(batttemp)
                + ", monMAX_num=" + Arrays.toString(monMAX_num) + ", monMIN_num=" + Arrays.toString(monMIN_num)
                + ", monvolMAX=" + Arrays.toString(monvolMAX) + ", monvolMIN=" + Arrays.toString(monvolMIN) + "]";
    }
}