1078-临时位置跟踪控制+位置信息查询
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.genersoft.iot.vmp.jt1078.cmd;
|
||||
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDeviceAttribute;
|
||||
import com.genersoft.iot.vmp.jt1078.proc.entity.Cmd;
|
||||
import com.genersoft.iot.vmp.jt1078.proc.response.*;
|
||||
import com.genersoft.iot.vmp.jt1078.session.SessionManager;
|
||||
@@ -23,6 +22,8 @@ public class JT1078Template {
|
||||
private static final String H8105 = "8105";
|
||||
private static final String H8106 = "8106";
|
||||
private static final String H8107 = "8107";
|
||||
private static final String H8201 = "8201";
|
||||
private static final String H8202 = "8202";
|
||||
private static final String H9101 = "9101";
|
||||
private static final String H9102 = "9102";
|
||||
private static final String H9201 = "9201";
|
||||
@@ -40,6 +41,7 @@ public class JT1078Template {
|
||||
private static final String H0001 = "0001";
|
||||
private static final String H0104 = "0104";
|
||||
private static final String H0107 = "0107";
|
||||
private static final String H0201 = "0201";
|
||||
private static final String H1205 = "1205";
|
||||
|
||||
/**
|
||||
@@ -318,6 +320,9 @@ public class JT1078Template {
|
||||
return (long) random.nextInt(1000) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备控制
|
||||
*/
|
||||
public Object deviceControl(String devId, J8105 j8105, int timeOut) {
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
@@ -329,6 +334,9 @@ public class JT1078Template {
|
||||
return SessionManager.INSTANCE.request(cmd, timeOut);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询终端属性
|
||||
*/
|
||||
public Object deviceAttribute(String devId, J8107 j8107, int timeOut) {
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
@@ -339,4 +347,29 @@ public class JT1078Template {
|
||||
.build();
|
||||
return SessionManager.INSTANCE.request(cmd, timeOut);
|
||||
}
|
||||
|
||||
/**
|
||||
* 位置信息查询
|
||||
*/
|
||||
public Object queryPositionInfo(String devId, J8201 j8201, int timeOut) {
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
.setPackageNo(randomInt())
|
||||
.setMsgId(H8201)
|
||||
.setRespId(H0201)
|
||||
.setRs(j8201)
|
||||
.build();
|
||||
return SessionManager.INSTANCE.request(cmd, timeOut);
|
||||
}
|
||||
|
||||
public Object tempPositionTrackingControl(String devId, J8202 j8202, int timeOut) {
|
||||
Cmd cmd = new Cmd.Builder()
|
||||
.setDevId(devId)
|
||||
.setPackageNo(randomInt())
|
||||
.setMsgId(H8202)
|
||||
.setRespId(H0001)
|
||||
.setRs(j8202)
|
||||
.build();
|
||||
return SessionManager.INSTANCE.request(cmd, timeOut);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package com.genersoft.iot.vmp.jt1078.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDeviceAttribute;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDeviceConfig;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDeviceConnectionControl;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.*;
|
||||
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;
|
||||
@@ -324,7 +320,7 @@ public class JT1078Controller {
|
||||
}
|
||||
|
||||
@Operation(summary = "设置终端参数", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备国标编号", required = true)
|
||||
@Parameter(name = "deviceId", description = "设备编号", required = true)
|
||||
@Parameter(name = "config", description = "终端参数", required = true)
|
||||
@PostMapping("/set-config")
|
||||
public void setConfig(@RequestBody SetConfigParam config){
|
||||
@@ -343,7 +339,7 @@ public class JT1078Controller {
|
||||
}
|
||||
|
||||
@Operation(summary = "终端控制-复位", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "control", description = "终端控制参数", required = true)
|
||||
@Parameter(name = "deviceId", description = "设备编号", required = true)
|
||||
@PostMapping("/control/reset")
|
||||
public void resetControl(String deviceId){
|
||||
|
||||
@@ -352,7 +348,7 @@ public class JT1078Controller {
|
||||
}
|
||||
|
||||
@Operation(summary = "终端控制-恢复出厂设置", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "control", description = "终端控制参数", required = true)
|
||||
@Parameter(name = "deviceId", description = "设备编号", required = true)
|
||||
@PostMapping("/control/factory-reset")
|
||||
public void factoryResetControl(String deviceId){
|
||||
|
||||
@@ -361,7 +357,7 @@ public class JT1078Controller {
|
||||
}
|
||||
|
||||
@Operation(summary = "查询终端属性", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "control", description = "终端控制参数", required = true)
|
||||
@Parameter(name = "deviceId", description = "设备编号", required = true)
|
||||
@GetMapping("/attribute")
|
||||
public JTDeviceAttribute attribute(String deviceId){
|
||||
|
||||
@@ -369,5 +365,25 @@ public class JT1078Controller {
|
||||
return service.attribute(deviceId);
|
||||
}
|
||||
|
||||
@Operation(summary = "查询位置信息", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备编号", required = true)
|
||||
@GetMapping("/position-info")
|
||||
public JTPositionBaseInfo queryPositionInfo(String deviceId){
|
||||
|
||||
logger.info("[1078-查询位置信息] deviceId: {}", deviceId);
|
||||
return service.queryPositionInfo(deviceId);
|
||||
}
|
||||
|
||||
@Operation(summary = "临时位置跟踪控制", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@Parameter(name = "deviceId", description = "设备编号", required = true)
|
||||
@Parameter(name = "timeInterval", description = "时间间隔,单位为秒,时间间隔为0 时停止跟踪,停止跟踪无需带后继字段", required = true)
|
||||
@Parameter(name = "validityPeriod", description = "位置跟踪有效期, 单位为秒,终端在接收到位置跟踪控制消息后,在有效期截止时间之前依据消息中的时间间隔发送位置汇报", required = true)
|
||||
@GetMapping("/control/temp-position-tracking")
|
||||
public void tempPositionTrackingControl(String deviceId, Integer timeInterval, Long validityPeriod){
|
||||
|
||||
logger.info("[1078-临时位置跟踪控制] deviceId: {}, 时间间隔 {}秒, 位置跟踪有效期 {}秒", deviceId, timeInterval, validityPeriod);
|
||||
service.tempPositionTrackingControl(deviceId, timeInterval, validityPeriod);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,8 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 实时消息上报
|
||||
* 位置信息汇报
|
||||
*
|
||||
* @author QingtaiJiang
|
||||
* @date 2023/4/27 18:06
|
||||
* @email qingtaij@163.com
|
||||
*/
|
||||
@MsgId(id = "0200")
|
||||
public class J0200 extends Re {
|
||||
@@ -32,15 +29,10 @@ public class J0200 extends Re {
|
||||
|
||||
@Override
|
||||
protected Rs decode0(ByteBuf buf, Header header, Session session) {
|
||||
|
||||
|
||||
|
||||
positionInfo = new JTPositionBaseInfo();
|
||||
int alarmSignInt = buf.readInt();
|
||||
positionInfo.setAlarmSign(new JTAlarmSign(alarmSignInt));
|
||||
positionInfo.setAlarmSign(new JTAlarmSign(buf.readInt()));
|
||||
|
||||
int statusInt = buf.readInt();
|
||||
positionInfo.setStatus(new JTStatus(statusInt));
|
||||
positionInfo.setStatus(new JTStatus(buf.readInt()));
|
||||
|
||||
positionInfo.setLatitude(buf.readInt() * 0.000001D);
|
||||
positionInfo.setLongitude(buf.readInt() * 0.000001D);
|
||||
@@ -121,6 +113,7 @@ public class J0200 extends Re {
|
||||
if (deviceInDb == null) {
|
||||
j8001.setResult(J8001.FAIL);
|
||||
}else {
|
||||
// TODO 优化为发送异步事件,定时读取队列写入数据库
|
||||
deviceInDb.setLongitude(positionInfo.getLongitude());
|
||||
deviceInDb.setLatitude(positionInfo.getLatitude());
|
||||
service.updateDevice(deviceInDb);
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.genersoft.iot.vmp.jt1078.proc.request;
|
||||
|
||||
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.*;
|
||||
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 com.genersoft.iot.vmp.jt1078.session.SessionManager;
|
||||
import com.genersoft.iot.vmp.jt1078.util.BCDUtil;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* 位置信息查询应答
|
||||
*
|
||||
* @author QingtaiJiang
|
||||
* @date 2023/4/27 18:06
|
||||
* @email qingtaij@163.com
|
||||
*/
|
||||
@MsgId(id = "0201")
|
||||
public class J0201 extends Re {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(J0100.class);
|
||||
private JTPositionBaseInfo positionInfo;
|
||||
|
||||
@Override
|
||||
protected Rs decode0(ByteBuf buf, Header header, Session session) {
|
||||
|
||||
int respNo = buf.readUnsignedShort();
|
||||
|
||||
positionInfo = new JTPositionBaseInfo();
|
||||
positionInfo.setAlarmSign(new JTAlarmSign(buf.readInt()));
|
||||
positionInfo.setStatus(new JTStatus(buf.readInt()));
|
||||
positionInfo.setLatitude(buf.readInt() * 0.000001D);
|
||||
positionInfo.setLongitude(buf.readInt() * 0.000001D);
|
||||
positionInfo.setAltitude(buf.readUnsignedShort());
|
||||
positionInfo.setSpeed(buf.readUnsignedShort());
|
||||
positionInfo.setDirection(buf.readUnsignedShort());
|
||||
byte[] timeBytes = new byte[6];
|
||||
buf.readBytes(timeBytes);
|
||||
positionInfo.setTime(BCDUtil.transform(timeBytes));
|
||||
|
||||
// 读取附加信息
|
||||
// JTPositionAdditionalInfo positionAdditionalInfo = new JTPositionAdditionalInfo();
|
||||
// Map<Integer, byte[]> additionalMsg = new HashMap<>();
|
||||
// getAdditionalMsg(buf, positionAdditionalInfo);
|
||||
log.info("[JT-位置信息查询应答]: {}", positionInfo.toString());
|
||||
SessionManager.INSTANCE.response(header.getTerminalId(), "0201", (long) respNo, positionInfo);
|
||||
return null;
|
||||
}
|
||||
|
||||
private void getAdditionalMsg(ByteBuf buf, JTPositionAdditionalInfo additionalInfo) {
|
||||
|
||||
if (buf.isReadable()) {
|
||||
int msgId = buf.readUnsignedByte();
|
||||
int length = buf.readUnsignedByte();
|
||||
ByteBuf byteBuf = buf.readBytes(length);
|
||||
switch (msgId) {
|
||||
case 1:
|
||||
// 里程
|
||||
long mileage = byteBuf.readUnsignedInt();
|
||||
log.info("[JT-位置汇报]: 里程: {} km", (double)mileage/10);
|
||||
break;
|
||||
case 2:
|
||||
// 油量
|
||||
int oil = byteBuf.readUnsignedShort();
|
||||
log.info("[JT-位置汇报]: 油量: {} L", (double)oil/10);
|
||||
break;
|
||||
case 3:
|
||||
// 速度
|
||||
int speed = byteBuf.readUnsignedShort();
|
||||
log.info("[JT-位置汇报]: 速度: {} km/h", (double)speed/10);
|
||||
break;
|
||||
case 4:
|
||||
// 需要人工确认报警事件的 ID
|
||||
int alarmId = byteBuf.readUnsignedShort();
|
||||
log.info("[JT-位置汇报]: 需要人工确认报警事件的 ID: {}", alarmId);
|
||||
break;
|
||||
case 5:
|
||||
byte[] tirePressureBytes = new byte[30];
|
||||
// 胎压
|
||||
byteBuf.readBytes(tirePressureBytes);
|
||||
log.info("[JT-位置汇报]: 胎压 {}", tirePressureBytes);
|
||||
break;
|
||||
case 6:
|
||||
// 车厢温度
|
||||
short carriageTemperature = byteBuf.readShort();
|
||||
log.info("[JT-位置汇报]: 车厢温度 {}摄氏度", carriageTemperature);
|
||||
break;
|
||||
case 11:
|
||||
// 超速报警
|
||||
short positionType = byteBuf.readUnsignedByte();
|
||||
long positionId = byteBuf.readUnsignedInt();
|
||||
log.info("[JT-位置汇报]: 超速报警, 位置类型: {}, 区域或路段 ID: {}", positionType, positionId);
|
||||
break;
|
||||
default:
|
||||
log.info("[JT-位置汇报]: 附加消息ID: {}, 消息长度: {}", msgId, length);
|
||||
break;
|
||||
|
||||
}
|
||||
getAdditionalMsg(buf, additionalInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Rs handler(Header header, Session session, Ijt1078Service service) {
|
||||
JTDevice deviceInDb = service.getDevice(header.getTerminalId());
|
||||
J8001 j8001 = new J8001();
|
||||
j8001.setRespNo(header.getSn());
|
||||
j8001.setRespId(header.getMsgId());
|
||||
if (deviceInDb == null) {
|
||||
j8001.setResult(J8001.FAIL);
|
||||
}else {
|
||||
// TODO 优化为发送异步事件,定时读取队列写入数据库
|
||||
deviceInDb.setLongitude(positionInfo.getLongitude());
|
||||
deviceInDb.setLatitude(positionInfo.getLatitude());
|
||||
service.updateDevice(deviceInDb);
|
||||
j8001.setResult(J8001.SUCCESS);
|
||||
}
|
||||
return j8001;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationEvent getEvent() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* 位置信息查询
|
||||
*/
|
||||
@MsgId(id = "8201")
|
||||
public class J8201 extends Rs {
|
||||
|
||||
@Override
|
||||
public ByteBuf encode() {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* 临时位置跟踪控制
|
||||
*/
|
||||
@MsgId(id = "8202")
|
||||
public class J8202 extends Rs {
|
||||
|
||||
/**
|
||||
* 时间间隔,单位为秒,时间间隔为0 时停止跟踪,停止跟踪无需带后继字段
|
||||
*/
|
||||
private int timeInterval;
|
||||
|
||||
/**
|
||||
* 位置跟踪有效期, 单位为秒,终端在接收到位置跟踪控制消息后,在有效期截止时间之前依据消息中的时间间隔发送位置汇报
|
||||
*/
|
||||
private long validityPeriod;
|
||||
|
||||
@Override
|
||||
public ByteBuf encode() {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
buffer.writeShort((short)(timeInterval & 0xffff));
|
||||
if (timeInterval > 0) {
|
||||
buffer.writeInt((int) (validityPeriod & 0xffffffffL));
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public int getTimeInterval() {
|
||||
return timeInterval;
|
||||
}
|
||||
|
||||
public void setTimeInterval(int timeInterval) {
|
||||
this.timeInterval = timeInterval;
|
||||
}
|
||||
|
||||
public long getValidityPeriod() {
|
||||
return validityPeriod;
|
||||
}
|
||||
|
||||
public void setValidityPeriod(long validityPeriod) {
|
||||
this.validityPeriod = validityPeriod;
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,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.JTDeviceAttribute;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDeviceConfig;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDeviceConnectionControl;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.*;
|
||||
import com.genersoft.iot.vmp.jt1078.proc.request.J1205;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
@@ -55,4 +52,8 @@ public interface Ijt1078Service {
|
||||
void factoryResetControl(String deviceId);
|
||||
|
||||
JTDeviceAttribute attribute(String deviceId);
|
||||
|
||||
JTPositionBaseInfo queryPositionInfo(String deviceId);
|
||||
|
||||
void tempPositionTrackingControl(String deviceId, Integer timeInterval, Long validityPeriod);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
package com.genersoft.iot.vmp.jt1078.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.GeneralCallback;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
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.JTDeviceAttribute;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDeviceConfig;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDeviceConnectionControl;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.*;
|
||||
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;
|
||||
@@ -25,8 +21,6 @@ import com.genersoft.iot.vmp.media.event.hook.HookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.event.hook.HookType;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam;
|
||||
import com.genersoft.iot.vmp.service.IMediaService;
|
||||
import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
|
||||
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
||||
@@ -39,11 +33,7 @@ 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;
|
||||
@@ -555,4 +545,18 @@ public class jt1078ServiceImpl implements Ijt1078Service {
|
||||
J8107 j8107 = new J8107();
|
||||
return (JTDeviceAttribute)jt1078Template.deviceAttribute(deviceId, j8107, 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JTPositionBaseInfo queryPositionInfo(String deviceId) {
|
||||
J8201 j8201 = new J8201();
|
||||
return (JTPositionBaseInfo)jt1078Template.queryPositionInfo(deviceId, j8201, 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tempPositionTrackingControl(String deviceId, Integer timeInterval, Long validityPeriod) {
|
||||
J8202 j8202 = new J8202();
|
||||
j8202.setTimeInterval(timeInterval);
|
||||
j8202.setValidityPeriod(validityPeriod);
|
||||
jt1078Template.tempPositionTrackingControl(deviceId, j8202, 20);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user