From a5bfe5049d71af4556a4bd390353b5eb011ade2b Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Thu, 2 May 2024 07:29:00 +0800 Subject: [PATCH] =?UTF-8?q?1078-=E8=BD=A6=E8=BE=86=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/jt1078/bean/JTVehicleControl.java | 36 ++++++++++ .../iot/vmp/jt1078/cmd/JT1078Template.java | 13 ++++ .../jt1078/controller/JT1078Controller.java | 16 +++++ .../iot/vmp/jt1078/proc/response/J8500.java | 70 +++++++++++++++++++ .../vmp/jt1078/service/Ijt1078Service.java | 1 + .../service/impl/jt1078ServiceImpl.java | 9 +++ 6 files changed, 145 insertions(+) create mode 100644 src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTVehicleControl.java create mode 100644 src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J8500.java diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTVehicleControl.java b/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTVehicleControl.java new file mode 100644 index 000000000..f98e778a5 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/bean/JTVehicleControl.java @@ -0,0 +1,36 @@ +package com.genersoft.iot.vmp.jt1078.bean; + +import com.genersoft.iot.vmp.jt1078.bean.common.ConfigAttribute; + +import java.util.Objects; + +/** + * 车辆控制类型 + */ +public class JTVehicleControl { + + private int length; + + private void setLength(Object value) { + if (Objects.isNull(value)) { + length--; + }else { + length ++; + } + } + public int getLength() { + return length; + } + + @ConfigAttribute(id = 0X0001, type="Byte", description = "车门, 0:车门锁闭 1:车门开启") + private Integer controlCarDoor; + + public Integer getControlCarDoor() { + return controlCarDoor; + } + + public void setControlCarDoor(Integer controlCarDoor) { + this.controlCarDoor = controlCarDoor; + setLength(controlCarDoor); + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/cmd/JT1078Template.java b/src/main/java/com/genersoft/iot/vmp/jt1078/cmd/JT1078Template.java index d856e09cb..cf4e3656a 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/cmd/JT1078Template.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/cmd/JT1078Template.java @@ -29,6 +29,7 @@ public class JT1078Template { private static final String H8300 = "8300"; private static final String H8400 = "8400"; private static final String H8401 = "8401"; + private static final String H8500 = "8500"; private static final String H9101 = "9101"; private static final String H9102 = "9102"; private static final String H9201 = "9201"; @@ -47,6 +48,7 @@ public class JT1078Template { private static final String H0104 = "0104"; private static final String H0107 = "0107"; private static final String H0201 = "0201"; + private static final String H0500 = "0500"; private static final String H1205 = "1205"; /** @@ -432,4 +434,15 @@ public class JT1078Template { .build(); return SessionManager.INSTANCE.request(cmd, timeOut); } + + public Object vehicleControl(String devId, J8500 j8500, int timeOut) { + Cmd cmd = new Cmd.Builder() + .setDevId(devId) + .setPackageNo(randomInt()) + .setMsgId(H8500) + .setRespId(H0500) + .setRs(j8500) + .build(); + return SessionManager.INSTANCE.request(cmd, timeOut); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/controller/JT1078Controller.java b/src/main/java/com/genersoft/iot/vmp/jt1078/controller/JT1078Controller.java index d5c74c6a0..bb6610be3 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/controller/JT1078Controller.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/controller/JT1078Controller.java @@ -468,5 +468,21 @@ public class JT1078Controller { } } + @Operation(summary = "1078-车门控制", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "deviceId", description = "设备编号", required = true) + @Parameter(name = "open", description = "开启车门", required = true) + @GetMapping("/control/door") + public WVPResult controlDoor(String deviceId, Boolean open){ + + logger.info("[1078-车门控制] deviceId: {}, open: {},", deviceId, open); + JTPositionBaseInfo positionBaseInfo = service.controlDoor(deviceId, open); + + if (open == !positionBaseInfo.getStatus().isDoorLocking()) { + return WVPResult.success(null); + }else { + return WVPResult.fail(ErrorCode.ERROR100); + } + } + } diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J8500.java b/src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J8500.java new file mode 100644 index 000000000..9283ad6e1 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/proc/response/J8500.java @@ -0,0 +1,70 @@ +package com.genersoft.iot.vmp.jt1078.proc.response; + +import com.genersoft.iot.vmp.jt1078.annotation.MsgId; +import com.genersoft.iot.vmp.jt1078.bean.JTPhoneBookContact; +import com.genersoft.iot.vmp.jt1078.bean.JTVehicleControl; +import com.genersoft.iot.vmp.jt1078.bean.common.ConfigAttribute; +import com.genersoft.iot.vmp.jt1078.bean.config.JTDeviceSubConfig; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; + +import java.lang.reflect.Field; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 车辆控制 + */ +@MsgId(id = "8500") +public class J8500 extends Rs { + + /** + * 控制类型 + */ + private JTVehicleControl vehicleControl; + + + @Override + public ByteBuf encode() { + ByteBuf buffer = Unpooled.buffer(); + buffer.writeShort((short)(vehicleControl.getLength() & 0xffff)); + + Field[] fields = vehicleControl.getClass().getDeclaredFields(); + for (Field field : fields) { + field.setAccessible(true); + Object value = null; + try { + value = field.get(vehicleControl); + if (value == null) { + continue; + } + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + + ConfigAttribute configAttribute = field.getAnnotation(ConfigAttribute.class); + if (configAttribute == null) { + continue; + } + buffer.writeShort((short)(configAttribute.id() & 0xffff)); + switch (configAttribute.type()) { + case "Byte": + field.setAccessible(true); + buffer.writeByte((int)value); + continue; + } + } + + return buffer; + } + + public JTVehicleControl getVehicleControl() { + return vehicleControl; + } + + public void setVehicleControl(JTVehicleControl vehicleControl) { + this.vehicleControl = vehicleControl; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/service/Ijt1078Service.java b/src/main/java/com/genersoft/iot/vmp/jt1078/service/Ijt1078Service.java index dc7e2320b..2894ee0fd 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/service/Ijt1078Service.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/service/Ijt1078Service.java @@ -68,4 +68,5 @@ public interface Ijt1078Service { int setPhoneBook(String deviceId, int type, List phoneBookContactList); + JTPositionBaseInfo controlDoor(String deviceId, Boolean open); } diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java index 553af8b2c..4086ca308 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java @@ -600,4 +600,13 @@ public class jt1078ServiceImpl implements Ijt1078Service { } return (int)jt1078Template.setPhoneBook(deviceId, j8401, 6); } + + @Override + public JTPositionBaseInfo controlDoor(String deviceId, Boolean open) { + J8500 j8500 = new J8500(); + JTVehicleControl jtVehicleControl = new JTVehicleControl(); + jtVehicleControl.setControlCarDoor(open?1:0); + j8500.setVehicleControl(jtVehicleControl); + return (JTPositionBaseInfo)jt1078Template.vehicleControl(deviceId, j8500, 20); + } }