whyclj
2019-11-11 dd4d4e91cdfb9806155d7dedca8907ef4fb67ae7
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
package com.concentrator;
 
import com.util.ComBase;
 
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
 
 
public class Concentrator_State {
    public static final int BYTE_LEN = 30;
    public static final int REG_LEN = 30;
 
    public static final int MON_REG_COUNT = 100;                //单体数据一次最多的汇集器数量
    public static final int SYS_REG_COUNT = 15;                    //系统状态的汇集器数量
 
    public static int monCount = 24;                        //单体数量
 
    private double sysversion;            //系统版本(0.1)
    private int sysstate;                //系统状态         0-常规模式    1-内阻模式    2-编址模式
    private double groupvol;            //组端电压(0.1)
    private double groupcurr;            //组端电流(0.1)
    private int battstate;                //电池状态    0-浮充     1-放电        2-充电
    private int currdirection;            //电流方向    0-充电       1-放电
 
    private int backup1;
    private int backup2;
    private int backup3;
    private int backup4;
    private int backup5;
    private int backup6;
    private int backup7;
    private int backup8;
    private int restestcount;            //内阻测试次数
 
    public double[]    mon_vols    = new double[Concentrator_ComBase.MonomerCountMax];                    //单体电压
    public double[]    mon_tmps    = new double[Concentrator_ComBase.MonomerCountMax];                    //单体温度
    public double[]    mon_ress    = new double[Concentrator_ComBase.MonomerCountMax];                    //单体内阻
 
 
    public ByteBuffer getReadBuffer() {
        ByteBuffer tmp = ByteBuffer.allocate(2);
        tmp.order(ByteOrder.BIG_ENDIAN);
        tmp.putShort(ComBase.changeIntToShort(REG_LEN));
        tmp.flip();
        return tmp;
    }
 
    public boolean putByteBuffer(ByteBuffer bf) {
        if(bf.limit() < BYTE_LEN) {
            return false;
        }
        ByteBuffer tmpbuf = bf;
        tmpbuf.position(0);
 
        sysversion = ComBase.changeShortToDouble(tmpbuf.getShort())/10;            //系统版本
        sysstate = ComBase.changeShortToInt(tmpbuf.getShort());                    //系统状态
        groupvol = ComBase.changeShortToDouble(tmpbuf.getShort())/10;            //组端电压
        groupcurr = ComBase.changeShortToDouble(tmpbuf.getShort())/10;            //组端电流
        battstate = ComBase.changeShortToInt(tmpbuf.getShort());                //电池状态
        currdirection = ComBase.changeShortToInt(tmpbuf.getShort());            //电流方向
 
        backup1 = ComBase.changeShortToInt(tmpbuf.getShort());
        backup2 = ComBase.changeShortToInt(tmpbuf.getShort());
        backup3 = ComBase.changeShortToInt(tmpbuf.getShort());
        backup4 = ComBase.changeShortToInt(tmpbuf.getShort());
        backup5 = ComBase.changeShortToInt(tmpbuf.getShort());
        backup6 = ComBase.changeShortToInt(tmpbuf.getShort());
        backup7 = ComBase.changeShortToInt(tmpbuf.getShort());
        backup8 = ComBase.changeShortToInt(tmpbuf.getShort());
        restestcount = ComBase.changeShortToInt(tmpbuf.getShort());            //内阻测试次数
 
        return true;
    }
 
    public boolean putMonDataBuffer(ByteBuffer bf,int reg_addr){
        if(bf.limit() < BYTE_LEN) {
            return false;
        }
        bf.position(0);
        int index = 0;
        int dataType = 1;
        int range = 1000;
        if(reg_addr >= 0x201B && reg_addr <= 0x2146){
            //单体电压
            dataType = 1;
            index = (reg_addr - 0x201B)/100;        //设置当前索引
        }else if(reg_addr >= 0x2147 && reg_addr<= 0x2272){
            //单体温度
            dataType = 2;
            index = (reg_addr - 0x2147)/100;
        }else if(reg_addr >= 0x2273 && reg_addr <= 0x239E){
            //单体内阻
            dataType = 3;
            index = (reg_addr - 0x2273)/100;
        }
        for(int i=0;i<100;i++){
            switch (dataType){
                case 1:{
                    mon_vols[index*100+i] = ComBase.changeShortToDouble(bf.getShort())/1000;
                }break;
                case 2:{
                    mon_tmps[index*100+i] = ComBase.changeShortToDouble(bf.getShort())/10;
                }break;
                case 3:{
                    mon_ress[index*100+i] = ComBase.changeShortToDouble(bf.getShort())/1000;
                }break;
            }
        }
        return true;
    }
 
 
 
    public int getBYTE_LEN() {
        return BYTE_LEN;
    }
 
 
    public double getSysversion() {
        return sysversion;
    }
 
    public int getSysstate() {
        return sysstate;
    }
 
    public double getGroupvol() {
        return groupvol;
    }
 
    public double getGroupcurr() {
        return groupcurr;
    }
 
    public int getBattstate() {
        return battstate;
    }
 
    public int getCurrdirection() {
        return currdirection;
    }
 
    public int getBackup1() {
        return backup1;
    }
 
    public int getBackup2() {
        return backup2;
    }
 
    public int getBackup3() {
        return backup3;
    }
 
    public int getBackup4() {
        return backup4;
    }
 
    public int getBackup5() {
        return backup5;
    }
 
    public int getBackup6() {
        return backup6;
    }
 
    public int getBackup7() {
        return backup7;
    }
 
    public int getBackup8() {
        return backup8;
    }
 
    public int getRestestcount() {
        return restestcount;
    }
 
 
    public void setSysversion(double sysversion) {
        this.sysversion = sysversion;
    }
 
    public void setSysstate(int sysstate) {
        this.sysstate = sysstate;
    }
 
    public void setGroupvol(double groupvol) {
        this.groupvol = groupvol;
    }
 
    public void setGroupcurr(double groupcurr) {
        this.groupcurr = groupcurr;
    }
 
    public void setBattstate(int battstate) {
        this.battstate = battstate;
    }
 
    public void setCurrdirection(int currdirection) {
        this.currdirection = currdirection;
    }
 
    public void setBackup1(int backup1) {
        this.backup1 = backup1;
    }
 
    public void setBackup2(int backup2) {
        this.backup2 = backup2;
    }
 
    public void setBackup3(int backup3) {
        this.backup3 = backup3;
    }
 
    public void setBackup4(int backup4) {
        this.backup4 = backup4;
    }
 
    public void setBackup5(int backup5) {
        this.backup5 = backup5;
    }
 
    public void setBackup6(int backup6) {
        this.backup6 = backup6;
    }
 
    public void setBackup7(int backup7) {
        this.backup7 = backup7;
    }
 
    public void setBackup8(int backup8) {
        this.backup8 = backup8;
    }
 
    public void setRestestcount(int restestcount) {
        this.restestcount = restestcount;
    }
 
    @Override
    public String toString() {
        return "Concentrator_State [sysversion=" + sysversion + ", sysstate=" + sysstate
                + ", groupvol=" + groupvol + ", groupcurr=" + groupcurr + ", battstate=" + battstate
                + ", currdirection=" + currdirection + ", backup1=" + backup1 + ", backup2=" + backup2 + ", backup3="
                + backup3 + ", backup4=" + backup4 + ", backup5=" + backup5 + ", backup6=" + backup6 + ", backup7="
                + backup7 + ", backup8=" + backup8 + ", restestcount=" + restestcount + "]";
    }
 
 
}