From 412ede0301a1f540f83777a92f5251960f3f98c3 Mon Sep 17 00:00:00 2001 From: wangshilong Date: Wed, 27 Nov 2024 23:46:40 +0800 Subject: [PATCH 1/2] Add ETC command points --- .../controller/CommandController.java | 5 +- .../data/Redis2DBPersistenceService.java | 2 +- .../modbus/impl/CommandServiceImpl.java | 55 +++++++++++--- .../isu/gaswellwatch/vo/command/Command.java | 30 +++++++- .../vo/command/etc/PlungerTimer.java | 53 +++++++++++++ .../vo/command/etc/SensorDelay.java | 76 +++++++++++++++++++ .../gaswellwatch/vo/command/etc/TurnOff.java | 28 +++++++ .../gaswellwatch/vo/command/etc/TurnOn.java | 28 +++++++ .../vo/command/knpcv1/mode/PlungerMode.java | 3 + .../vo/command/knpcv1/mode/PressureMode.java | 5 ++ .../command/knpcv1/mode/TimePressureMode.java | 3 + .../vo/command/knpcv1/mode/TimerMode.java | 8 +- .../vo/command/knpcv1/mode/TimingMode.java | 4 + .../gaswellwatch/vo/command/scss/TurnOff.java | 28 +++++++ .../gaswellwatch/vo/command/scss/TurnOn.java | 28 +++++++ 15 files changed, 335 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/isu/gaswellwatch/vo/command/etc/PlungerTimer.java create mode 100644 src/main/java/com/isu/gaswellwatch/vo/command/etc/SensorDelay.java create mode 100644 src/main/java/com/isu/gaswellwatch/vo/command/etc/TurnOff.java create mode 100644 src/main/java/com/isu/gaswellwatch/vo/command/etc/TurnOn.java create mode 100644 src/main/java/com/isu/gaswellwatch/vo/command/scss/TurnOff.java create mode 100644 src/main/java/com/isu/gaswellwatch/vo/command/scss/TurnOn.java diff --git a/src/main/java/com/isu/gaswellwatch/controller/CommandController.java b/src/main/java/com/isu/gaswellwatch/controller/CommandController.java index b57cd31..9a12334 100644 --- a/src/main/java/com/isu/gaswellwatch/controller/CommandController.java +++ b/src/main/java/com/isu/gaswellwatch/controller/CommandController.java @@ -7,6 +7,7 @@ import com.isu.gaswellwatch.modbus.CommandService; import com.isu.gaswellwatch.vo.command.CollectCommand; import com.isu.gaswellwatch.vo.command.Command; import lombok.RequiredArgsConstructor; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -25,13 +26,13 @@ public class CommandController { @PostMapping(value = "/control") @OperationLog(description = "下发控制指令", type = LogType.ADD) - public Response control(@RequestBody Command command) { + public Response control(@RequestBody @Validated Command command) { return this.commandService.control(command); } @PostMapping(value = "/collect") @OperationLog(description = "下发采集指令", type = LogType.ADD) - public Response collect(@RequestBody CollectCommand command) { + public Response collect(@RequestBody @Validated CollectCommand command) { return this.commandService.collect(command); } diff --git a/src/main/java/com/isu/gaswellwatch/modbus/data/Redis2DBPersistenceService.java b/src/main/java/com/isu/gaswellwatch/modbus/data/Redis2DBPersistenceService.java index 10ff195..8b7826d 100644 --- a/src/main/java/com/isu/gaswellwatch/modbus/data/Redis2DBPersistenceService.java +++ b/src/main/java/com/isu/gaswellwatch/modbus/data/Redis2DBPersistenceService.java @@ -37,7 +37,7 @@ import java.util.stream.Collectors; public class Redis2DBPersistenceService { public static final String DEFAULT_DATA_TABLE = "t_device_data_"; - private static final String DEVICE_INFO_SQL = "SELECT d.*, dp.code as modbus_device_product_code from device d " + public static final String DEVICE_INFO_SQL = "SELECT d.*, dp.code as modbus_device_product_code from device d " + "join dictionary dp on dp.id = d.product where d.id = "; private static final String EXISTS_TABLE_SQL = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA" + " IN ('gaswellwatch', 'gas_well_watch') AND TABLE_NAME='$TableName$'"; 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 38d496a..9fb00b6 100644 --- a/src/main/java/com/isu/gaswellwatch/modbus/impl/CommandServiceImpl.java +++ b/src/main/java/com/isu/gaswellwatch/modbus/impl/CommandServiceImpl.java @@ -1,20 +1,29 @@ package com.isu.gaswellwatch.modbus.impl; -import com.isu.gaswellwatch.dao.DeviceDao; +import cn.hutool.core.map.MapUtil; import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; import com.isu.gaswellwatch.entity.Response; import com.isu.gaswellwatch.modbus.CommandService; +import com.isu.gaswellwatch.modbus.data.PersistenceHandler; +import com.isu.gaswellwatch.modbus.data.Redis2DBPersistenceService; import com.isu.gaswellwatch.vo.command.Command; +import jakarta.annotation.Resource; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.core.ParameterizedTypeReference; +import org.springframework.data.redis.core.HashOperations; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; /** @@ -26,7 +35,9 @@ import java.util.Objects; @RequiredArgsConstructor public class CommandServiceImpl implements CommandService { - private final DeviceDao deviceDao; + private final JdbcTemplate jdbcTemplate; + @Resource(name = "stringRedisTemplate") + private RedisTemplate redisTemplate; private final RestTemplate restTemplate = new RestTemplate(); @Override @@ -46,16 +57,38 @@ public class CommandServiceImpl implements CommandService { if (ObjectUtils.isEmpty(modbusCommands)) { return Response.failed("Modbus command is empty"); } - this.deviceDao.getDeviceById(command.getDeviceId()); + HashOperations operations = this.redisTemplate.opsForHash(); + Map deviceInfoMap = operations.entries( + PersistenceHandler.DEVICE_INFO_CACHE + command.getDeviceId()); + if (ObjectUtils.isEmpty(deviceInfoMap)) { + Map deviceInfo = this.jdbcTemplate.queryForMap( + Redis2DBPersistenceService.DEVICE_INFO_SQL + command.getDeviceId()); + if (ObjectUtils.isNotEmpty(deviceInfo)) { + deviceInfoMap = new HashMap<>(deviceInfo.size()); + for (Map.Entry entry : deviceInfo.entrySet()) { + deviceInfoMap.put(entry.getKey(), + Objects.isNull(entry.getValue()) ? null : String.valueOf(entry.getValue())); + } + operations.putAll(PersistenceHandler.DEVICE_INFO_CACHE + command.getDeviceId(), deviceInfoMap); + } + } - modbusCommands.forEach(item -> { -// .key(StringUtils.joinWith("/", identifier, -// MapUtil.getStr(item, "deviceId"), -// MapUtil.getStr(item, "commandId"), -// timestamp)) - item.setKey(""); - item.setIdentifier(""); - }); + String identifier; + long timestamp = System.currentTimeMillis(); + for (ModbusCommandDto item : modbusCommands) { + if (StringUtils.isBlank(item.getCommand())) { + return Response.failed("Modbus command is empty"); + } + if (item.getLength() < 10) { + return Response.failed("Modbus command return message length failed"); + } + identifier = MapUtil.getStr(deviceInfoMap, "gateway_sn"); + item.setKey(StringUtils.joinWith("/", identifier, + MapUtil.getStr(deviceInfoMap, "deviceId"), + MapUtil.getStr(deviceInfoMap, "commandId"), + timestamp)); + item.setIdentifier(identifier); + } RequestEntity> request = RequestEntity .post("http://localhost:9999/modbus-tcp/" + type) .body(modbusCommands); 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 d13041d..b08dedf 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/command/Command.java +++ b/src/main/java/com/isu/gaswellwatch/vo/command/Command.java @@ -3,9 +3,9 @@ package com.isu.gaswellwatch.vo.command; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; -import com.isu.gaswellwatch.vo.command.knpcv1.TurnOff; -import com.isu.gaswellwatch.vo.command.knpcv1.TurnOn; import com.isu.gaswellwatch.vo.command.knpcv1.mode.*; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -25,14 +25,18 @@ import java.util.Objects; */ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "code") @JsonSubTypes(value = { - @JsonSubTypes.Type(value = TurnOn.class, name = Command.KNPCV1_TURN_ON_THE_WELL), - @JsonSubTypes.Type(value = TurnOff.class, name = Command.KNPCV1_TURN_OFF_THE_WELL), @JsonSubTypes.Type(value = TimerMode.class, name = Command.KNPCV1_RUN_TIMER), @JsonSubTypes.Type(value = TimingMode.class, name = Command.KNPCV1_RUN_TIMING), @JsonSubTypes.Type(value = ManualMode.class, name = Command.KNPCV1_RUN_MANUAL), @JsonSubTypes.Type(value = PlungerMode.class, name = Command.KNPCV1_RUN_PLUNGER), @JsonSubTypes.Type(value = PressureMode.class, name = Command.KNPCV1_RUN_PRESSURE), @JsonSubTypes.Type(value = TimePressureMode.class, name = Command.KNPCV1_RUN_TIME_PRESSURE), + @JsonSubTypes.Type(value = com.isu.gaswellwatch.vo.command.etc.TurnOn.class, name = Command.ETC_TURN_ON_THE_WELL), + @JsonSubTypes.Type(value = com.isu.gaswellwatch.vo.command.etc.TurnOff.class, name = Command.ETC_TURN_OFF_THE_WELL), + @JsonSubTypes.Type(value = com.isu.gaswellwatch.vo.command.scss.TurnOn.class, name = Command.SCSS_TURN_ON_THE_WELL), + @JsonSubTypes.Type(value = com.isu.gaswellwatch.vo.command.scss.TurnOff.class, name = Command.SCSS_TURN_OFF_THE_WELL), + @JsonSubTypes.Type(value = com.isu.gaswellwatch.vo.command.knpcv1.TurnOn.class, name = Command.KNPCV1_TURN_ON_THE_WELL), + @JsonSubTypes.Type(value = com.isu.gaswellwatch.vo.command.knpcv1.TurnOff.class, name = Command.KNPCV1_TURN_OFF_THE_WELL), }) @Getter @Setter @@ -57,8 +61,26 @@ public abstract class Command implements Serializable { public static final String KNPCV1_RUN_TIME_PRESSURE = "KNPCV1.RUN.TIME_PRESSURE"; /* 点表类型:KNPCV1 end */ + /* 点表类型:SCSS start */ + /* 开关井 */ + public static final String SCSS_TURN_ON_THE_WELL = "SCSS.TURN_ON_THE_WELL"; + public static final String SCSS_TURN_OFF_THE_WELL = "SCSS.TURN_OFF_THE_WELL"; + /* 运行模式*/ + + /* 点表类型:SCSS end */ + + /* 点表类型:ETC start */ + /* 开关井 */ + public static final String ETC_TURN_ON_THE_WELL = "ETC.TURN_ON_THE_WELL"; + public static final String ETC_TURN_OFF_THE_WELL = "ETC.TURN_OFF_THE_WELL"; + /* 运行模式*/ + + /* 点表类型:ETC end */ + + @NotBlank(message = "指令编码不能为空") private String code; + @NotNull(message = "下发设备标识不能为空") private Long deviceId; public Collection buildModbusCommand() { diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/etc/PlungerTimer.java b/src/main/java/com/isu/gaswellwatch/vo/command/etc/PlungerTimer.java new file mode 100644 index 0000000..9a34080 --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/vo/command/etc/PlungerTimer.java @@ -0,0 +1,53 @@ +package com.isu.gaswellwatch.vo.command.etc; + +import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; +import com.isu.gaswellwatch.vo.command.Command; +import com.isu.gaswellwatch.vo.command.Timing; +import jakarta.validation.constraints.NotBlank; +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 王仕龙 + * 2024/11/27 22:56 + */ +@Getter +@Setter +@SuperBuilder +public class PlungerTimer extends Command implements Timing { + + @Serial + private static final long serialVersionUID = 888739283997908251L; + + /** + * 柱塞上升时间。[0-999]:[0-59]:[0-59] + */ + @NotBlank(message = "柱塞上升时间不能为空") + private String plungerRiseTime; + + @Override + public boolean validate() { + return super.validate() && StringUtils.isNotBlank(this.plungerRiseTime); + } + + @Override + protected Collection builderModbusCommand() { + StringBuilder command = new StringBuilder(60); + // 0003*2->hex + // 地址码 功能码 起始地址 连续长度 连续字长 + // 01 10 006A 0003 06 + command.append("0110006A000306").append(this.toHexString(this.plungerRiseTime)); + return List.of(ModbusCommandDto.builder().command(command.toString()).length(16).build()); + } + + public void setPlungerRiseTime(String plungerRiseTime) { + this.plungerRiseTime = this.timingValidate(plungerRiseTime, "plungerRiseTime"); + } + +} diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/etc/SensorDelay.java b/src/main/java/com/isu/gaswellwatch/vo/command/etc/SensorDelay.java new file mode 100644 index 0000000..fb58ad4 --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/vo/command/etc/SensorDelay.java @@ -0,0 +1,76 @@ +package com.isu.gaswellwatch.vo.command.etc; + +import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; +import com.isu.gaswellwatch.vo.command.Command; +import com.isu.gaswellwatch.vo.command.Timing; +import jakarta.validation.constraints.NotBlank; +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 王仕龙 + * 2024/11/27 23:04 + */ +@Getter +@Setter +@SuperBuilder +public class SensorDelay extends Command implements Timing { + + @Serial + private static final long serialVersionUID = -126267138442242492L; + /** + * 到达传感器延时时间。[0-999]:[0-59]:[0-59] + */ + @NotBlank(message = "到达传感器延时时间不能为空") + private String arrivalSensorDelayTime; + /** + * 关井时间。[0-999]:[0-59]:[0-59] + */ + @NotBlank(message = "关井时间不能为空") + private String wellShutInTime; + /** + * 续流时间。[0-999]:[0-59]:[0-59] + */ + @NotBlank(message = "续流时间不能为空") + private String afterFlowTime; + + @Override + public boolean validate() { + return super.validate() + && StringUtils.isNotBlank(this.afterFlowTime) + && StringUtils.isNotBlank(this.wellShutInTime) + && StringUtils.isNotBlank(this.arrivalSensorDelayTime); + } + + @Override + protected Collection builderModbusCommand() { + StringBuilder command = new StringBuilder(60); + // 0009*2->hex + // 地址码 功能码 起始地址 连续长度 连续字长 + // 01 10 008B 0009 12 + command.append("0110008B000912") + .append(this.toHexString(this.arrivalSensorDelayTime)) + .append(this.toHexString(this.wellShutInTime)) + .append(this.toHexString(this.afterFlowTime)); + return List.of(ModbusCommandDto.builder().command(command.toString()).length(16).build()); + } + + public void setAfterFlowTime(String afterFlowTime) { + this.afterFlowTime = this.timingValidate(afterFlowTime, "afterFlowTime"); + } + + public void setWellShutInTime(String wellShutInTime) { + this.wellShutInTime = this.timingValidate(wellShutInTime, "wellShutInTime"); + } + + public void setArrivalSensorDelayTime(String arrivalSensorDelayTime) { + this.arrivalSensorDelayTime = this.timingValidate(arrivalSensorDelayTime, "arrivalSensorDelayTime"); + } + +} diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/etc/TurnOff.java b/src/main/java/com/isu/gaswellwatch/vo/command/etc/TurnOff.java new file mode 100644 index 0000000..be3f4eb --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/vo/command/etc/TurnOff.java @@ -0,0 +1,28 @@ +package com.isu.gaswellwatch.vo.command.etc; + +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/27 22:44 + */ +public class TurnOff extends Command { + + @Serial + private static final long serialVersionUID = 5520601184417717931L; + + public TurnOff() { + this.setCode("ETC.TURN_OFF_THE_WELL"); + } + + @Override + protected Collection builderModbusCommand() { + return List.of(ModbusCommandDto.builder().command("01050001FF00").length(16).build()); + } + +} diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/etc/TurnOn.java b/src/main/java/com/isu/gaswellwatch/vo/command/etc/TurnOn.java new file mode 100644 index 0000000..7e9c638 --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/vo/command/etc/TurnOn.java @@ -0,0 +1,28 @@ +package com.isu.gaswellwatch.vo.command.etc; + +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/27 22:48 + */ +public class TurnOn extends Command { + + @Serial + private static final long serialVersionUID = 7288866205502636187L; + + public TurnOn() { + this.setCode("ETC.TURN_ON_THE_WELL"); + } + + @Override + protected Collection builderModbusCommand() { + return List.of(ModbusCommandDto.builder().command("01050001FF00").length(16).build()); + } + +} diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/PlungerMode.java b/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/PlungerMode.java index 586abfe..2124732 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/PlungerMode.java +++ b/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/PlungerMode.java @@ -4,6 +4,7 @@ import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; import com.isu.gaswellwatch.vo.command.Command; import com.isu.gaswellwatch.vo.command.Timing; import com.isu.gaswellwatch.vo.command.knpcv1.ChangeRunMode; +import jakarta.validation.constraints.NotBlank; import lombok.Builder; import lombok.Getter; import lombok.Setter; @@ -37,10 +38,12 @@ public class PlungerMode extends ChangeRunMode implements Timing { /** * 柱塞模式续流时长。[0-999]:[0-59]:[0-59] */ + @NotBlank(message = "续流时长不能为空") private String plugSustainTime; /** * 柱塞模式关井时长。[0-999]:[0-59]:[0-59] */ + @NotBlank(message = "关井时长不能为空") private String plugCloseTime; diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/PressureMode.java b/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/PressureMode.java index e2e1770..24de88d 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/PressureMode.java +++ b/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/PressureMode.java @@ -4,6 +4,7 @@ import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; import com.isu.gaswellwatch.vo.command.Command; import com.isu.gaswellwatch.vo.command.Timing; import com.isu.gaswellwatch.vo.command.knpcv1.ChangeRunMode; +import jakarta.validation.constraints.NotBlank; import lombok.Builder; import lombok.Getter; import lombok.Setter; @@ -62,21 +63,25 @@ public class PressureMode extends ChangeRunMode implements Timing { * 最大开井时长 */ @Builder.Default + @NotBlank(message = "最大开井时长不能为空") private String maxOpenWell = "00:00:00"; /** * 最小开井时长 */ @Builder.Default + @NotBlank(message = "最小开井时长不能为空") private String minOpenWell = "00:00:00"; /** * 最大关井时长 */ @Builder.Default + @NotBlank(message = "最大关井时长不能为空") private String maxCloseWell = "00:00:00"; /** * 最小关井时长 */ @Builder.Default + @NotBlank(message = "最小关井时长不能为空") private String minCloseWell = "00:00:00"; /** * 开井压力保护使能 diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/TimePressureMode.java b/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/TimePressureMode.java index b4d7392..59b58c8 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/TimePressureMode.java +++ b/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/TimePressureMode.java @@ -4,6 +4,7 @@ import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; import com.isu.gaswellwatch.vo.command.Command; import com.isu.gaswellwatch.vo.command.Timing; import com.isu.gaswellwatch.vo.command.knpcv1.ChangeRunMode; +import jakarta.validation.constraints.NotBlank; import lombok.Builder; import lombok.Getter; import lombok.Setter; @@ -51,6 +52,7 @@ public class TimePressureMode extends ChangeRunMode implements Timing { * 时压模式开井时长 */ @Builder.Default + @NotBlank(message = "开井时长不能为空") private String tpOpenTiming = "00:00:00"; /** * 时压模式关井源 @@ -73,6 +75,7 @@ public class TimePressureMode extends ChangeRunMode implements Timing { * 时压模式关井时长 */ @Builder.Default + @NotBlank(message = "关井时长不能为空") private String tpCloseTiming = "00:00:00"; /** * 时压模式压力稳定时长:秒,[0-120] diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/TimerMode.java b/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/TimerMode.java index 694b65c..24d5b6d 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/TimerMode.java +++ b/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/TimerMode.java @@ -4,6 +4,7 @@ import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; import com.isu.gaswellwatch.vo.command.Command; import com.isu.gaswellwatch.vo.command.Timing; import com.isu.gaswellwatch.vo.command.knpcv1.ChangeRunMode; +import jakarta.validation.constraints.NotNull; import lombok.Builder; import lombok.Getter; import lombok.Setter; @@ -52,24 +53,26 @@ public class TimerMode extends ChangeRunMode implements Timing { * 定时器1开井时间 */ @Builder.Default + @NotNull(message = "定时器1开井时间不能为空") private LocalTime timer1Open = LocalTime.MIN; /** * 定时器1关井时间 */ @Builder.Default + @NotNull(message = "定时器1关井时间不能为空") private LocalTime timer1Close = LocalTime.MIN; - /** * 定时器2开井时间 */ @Builder.Default + @NotNull(message = "定时器2开井时间不能为空") private LocalTime timer2Open = LocalTime.MIN; /** * 定时器2关井时间 */ @Builder.Default + @NotNull(message = "定时器2关井时间不能为空") private LocalTime timer2Close = LocalTime.MIN; - /** * 定时器3开井时间 */ @@ -80,7 +83,6 @@ public class TimerMode extends ChangeRunMode implements Timing { */ @Builder.Default private LocalTime timer3Close = LocalTime.MIN; - /** * 定时器4开井时间 */ diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/TimingMode.java b/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/TimingMode.java index a2c91e4..c336ef4 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/TimingMode.java +++ b/src/main/java/com/isu/gaswellwatch/vo/command/knpcv1/mode/TimingMode.java @@ -4,6 +4,7 @@ import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; import com.isu.gaswellwatch.vo.command.Command; import com.isu.gaswellwatch.vo.command.Timing; import com.isu.gaswellwatch.vo.command.knpcv1.ChangeRunMode; +import jakarta.validation.constraints.NotBlank; import lombok.Builder; import lombok.Getter; import lombok.Setter; @@ -30,16 +31,19 @@ public class TimingMode extends ChangeRunMode implements Timing { * 计时器开井时长。[0-999]:[0-59]:[0-59] */ @Builder.Default + @NotBlank(message = "开井时长不能为空") private String timingOpen = "00:00:00"; /** * 计时器关井时长。[0-999]:[0-59]:[0-59] */ @Builder.Default + @NotBlank(message = "关井时长不能为空") private String timingClose = "00:00:00"; /** * 计时器延时时长。[0-999]:[0-59]:[0-59] */ @Builder.Default + @NotBlank(message = "延时时长不能为空") private String timingCelay = "00:00:00"; public TimingMode() { diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/scss/TurnOff.java b/src/main/java/com/isu/gaswellwatch/vo/command/scss/TurnOff.java new file mode 100644 index 0000000..db392a8 --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/vo/command/scss/TurnOff.java @@ -0,0 +1,28 @@ +package com.isu.gaswellwatch.vo.command.scss; + +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/27 22:40 + */ +public class TurnOff extends Command { + + @Serial + private static final long serialVersionUID = 5520601184417717931L; + + public TurnOff() { + this.setCode("SCSS.TURN_OFF_THE_WELL"); + } + + @Override + protected Collection builderModbusCommand() { + return List.of(ModbusCommandDto.builder().command("010500010000").length(16).build()); + } + +} diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/scss/TurnOn.java b/src/main/java/com/isu/gaswellwatch/vo/command/scss/TurnOn.java new file mode 100644 index 0000000..ddb49ad --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/vo/command/scss/TurnOn.java @@ -0,0 +1,28 @@ +package com.isu.gaswellwatch.vo.command.scss; + +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/27 22:57 + */ +public class TurnOn extends Command { + + @Serial + private static final long serialVersionUID = 7288866205502636187L; + + public TurnOn() { + this.setCode("SCSS.TURN_ON_THE_WELL"); + } + + @Override + protected Collection builderModbusCommand() { + return List.of(ModbusCommandDto.builder().command("01050001FF00").length(16).build()); + } + +} From a48c60bcdb7caa21e46addedcaae6bca4124f09d Mon Sep 17 00:00:00 2001 From: wangshilong Date: Thu, 28 Nov 2024 00:56:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=20=E6=B7=BB=E5=8A=A0=E5=9B=9B=E5=B7=9D?= =?UTF-8?q?=E5=8F=8C=E6=99=9F=E6=8E=A7=E5=88=B6=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../isu/gaswellwatch/vo/command/Command.java | 23 ++- .../vo/command/etc/PlungerTimer.java | 6 +- .../vo/command/etc/SensorDelay.java | 6 +- .../vo/command/scss/ControlMode.java | 176 ++++++++++++++++++ .../vo/command/scss/PlungerLogicMode.java | 161 ++++++++++++++++ .../vo/command/scss/SimpleLogicMode.java | 119 ++++++++++++ .../vo/command/scss/SystemInfo.java | 77 ++++++++ 7 files changed, 564 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/isu/gaswellwatch/vo/command/scss/ControlMode.java create mode 100644 src/main/java/com/isu/gaswellwatch/vo/command/scss/PlungerLogicMode.java create mode 100644 src/main/java/com/isu/gaswellwatch/vo/command/scss/SimpleLogicMode.java create mode 100644 src/main/java/com/isu/gaswellwatch/vo/command/scss/SystemInfo.java 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 b08dedf..9dce5c1 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/command/Command.java +++ b/src/main/java/com/isu/gaswellwatch/vo/command/Command.java @@ -3,7 +3,13 @@ package com.isu.gaswellwatch.vo.command; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; +import com.isu.gaswellwatch.vo.command.etc.PlungerTimer; +import com.isu.gaswellwatch.vo.command.etc.SensorDelay; import com.isu.gaswellwatch.vo.command.knpcv1.mode.*; +import com.isu.gaswellwatch.vo.command.scss.ControlMode; +import com.isu.gaswellwatch.vo.command.scss.PlungerLogicMode; +import com.isu.gaswellwatch.vo.command.scss.SimpleLogicMode; +import com.isu.gaswellwatch.vo.command.scss.SystemInfo; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; @@ -31,6 +37,12 @@ import java.util.Objects; @JsonSubTypes.Type(value = PlungerMode.class, name = Command.KNPCV1_RUN_PLUNGER), @JsonSubTypes.Type(value = PressureMode.class, name = Command.KNPCV1_RUN_PRESSURE), @JsonSubTypes.Type(value = TimePressureMode.class, name = Command.KNPCV1_RUN_TIME_PRESSURE), + @JsonSubTypes.Type(value = SensorDelay.class, name = Command.ETC_SENSOR_DELAY), + @JsonSubTypes.Type(value = PlungerTimer.class, name = Command.ETC_PLUNGER_TIMER), + @JsonSubTypes.Type(value = SystemInfo.class, name = Command.SCSS_SYSTEM_INFO), + @JsonSubTypes.Type(value = ControlMode.class, name = Command.SCSS_CONTROL_MODE), + @JsonSubTypes.Type(value = SimpleLogicMode.class, name = Command.SCSS_SIMPLE_LOGIC_MODE), + @JsonSubTypes.Type(value = PlungerLogicMode.class, name = Command.SCSS_PLUNGER_LOGIC_MODE), @JsonSubTypes.Type(value = com.isu.gaswellwatch.vo.command.etc.TurnOn.class, name = Command.ETC_TURN_ON_THE_WELL), @JsonSubTypes.Type(value = com.isu.gaswellwatch.vo.command.etc.TurnOff.class, name = Command.ETC_TURN_OFF_THE_WELL), @JsonSubTypes.Type(value = com.isu.gaswellwatch.vo.command.scss.TurnOn.class, name = Command.SCSS_TURN_ON_THE_WELL), @@ -62,10 +74,15 @@ public abstract class Command implements Serializable { /* 点表类型:KNPCV1 end */ /* 点表类型:SCSS start */ + /* 系统基本信息 */ + public static final String SCSS_SYSTEM_INFO = "SCSS.SYSTEM_INFO"; /* 开关井 */ public static final String SCSS_TURN_ON_THE_WELL = "SCSS.TURN_ON_THE_WELL"; public static final String SCSS_TURN_OFF_THE_WELL = "SCSS.TURN_OFF_THE_WELL"; - /* 运行模式*/ + /* 模式指令 */ + public static final String SCSS_CONTROL_MODE = "SCSS.CONTROL_MODE"; + public static final String SCSS_SIMPLE_LOGIC_MODE = "SCSS.SIMPLE_LOGIC_MODE"; + public static final String SCSS_PLUNGER_LOGIC_MODE = "SCSS.PLUNGER_LOGIC_MODE"; /* 点表类型:SCSS end */ @@ -73,7 +90,9 @@ public abstract class Command implements Serializable { /* 开关井 */ public static final String ETC_TURN_ON_THE_WELL = "ETC.TURN_ON_THE_WELL"; public static final String ETC_TURN_OFF_THE_WELL = "ETC.TURN_OFF_THE_WELL"; - /* 运行模式*/ + /* 模式指令*/ + public static final String ETC_SENSOR_DELAY = "ETC.SENSOR_DELAY"; + public static final String ETC_PLUNGER_TIMER = "ETC.PLUNGER_TIMER"; /* 点表类型:ETC end */ diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/etc/PlungerTimer.java b/src/main/java/com/isu/gaswellwatch/vo/command/etc/PlungerTimer.java index 9a34080..b0d5cb3 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/command/etc/PlungerTimer.java +++ b/src/main/java/com/isu/gaswellwatch/vo/command/etc/PlungerTimer.java @@ -14,7 +14,7 @@ import java.util.Collection; import java.util.List; /** - * @author 王仕龙 + * @author 王仕龙 * 2024/11/27 22:56 */ @Getter @@ -31,6 +31,10 @@ public class PlungerTimer extends Command implements Timing { @NotBlank(message = "柱塞上升时间不能为空") private String plungerRiseTime; + public PlungerTimer() { + this.setCode("ETC.PLUNGER_TIMER"); + } + @Override public boolean validate() { return super.validate() && StringUtils.isNotBlank(this.plungerRiseTime); diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/etc/SensorDelay.java b/src/main/java/com/isu/gaswellwatch/vo/command/etc/SensorDelay.java index fb58ad4..619d210 100644 --- a/src/main/java/com/isu/gaswellwatch/vo/command/etc/SensorDelay.java +++ b/src/main/java/com/isu/gaswellwatch/vo/command/etc/SensorDelay.java @@ -14,7 +14,7 @@ import java.util.Collection; import java.util.List; /** - * @author 王仕龙 + * @author 王仕龙 * 2024/11/27 23:04 */ @Getter @@ -40,6 +40,10 @@ public class SensorDelay extends Command implements Timing { @NotBlank(message = "续流时间不能为空") private String afterFlowTime; + public SensorDelay() { + this.setCode("ETC.SENSOR_DELAY"); + } + @Override public boolean validate() { return super.validate() diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/scss/ControlMode.java b/src/main/java/com/isu/gaswellwatch/vo/command/scss/ControlMode.java new file mode 100644 index 0000000..48858f1 --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/vo/command/scss/ControlMode.java @@ -0,0 +1,176 @@ +package com.isu.gaswellwatch.vo.command.scss; + +import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; +import com.isu.gaswellwatch.vo.command.Command; +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 builderModbusCommand() { + StringBuilder command = new StringBuilder(250); + // 地址码 功能码 起始地址 连续长度 连续字长 + // 01 10 0032 0036 6C + command.append("0110003200366C"); + command.append(StringUtils.leftPad(Integer.toHexString(this.ctlModel), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.minPressure), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.maxPressure), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.pressureMinVoltage), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.pressureMaxVoltage), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.oilMin), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.oliMax), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.oilMinVoltage), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.oilMaxVoltage), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.inputPressureMinValue), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.inputPressureMaxValue), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.inputVoltageMinValue), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.inputVoltageMaxValue), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.flowRateMinValue), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.flowRateMaxValue), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.flowVoltageMinValue), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.flowVoltageMaxValue), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.continuousSamplingIntervalDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.sensorSignalEffectiveLevel), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.pressureCompensationPolarityFlag), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.pressureCompensationValueSetting), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.oilPressureCompensationPolarityFlag), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.oilPressureCompensationValueSetting), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.inputPressureCompensationPolarityFlag), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.inputPressureCompensationValueSetting), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.flowCompensationPolarityFlag), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.flowCompensationValueSetting), 8, "0")); + return List.of(ModbusCommandDto.builder().command(command.toString()).length(16).build()); + } +} diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/scss/PlungerLogicMode.java b/src/main/java/com/isu/gaswellwatch/vo/command/scss/PlungerLogicMode.java new file mode 100644 index 0000000..b1d3e66 --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/vo/command/scss/PlungerLogicMode.java @@ -0,0 +1,161 @@ +package com.isu.gaswellwatch.vo.command.scss; + +import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; +import com.isu.gaswellwatch.vo.command.Command; +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 builderModbusCommand() { + StringBuilder command = new StringBuilder(130); + // 地址码 功能码 起始地址 连续长度 连续字长 + // 01 10 00C8 0030 60 + command.append("011000C8003060"); + command.append(StringUtils.leftPad(Integer.toHexString(this.plungerRiseDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.continuosFlowDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.wellCloseTimeDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.wellCloseTimeNotReachedDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.wellCloseNotReachedCountValue), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.plungerDelayDurationRepeat), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.targetTimeTimestamp), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.targetTimeRangeValue), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.continuosFlowIncreaseDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.continuosFlowDecreaseDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.wellCloseIncreaseDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.wellCloseDecreaseDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.minWellCloseTimeDuration2), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.maxWellCloseTimeDuration2), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.minContinuosFlowTimeDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.maxContinuosFlowTimeDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.minWellOpenTimeDuration2), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.maxWellOpenTimeDuration2), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.wellOpenPressureValueAtOpen), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.wellOpenOilPressureValueAtOpen), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.wellOpenLoadFactorPresetsAtOpen), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.wellClosePressureValueAtClose), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.wellCloseOilPressureValueAtClose), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.wellCloseFlowValueAtClose), 8, "0")); + return List.of(ModbusCommandDto.builder().command(command.toString()).length(16).build()); + } +} diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/scss/SimpleLogicMode.java b/src/main/java/com/isu/gaswellwatch/vo/command/scss/SimpleLogicMode.java new file mode 100644 index 0000000..81b0ce3 --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/vo/command/scss/SimpleLogicMode.java @@ -0,0 +1,119 @@ +package com.isu.gaswellwatch.vo.command.scss; + +import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; +import com.isu.gaswellwatch.vo.command.Command; +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 builderModbusCommand() { + StringBuilder command = new StringBuilder(130); + // 地址码 功能码 起始地址 连续长度 连续字长 + // 01 10 0096 0020 40 + command.append("01100096002040"); + 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.wellOpenOilPressureValue), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.wellOpenLoadFactorPresets), 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.wellCloseOilPressureValue), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.wellCloseFlowValue), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.inWellOpenTimeDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.axWellOpenTimeDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.inWellCloseTimeDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.axWellCloseTimeDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.ressureStabilizationDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.lowStabilizationDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.loadFactorStabilizationDuration), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.plungerDelayDuration), 8, "0")); + return List.of(ModbusCommandDto.builder().command(command.toString()).length(16).build()); + } +} diff --git a/src/main/java/com/isu/gaswellwatch/vo/command/scss/SystemInfo.java b/src/main/java/com/isu/gaswellwatch/vo/command/scss/SystemInfo.java new file mode 100644 index 0000000..fc084ca --- /dev/null +++ b/src/main/java/com/isu/gaswellwatch/vo/command/scss/SystemInfo.java @@ -0,0 +1,77 @@ +package com.isu.gaswellwatch.vo.command.scss; + +import com.isu.gaswellwatch.dto.modbus.ModbusCommandDto; +import com.isu.gaswellwatch.vo.command.Command; +import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.SuperBuilder; +import org.apache.commons.lang3.StringUtils; + +import java.io.Serial; +import java.time.LocalDateTime; +import java.time.temporal.ChronoField; +import java.util.Collection; +import java.util.List; +import java.util.Objects; + +/** + * @author 王仕龙 + * 2024/11/27 23:53 + */ +@Getter +@Setter +@SuperBuilder +public class SystemInfo extends Command { + + @Serial + private static final long serialVersionUID = -4927792179148968016L; + + /** + * 日期时间, yyyy-MM-dd HH:mm:ss.SSS + */ + @NotNull(message = "系统时间不能为空") + private LocalDateTime dataTime; + /** + * 显示延时 + */ + private int showDelay = 0; + /** + * 开井采样间隔 + */ + private int openWellSamplingInterval = 0; + /** + * 关井采样间隔 + */ + private int closeWellSamplingInterval = 0; + + public SystemInfo() { + this.setCode("SCSS.SYSTEM_INFO"); + } + + @Override + public boolean validate() { + return super.validate() && Objects.isNull(this.dataTime); + } + + @Override + protected Collection builderModbusCommand() { + StringBuilder command = new StringBuilder(100); + // 0014*2->hex + // 地址码 功能码 起始地址 连续长度 连续字长 + // 01 10 0000 0014 28 + command.append("01100000001428"); + command.append(StringUtils.leftPad(Integer.toHexString(this.dataTime.getYear() - 2000), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.dataTime.getMonthValue()), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.dataTime.getDayOfMonth()), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.dataTime.getHour()), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.dataTime.getMinute()), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.dataTime.getSecond()), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.dataTime.get(ChronoField.MILLI_OF_SECOND)), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.showDelay), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.openWellSamplingInterval), 8, "0")); + command.append(StringUtils.leftPad(Integer.toHexString(this.closeWellSamplingInterval), 8, "0")); + return List.of(ModbusCommandDto.builder().command(command.toString()).length(16).build()); + } + +}