From 66174695a37f437464b9627c3613ba1280e22fd3 Mon Sep 17 00:00:00 2001 From: wangshilong Date: Mon, 24 Feb 2025 09:20:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=80=81=E7=89=88=E7=BB=B4?= =?UTF-8?q?=E5=B0=94=E6=99=AE=E6=96=AF=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ByteToStringDecodeHandler.java | 20 ++-- .../decode/impl/HighLowBinDecodeHandler.java | 2 +- ...WepsCurrentLocalDateTimeDecodeHandler.java | 19 +-- .../impl/weps/WepsDecimalDecodeHandler.java | 5 +- .../WepsRemainingLocalTimeDecodeHandler.java | 6 - .../ModbusMessagePersistListener.java | 22 +++- .../modbus/impl/CommandServiceImpl.java | 16 +-- .../isu/gaswellwatch/vo/command/Command.java | 4 +- .../vo/command/weps/MiWepsPlugControl.java | 110 ++++++++++++++++++ .../vo/command/weps/MiWepsTurnOff.java | 29 +++++ .../vo/command/weps/MiWepsTurnOn.java | 30 +++++ .../vo/command/weps/WepsTurnOff.java | 1 + src/main/resources/change_2020220.sql | 69 ++++++++++- src/main/resources/mapper/DeviceDao.xml | 8 +- .../isu/gaswellwatch/MIWrpsDecodeTest.java | 58 +++++++++ 15 files changed, 349 insertions(+), 50 deletions(-) create mode 100644 src/main/java/com/isu/gaswellwatch/vo/command/weps/MiWepsPlugControl.java create mode 100644 src/main/java/com/isu/gaswellwatch/vo/command/weps/MiWepsTurnOff.java create mode 100644 src/main/java/com/isu/gaswellwatch/vo/command/weps/MiWepsTurnOn.java create mode 100644 src/test/java/com/isu/gaswellwatch/MIWrpsDecodeTest.java diff --git a/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/ByteToStringDecodeHandler.java b/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/ByteToStringDecodeHandler.java index 64b55b2..2e9f128 100644 --- a/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/ByteToStringDecodeHandler.java +++ b/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/ByteToStringDecodeHandler.java @@ -3,8 +3,6 @@ package com.isu.gaswellwatch.modbus.data.decode.impl; import com.isu.gaswellwatch.modbus.data.ModbusMessage; import com.isu.gaswellwatch.modbus.data.decode.DecodeHandler; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.math.NumberUtils; import org.springframework.stereotype.Component; import java.util.Map; @@ -20,15 +18,15 @@ public class ByteToStringDecodeHandler implements DecodeHandler { @Override public String decode(Map commandPointMap, String value) { - if (StringUtils.isBlank(value)) { - return value; - } - int length = value.length() / 4; - byte[] bytes = new byte[length]; - for (int i = 0; i < length; i++) { - bytes[0] = NumberUtils.createInteger(value.substring(i * 4, i * 4 + 4)).byteValue(); - } - return new String(bytes); +// if (StringUtils.isBlank(value)) { +// return value; +// } +// int length = value.length() / 4; +// byte[] bytes = new byte[length]; +// for (int i = 0; i < length; i++) { +// bytes[0] = NumberUtils.createInteger(value.substring(i * 4, i * 4 + 4)).byteValue(); +// } + return value; } @Override diff --git a/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/HighLowBinDecodeHandler.java b/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/HighLowBinDecodeHandler.java index b5c7ba2..8eaf454 100644 --- a/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/HighLowBinDecodeHandler.java +++ b/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/HighLowBinDecodeHandler.java @@ -23,7 +23,7 @@ public class HighLowBinDecodeHandler implements DecodeHandler { if (StringUtils.isBlank(value)) { return value; } - return String.valueOf(Integer.parseInt(value, 16)); + return String.valueOf(Long.parseLong(value, 16)); } @Override diff --git a/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/weps/WepsCurrentLocalDateTimeDecodeHandler.java b/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/weps/WepsCurrentLocalDateTimeDecodeHandler.java index 8bee2d9..29c53c0 100644 --- a/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/weps/WepsCurrentLocalDateTimeDecodeHandler.java +++ b/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/weps/WepsCurrentLocalDateTimeDecodeHandler.java @@ -31,23 +31,16 @@ public class WepsCurrentLocalDateTimeDecodeHandler implements DecodeHandler { String minuteSecond = times[0]; String weekHour = times[1]; String monthDay = times[2]; - String year = times[4]; + String year = times[3]; + +// minuteSecond = Integer.toHexString(NumberUtils.createInteger(minuteSecond)); +// weekHour = Integer.toHexString(NumberUtils.createInteger(weekHour)); +// monthDay = Integer.toHexString(NumberUtils.createInteger(monthDay)); +// year = Integer.toHexString(NumberUtils.createInteger(year)); - if (StringUtils.startsWithIgnoreCase(minuteSecond, "0x")) { - minuteSecond = StringUtils.substring(minuteSecond, 2); - } minuteSecond = StringUtils.leftPad(minuteSecond, 4, '0'); - if (StringUtils.startsWithIgnoreCase(weekHour, "0x")) { - weekHour = StringUtils.substring(weekHour, 2); - } weekHour = StringUtils.leftPad(weekHour, 4, '0'); - if (StringUtils.startsWithIgnoreCase(monthDay, "0x")) { - monthDay = StringUtils.substring(monthDay, 2); - } monthDay = StringUtils.leftPad(monthDay, 4, '0'); - if (StringUtils.startsWithIgnoreCase(year, "0x")) { - year = StringUtils.substring(year, 2); - } return year + "-" + StringUtils.substring(monthDay, 0, 2) + "-" + StringUtils.substring(monthDay, 2) + " " + StringUtils.substring(weekHour, 2) + ":" + diff --git a/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/weps/WepsDecimalDecodeHandler.java b/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/weps/WepsDecimalDecodeHandler.java index a7ab5d4..03445c5 100644 --- a/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/weps/WepsDecimalDecodeHandler.java +++ b/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/weps/WepsDecimalDecodeHandler.java @@ -24,11 +24,12 @@ public class WepsDecimalDecodeHandler implements DecodeHandler { return value; } if (StringUtils.startsWith(value, ".")) { - return NumberUtils.createBigDecimal("0" + value).toString(); + return NumberUtils.createBigDecimal("0" + StringUtils.strip(value, "-")).toString(); } else if (StringUtils.endsWith(value, ".")) { return NumberUtils.createBigDecimal(value + "0").toString(); } else { - return value; + String[] numbers = StringUtils.split(value, "."); + return numbers[0] + "." + Math.abs(NumberUtils.createLong(numbers[1])); } } diff --git a/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/weps/WepsRemainingLocalTimeDecodeHandler.java b/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/weps/WepsRemainingLocalTimeDecodeHandler.java index 3e13df5..f05f1ba 100644 --- a/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/weps/WepsRemainingLocalTimeDecodeHandler.java +++ b/src/main/java/com/isu/gaswellwatch/modbus/data/decode/impl/weps/WepsRemainingLocalTimeDecodeHandler.java @@ -32,13 +32,7 @@ public class WepsRemainingLocalTimeDecodeHandler implements DecodeHandler { String minuteSecond = times[0]; String dayHour = times[1]; - if (StringUtils.startsWithIgnoreCase(minuteSecond, "0x")) { - minuteSecond = StringUtils.substring(minuteSecond, 2); - } minuteSecond = StringUtils.leftPad(minuteSecond, 4, '0'); - if (StringUtils.startsWithIgnoreCase(dayHour, "0x")) { - dayHour = StringUtils.substring(dayHour, 2); - } dayHour = StringUtils.leftPad(dayHour, 4, '0'); long daySeconds = TimeUnit.DAYS.toSeconds(NumberUtils.createLong(StringUtils.substring(dayHour, 0, 2))); diff --git a/src/main/java/com/isu/gaswellwatch/modbus/data/listener/ModbusMessagePersistListener.java b/src/main/java/com/isu/gaswellwatch/modbus/data/listener/ModbusMessagePersistListener.java index 4c639b2..552268c 100644 --- a/src/main/java/com/isu/gaswellwatch/modbus/data/listener/ModbusMessagePersistListener.java +++ b/src/main/java/com/isu/gaswellwatch/modbus/data/listener/ModbusMessagePersistListener.java @@ -265,7 +265,15 @@ public class ModbusMessagePersistListener implements BatchMessageListener { ModbusMessage.MessagePoint messagePoint; for (int i = 0; i < stepSize; i++) { messagePoint = pointMap.get(StringUtils.leftPad(String.valueOf(startAddress + i), 4, '0')); - values[i] = messagePoint.getValue(); + if (MapUtil.getBool(commandPointMap, "use_hex", Boolean.FALSE)) { + values[i] = messagePoint.getOriginalValue(); + } else { + if (Objects.isNull(messagePoint)) { + values[i] = StringUtils.EMPTY; + } else { + values[i] = messagePoint.getValue(); + } + } } String format = MapUtil.getStr(commandPointMap, "format"); return decodeMessage(decodeName, commandPointMap, @@ -278,7 +286,11 @@ public class ModbusMessagePersistListener implements BatchMessageListener { ModbusMessage.MessagePoint messagePoint; for (int i = 0; i < 2; i++) { messagePoint = pointMap.get(StringUtils.leftPad(String.valueOf(startAddress + i), 4, '0')); - values[i] = messagePoint.getOriginalValue(); + if (Objects.isNull(messagePoint)) { + values[i] = StringUtils.EMPTY; + } else { + values[i] = messagePoint.getOriginalValue(); + } } return highLowBinDecodeHandler.decode(commandPointMap, StringUtils.join(values)); } @@ -291,7 +303,11 @@ public class ModbusMessagePersistListener implements BatchMessageListener { for (int i = 0; i < stepSize; i++) { highPoint = pointMap.get(StringUtils.leftPad(String.valueOf(startAddress + i * 2), 4, '0')); lowPoint = pointMap.get(StringUtils.leftPad(String.valueOf(startAddress + i * 2 + 1), 4, '0')); - values[i] = highLowBinDecodeHandler.decode(commandPointMap, highPoint.getOriginalValue() + lowPoint.getOriginalValue()); + if (Objects.isNull(highPoint) || Objects.isNull(lowPoint)) { + values[i] = StringUtils.EMPTY; + } else { + values[i] = highLowBinDecodeHandler.decode(commandPointMap, highPoint.getOriginalValue() + lowPoint.getOriginalValue()); + } } String format = MapUtil.getStr(commandPointMap, "format"); diff --git a/src/main/java/com/isu/gaswellwatch/modbus/impl/CommandServiceImpl.java b/src/main/java/com/isu/gaswellwatch/modbus/impl/CommandServiceImpl.java index af84864..1c27c0d 100644 --- a/src/main/java/com/isu/gaswellwatch/modbus/impl/CommandServiceImpl.java +++ b/src/main/java/com/isu/gaswellwatch/modbus/impl/CommandServiceImpl.java @@ -14,6 +14,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.core.ParameterizedTypeReference; import org.springframework.data.redis.core.HashOperations; import org.springframework.data.redis.core.RedisTemplate; @@ -43,6 +44,8 @@ public class CommandServiceImpl implements CommandService { private final RestTemplate restTemplate = new RestTemplate(); @Resource private DeviceOptLogService deviceOptLogService; + @Value("${app.modbus-rtcp-host:http://localhost:9999}") + private String modbusRtcpHost; @Override public Response control(Command command) { @@ -50,15 +53,14 @@ public class CommandServiceImpl implements CommandService { //记录用户保存控制指令日志 Integer flag = null; - if (Command.KNPCV1_TURN_ON_THE_WELL.equals(command.getCode())||Command.ETC_TURN_ON_THE_WELL.equals(command.getCode())|| - Command.SCSS_TURN_ON_THE_WELL.equals(command.getCode())) { + if (StringUtils.equalsAny(command.getCode(), Command.KNPCV1_TURN_ON_THE_WELL, Command.ETC_TURN_ON_THE_WELL, + Command.SCSS_TURN_ON_THE_WELL, Command.WEPS_TURN_ON_THE_WELL, Command.MI_WEPS_TURN_ON_THE_WELL)) { flag = 1; - } else if (Command.KNPCV1_TURN_OFF_THE_WELL.equals(command.getCode())|| - Command.ETC_TURN_OFF_THE_WELL.equals(command.getCode())|| - Command.SCSS_TURN_OFF_THE_WELL.equals(command.getCode())) { + } else if (StringUtils.equalsAny(command.getCode(), Command.KNPCV1_TURN_OFF_THE_WELL, Command.ETC_TURN_OFF_THE_WELL, + Command.SCSS_TURN_OFF_THE_WELL, Command.WEPS_TURN_OFF_THE_WELL, Command.MI_WEPS_TURN_OFF_THE_WELL)) { flag = 0; } - this.deviceOptLogService.saveGasWellOptLog(flag, command.getDeviceId(),""); + this.deviceOptLogService.saveGasWellOptLog(flag, command.getDeviceId(), ""); return result; } @@ -111,7 +113,7 @@ public class CommandServiceImpl implements CommandService { item.setIdentifier(identifier); } RequestEntity> request = RequestEntity - .post("http://localhost:9999/modbus-tcp/" + type) + .post(this.modbusRtcpHost + "/modbus-tcp/" + type) .body(modbusCommands); ResponseEntity> response = this.restTemplate.exchange(request, new ParameterizedTypeReference>() { diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/Command.java b/src/main/java/com/isu/gaswellwatch/vo/command/Command.java index f660c6c..719ae88 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/command/Command.java +++ b/src/main/java/com/isu/gaswellwatch/vo/command/Command.java @@ -124,16 +124,16 @@ public abstract class Command implements Serializable { /* 点表类型:新版威尔普斯 start */ // 新版威尔普斯,柱塞模式 + public static final String WEPS_PLUG_CONTROL = "WEPS.PLUG.CONTROL"; public static final String WEPS_TURN_ON_THE_WELL = "WEPS.TURN_ON_THE_WELL"; public static final String WEPS_TURN_OFF_THE_WELL = "WEPS.TURN_OFF_THE_WELL"; - public static final String WEPS_PLUG_CONTROL = "WEPS.PLUG.CONTROL"; /* 点表类型:新版威尔普斯 end */ /* 点表类型:老版威尔普斯 start */ // 老版威尔普斯,柱塞模式 + public static final String MI_WEPS_PLUG_CONTROL = "MI_WEPS.PLUG.CONTROL"; public static final String MI_WEPS_TURN_ON_THE_WELL = "MI_WEPS.TURN_ON_THE_WELL"; public static final String MI_WEPS_TURN_OFF_THE_WELL = "MI_WEPS.TURN_OFF_THE_WELL"; - public static final String MI_WEPS_PLUG_CONTROL = "MI_WEPS.PLUG.CONTROL"; /* 点表类型:老版威尔普斯 end */ public static final BigDecimal ONE_SIXTY = BigDecimal.valueOf(60); diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/weps/MiWepsPlugControl.java b/src/main/java/com/isu/gaswellwatch/vo/command/weps/MiWepsPlugControl.java new file mode 100644 index 0000000..c989576 --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/vo/command/weps/MiWepsPlugControl.java @@ -0,0 +1,110 @@ +package com.isu.gaswellwatch.vo.command.weps; + +import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; +import com.isu.gaswellwatch.vo.command.Command; +import com.isu.gaswellwatch.vo.command.Timing; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.SuperBuilder; + +import java.io.Serial; +import java.math.BigDecimal; +import java.util.Collection; +import java.util.List; + +/** + * 威尔普斯控制指令 + * + * @author 王仕龙 + * 2025/1/10 11:00 + */ +@Getter +@Setter +@SuperBuilder +public class MiWepsPlugControl extends Command implements Timing { + @Serial + private static final long serialVersionUID = -7540015879950965127L; + + // private Integer gasWellNumber; // 气井编号 + private Integer depthOfLockDevice; // 卡定器深度 单位:米 + private Integer arrivingSensor; // 到达传感器 0/1:禁用/启用 + private Integer zigbee; // Zigbee 0/1:禁用/启用 + private Integer pulseWidth; // 脉冲宽度 驱动电磁阀使用 + private Integer plugRisingSpeed; // 上升速度 米/分钟 + private Integer plugTooFastSpeed; // 过快速度 米/分钟 + private Integer plugTooSlowSpeed; // 过缓速度 米/分钟 + // private Integer gasWellName; // 气井名称 +// 分段 + private Integer oilAndCasDataCollectionInterval; // 油、套压数据采集间隔 0:每5秒采样;1:每10秒采样;2:每15秒采样;3:每30秒采样;4:每1秒采样;5:每2秒采样;6:每3秒采样;7:每4秒采样 + private Integer storeDataIntervalOnOpenWell; // 数据存储间隔(开井期间) 0:每1分钟存储;1:每5分钟存储;2:每10分钟存储;3:每15分钟存储;4:每30秒存储;5:每15秒存储;6:每5秒存储 + private Integer storeDataIntervalOnCloseWell; // 数据存储间隔(关井期间) 0:每1分钟存储;1:每5分钟存储;2:每10分钟存储;3:每15分钟存储;4:每30秒存储;5:每15秒存储;6:每5秒存储 + // 分段 + // private Integer communicationPowerThreshold; // 通信电量门限 Zigbee通讯使用 +// private Integer reserve1; // 保留 Zigbee通讯使用 +// private Integer startTimeOfDaytime; // 白天起始时间 Zigbee通讯使用 +// private Integer endTimeOfDaytime; // 白天结束时间 Zigbee通讯使用 + private Integer controlWorkTime; // 控制器工作状态 0:生产模式;1:常开模式;2:常关模式 + private Integer produceMode; // 生产制度设置 0:定时开关井;1:时间优化模式;2:压力微升模式;3:压力回升模式;4:压力跌落模式 + private String plungerRiseTime; // 上升时间 单位:秒 + private String dangerousRiseTime; // 危险上升时间 单位:秒 + private String tooFastRiseTime; // 过快上升时间 单位:秒 + private String tooSlowRiseTime; // 过缓上升时间 单位:秒 + private Integer tooFastCount; // 过快次数 + private String tooFastRaiseOpenWellTime; // 过快增加开井时间 单位:秒 + private String tooFastLowerCloseWellTime; // 过快减少关井时间 单位:秒 + private String tooSlowLowerOpenWellTime; // 过缓减少开井时间 单位:秒 + private String tooSlowRaiseCloseWellTime; // 过缓增加关井时间 单位:秒 + private String checkStabilityTime; // 检测稳定时间 单位:秒 + private String minCloseWellTime; // 最小关井时间 单位:秒 + private String maxCloseWellTime; // 最大关井时间 单位:秒 + private String wellCloseTimeNotReachedDuration; // 未到达关井时间 单位:秒 + private String minOpenWellTime; // 最小开井时间 单位:秒 + private String maxOpenWellTime; // 最大开井时间 单位:秒 + private String afterFlowTime; // 续流时间 单位:秒 + private String notReachedFlowTime; // 未到续流时间 单位:秒 + private String closeTime; // 关井时间 单位:秒 + private String openTime; // 开井时间 单位:秒 + private BigDecimal openPressure; // 开井压力 单位:MPa + private BigDecimal closePressure; // 关井压力 单位:MPa + private BigDecimal littleRisePressure; // 微升压力 单位:MPa + private Integer gasCollectionMode; // 集气模式 0:低压集气模式;1:高压集气模式 + // private Integer reserve2; // 保留 +// 分段 + private BigDecimal protectionPressure; // 保护压力 单位:MPa + + public MiWepsPlugControl() { + this.setCode("MI_WEPS.PLUG.CONTROL"); + } + + + @Override + protected Collection builderModbusCommand() { + + StringBuilder command = new StringBuilder(250); + // 100 + // 地址码 功能码 起始地址 连续长度 连续字长 + // 01 10 003F 0013 26 + command.append("0110003F001326"); +// command.append(StringUtils.leftPad(Integer.toHexString(this.runMode), 4, "0")); +// command.append(StringUtils.leftPad(Integer.toHexString(this.wellStatus), 4, "0")); +// command.append(StringUtils.leftPad(Integer.toHexString(this.gasCollectionMethod), 4, "0")); +// command.append(StringUtils.leftPad(Long.toHexString(this.highPressureProtection.multiply(ONE_HUNDRED).longValue()), 4, "0")); +// command.append(StringUtils.leftPad(Long.toHexString(this.lowPressureProtection.multiply(ONE_HUNDRED).longValue()), 4, "0")); +// command.append(StringUtils.leftPad(Integer.toHexString(this.tooFastCount), 4, "0")); +// command.append(StringUtils.leftPad(Long.toHexString(this.toSeconds(this.dangerousRiseTime)), 4, "0")); +// command.append(StringUtils.leftPad(Long.toHexString(this.toSeconds(this.tooFastRiseTime)), 4, "0")); +// command.append(StringUtils.leftPad(Long.toHexString(this.openWellTime.multiply(ONE_SIXTY).longValue()), 4, "0")); +// command.append(StringUtils.leftPad(Long.toHexString(this.closeWellTime.multiply(ONE_SIXTY).longValue()), 4, "0")); +// command.append(StringUtils.leftPad(Long.toHexString(this.openWellCasPressure.multiply(ONE_HUNDRED).longValue()), 4, "0")); +// command.append(StringUtils.leftPad(Long.toHexString(this.littleRiseCasPressure.multiply(ONE_HUNDRED).longValue()), 4, "0")); +// command.append(StringUtils.leftPad(Long.toHexString(this.toSeconds(this.checkStabilityTime)), 4, "0")); +// command.append(StringUtils.leftPad(Long.toHexString(this.toMinutes(this.minCloseWellTime)), 4, "0")); +// command.append(StringUtils.leftPad(Long.toHexString(this.toMinutes(this.maxCloseWellTime)), 4, "0")); +// command.append(StringUtils.leftPad(Long.toHexString(this.toMinutes(this.minOpenWellTime)), 4, "0")); +// command.append(StringUtils.leftPad(Long.toHexString(this.toMinutes(this.maxOpenWellTime)), 4, "0")); +// command.append(StringUtils.leftPad(Integer.toHexString(this.wellDepth), 4, "0")); +// command.append(StringUtils.leftPad(Integer.toHexString(this.produceMode), 4, "0")); + return List.of(ModbusCommandDto.builder().command(command.toString()).length(16).build()); + } + +} diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/weps/MiWepsTurnOff.java b/src/main/java/com/isu/gaswellwatch/vo/command/weps/MiWepsTurnOff.java new file mode 100644 index 0000000..bd969f9 --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/vo/command/weps/MiWepsTurnOff.java @@ -0,0 +1,29 @@ +package com.isu.gaswellwatch.vo.command.weps; + +import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; +import com.isu.gaswellwatch.vo.command.Command; + +import java.io.Serial; +import java.util.Collection; +import java.util.List; + +/** + * 老版威尔普斯关井 + * + * @author 王仕龙 + * 2024/11/26 19:57 + */ +public class MiWepsTurnOff extends Command { + + @Serial + private static final long serialVersionUID = -6219690846185319542L; + + public MiWepsTurnOff() { + this.setCode("MI_WEPS.TURN_OFF_THE_WELL"); + } + + @Override + protected Collection builderModbusCommand() { + return List.of(ModbusCommandDto.builder().command("010600400002").length(16).build()); + } +} diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/weps/MiWepsTurnOn.java b/src/main/java/com/isu/gaswellwatch/vo/command/weps/MiWepsTurnOn.java new file mode 100644 index 0000000..c090332 --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/vo/command/weps/MiWepsTurnOn.java @@ -0,0 +1,30 @@ +package com.isu.gaswellwatch.vo.command.weps; + +import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; +import com.isu.gaswellwatch.vo.command.Command; + +import java.io.Serial; +import java.util.Collection; +import java.util.List; + +/** + * 老版威尔普斯开井 + * + * @author 王仕龙 + * 2024/11/26 19:57 + */ +public class MiWepsTurnOn extends Command { + + @Serial + private static final long serialVersionUID = -7123367842204864916L; + + public MiWepsTurnOn() { + this.setCode("MI_WEPS.TURN_ON_THE_WELL"); + } + + @Override + protected Collection builderModbusCommand() { + return List.of(ModbusCommandDto.builder().command("010600400001").length(16).build()); + } + +} diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/weps/WepsTurnOff.java b/src/main/java/com/isu/gaswellwatch/vo/command/weps/WepsTurnOff.java index 71f9681..883640b 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/command/weps/WepsTurnOff.java +++ b/src/main/java/com/isu/gaswellwatch/vo/command/weps/WepsTurnOff.java @@ -26,4 +26,5 @@ public class WepsTurnOff extends Command { protected Collection builderModbusCommand() { return List.of(ModbusCommandDto.builder().command("010600400002").length(16).build()); } + } diff --git a/src/main/resources/change_2020220.sql b/src/main/resources/change_2020220.sql index 005bf2a..ed39def 100644 --- a/src/main/resources/change_2020220.sql +++ b/src/main/resources/change_2020220.sql @@ -20,6 +20,15 @@ VALUES (37, 'miWepsRunMode', 'ylhsms', '压力回升模式', '3', 4, now(), now( INSERT INTO `dictionary` (`id`, `type`, `code`, `name`, `value`, `sort`, `create_time`, `update_time`) VALUES (38, 'miWepsRunMode', 'yldlms', '压力跌落模式', '4', 5, now(), now()); +INSERT INTO `commands` (`id`, `ref_type`, `ref_id`, `name`, `code`, `type`, `collection_frequency`, `command`, + `start_address`, `message_length`, `details`) +VALUES (10301, 'DEVICE_PRODUCT_CODE', 29, '采集实时数据地址表', 'READ_REAL_TIME_DATA', 'COLLECTION', 30, '010300000016', + 0, 98, '(老板)维尔普斯控制器实时数据地址表'); +INSERT INTO `commands` (`id`, `ref_type`, `ref_id`, `name`, `code`, `type`, `collection_frequency`, `command`, + `start_address`, `message_length`, `details`) +VALUES (10302, 'DEVICE_PRODUCT_CODE', 29, '采集控制器参数地址表', 'READ_CONTROL_PARAM_DATA', 'COLLECTION', 30, + '010303EC0047', 1004, 294, '(老板)维尔普斯控制器参数地址表数据采集'); + INSERT INTO `command_points` (`id`, `command_id`, `field`, `name`, `details`, `start_address`, `step_size`, `factor`, `precision`, `format`, `decode_name`) @@ -207,4 +216,62 @@ INSERT INTO `command_points` (`id`, `command_id`, `field`, `name`, `details`, `s VALUES (13241, 10302, 'reserve2', '保留', NULL, 1073, 1, NULL, NULL, NULL, NULL); INSERT INTO `command_points` (`id`, `command_id`, `field`, `name`, `details`, `start_address`, `step_size`, `factor`, `precision`, `format`, `decode_name`) -VALUES (13242, 10302, 'protectionPressure', '保护压力', '单位:MPa', 1074, 2, NULL, NULL, '%s.%s', 'wepsDecimal'); \ No newline at end of file +VALUES (13242, 10302, 'protectionPressure', '保护压力', '单位:MPa', 1074, 2, NULL, NULL, '%s.%s', 'wepsDecimal'); + + + +UPDATE `commands` +SET `ref_type` = 'DEVICE_PRODUCT_CODE', + `ref_id` = 29, + `name` = '采集控制器参数地址表', + `code` = 'READ_CONTROL_PARAM_DATA', + `type` = 'COLLECTION', + `collection_frequency` = 30, + `command` = '010303EC0048', + `start_address` = 1004, + `message_length` = 202, + `details` = '(老板)维尔普斯控制器参数地址表数据采集' +WHERE `id` = 10302; + +ALTER TABLE `command_points` + ADD COLUMN `use_hex` bit NULL COMMENT '采用16进制值' AFTER `precision`; + +UPDATE `command_points` +SET `command_id` = 10301, + `field` = 'currentTime', + `name` = '当前时间', + `details` = '控制器时间。\n示例:0x4830:0x0211:0x0924:0x2013。\n结果:2013-09-24 11:48:30', + `start_address` = 3, + `step_size` = 4, + `factor` = NULL, + `precision` = NULL, + `use_hex` = b'1', + `format` = '%s:%s:%s:%s', + `decode_name` = 'wepsCurrentLocalDateTime' +WHERE `id` = 13102; +UPDATE `command_points` +SET `command_id` = 10301, + `field` = 'remainingTime', + `name` = '剩余时间', + `details` = '组合后时间格式:天.小时:分钟:秒\n示例:0x0930:0x0001\n结果:0.1:09:30', + `start_address` = 7, + `step_size` = 2, + `factor` = NULL, + `precision` = NULL, + `use_hex` = b'1', + `format` = '%s:%s', + `decode_name` = 'wepsRemainingLocalTime' +WHERE `id` = 13103; +UPDATE `command_points` +SET `command_id` = 10302, + `field` = 'gasWellName', + `name` = '气井名称', + `details` = NULL, + `start_address` = 1012, + `step_size` = 16, + `factor` = NULL, + `precision` = NULL, + `use_hex` = b'1', + `format` = NULL, + `decode_name` = 'byteToString' +WHERE `id` = 13208; diff --git a/src/main/resources/mapper/DeviceDao.xml b/src/main/resources/mapper/DeviceDao.xml index 9b871f6..9947d8b 100644 --- a/src/main/resources/mapper/DeviceDao.xml +++ b/src/main/resources/mapper/DeviceDao.xml @@ -101,10 +101,10 @@ ,t.solar_voltage,t.first_solenoid_status as wellStatus - ,'weps_plug' as type,case t.run_mode as runMode + ,'weps_plug' as type, t.run_mode as runMode ,case t.solenoid_valve_status when 2 then t.open_well_remaining_time when 1 then t.close_well_remaining_time else null end as statusEndTime - ,case t.solenoid_valve_status when 2 then 0 when 1 then 1 else null end as wellStatus + ,case t.solenoid_valve_status when 2 then 1 when 1 then 0 else null end as wellStatus ,t.produce_mode as runMode,t.remaining_time as statusEndTime @@ -199,10 +199,10 @@ ,t.solar_voltage,t.first_solenoid_status as wellStatus - ,'weps_plug' as type,case t.run_mode as runMode + ,'weps_plug' as type, t.run_mode as runMode ,case t.solenoid_valve_status when 2 then t.open_well_remaining_time when 1 then t.close_well_remaining_time else null end as statusEndTime - ,case t.solenoid_valve_status when 2 then 0 when 1 then 1 else null end as wellStatus + ,case t.solenoid_valve_status when 2 then 1 when 1 then 0 else null end as wellStatus ,t.produce_mode as runMode,t.remaining_time as statusEndTime diff --git a/src/test/java/com/isu/gaswellwatch/MIWrpsDecodeTest.java b/src/test/java/com/isu/gaswellwatch/MIWrpsDecodeTest.java new file mode 100644 index 0000000..7359109 --- /dev/null +++ b/src/test/java/com/isu/gaswellwatch/MIWrpsDecodeTest.java @@ -0,0 +1,58 @@ +package com.isu.gaswellwatch; + + +import cn.hutool.json.JSONUtil; +import com.isu.gaswellwatch.modbus.data.listener.DynamicRabbitListener; +import jakarta.annotation.Resource; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.amqp.core.Message; +import org.springframework.amqp.core.MessageProperties; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.test.context.ActiveProfiles; + +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.LockSupport; + +/** + * @author 王仕龙 + * 2025/2/20 21:13 + */ +@SpringBootTest +@ActiveProfiles("test") +public class MIWrpsDecodeTest { + + private String message10301 = "564D2E53352E31352E34315831/50002/10301/1740200010000/1740200016203/01032C0003000000E0553106120222202500000000800358C0411E27B13F46AACB411ED507408C000042C80000000071B2"; + private String message10302 = "564D2E53352E31352E34315831/50002/10302/1740197640001/1740197646124/01038E00000CE9000100010A8C00FA028A0064D5CB2D353531342D583100310000000000000000000000000000000000000000000000000000000041C800010007001900020000070800000000D960FFFEFEFE2300FEFEFFFEEEFF00C41000000E08000007580000022000001C2000001C0000A000BAFEE770002002580000A000FEFE0000000000006B0000000000000046D5"; + + @Resource(name = "stringRedisTemplate") + protected RedisTemplate redisTemplate; + @Resource + private DynamicRabbitListener dynamicRabbitListener; + + @Test + public void testWrpsDecode() { + Message testMessage10301 = Mockito.mock(Message.class); + Message testMessage10302 = Mockito.mock(Message.class); + MessageProperties testMessageProperties = Mockito.mock(MessageProperties.class); + Mockito.doReturn(this.message10301.getBytes()).when(testMessage10301).getBody(); + Mockito.doReturn(this.message10302.getBytes()).when(testMessage10302).getBody(); + Mockito.doReturn(testMessageProperties).when(testMessage10301).getMessageProperties(); + Mockito.doReturn(testMessageProperties).when(testMessage10302).getMessageProperties(); + Mockito.doReturn("/modbus/collect/0").when(testMessageProperties).getConsumerQueue(); + + this.dynamicRabbitListener.getComposeListener().onMessage(testMessage10301); + this.dynamicRabbitListener.getComposeListener().onMessage(testMessage10302); + + LockSupport.parkNanos(TimeUnit.SECONDS.toNanos(2)); + + Map row = this.redisTemplate.opsForHash().entries("data:device:50002"); + + System.out.println(JSONUtil.toJsonStr(row)); + + } + +} +