控制数据,进位转换
This commit is contained in:
parent
2dddc8115b
commit
d764a3143f
|
@ -5,6 +5,7 @@ import com.isu.gaswellwatch.vo.command.Command;
|
||||||
import com.isu.gaswellwatch.vo.command.Timing;
|
import com.isu.gaswellwatch.vo.command.Timing;
|
||||||
import com.isu.gaswellwatch.vo.command.knpcv1.ChangeRunMode;
|
import com.isu.gaswellwatch.vo.command.knpcv1.ChangeRunMode;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
@ -12,9 +13,12 @@ import lombok.experimental.SuperBuilder;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 压力模式:存在3个不同的地址段,需要发发送4条命令
|
* 压力模式:存在3个不同的地址段,需要发发送4条命令
|
||||||
|
@ -29,6 +33,8 @@ public class PressureMode extends ChangeRunMode implements Timing {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 8128429933652613769L;
|
private static final long serialVersionUID = 8128429933652613769L;
|
||||||
|
public static final BigDecimal MAX_VALUE = BigDecimal.valueOf(9999);
|
||||||
|
public static final BigDecimal MULTIPLE = BigDecimal.valueOf(100);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 压力源
|
* 压力源
|
||||||
|
@ -45,13 +51,15 @@ public class PressureMode extends ChangeRunMode implements Timing {
|
||||||
* 开井压力:单位Mpa,*100,[0~9999]
|
* 开井压力:单位Mpa,*100,[0~9999]
|
||||||
*/
|
*/
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
private int pressureOpen = 0;
|
@NotNull(message = "开井压力不能为空")
|
||||||
|
private BigDecimal pressureOpen = BigDecimal.ZERO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关井压力: 单位Mpa,*100,[0~9999]
|
* 关井压力: 单位Mpa,*100,[0~9999]
|
||||||
*/
|
*/
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
private int pressureClose = 0;
|
@NotNull(message = "关井压力不能为空")
|
||||||
|
private BigDecimal pressureClose = BigDecimal.ZERO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 传感器压力稳定时间:秒,[0~36000]
|
* 传感器压力稳定时间:秒,[0~36000]
|
||||||
|
@ -97,12 +105,14 @@ public class PressureMode extends ChangeRunMode implements Timing {
|
||||||
* 开井压力限制上限,[0-9999]
|
* 开井压力限制上限,[0-9999]
|
||||||
*/
|
*/
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
private int openWellLimitMax = 0;
|
@NotNull(message = "开井压力限制上限不能为空")
|
||||||
|
private BigDecimal openWellLimitMax = BigDecimal.ZERO;
|
||||||
/**
|
/**
|
||||||
* 开井压力限制下限,[0-9999]
|
* 开井压力限制下限,[0-9999]
|
||||||
*/
|
*/
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
private int openWellLimitMin = 0;
|
@NotNull(message = "开井压力限制下限不能为空")
|
||||||
|
private BigDecimal openWellLimitMin = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
|
||||||
public PressureMode() {
|
public PressureMode() {
|
||||||
|
@ -121,10 +131,18 @@ public class PressureMode extends ChangeRunMode implements Timing {
|
||||||
&& this.presproTect >= 0 && this.presproTect <= 1
|
&& this.presproTect >= 0 && this.presproTect <= 1
|
||||||
&& this.triggerType >= 0 && this.triggerType <= 3
|
&& this.triggerType >= 0 && this.triggerType <= 3
|
||||||
&& this.presproSource >= 0 && this.presproSource <= 3
|
&& this.presproSource >= 0 && this.presproSource <= 3
|
||||||
&& this.pressureOpen >= 0 && this.pressureOpen <= 9999
|
&& Objects.nonNull(this.pressureOpen)
|
||||||
&& this.pressureClose >= 0 && this.pressureClose <= 9999
|
&& this.pressureOpen.compareTo(BigDecimal.ZERO) >= 0
|
||||||
&& this.openWellLimitMax >= 0 && this.openWellLimitMax <= 9999
|
&& this.pressureOpen.multiply(MULTIPLE).compareTo(MAX_VALUE) <= 0
|
||||||
&& this.openWellLimitMin >= 0 && this.openWellLimitMin <= 9999
|
&& Objects.nonNull(this.pressureClose)
|
||||||
|
&& this.pressureClose.compareTo(BigDecimal.ZERO) >= 0
|
||||||
|
&& this.pressureClose.multiply(MULTIPLE).compareTo(MAX_VALUE) <= 0
|
||||||
|
&& Objects.nonNull(this.openWellLimitMax)
|
||||||
|
&& this.openWellLimitMax.compareTo(BigDecimal.ZERO) >= 0
|
||||||
|
&& this.openWellLimitMax.multiply(MULTIPLE).compareTo(MAX_VALUE) <= 0
|
||||||
|
&& Objects.nonNull(this.openWellLimitMin)
|
||||||
|
&& this.openWellLimitMin.compareTo(BigDecimal.ZERO) >= 0
|
||||||
|
&& this.openWellLimitMin.multiply(MULTIPLE).compareTo(MAX_VALUE) <= 0
|
||||||
&& this.stabilityTime >= 0 && this.stabilityTime <= 36000;
|
&& this.stabilityTime >= 0 && this.stabilityTime <= 36000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,8 +155,8 @@ public class PressureMode extends ChangeRunMode implements Timing {
|
||||||
// 01 10 00A0 0005 0A
|
// 01 10 00A0 0005 0A
|
||||||
command.append("011000A000050A");
|
command.append("011000A000050A");
|
||||||
command.append(StringUtils.leftPad(Integer.toHexString(this.presource), 4, "0"));
|
command.append(StringUtils.leftPad(Integer.toHexString(this.presource), 4, "0"));
|
||||||
command.append(StringUtils.leftPad(Integer.toHexString(this.pressureOpen), 4, "0"));
|
command.append(StringUtils.leftPad(Integer.toHexString(this.pressureOpen.multiply(MULTIPLE).intValue()), 4, "0"));
|
||||||
command.append(StringUtils.leftPad(Integer.toHexString(this.pressureClose), 4, "0"));
|
command.append(StringUtils.leftPad(Integer.toHexString(this.pressureClose.multiply(MULTIPLE).intValue()), 4, "0"));
|
||||||
command.append(StringUtils.leftPad(Integer.toHexString(this.triggerType), 4, "0"));
|
command.append(StringUtils.leftPad(Integer.toHexString(this.triggerType), 4, "0"));
|
||||||
command.append(StringUtils.leftPad(Integer.toHexString(this.stabilityTime), 4, "0"));
|
command.append(StringUtils.leftPad(Integer.toHexString(this.stabilityTime), 4, "0"));
|
||||||
commandList.add(ModbusCommandDto.builder().command(command.toString()).length(16).build());
|
commandList.add(ModbusCommandDto.builder().command(command.toString()).length(16).build());
|
||||||
|
@ -161,8 +179,8 @@ public class PressureMode extends ChangeRunMode implements Timing {
|
||||||
command.append("01100140000408");
|
command.append("01100140000408");
|
||||||
command.append("000").append(this.presproTect);
|
command.append("000").append(this.presproTect);
|
||||||
command.append(StringUtils.leftPad(Integer.toHexString(this.presproSource), 4, "0"));
|
command.append(StringUtils.leftPad(Integer.toHexString(this.presproSource), 4, "0"));
|
||||||
command.append(StringUtils.leftPad(Integer.toHexString(this.openWellLimitMax), 4, "0"));
|
command.append(StringUtils.leftPad(Integer.toHexString(this.openWellLimitMax.setScale(2, RoundingMode.HALF_UP).intValue()), 4, "0"));
|
||||||
command.append(StringUtils.leftPad(Integer.toHexString(this.openWellLimitMin), 4, "0"));
|
command.append(StringUtils.leftPad(Integer.toHexString(this.openWellLimitMin.setScale(2, RoundingMode.HALF_UP).intValue()), 4, "0"));
|
||||||
commandList.add(ModbusCommandDto.builder().command(command.toString()).length(16).build());
|
commandList.add(ModbusCommandDto.builder().command(command.toString()).length(16).build());
|
||||||
|
|
||||||
return commandList;
|
return commandList;
|
||||||
|
|
|
@ -2,14 +2,18 @@ package com.isu.gaswellwatch.vo.command.scss;
|
||||||
|
|
||||||
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.Command;
|
||||||
|
import com.isu.gaswellwatch.vo.command.knpcv1.mode.PressureMode;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 逻辑定值-简单模式定值数据寄存器地址
|
* 逻辑定值-简单模式定值数据寄存器地址
|
||||||
|
@ -30,15 +34,18 @@ public class SimpleLogicMode extends Command {
|
||||||
/**
|
/**
|
||||||
* 开井套压
|
* 开井套压
|
||||||
*/
|
*/
|
||||||
private int wellOpenPressureValue;
|
@NotNull(message = "开井套压不能为空")
|
||||||
|
private BigDecimal wellOpenPressureValue = BigDecimal.ZERO;
|
||||||
/**
|
/**
|
||||||
* 开井油压
|
* 开井油压
|
||||||
*/
|
*/
|
||||||
private int wellOpenOilPressureValue;
|
@NotNull(message = "开井油压不能为空")
|
||||||
|
private BigDecimal wellOpenOilPressureValue = BigDecimal.ZERO;
|
||||||
/**
|
/**
|
||||||
* 开井载荷因子预设值
|
* 开井载荷因子预设值
|
||||||
*/
|
*/
|
||||||
private int wellOpenLoadFactorPresets;
|
@NotNull(message = "开井载荷因子预设值不能为空")
|
||||||
|
private BigDecimal wellOpenLoadFactorPresets = BigDecimal.ZERO;
|
||||||
/**
|
/**
|
||||||
* 关井时间
|
* 关井时间
|
||||||
*/
|
*/
|
||||||
|
@ -92,6 +99,20 @@ public class SimpleLogicMode extends Command {
|
||||||
this.setCode("SCSS.SIMPLE_LOGIC_MODE");
|
this.setCode("SCSS.SIMPLE_LOGIC_MODE");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean validate() {
|
||||||
|
return super.validate()
|
||||||
|
&& Objects.nonNull(this.wellOpenPressureValue)
|
||||||
|
&& this.wellOpenPressureValue.compareTo(BigDecimal.ZERO) >= 0
|
||||||
|
&& this.wellOpenPressureValue.multiply(PressureMode.MULTIPLE).compareTo(PressureMode.MAX_VALUE) <= 0
|
||||||
|
&& Objects.nonNull(this.wellOpenOilPressureValue)
|
||||||
|
&& this.wellOpenOilPressureValue.compareTo(BigDecimal.ZERO) >= 0
|
||||||
|
&& this.wellOpenOilPressureValue.multiply(PressureMode.MULTIPLE).compareTo(PressureMode.MAX_VALUE) <= 0
|
||||||
|
&& Objects.nonNull(this.wellOpenLoadFactorPresets)
|
||||||
|
&& this.wellOpenLoadFactorPresets.compareTo(BigDecimal.ZERO) >= 0
|
||||||
|
&& this.wellOpenLoadFactorPresets.multiply(PressureMode.MULTIPLE).compareTo(PressureMode.MAX_VALUE) <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Collection<ModbusCommandDto> builderModbusCommand() {
|
protected Collection<ModbusCommandDto> builderModbusCommand() {
|
||||||
StringBuilder command = new StringBuilder(130);
|
StringBuilder command = new StringBuilder(130);
|
||||||
|
@ -99,9 +120,9 @@ public class SimpleLogicMode extends Command {
|
||||||
// 01 10 0096 0020 40
|
// 01 10 0096 0020 40
|
||||||
command.append("01100096002040");
|
command.append("01100096002040");
|
||||||
command.append(StringUtils.leftPad(Integer.toHexString(this.wellOpenTimeTimestamp), 8, "0"));
|
command.append(StringUtils.leftPad(Integer.toHexString(this.wellOpenTimeTimestamp), 8, "0"));
|
||||||
command.append(StringUtils.leftPad(Integer.toHexString(this.wellOpenPressureValue), 8, "0"));
|
command.append(StringUtils.leftPad(Integer.toHexString(this.wellOpenPressureValue.multiply(PressureMode.MULTIPLE).intValue()), 8, "0"));
|
||||||
command.append(StringUtils.leftPad(Integer.toHexString(this.wellOpenOilPressureValue), 8, "0"));
|
command.append(StringUtils.leftPad(Integer.toHexString(this.wellOpenOilPressureValue.multiply(PressureMode.MULTIPLE).intValue()), 8, "0"));
|
||||||
command.append(StringUtils.leftPad(Integer.toHexString(this.wellOpenLoadFactorPresets), 8, "0"));
|
command.append(StringUtils.leftPad(Integer.toHexString(this.wellOpenLoadFactorPresets.multiply(PressureMode.MULTIPLE).intValue()), 8, "0"));
|
||||||
command.append(StringUtils.leftPad(Integer.toHexString(this.wellCloseTimeTimestamp), 8, "0"));
|
command.append(StringUtils.leftPad(Integer.toHexString(this.wellCloseTimeTimestamp), 8, "0"));
|
||||||
command.append(StringUtils.leftPad(Integer.toHexString(this.wellClosePressureValue), 8, "0"));
|
command.append(StringUtils.leftPad(Integer.toHexString(this.wellClosePressureValue), 8, "0"));
|
||||||
command.append(StringUtils.leftPad(Integer.toHexString(this.wellCloseOilPressureValue), 8, "0"));
|
command.append(StringUtils.leftPad(Integer.toHexString(this.wellCloseOilPressureValue), 8, "0"));
|
||||||
|
|
Loading…
Reference in New Issue