9度通讯程序适用于9度多组设备
Administrator
2023-12-27 c736aaea5522e295b42676f094d313e7f6a4afb4
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
251
package com.dev.fbs9009;
 
import java.nio.ByteBuffer;
 
import com.base.Com;
import com.base.ComBase;
import com.dev.fbs9009.LD_batt_states.LD_batt_state;
import com.dev.modbus4j.MyModbusMaster;
import com.dev.modbus4j.MyModbusUtils;
import com.serotonin.modbus4j.BatchRead;
import com.serotonin.modbus4j.BatchResults;
import com.serotonin.modbus4j.code.DataType;
 
public class ConcentratorState {
    public static final int BYTE_LEN = 20;                //¼Ä´æÆ÷¸öÊý
    
    private double systemVersion;                        //ϵͳ°æ±¾(01)
    private int systemState;                            //ϵͳ״̬(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 double rippleCurrAvg;                        //ÎÆ²¨µçÁ÷¾ùÖµ(0.01)
    private double rippleCurrTop;                        //ÎÆ²¨µçÁ÷·åÖµ(0.01)
    
    private int    backup1;                                
    private int    backup2;
    private int    backup3;
    private int    backup4;
    private int    backup5;
    private int    backup6;
    
    private int resTestCount;                            //ÄÚ×è²âÊÔ´ÎÊý
    private int resTestMethod;                            //ÄÚ×è²âÊÔ·½·¨(0-dµ¥½Ú·Åµç·¨           1-¹ã²¥·Åµç·¨     2-¼²¨·¨)
    
    private int backup7;
    private int backup8;
    private int backup9;
    private int backup10;
    
    public BaseData baseData = new BaseData();
    
    
    public boolean setConcenState(ByteBuffer bf) {
          ByteBuffer tmpbuf = bf;    
          tmpbuf.position(0);    
          if(!this.baseData.putByteBuffer(bf)){
              return false;
          }
          this.systemVersion = ComBase.changeShortToDouble(tmpbuf.getShort())/10;
          this.systemState = ComBase.changeShortToInt(tmpbuf.getShort());
          this.groupVol = ComBase.changeShortToDouble(tmpbuf.getShort())/10;
          this.groupCurr = ComBase.changeShortToDouble(tmpbuf.getShort())/10;
          this.battState = ComBase.changeShortToInt(tmpbuf.getShort());
          this.currDirection = ComBase.changeShortToInt(tmpbuf.getShort());
          this.rippleCurrAvg = ComBase.changeShortToDouble(tmpbuf.getShort())/100;
          this.rippleCurrTop = ComBase.changeShortToDouble(tmpbuf.getShort())/100;
          this.backup1 = ComBase.changeShortToInt(tmpbuf.getShort());
          this.backup2 = ComBase.changeShortToInt(tmpbuf.getShort());
          this.backup3 = ComBase.changeShortToInt(tmpbuf.getShort());
          this.backup4 = ComBase.changeShortToInt(tmpbuf.getShort());
          this.backup5 = ComBase.changeShortToInt(tmpbuf.getShort());
          this.backup6 = ComBase.changeShortToInt(tmpbuf.getShort());
          this.resTestCount = ComBase.changeShortToInt(tmpbuf.getShort());
          this.resTestMethod = ComBase.changeShortToInt(tmpbuf.getShort());
          this.backup7 = ComBase.changeShortToInt(tmpbuf.getShort());
          this.backup8 = ComBase.changeShortToInt(tmpbuf.getShort());
          this.backup9 = ComBase.changeShortToInt(tmpbuf.getShort());
          this.backup10 = ComBase.changeShortToInt(tmpbuf.getShort());
        //this.groupCurr = 15+Math.random();
        //this.battState = 2;
          
          return true;
    }
    
    public double getSystemVersion() {
        return systemVersion;
    }
    public int getSystemState() {
        return systemState;
    }
    public double getGroupVol() {
        return groupVol;
    }
    public double getGroupCurr() {
        return groupCurr;
    }
    public int getBattState() {
        return battState;
    }
    public int getCurrDirection() {
        return currDirection;
    }
    public double getRippleCurrAvg() {
        return rippleCurrAvg;
    }
    public double getRippleCurrTop() {
        return rippleCurrTop;
    }
    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 getResTestCount() {
        return resTestCount;
    }
    public int getResTestMethod() {
        return resTestMethod;
    }
    public int getBackup7() {
        return backup7;
    }
    public int getBackup8() {
        return backup8;
    }
    public int getBackup9() {
        return backup9;
    }
    public int getBackup10() {
        return backup10;
    }
    public void setSystemVersion(double systemVersion) {
        this.systemVersion = systemVersion;
    }
    public void setSystemState(int systemState) {
        this.systemState = systemState;
    }
    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 setRippleCurrAvg(double rippleCurrAvg) {
        this.rippleCurrAvg = rippleCurrAvg;
    }
    public void setRippleCurrTop(double rippleCurrTop) {
        this.rippleCurrTop = rippleCurrTop;
    }
    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 setResTestCount(int resTestCount) {
        this.resTestCount = resTestCount;
    }
    public void setResTestMethod(int resTestMethod) {
        this.resTestMethod = resTestMethod;
    }
    public void setBackup7(int backup7) {
        this.backup7 = backup7;
    }
    public void setBackup8(int backup8) {
        this.backup8 = backup8;
    }
    public void setBackup9(int backup9) {
        this.backup9 = backup9;
    }
    public void setBackup10(int backup10) {
        this.backup10 = backup10;
    }
 
    public BatchRead<Integer> createConcenStateBatchRead(MyModbusMaster master) {
        int offset = MyModBusCom.LD_BATT_COLLECTIO_DATA_ADDR;
        int count = 0;
        BatchRead<Integer> batch = new BatchRead<Integer>();
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //ϵͳ°æ±¾                        
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //ϵͳ״̬                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //×é¶Ëµçѹ                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //×é¶ËµçÁ÷                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //µç³Ø×´Ì¬                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //µçÁ÷·½Ïß                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //ÎÆ²¨µçÁ÷¾ùÖµ                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //ÎÆ²¨µçÁ÷·åÖµ                    
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //±¸Óà                           
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //±¸Óà                           
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //±¸Óà                           
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //±¸Óà                           
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //±¸Óà                       
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //±¸Óà                       
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //ÄÚ×è²âÊÔ´ÎÊý                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //ÄÚ×è²âÊÔ·½·¨                            
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //±¸Óà               
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //±¸Óà                       
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //±¸Óà                       
        batch.addLocator(count,MyModbusUtils.createBaseLocator(offset+count++,DataType.TWO_BYTE_INT_UNSIGNED, master));        //±¸Óà                       
        return batch;
    }
 
    public boolean putConcenStateBatchResult(BatchResults<Integer> res) {
        if(null != res) {
            int index = 0;
            this.systemVersion = (double)res.getIntValue(index++)/10;
              this.systemState = res.getIntValue(index++);
              this.groupVol = (double)res.getIntValue(index++)/10;
              this.groupCurr = (double)res.getIntValue(index++)/10;
              this.battState = res.getIntValue(index++);
              this.currDirection = res.getIntValue(index++);
              this.rippleCurrAvg = (double)res.getIntValue(index++)/100;
              this.rippleCurrTop = (double)res.getIntValue(index++)/100;
              this.backup1 = res.getIntValue(index++);
              this.backup2 = res.getIntValue(index++);
              this.backup3 = res.getIntValue(index++);
              this.backup4 = res.getIntValue(index++);
              this.backup5 = res.getIntValue(index++);
              this.backup6 = res.getIntValue(index++);
              this.resTestCount = res.getIntValue(index++);
              this.resTestMethod = res.getIntValue(index++);
              this.backup7 = res.getIntValue(index++);
              this.backup8 = res.getIntValue(index++);
              this.backup9 = res.getIntValue(index++);
              this.backup10 = res.getIntValue(index++);
            return true;
        }
        return false;
    }
}