1078-车辆控制

This commit is contained in:
648540858
2024-05-02 07:29:00 +08:00
parent c946b97514
commit a5bfe5049d
6 changed files with 145 additions and 0 deletions

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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<Integer> 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);
}
}
}

View File

@@ -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;
}
}

View File

@@ -68,4 +68,5 @@ public interface Ijt1078Service {
int setPhoneBook(String deviceId, int type, List<JTPhoneBookContact> phoneBookContactList);
JTPositionBaseInfo controlDoor(String deviceId, Boolean open);
}

View File

@@ -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);
}
}