KNPCV1新增3中指令,并测试指令转换及发送
This commit is contained in:
parent
46665482de
commit
d9b9ff9011
|
@ -4,6 +4,7 @@ import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
@ -31,4 +32,8 @@ public class ModbusCommandDto extends CommandTypeComparable implements CommandDt
|
||||||
* 网关唯一标识符
|
* 网关唯一标识符
|
||||||
*/
|
*/
|
||||||
private String identifier;
|
private String identifier;
|
||||||
|
|
||||||
|
public String getCommand() {
|
||||||
|
return StringUtils.isBlank(this.command) ? this.command : this.command.toUpperCase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class CommandServiceImpl implements CommandService {
|
||||||
return response.getBody();
|
return response.getBody();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Send command fail", e);
|
log.error("Send command fail", e);
|
||||||
return Response.failed("Send command fail");
|
return Response.failed("Send command fail, error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,8 @@ import java.util.Objects;
|
||||||
@JsonSubTypes.Type(value = TimingMode.class, name = Command.KNPCV1_RUN_TIMING),
|
@JsonSubTypes.Type(value = TimingMode.class, name = Command.KNPCV1_RUN_TIMING),
|
||||||
@JsonSubTypes.Type(value = ManualMode.class, name = Command.KNPCV1_RUN_MANUAL),
|
@JsonSubTypes.Type(value = ManualMode.class, name = Command.KNPCV1_RUN_MANUAL),
|
||||||
@JsonSubTypes.Type(value = PlungerMode.class, name = Command.KNPCV1_RUN_PLUNGER),
|
@JsonSubTypes.Type(value = PlungerMode.class, name = Command.KNPCV1_RUN_PLUNGER),
|
||||||
@JsonSubTypes.Type(value = PressureMode.class, name = Command.KNPCV1_RUN_TIME_PRESSURE),
|
@JsonSubTypes.Type(value = PressureMode.class, name = Command.KNPCV1_RUN_PRESSURE),
|
||||||
|
@JsonSubTypes.Type(value = TimePressureMode.class, name = Command.KNPCV1_RUN_TIME_PRESSURE),
|
||||||
})
|
})
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
@ -52,6 +53,7 @@ public abstract class Command implements Serializable {
|
||||||
public static final String KNPCV1_RUN_TIMING = "KNPCV1.RUN.TIMING";
|
public static final String KNPCV1_RUN_TIMING = "KNPCV1.RUN.TIMING";
|
||||||
public static final String KNPCV1_RUN_MANUAL = "KNPCV1.RUN.MANUAL";
|
public static final String KNPCV1_RUN_MANUAL = "KNPCV1.RUN.MANUAL";
|
||||||
public static final String KNPCV1_RUN_PLUNGER = "KNPCV1.RUN.PLUNGER";
|
public static final String KNPCV1_RUN_PLUNGER = "KNPCV1.RUN.PLUNGER";
|
||||||
|
public static final String KNPCV1_RUN_PRESSURE = "KNPCV1.RUN.PRESSURE";
|
||||||
public static final String KNPCV1_RUN_TIME_PRESSURE = "KNPCV1.RUN.TIME_PRESSURE";
|
public static final String KNPCV1_RUN_TIME_PRESSURE = "KNPCV1.RUN.TIME_PRESSURE";
|
||||||
/* 点表类型:KNPCV1 end */
|
/* 点表类型:KNPCV1 end */
|
||||||
|
|
||||||
|
@ -60,7 +62,7 @@ public abstract class Command implements Serializable {
|
||||||
private Long deviceId;
|
private Long deviceId;
|
||||||
|
|
||||||
public Collection<ModbusCommandDto> buildModbusCommand() {
|
public Collection<ModbusCommandDto> buildModbusCommand() {
|
||||||
if (this.validate()) {
|
if (!this.validate()) {
|
||||||
throw new InvalidParameterException("Invalid command");
|
throw new InvalidParameterException("Invalid command");
|
||||||
}
|
}
|
||||||
return this.builderModbusCommand();
|
return this.builderModbusCommand();
|
||||||
|
|
|
@ -63,7 +63,7 @@ public interface Timing {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
default String toHexString(String stringTime) {
|
default String toHexString(String stringTime) {
|
||||||
if (StringUtils.equals(stringTime, "00:00:00")) {
|
if (StringUtils.equals(stringTime, "00:00") || StringUtils.equals(stringTime, "00:00:00")) {
|
||||||
return "000000000000";
|
return "000000000000";
|
||||||
}
|
}
|
||||||
if (StringUtils.equals(stringTime, "23:59:59")) {
|
if (StringUtils.equals(stringTime, "23:59:59")) {
|
||||||
|
@ -73,9 +73,9 @@ public interface Timing {
|
||||||
return "03E7003B003B";
|
return "03E7003B003B";
|
||||||
}
|
}
|
||||||
String[] items = StringUtils.split(stringTime, ":");
|
String[] items = StringUtils.split(stringTime, ":");
|
||||||
int hours = NumberUtils.createInteger(items[0]);
|
int hours = Integer.parseInt(items[0]);
|
||||||
int minutes = NumberUtils.createInteger(items[1]);
|
int minutes = items.length < 2 ? 0 : Integer.parseInt(items[1]);
|
||||||
int seconds = NumberUtils.createInteger(items[2]);
|
int seconds = items.length < 3 ? 0 : Integer.parseInt(items[2]);
|
||||||
return StringUtils.leftPad(Integer.toHexString(hours), 4, "0") +
|
return StringUtils.leftPad(Integer.toHexString(hours), 4, "0") +
|
||||||
StringUtils.leftPad(Integer.toHexString(minutes), 4, "0") +
|
StringUtils.leftPad(Integer.toHexString(minutes), 4, "0") +
|
||||||
StringUtils.leftPad(Integer.toHexString(seconds), 4, "0");
|
StringUtils.leftPad(Integer.toHexString(seconds), 4, "0");
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.isu.gaswellwatch.vo.command.knpcv1.mode;
|
package com.isu.gaswellwatch.vo.command.knpcv1.mode;
|
||||||
|
|
||||||
import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto;
|
import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto;
|
||||||
|
import com.isu.gaswellwatch.vo.command.Command;
|
||||||
import com.isu.gaswellwatch.vo.command.knpcv1.ChangeRunMode;
|
import com.isu.gaswellwatch.vo.command.knpcv1.ChangeRunMode;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
|
@ -17,7 +18,7 @@ public class ManualMode extends ChangeRunMode {
|
||||||
|
|
||||||
public ManualMode() {
|
public ManualMode() {
|
||||||
super(0);
|
super(0);
|
||||||
this.setCode("KNPCV1.RUN.MANUAL");
|
this.setCode(Command.KNPCV1_RUN_MANUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
package com.isu.gaswellwatch.vo.command.knpcv1.mode;
|
||||||
|
|
||||||
|
import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto;
|
||||||
|
import com.isu.gaswellwatch.vo.command.Command;
|
||||||
|
import com.isu.gaswellwatch.vo.command.knpcv1.ChangeRunMode;
|
||||||
|
import com.isu.gaswellwatch.vo.command.knpcv1.Timing;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author <a href="mailto:scwsl@foxmail.com">王仕龙</a>
|
||||||
|
* 2024/11/26 21:02
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@SuperBuilder
|
||||||
|
public class PlungerMode extends ChangeRunMode implements Timing {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 9127026055666073752L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 柱塞模式初始气井状态。
|
||||||
|
* true:开井
|
||||||
|
* false:关井
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private boolean enable = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 柱塞模式续流时长。[0-999]:[0-59]:[0-59]
|
||||||
|
*/
|
||||||
|
private String sustainTiming;
|
||||||
|
/**
|
||||||
|
* 柱塞模式关井时长。[0-999]:[0-59]:[0-59]
|
||||||
|
*/
|
||||||
|
private String closeTiming;
|
||||||
|
|
||||||
|
|
||||||
|
public PlungerMode() {
|
||||||
|
super(4);
|
||||||
|
this.setCode(Command.KNPCV1_RUN_PLUNGER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean validate() {
|
||||||
|
return super.validate() && StringUtils.isNotBlank(this.sustainTiming)
|
||||||
|
&& StringUtils.isNotBlank(this.closeTiming);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<ModbusCommandDto> builderSubModbusCommand() {
|
||||||
|
StringBuilder command = new StringBuilder(150);
|
||||||
|
// 0007*2->hex
|
||||||
|
// 地址码 功能码 起始地址 连续长度 连续字长
|
||||||
|
// 01 10 015C 0007 0E
|
||||||
|
command.append("0110015C00070E");
|
||||||
|
command.append("000").append(this.enable ? "1" : "0");
|
||||||
|
command.append(this.toHexString(this.sustainTiming)).append(this.toHexString(this.closeTiming));
|
||||||
|
return List.of(ModbusCommandDto.builder().command(command.toString()).length(16).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSustainTiming(String sustainTiming) {
|
||||||
|
this.sustainTiming = this.timingValidate(sustainTiming, "sustainTiming");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCloseTiming(String closeTiming) {
|
||||||
|
this.closeTiming = this.timingValidate(closeTiming, "closeTiming");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,226 @@
|
||||||
|
package com.isu.gaswellwatch.vo.command.knpcv1.mode;
|
||||||
|
|
||||||
|
import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto;
|
||||||
|
import com.isu.gaswellwatch.vo.command.Command;
|
||||||
|
import com.isu.gaswellwatch.vo.command.knpcv1.ChangeRunMode;
|
||||||
|
import com.isu.gaswellwatch.vo.command.knpcv1.Timing;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 压力模式:存在3个不同的地址段,需要发发送4条命令
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:scwsl@foxmail.com">王仕龙</a>
|
||||||
|
* 2024/11/26 20:44
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@SuperBuilder
|
||||||
|
public class PressureMode extends ChangeRunMode implements Timing {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 8128429933652613769L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 压力源
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private PresourceEnum presource = PresourceEnum.OIL;
|
||||||
|
/**
|
||||||
|
* 压力触发类型
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private TriggerTypeEnum triggerType = TriggerTypeEnum.L0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开井压力:单位Mpa,*100,[0~9999]
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private int pressureOpen = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关井压力: 单位Mpa,*100,[0~9999]
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private int pressureClose = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 传感器压力稳定时间:秒,[0~36000]
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private int stabilityTime = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大开井时长
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private String maxOpenWell = "00:00:00";
|
||||||
|
/**
|
||||||
|
* 最小开井时长
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private String minOpenWell = "00:00:00";
|
||||||
|
/**
|
||||||
|
* 最大关井时长
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private String maxCloseWell = "00:00:00";
|
||||||
|
/**
|
||||||
|
* 最小关井时长
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private String minCloseWell = "00:00:00";
|
||||||
|
/**
|
||||||
|
* 开井压力保护使能
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private boolean presproTect = false;
|
||||||
|
/**
|
||||||
|
* 开井压力保护源
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private PresourceEnum presproSource = PresourceEnum.OIL;
|
||||||
|
/**
|
||||||
|
* 开井压力限制上限,[0-9999]
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private int openWellLimitMax = 0;
|
||||||
|
/**
|
||||||
|
* 开井压力限制下限,[0-9999]
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private int openWellLimitMin = 0;
|
||||||
|
|
||||||
|
|
||||||
|
public PressureMode() {
|
||||||
|
super(3);
|
||||||
|
this.setCode(Command.KNPCV1_RUN_PRESSURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean validate() {
|
||||||
|
return super.validate()
|
||||||
|
&& Objects.nonNull(this.presource)
|
||||||
|
&& Objects.nonNull(this.triggerType)
|
||||||
|
&& Objects.nonNull(this.presproSource)
|
||||||
|
&& StringUtils.isNotBlank(this.maxOpenWell)
|
||||||
|
&& StringUtils.isNotBlank(this.minOpenWell)
|
||||||
|
&& StringUtils.isNotBlank(this.maxCloseWell)
|
||||||
|
&& StringUtils.isNotBlank(this.minCloseWell)
|
||||||
|
&& this.pressureOpen >= 0 && this.pressureOpen <= 9999
|
||||||
|
&& this.pressureClose >= 0 && this.pressureClose <= 9999
|
||||||
|
&& this.openWellLimitMax >= 0 && this.openWellLimitMax <= 9999
|
||||||
|
&& this.openWellLimitMin >= 0 && this.openWellLimitMin <= 9999
|
||||||
|
&& this.stabilityTime >= 0 && this.stabilityTime <= 36000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<ModbusCommandDto> builderSubModbusCommand() {
|
||||||
|
List<ModbusCommandDto> commandList = new ArrayList<>(4);
|
||||||
|
StringBuilder command = new StringBuilder(150);
|
||||||
|
// 0005*2->hex
|
||||||
|
// 地址码 功能码 起始地址 连续长度 连续字长
|
||||||
|
// 01 10 00A0 0005 0A
|
||||||
|
command.append("011000A000050A");
|
||||||
|
command.append(StringUtils.leftPad(Integer.toHexString(this.presource.getCode()), 4, "0"));
|
||||||
|
command.append(StringUtils.leftPad(Integer.toHexString(this.pressureOpen), 4, "0"));
|
||||||
|
command.append(StringUtils.leftPad(Integer.toHexString(this.pressureClose), 4, "0"));
|
||||||
|
command.append(StringUtils.leftPad(Integer.toHexString(this.triggerType.getCode()), 4, "0"));
|
||||||
|
command.append(StringUtils.leftPad(Integer.toHexString(this.stabilityTime), 4, "0"));
|
||||||
|
commandList.add(ModbusCommandDto.builder().command(command.toString()).length(16).build());
|
||||||
|
|
||||||
|
command.setLength(0);
|
||||||
|
// 000C*2->hex
|
||||||
|
// 地址码 功能码 起始地址 连续长度 连续字长
|
||||||
|
// 01 10 00AA 000C 18
|
||||||
|
command.append("011000AA000C18");
|
||||||
|
command.append(this.toHexString(this.maxOpenWell));
|
||||||
|
command.append(this.toHexString(this.minOpenWell));
|
||||||
|
command.append(this.toHexString(this.maxCloseWell));
|
||||||
|
command.append(this.toHexString(this.minCloseWell));
|
||||||
|
commandList.add(ModbusCommandDto.builder().command(command.toString()).length(16).build());
|
||||||
|
|
||||||
|
command.setLength(0);
|
||||||
|
// 0004*2->hex
|
||||||
|
// 地址码 功能码 起始地址 连续长度 连续字长
|
||||||
|
// 01 10 0140 0004 08
|
||||||
|
command.append("01100140000408");
|
||||||
|
command.append("000").append(this.presproTect ? "1" : "0");
|
||||||
|
command.append(StringUtils.leftPad(Integer.toHexString(this.presproSource.getCode()), 4, "0"));
|
||||||
|
command.append(StringUtils.leftPad(Integer.toHexString(this.openWellLimitMax), 4, "0"));
|
||||||
|
command.append(StringUtils.leftPad(Integer.toHexString(this.openWellLimitMin), 4, "0"));
|
||||||
|
commandList.add(ModbusCommandDto.builder().command(command.toString()).length(16).build());
|
||||||
|
|
||||||
|
return commandList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxOpenWell(String maxOpenWell) {
|
||||||
|
this.maxOpenWell = this.timingValidate(maxOpenWell, "maxOpenWell");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinOpenWell(String minOpenWell) {
|
||||||
|
this.minOpenWell = this.timingValidate(minOpenWell, "minOpenWell");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxCloseWell(String maxCloseWell) {
|
||||||
|
this.maxCloseWell = this.timingValidate(maxCloseWell, "maxCloseWell");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinCloseWell(String minCloseWell) {
|
||||||
|
this.minCloseWell = this.timingValidate(minCloseWell, "minCloseWell");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 触发压力源:
|
||||||
|
* 0:油压
|
||||||
|
* 1:套压
|
||||||
|
* 2:输压
|
||||||
|
* 3:差压
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum PresourceEnum {
|
||||||
|
OIL(0, "油压"), CAS(1, "套压"), PRE(2, "输压"), DIFF(3, "差压");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
PresourceEnum(int code, String name) {
|
||||||
|
this.code = code;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 压力触发类型:
|
||||||
|
* 0:大于开井压力开井、小于关井压力关井
|
||||||
|
* 1:大于开井压力开井、大于关井压力关井
|
||||||
|
* 2:小于开井压力开井、小于关井压力关井
|
||||||
|
* 3:小于开井压力开井、大于关井压力关井
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum TriggerTypeEnum {
|
||||||
|
L0(0, "大于开井压力开井、小于关井压力关井"),
|
||||||
|
L1(1, "大于开井压力开井、大于关井压力关井"),
|
||||||
|
L2(2, "小于开井压力开井、小于关井压力关井"),
|
||||||
|
L3(3, "小于开井压力开井、大于关井压力关井");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
TriggerTypeEnum(int code, String name) {
|
||||||
|
this.code = code;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,157 @@
|
||||||
|
package com.isu.gaswellwatch.vo.command.knpcv1.mode;
|
||||||
|
|
||||||
|
import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto;
|
||||||
|
import com.isu.gaswellwatch.vo.command.Command;
|
||||||
|
import com.isu.gaswellwatch.vo.command.knpcv1.ChangeRunMode;
|
||||||
|
import com.isu.gaswellwatch.vo.command.knpcv1.Timing;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author <a href="mailto:scwsl@foxmail.com">王仕龙</a>
|
||||||
|
* 2024/11/26 21:44
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@SuperBuilder
|
||||||
|
public class TimePressureMode extends ChangeRunMode implements Timing {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 8128429933652613769L;
|
||||||
|
/**
|
||||||
|
* 时压模式初始气井状态
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private boolean tpInitStatus = false;
|
||||||
|
/**
|
||||||
|
* 时压模式开井源
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private TimePressureOpenSouceEnum tpOpenSource = TimePressureOpenSouceEnum.OIL;
|
||||||
|
/**
|
||||||
|
* 时压模式开井压力触发模式:
|
||||||
|
* 0:大于压力触发
|
||||||
|
* 1:小于压力触发
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private int tpOpenTrigger = 0;
|
||||||
|
/**
|
||||||
|
* 时压模式开井压力,[0~9999]
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private int tpOpenPressure = 0;
|
||||||
|
/**
|
||||||
|
* 时压模式开井时长
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private String tpOpenTiming = "00:00:00";
|
||||||
|
/**
|
||||||
|
* 时压模式关井源
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private TimePressureOpenSouceEnum tpCloseSource = TimePressureOpenSouceEnum.OIL;
|
||||||
|
/**
|
||||||
|
* 时压模式关井触发
|
||||||
|
* 0:大于压力触发
|
||||||
|
* 1:小于压力触发
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private int tpCloseTrigger = 0;
|
||||||
|
/**
|
||||||
|
* 时压模式关井压力,[0~9999]
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private int tpClosePressure = 0;
|
||||||
|
/**
|
||||||
|
* 时压模式关井时长
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private String tpCloseTiming = "00:00:00";
|
||||||
|
/**
|
||||||
|
* 时压模式压力稳定时长:秒,[0-120]
|
||||||
|
*/
|
||||||
|
@Builder.Default
|
||||||
|
private int tpStabilityTime = 0;
|
||||||
|
|
||||||
|
public TimePressureMode() {
|
||||||
|
super(5);
|
||||||
|
this.setCode(Command.KNPCV1_RUN_TIME_PRESSURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean validate() {
|
||||||
|
return super.validate()
|
||||||
|
&& Objects.nonNull(this.tpOpenSource)
|
||||||
|
&& Objects.nonNull(this.tpCloseSource)
|
||||||
|
&& StringUtils.isNotBlank(this.tpOpenTiming)
|
||||||
|
&& StringUtils.isNotBlank(this.tpCloseTiming)
|
||||||
|
&& this.tpOpenTrigger >= 0 && this.tpOpenTrigger <= 1
|
||||||
|
&& this.tpCloseTrigger >= 0 && this.tpCloseTrigger <= 1
|
||||||
|
&& this.tpOpenPressure >= 0 && this.tpOpenPressure <= 9999
|
||||||
|
&& this.tpClosePressure >= 0 && this.tpClosePressure <= 9999
|
||||||
|
&& this.tpStabilityTime >= 0 && this.tpStabilityTime <= 120;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<ModbusCommandDto> builderSubModbusCommand() {
|
||||||
|
StringBuilder command = new StringBuilder(150);
|
||||||
|
// 000E*2->hex
|
||||||
|
// 地址码 功能码 起始地址 连续长度 连续字长
|
||||||
|
// 01 10 0177 000E 1C
|
||||||
|
command.append("01100177000E1C");
|
||||||
|
command.append("000").append(this.tpInitStatus ? "1" : "0");
|
||||||
|
command.append(StringUtils.leftPad(Integer.toHexString(this.tpOpenSource.getCode()), 4, "0"));
|
||||||
|
command.append(StringUtils.leftPad(Integer.toHexString(this.tpOpenTrigger), 4, "0"));
|
||||||
|
command.append(StringUtils.leftPad(Integer.toHexString(this.tpOpenPressure), 4, "0"));
|
||||||
|
command.append(this.toHexString(this.tpOpenTiming));
|
||||||
|
command.append(StringUtils.leftPad(Integer.toHexString(this.tpCloseSource.getCode()), 4, "0"));
|
||||||
|
command.append(StringUtils.leftPad(Integer.toHexString(this.tpCloseTrigger), 4, "0"));
|
||||||
|
command.append(StringUtils.leftPad(Integer.toHexString(this.tpClosePressure), 4, "0"));
|
||||||
|
command.append(this.toHexString(this.tpCloseTiming));
|
||||||
|
command.append(StringUtils.leftPad(Integer.toHexString(this.tpStabilityTime), 4, "0"));
|
||||||
|
return List.of(ModbusCommandDto.builder().command(command.toString()).length(16).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTpOpenTiming(String tpOpenTiming) {
|
||||||
|
this.tpOpenTiming = this.timingValidate(tpOpenTiming, "tpOpenTiming");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTpCloseTiming(String tpCloseTiming) {
|
||||||
|
this.tpCloseTiming = this.timingValidate(tpCloseTiming, "tpCloseTiming");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时压模式开井源:
|
||||||
|
* 0:油压
|
||||||
|
* 1:套压
|
||||||
|
* 2:输压
|
||||||
|
* 3:差压
|
||||||
|
* <p>
|
||||||
|
* 4:时间
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum TimePressureOpenSouceEnum {
|
||||||
|
OIL(0, "油压"),
|
||||||
|
CAS(1, "套压"),
|
||||||
|
PRE(2, "输压"),
|
||||||
|
DIFF(3, "差压"),
|
||||||
|
TIME(4, "时间");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
TimePressureOpenSouceEnum(int code, String name) {
|
||||||
|
this.code = code;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package com.isu.gaswellwatch.vo.command.knpcv1.mode;
|
package com.isu.gaswellwatch.vo.command.knpcv1.mode;
|
||||||
|
|
||||||
import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto;
|
import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto;
|
||||||
|
import com.isu.gaswellwatch.vo.command.Command;
|
||||||
import com.isu.gaswellwatch.vo.command.knpcv1.ChangeRunMode;
|
import com.isu.gaswellwatch.vo.command.knpcv1.ChangeRunMode;
|
||||||
import com.isu.gaswellwatch.vo.command.knpcv1.Timing;
|
import com.isu.gaswellwatch.vo.command.knpcv1.Timing;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
|
@ -93,11 +94,43 @@ public class TimerMode extends ChangeRunMode implements Timing {
|
||||||
|
|
||||||
public TimerMode() {
|
public TimerMode() {
|
||||||
super(1);
|
super(1);
|
||||||
this.setCode("KNPCV1.RUN.TIMER");
|
this.setCode(Command.KNPCV1_RUN_TIMER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean validate() {
|
public boolean validate() {
|
||||||
|
if (!this.enable1) {
|
||||||
|
if (Objects.isNull(this.openTimer1)) {
|
||||||
|
this.openTimer1 = LocalTime.MIN;
|
||||||
|
}
|
||||||
|
if (Objects.isNull(this.closeTimer1)) {
|
||||||
|
this.closeTimer1 = LocalTime.MIN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!this.enable2) {
|
||||||
|
if (Objects.isNull(this.openTimer2)) {
|
||||||
|
this.openTimer2 = LocalTime.MIN;
|
||||||
|
}
|
||||||
|
if (Objects.isNull(this.closeTimer2)) {
|
||||||
|
this.closeTimer2 = LocalTime.MIN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!this.enable3) {
|
||||||
|
if (Objects.isNull(this.openTimer3)) {
|
||||||
|
this.openTimer3 = LocalTime.MIN;
|
||||||
|
}
|
||||||
|
if (Objects.isNull(this.closeTimer3)) {
|
||||||
|
this.closeTimer3 = LocalTime.MIN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!this.enable4) {
|
||||||
|
if (Objects.isNull(this.openTimer4)) {
|
||||||
|
this.openTimer4 = LocalTime.MIN;
|
||||||
|
}
|
||||||
|
if (Objects.isNull(this.closeTimer4)) {
|
||||||
|
this.closeTimer4 = LocalTime.MIN;
|
||||||
|
}
|
||||||
|
}
|
||||||
return super.validate()
|
return super.validate()
|
||||||
&& Objects.nonNull(this.openTimer1) && Objects.nonNull(this.closeTimer1)
|
&& Objects.nonNull(this.openTimer1) && Objects.nonNull(this.closeTimer1)
|
||||||
&& Objects.nonNull(this.openTimer2) && Objects.nonNull(this.closeTimer2)
|
&& Objects.nonNull(this.openTimer2) && Objects.nonNull(this.closeTimer2)
|
||||||
|
@ -108,6 +141,9 @@ public class TimerMode extends ChangeRunMode implements Timing {
|
||||||
@Override
|
@Override
|
||||||
protected Collection<ModbusCommandDto> builderSubModbusCommand() {
|
protected Collection<ModbusCommandDto> builderSubModbusCommand() {
|
||||||
StringBuilder command = new StringBuilder(150);
|
StringBuilder command = new StringBuilder(150);
|
||||||
|
// 001C*2->hex
|
||||||
|
// 地址码 功能码 起始地址 连续长度 连续字长
|
||||||
|
// 01 10 006E 001C 38
|
||||||
command.append("0110006E001C38");
|
command.append("0110006E001C38");
|
||||||
command.append("000").append(this.enable1 ? "1" : "0");
|
command.append("000").append(this.enable1 ? "1" : "0");
|
||||||
command.append("000").append(this.enable2 ? "1" : "0");
|
command.append("000").append(this.enable2 ? "1" : "0");
|
||||||
|
@ -117,9 +153,7 @@ public class TimerMode extends ChangeRunMode implements Timing {
|
||||||
.append(this.toHexString(this.openTimer2)).append(this.toHexString(this.closeTimer2))
|
.append(this.toHexString(this.openTimer2)).append(this.toHexString(this.closeTimer2))
|
||||||
.append(this.toHexString(this.openTimer3)).append(this.toHexString(this.closeTimer3))
|
.append(this.toHexString(this.openTimer3)).append(this.toHexString(this.closeTimer3))
|
||||||
.append(this.toHexString(this.openTimer4)).append(this.toHexString(this.closeTimer4));
|
.append(this.toHexString(this.openTimer4)).append(this.toHexString(this.closeTimer4));
|
||||||
return List.of(ModbusCommandDto.builder()
|
return List.of(ModbusCommandDto.builder().command(command.toString()).length(16).build());
|
||||||
.command(command.toString())
|
|
||||||
.length(16).build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.isu.gaswellwatch.vo.command.knpcv1.mode;
|
package com.isu.gaswellwatch.vo.command.knpcv1.mode;
|
||||||
|
|
||||||
import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto;
|
import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto;
|
||||||
|
import com.isu.gaswellwatch.vo.command.Command;
|
||||||
import com.isu.gaswellwatch.vo.command.knpcv1.ChangeRunMode;
|
import com.isu.gaswellwatch.vo.command.knpcv1.ChangeRunMode;
|
||||||
import com.isu.gaswellwatch.vo.command.knpcv1.Timing;
|
import com.isu.gaswellwatch.vo.command.knpcv1.Timing;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
|
@ -43,7 +44,7 @@ public class TimingMode extends ChangeRunMode implements Timing {
|
||||||
|
|
||||||
public TimingMode() {
|
public TimingMode() {
|
||||||
super(2);
|
super(2);
|
||||||
this.setCode("KNPCV1.RUN.TIMING");
|
this.setCode(Command.KNPCV1_RUN_TIMING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,7 +58,7 @@ public class TimingMode extends ChangeRunMode implements Timing {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCloseTiming(String closeTiming) {
|
public void setCloseTiming(String closeTiming) {
|
||||||
this.closeTiming = this.timingValidate(this.openTiming, "closeTiming");
|
this.closeTiming = this.timingValidate(closeTiming, "closeTiming");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDelayTiming(String delayTiming) {
|
public void setDelayTiming(String delayTiming) {
|
||||||
|
@ -67,14 +68,15 @@ public class TimingMode extends ChangeRunMode implements Timing {
|
||||||
@Override
|
@Override
|
||||||
protected Collection<ModbusCommandDto> builderSubModbusCommand() {
|
protected Collection<ModbusCommandDto> builderSubModbusCommand() {
|
||||||
StringBuilder command = new StringBuilder(60);
|
StringBuilder command = new StringBuilder(60);
|
||||||
|
// 000A*2->hex
|
||||||
|
// 地址码 功能码 起始地址 连续长度 连续字长
|
||||||
|
// 01 10 0096 000A 14
|
||||||
command.append("01100096000A14")
|
command.append("01100096000A14")
|
||||||
.append(this.toHexString(this.openTiming))
|
.append(this.toHexString(this.openTiming))
|
||||||
.append(this.toHexString(this.closeTiming))
|
.append(this.toHexString(this.closeTiming))
|
||||||
.append("0000") // 地址位:0154,值为空
|
.append("0000") // 地址位:0156,值为空
|
||||||
.append(this.toHexString(this.delayTiming));
|
.append(this.toHexString(this.delayTiming));
|
||||||
return List.of(ModbusCommandDto.builder()
|
return List.of(ModbusCommandDto.builder().command(command.toString()).length(16).build());
|
||||||
.command(command.toString())
|
|
||||||
.length(16).build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue