1078-添加查询指定终端参数

This commit is contained in:
648540858
2024-04-15 00:31:11 +08:00
parent 205e529660
commit 570307669e
7 changed files with 165 additions and 7 deletions

View File

@@ -1,8 +1,12 @@
package com.genersoft.iot.vmp.jt1078.bean.common;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface ConfigAttribute {
int id();
byte id();
String description();
}

View File

@@ -17,6 +17,8 @@ public class JT1078Template {
private final Random random = new Random();
private static final String H8104 = "8104";
private static final String H8106 = "8106";
private static final String H9101 = "9101";
private static final String H9102 = "9102";
private static final String H9201 = "9201";
@@ -32,6 +34,7 @@ public class JT1078Template {
private static final String H9306 = "9306";
private static final String H0001 = "0001";
private static final String H0104 = "0104";
private static final String H1205 = "1205";
/**
@@ -255,6 +258,23 @@ public class JT1078Template {
return SessionManager.INSTANCE.request(cmd, timeOut);
}
/**
* 查询终端参数
*
* @param devId 设备号
*/
public String getDeviceConfig(String devId, J8106 j8106, Integer timeOut) {
Cmd cmd = new Cmd.Builder()
.setDevId(devId)
.setPackageNo(randomInt())
.setMsgId(H8106)
.setRespId(H0104)
.setRs(j8106)
.build();
return SessionManager.INSTANCE.request(cmd, timeOut);
}
private Long randomInt() {
return (long) random.nextInt(1000) + 1;
}

View File

@@ -1,10 +1,9 @@
package com.genersoft.iot.vmp.jt1078.config;
package com.genersoft.iot.vmp.jt1078.controller;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.conf.security.JwtUtils;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
import com.genersoft.iot.vmp.jt1078.bean.JTDeviceConfig;
import com.genersoft.iot.vmp.jt1078.proc.request.J1205;
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
@@ -25,11 +24,8 @@ import org.springframework.web.context.request.async.DeferredResult;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.ParseException;
import java.util.List;
@@ -315,5 +311,14 @@ public class JT1078Controller {
service.wiper(deviceId, channelId, command);
}
@Operation(summary = "查询终端参数", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
@GetMapping("/config")
public void config(String deviceId, String[] params){
logger.info("[1078-查询终端参数] deviceId{}", deviceId);
service.config(deviceId, params, null);
}
}

View File

@@ -0,0 +1,49 @@
package com.genersoft.iot.vmp.jt1078.proc.request;
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
import com.genersoft.iot.vmp.jt1078.proc.Header;
import com.genersoft.iot.vmp.jt1078.proc.response.J8001;
import com.genersoft.iot.vmp.jt1078.proc.response.Rs;
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
import com.genersoft.iot.vmp.jt1078.session.Session;
import io.netty.buffer.ByteBuf;
import org.springframework.context.ApplicationEvent;
import java.nio.charset.Charset;
/**
* 查询终端参数应答
*
*/
@MsgId(id = "0104")
public class J0104 extends Re {
Integer respNo;
Integer paramLength;
@Override
protected Rs decode0(ByteBuf buf, Header header, Session session) {
respNo = buf.readUnsignedShort();
paramLength = (int)buf.readUnsignedByte();
System.out.println(respNo);
System.out.println(paramLength);
return null;
}
@Override
protected Rs handler(Header header, Session session, Ijt1078Service service) {
J8001 j8001 = new J8001();
j8001.setRespNo(header.getSn());
j8001.setRespId(header.getMsgId());
j8001.setResult(J8001.SUCCESS);
return j8001;
}
@Override
public ApplicationEvent getEvent() {
return null;
}
}

View File

@@ -0,0 +1,42 @@
package com.genersoft.iot.vmp.jt1078.proc.response;
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;
import java.util.Arrays;
/**
* 查询指定终端参数
*/
@MsgId(id = "8106")
public class J8106 extends Rs {
private byte[] params;
@Override
public ByteBuf encode() {
ByteBuf buffer = Unpooled.buffer();
buffer.writeByte(params.length);
for (int param : params) {
buffer.writeByte(param);
}
return buffer;
}
public byte[] getParams() {
return params;
}
public void setParams(byte[] params) {
this.params = params;
}
@Override
public String toString() {
return "J8106{" +
"params=" + Arrays.toString(params) +
'}';
}
}

View File

@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.jt1078.service;
import com.genersoft.iot.vmp.common.GeneralCallback;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
import com.genersoft.iot.vmp.jt1078.bean.JTDeviceConfig;
import com.genersoft.iot.vmp.jt1078.proc.request.J1205;
import com.github.pagehelper.PageInfo;
@@ -40,4 +41,6 @@ public interface Ijt1078Service {
void supplementaryLight(String deviceId, String channelId, String command);
void wiper(String deviceId, String channelId, String command);
void config(String deviceId, String[] params, GeneralCallback<StreamInfo> callback);
}

View File

@@ -8,6 +8,8 @@ import com.genersoft.iot.vmp.common.VideoManagerConstants;
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
import com.genersoft.iot.vmp.jt1078.bean.JTDeviceConfig;
import com.genersoft.iot.vmp.jt1078.bean.common.ConfigAttribute;
import com.genersoft.iot.vmp.jt1078.cmd.JT1078Template;
import com.genersoft.iot.vmp.jt1078.dao.JTDeviceMapper;
import com.genersoft.iot.vmp.jt1078.event.CallbackManager;
@@ -35,6 +37,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -487,4 +494,32 @@ public class jt1078ServiceImpl implements Ijt1078Service {
}
jt1078Template.ptzWiper(deviceId, j9304, 6);
}
@Override
public void config(String deviceId, String[] params, GeneralCallback<StreamInfo> callback) {
if (deviceId == null) {
return;
}
if (params == null || params.length == 0) {
return;
}
byte[] paramBytes = new byte[params.length];
for (int i = 0; i < params.length; i++) {
try {
Field field = JTDeviceConfig.class.getDeclaredField(params[i]);
if (field.isAnnotationPresent(ConfigAttribute.class) ) {
ConfigAttribute configAttribute = field.getAnnotation(ConfigAttribute.class);
byte id = configAttribute.id();
String description = configAttribute.description();
System.out.println(description + ": " + id);
paramBytes[i] = configAttribute.id();
}
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
}
J8106 j8106 = new J8106();
j8106.setParams(paramBytes);
jt1078Template.getDeviceConfig(deviceId, j8106, 6);
}
}