Browse Source

读取博海粤能约定字段测试完成

lloyd 2 months ago
parent
commit
5aec4884e1

+ 0 - 14
src/main/java/com/gct/edge/EdgeCalculateApplication.java

@@ -12,21 +12,7 @@ import java.io.IOException;
12 12
 @Slf4j
13 13
 public class EdgeCalculateApplication {
14 14
 
15
-    public static void init(){
16
-        try {
17
-            Runtime.getRuntime().exec("bash ./shell/dbm.sh init");
18
-            Runtime.getRuntime().exec("bash ./shell.dbm.sh load");
19
-            Thread.sleep(2000);
20
-            log.info("Database checked,it's available.");
21
-        } catch (Exception e) {
22
-            log.info("Database check failed");
23
-            System.exit(-1);
24
-        }
25
-
26
-    }
27
-
28 15
     public static void main(String[] args) {
29
-        init();
30 16
         SpringApplication.run(EdgeCalculateApplication.class, args);
31 17
     }
32 18
 

+ 1 - 1
src/main/java/com/gct/edge/service/excutor/DataSendService.java

@@ -99,7 +99,6 @@ public class DataSendService {
99 99
 
100 100
     private <T> String serialRow(T t, Class<T> clz) {
101 101
         StringBuilder res = new StringBuilder();
102
-        res.append("|");
103 102
         try {
104 103
             for (Field field : clz.getDeclaredFields()) {
105 104
                 String getMethodName = "get" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
@@ -107,6 +106,7 @@ public class DataSendService {
107 106
                 if (Objects.isNull(val)) res.append("|");
108 107
                 else res.append(val.toString()).append("|");
109 108
             }
109
+            if(res.charAt(res.length()-1) == '|') res.deleteCharAt(res.length()-1);
110 110
             res.append("\n");
111 111
         } catch (Exception e) {
112 112
             log.error("serial data failed: {}, message: {}", JSONObject.toJSONString(t), e.getMessage());

+ 232 - 1
src/main/java/com/gct/etl/BHModbusDataBody.java

@@ -3,6 +3,7 @@ package com.gct.etl;
3 3
 import lombok.AllArgsConstructor;
4 4
 import lombok.Data;
5 5
 import lombok.NoArgsConstructor;
6
+import lombok.Setter;
6 7
 
7 8
 import java.time.LocalDateTime;
8 9
 
@@ -15,7 +16,6 @@ import java.time.LocalDateTime;
15 16
 @NoArgsConstructor
16 17
 public class BHModbusDataBody {
17 18
 
18
-    private LocalDateTime prodTime;
19 19
 
20 20
     private Double maxLoad;
21 21
 
@@ -75,4 +75,235 @@ public class BHModbusDataBody {
75 75
 
76 76
     private Double elecCostPerHundredMeter;
77 77
 
78
+    public Double getMaxLoad() {
79
+        return maxLoad;
80
+    }
81
+
82
+    public void setMaxLoad(Double maxLoad) {
83
+        this.maxLoad = maxLoad;
84
+    }
85
+
86
+    public Double getMinLoad() {
87
+        return minLoad;
88
+    }
89
+
90
+    public void setMinLoad(Double minLoad) {
91
+        this.minLoad = minLoad;
92
+    }
93
+
94
+    public Double getTheoryUpLoad() {
95
+        return theoryUpLoad;
96
+    }
97
+
98
+    public void setTheoryUpLoad(Double theoryUpLoad) {
99
+        this.theoryUpLoad = theoryUpLoad;
100
+    }
101
+
102
+    public Double getTheoryDownLoad() {
103
+        return theoryDownLoad;
104
+    }
105
+
106
+    public void setTheoryDownLoad(Double theoryDownLoad) {
107
+        this.theoryDownLoad = theoryDownLoad;
108
+    }
109
+
110
+    public Double getFillCoefficient() {
111
+        return fillCoefficient;
112
+    }
113
+
114
+    public void setFillCoefficient(Double fillCoefficient) {
115
+        this.fillCoefficient = fillCoefficient;
116
+    }
117
+
118
+    public Double getEmptyFillCoefficient() {
119
+        return emptyFillCoefficient;
120
+    }
121
+
122
+    public void setEmptyFillCoefficient(Double emptyFillCoefficient) {
123
+        this.emptyFillCoefficient = emptyFillCoefficient;
124
+    }
125
+
126
+    public Double getLiqProdMass() {
127
+        return liqProdMass;
128
+    }
129
+
130
+    public void setLiqProdMass(Double liqProdMass) {
131
+        this.liqProdMass = liqProdMass;
132
+    }
133
+
134
+    public Double getOilProdMass() {
135
+        return oilProdMass;
136
+    }
137
+
138
+    public void setOilProdMass(Double oilProdMass) {
139
+        this.oilProdMass = oilProdMass;
140
+    }
141
+
142
+    public Double getWaterProdMass() {
143
+        return waterProdMass;
144
+    }
145
+
146
+    public void setWaterProdMass(Double waterProdMass) {
147
+        this.waterProdMass = waterProdMass;
148
+    }
149
+
150
+    public Double getLiqProdVolume() {
151
+        return liqProdVolume;
152
+    }
153
+
154
+    public void setLiqProdVolume(Double liqProdVolume) {
155
+        this.liqProdVolume = liqProdVolume;
156
+    }
157
+
158
+    public Double getOilProdVolume() {
159
+        return oilProdVolume;
160
+    }
161
+
162
+    public void setOilProdVolume(Double oilProdVolume) {
163
+        this.oilProdVolume = oilProdVolume;
164
+    }
165
+
166
+    public Double getWaterProdVolume() {
167
+        return waterProdVolume;
168
+    }
169
+
170
+    public void setWaterProdVolume(Double waterProdVolume) {
171
+        this.waterProdVolume = waterProdVolume;
172
+    }
173
+
174
+    public Double getTheoryDisplacement() {
175
+        return theoryDisplacement;
176
+    }
177
+
178
+    public void setTheoryDisplacement(Double theoryDisplacement) {
179
+        this.theoryDisplacement = theoryDisplacement;
180
+    }
181
+
182
+    public Double getPumpEfficient() {
183
+        return pumpEfficient;
184
+    }
185
+
186
+    public void setPumpEfficient(Double pumpEfficient) {
187
+        this.pumpEfficient = pumpEfficient;
188
+    }
189
+
190
+    public Integer getGkCode() {
191
+        return gkCode;
192
+    }
193
+
194
+    public void setGkCode(Integer gkCode) {
195
+        this.gkCode = gkCode;
196
+    }
197
+
198
+    public Double getInversionDynamicLiquidLevel() {
199
+        return inversionDynamicLiquidLevel;
200
+    }
201
+
202
+    public void setInversionDynamicLiquidLevel(Double inversionDynamicLiquidLevel) {
203
+        this.inversionDynamicLiquidLevel = inversionDynamicLiquidLevel;
204
+    }
205
+
206
+    public Double getLiquidCorrectDifference() {
207
+        return liquidCorrectDifference;
208
+    }
209
+
210
+    public void setLiquidCorrectDifference(Double liquidCorrectDifference) {
211
+        this.liquidCorrectDifference = liquidCorrectDifference;
212
+    }
213
+
214
+    public Double getSubmergenceDegree() {
215
+        return submergenceDegree;
216
+    }
217
+
218
+    public void setSubmergenceDegree(Double submergenceDegree) {
219
+        this.submergenceDegree = submergenceDegree;
220
+    }
221
+
222
+    public Double getDownStrokeMaxElec() {
223
+        return downStrokeMaxElec;
224
+    }
225
+
226
+    public void setDownStrokeMaxElec(Double downStrokeMaxElec) {
227
+        this.downStrokeMaxElec = downStrokeMaxElec;
228
+    }
229
+
230
+    public Double getUpStrokeMaxElec() {
231
+        return upStrokeMaxElec;
232
+    }
233
+
234
+    public void setUpStrokeMaxElec(Double upStrokeMaxElec) {
235
+        this.upStrokeMaxElec = upStrokeMaxElec;
236
+    }
237
+
238
+    public Double getElecBalance() {
239
+        return elecBalance;
240
+    }
241
+
242
+    public void setElecBalance(Double elecBalance) {
243
+        this.elecBalance = elecBalance;
244
+    }
245
+
246
+    public Double getDownStrokeMaxPower() {
247
+        return downStrokeMaxPower;
248
+    }
249
+
250
+    public void setDownStrokeMaxPower(Double downStrokeMaxPower) {
251
+        this.downStrokeMaxPower = downStrokeMaxPower;
252
+    }
253
+
254
+    public Double getUpStrokeMaxPower() {
255
+        return upStrokeMaxPower;
256
+    }
257
+
258
+    public void setUpStrokeMaxPower(Double upStrokeMaxPower) {
259
+        this.upStrokeMaxPower = upStrokeMaxPower;
260
+    }
261
+
262
+    public Double getPowerBalance() {
263
+        return powerBalance;
264
+    }
265
+
266
+    public void setPowerBalance(Double powerBalance) {
267
+        this.powerBalance = powerBalance;
268
+    }
269
+
270
+    public Double getStroke() {
271
+        return stroke;
272
+    }
273
+
274
+    public void setStroke(Double stroke) {
275
+        this.stroke = stroke;
276
+    }
277
+
278
+    public Double getDownholeSystemEfficient() {
279
+        return downholeSystemEfficient;
280
+    }
281
+
282
+    public void setDownholeSystemEfficient(Double downholeSystemEfficient) {
283
+        this.downholeSystemEfficient = downholeSystemEfficient;
284
+    }
285
+
286
+    public Double getUpholeSystemEfficient() {
287
+        return upholeSystemEfficient;
288
+    }
289
+
290
+    public void setUpholeSystemEfficient(Double upholeSystemEfficient) {
291
+        this.upholeSystemEfficient = upholeSystemEfficient;
292
+    }
293
+
294
+    public Double getSystemEfficient() {
295
+        return systemEfficient;
296
+    }
297
+
298
+    public void setSystemEfficient(Double systemEfficient) {
299
+        this.systemEfficient = systemEfficient;
300
+    }
301
+
302
+    public Double getElecCostPerHundredMeter() {
303
+        return elecCostPerHundredMeter;
304
+    }
305
+
306
+    public void setElecCostPerHundredMeter(Double elecCostPerHundredMeter) {
307
+        this.elecCostPerHundredMeter = elecCostPerHundredMeter;
308
+    }
78 309
 }

+ 33 - 38
src/main/java/com/gct/etl/BHModbusReadConfig.java

@@ -1,75 +1,70 @@
1 1
 package com.gct.etl;
2 2
 
3 3
 import com.gct.etl.ModbusReadConfig.Section;
4
+import lombok.Data;
5
+
4 6
 /**
5 7
  * @author xusirui 2024/7/9
6 8
  */
9
+@Data
7 10
 public class BHModbusReadConfig {
11
+    private int offset = 7501;
8 12
 
9
-    public static class SerialConfig {
10
-        public String serialName = "serial";
11
-        public int baudRate = 9600;
12
-
13
-        public int openDaly = 1000;
14
-        public boolean isRs485 = false;
15
-    }
16
-
17
-
18
-    private Section maxLoad = new Section(1, 9500, 2);
13
+    private Section maxLoad = new Section(1, 9500 - offset, 2);
19 14
 
20
-    private Section minLoad = new Section(1, 9502, 2);
15
+    private Section minLoad = new Section(1, 9502 - offset, 2);
21 16
 
22
-    private Section theoryUpLoad = new Section(1, 9504, 2);
17
+    private Section theoryUpLoad = new Section(1, 9504 - offset, 2);
23 18
 
24
-    private Section theoryDownLoad = new Section(1, 9506, 2);
19
+    private Section theoryDownLoad = new Section(1, 9506 - offset, 2);
25 20
 
26
-    private Section fillCoefficient = new Section(1, 9508, 2);
21
+    private Section fillCoefficient = new Section(1, 9508 - offset, 2);
27 22
 
28
-    private Section emptyFillCoefficient = new Section(1, 9510, 2);
23
+    private Section emptyFillCoefficient = new Section(1, 9510 - offset, 2);
29 24
 
30
-    private Section liqProdMass = new Section(1, 9512, 2);
25
+    private Section liqProdMass = new Section(1, 9512 - offset, 2);
31 26
 
32
-    private Section oilProdMass = new Section(1, 9514, 2);
27
+    private Section oilProdMass = new Section(1, 9514 - offset, 2);
33 28
 
34
-    private Section waterProdMass = new Section(1, 9516, 2);
29
+    private Section waterProdMass = new Section(1, 9516 - offset, 2);
35 30
 
36
-    private Section liqProdVolume = new Section(1, 9518, 2);
31
+    private Section liqProdVolume = new Section(1, 9518 - offset, 2);
37 32
 
38
-    private Section oilProdVolume = new Section(1, 9520, 2);
33
+    private Section oilProdVolume = new Section(1, 9520 - offset, 2);
39 34
 
40
-    private Section waterProdVolume = new Section(1, 9522, 2);
35
+    private Section waterProdVolume = new Section(1, 9522 - offset, 2);
41 36
 
42
-    private Section theoryDisplacement = new Section(1, 9524, 2);
37
+    private Section theoryDisplacement = new Section(1, 9524 - offset, 2);
43 38
 
44
-    private Section pumpEfficient = new Section(1, 9526, 2);
39
+    private Section pumpEfficient = new Section(1, 9526 - offset, 2);
45 40
 
46
-    private Section gkCode = new Section(1, 9528, 1);
41
+    private Section gkCode = new Section(1, 9528 - offset, 1);
47 42
 
48
-    private Section inversionDynamicLiquidLevel = new Section(1, 9529, 2);
43
+    private Section inversionDynamicLiquidLevel = new Section(1, 9529 - offset, 2);
49 44
 
50
-    private Section liquidCorrectDifference = new Section(1, 9531, 2);
45
+    private Section liquidCorrectDifference = new Section(1, 9531 - offset, 2);
51 46
 
52
-    private Section submergenceDegree = new Section(1, 9533, 2);
47
+    private Section submergenceDegree = new Section(1, 9533 - offset, 2);
53 48
 
54
-    private Section downStrokeMaxElec = new Section(1, 9535, 2);
49
+    private Section downStrokeMaxElec = new Section(1, 9535 - offset, 2);
55 50
 
56
-    private Section upStrokeMaxElec = new Section(1, 9537, 2);
51
+    private Section upStrokeMaxElec = new Section(1, 9537 - offset, 2);
57 52
 
58
-    private Section elecBalance = new Section(1, 9539, 2);
53
+    private Section elecBalance = new Section(1, 9539 - offset, 2);
59 54
 
60
-    private Section downStrokeMaxPower = new Section(1, 9541, 2);
55
+    private Section downStrokeMaxPower = new Section(1, 9541 - offset, 2);
61 56
 
62
-    private Section upStrokeMaxPower = new Section(1, 9543, 2);
57
+    private Section upStrokeMaxPower = new Section(1, 9543 - offset, 2);
63 58
 
64
-    private Section powerBalance = new Section(1, 9545, 2);
59
+    private Section powerBalance = new Section(1, 9545 - offset, 2);
65 60
 
66
-    private Section stroke = new Section(1, 9547, 2);
61
+    private Section stroke = new Section(1, 9547 - offset, 2);
67 62
 
68
-    private Section downholeSystemEfficient = new Section(1, 9549, 2);
63
+    private Section downholeSystemEfficient = new Section(1, 9549 - offset, 2);
69 64
 
70
-    private Section  upholeSystemEfficient = new Section(1, 9551, 2);
65
+    private Section upholeSystemEfficient = new Section(1, 9551 - offset, 2);
71 66
 
72
-    private Section systemEfficient = new Section(1, 9553, 2);
67
+    private Section systemEfficient = new Section(1, 9553 - offset, 2);
73 68
 
74
-    private Section elecCostPerHundredMeter = new Section(1, 9555, 2);
69
+    private Section elecCostPerHundredMeter = new Section(1, 9555 - offset, 2);
75 70
 }

+ 28 - 15
src/main/java/com/gct/etl/ModbusRTUReader.java

@@ -42,8 +42,9 @@ public class ModbusRTUReader {
42 42
 //        手动调试串口数据
43 43
 //        debugSerial();
44 44
 //        测试功图读取
45
-        writeSample(true);//true 只刷新功图时间
46
-        testReadDataBody();
45
+//        writeSample(true);//true 只刷新功图时间
46
+//        testReadDataBody();
47
+        testReadFloat();
47 48
 //        testReadMultiBody();
48 49
     }
49 50
 
@@ -143,7 +144,7 @@ public class ModbusRTUReader {
143 144
             offset[i] = new SimpleRegister(Double.valueOf(arr[i][0] * 1000).intValue());
144 145
         }
145 146
         LocalDateTime now = LocalDateTime.now();
146
-        SimpleRegister[] time = new SimpleRegister[]{new SimpleRegister(now.getYear()-2000),
147
+        SimpleRegister[] time = new SimpleRegister[]{new SimpleRegister(now.getYear() - 2000),
147 148
                 new SimpleRegister(now.getMonthValue()),
148 149
                 new SimpleRegister(now.getDayOfMonth()),
149 150
                 new SimpleRegister(now.getHour()),
@@ -152,7 +153,7 @@ public class ModbusRTUReader {
152 153
 
153 154
         try {
154 155
             master.writeMultipleRegisters(regConfig.prodTimeReg.stationId, regConfig.prodTimeReg.register, time);
155
-            if(onlyRefreshTime) return;
156
+            if (onlyRefreshTime) return;
156 157
             master.writeMultipleRegisters(regConfig.sReg.stationId, regConfig.sReg.register, new Register[]{s});
157 158
             master.writeMultipleRegisters(regConfig.nReg.stationId, regConfig.nReg.register, new Register[]{n});
158 159
             master.writeMultipleRegisters(regConfig.pointNumReg.stationId, regConfig.pointNumReg.register, new Register[]{new SimpleRegister(arr.length)});
@@ -161,7 +162,7 @@ public class ModbusRTUReader {
161 162
 
162 163
         } catch (ModbusException e) {
163 164
             throw new RuntimeException(e);
164
-        }finally {
165
+        } finally {
165 166
             System.out.println("模拟功图运行完成");
166 167
         }
167 168
 
@@ -171,7 +172,7 @@ public class ModbusRTUReader {
171 172
         for (int i = 0; i < payloadRegs.size(); i++) {
172 173
             ModbusReadConfig.Section reg = payloadRegs.get(i);
173 174
             master.writeMultipleRegisters(reg.stationId, reg.register,
174
-                    Arrays.stream(payload).skip((i)*reg.length).limit(reg.length).collect(Collectors.toList()).toArray(new SimpleRegister[]{}));
175
+                    Arrays.stream(payload).skip((i) * reg.length).limit(reg.length).collect(Collectors.toList()).toArray(new SimpleRegister[]{}));
175 176
         }
176 177
     }
177 178
     //endregion
@@ -266,30 +267,42 @@ public class ModbusRTUReader {
266 267
         return body;
267 268
     }
268 269
 
269
-    public static synchronized  BHModbusDataBody readBHBody(){
270
+    public static synchronized BHModbusDataBody readBHBody() {
270 271
         connect();
271
-        try{
272
+        try {
272 273
             BHModbusDataBody body = new BHModbusDataBody();
273 274
             BHModbusReadConfig readConfig = new BHModbusReadConfig();
274
-            for (Field element : BHModbusDataBody.class.getFields()) {
275
+            for (Field element : BHModbusDataBody.class.getDeclaredFields()) {
275 276
                 String filedName = element.getName().substring(0, 1).toUpperCase() + element.getName().substring(1);
276 277
                 String getMethodName = "get" + filedName;
277 278
                 String setMethodName = "set" + filedName;
278
-                ModbusReadConfig.Section regConfig = (ModbusReadConfig.Section)BHModbusReadConfig.class.getMethod(getMethodName).invoke(readConfig);
279
-                if (Objects.isNull(regConfig))continue;
279
+                ModbusReadConfig.Section regConfig = (ModbusReadConfig.Section) BHModbusReadConfig.class.getMethod(getMethodName).invoke(readConfig);
280
+                if (Objects.isNull(regConfig)) continue;
280 281
                 if (element.getType().equals(Double.class)) {
281
-                    BHModbusDataBody.class.getMethod(setMethodName).invoke(body,readDoubleSingle(regConfig,new ByteToFloat()));
282
-                }else if(element.getType().equals(Integer.class)){
283
-                    BHModbusDataBody.class.getMethod(setMethodName).invoke(body,readIntegerSingle(regConfig,new DefaultParser()));
282
+                    BHModbusDataBody.class.getMethod(setMethodName,Double.class).invoke(body, readDoubleSingle(regConfig, new ByteToFloat()));
283
+                } else if (element.getType().equals(Integer.class)) {
284
+                    BHModbusDataBody.class.getMethod(setMethodName,Integer.class).invoke(body, readIntegerSingle(regConfig, new DefaultParser()));
284 285
                 }
285 286
             }
286 287
             return body;
287
-        }catch (Exception e){
288
+        } catch (Exception e) {
288 289
             e.printStackTrace();
289 290
         }
290 291
         return null;
291 292
     }
292 293
 
294
+    public static void testReadFloat() {
295
+        regConfig.serial.serialName = "COM3";
296
+        regConfig.serial.baudRate = 115200;//232口使用115200,485口注释此行
297
+        BHModbusDataBody body = readBHBody();
298
+        System.out.println(body);
299
+//        connect();
300
+//
301
+//        Register[] regs = tryReadMultipleRegisters(1, 2000, 2);
302
+//        for (int i = 0; i < regs.length; i++) {
303
+//            System.out.println(regs[i].getValue());
304
+//        }
305
+    }
293 306
 
294 307
     public static synchronized ModbusDataBody readBody(int stationId) {
295 308
         regConfig = configLoader.loadById(stationId);

+ 2 - 2
src/main/java/com/gct/etl/parser/ByteToFloat.java

@@ -14,9 +14,9 @@ public class ByteToFloat implements RegisterParser<Double> {
14 14
 
15 15
     @Override
16 16
     public Double apply(Register... register) {
17
-        byte[] array = new byte[9];
17
+        byte[] array = new byte[4];
18 18
         int index = 0;
19
-        for (int i = 0; i <= 1; i++) {
19
+        for (int i = 1; i >= 0; i--) {
20 20
             for (byte b : register[i].toBytes()) {
21 21
                 array[index++] = b;
22 22
             }