设备信息

This commit is contained in:
shikong 2023-09-13 14:50:28 +08:00
parent 90b716e404
commit 69b554c679
4 changed files with 117 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import cn.skcks.docking.gb28181.core.sip.message.processor.message.request.dto.M
import cn.skcks.docking.gb28181.core.sip.message.sender.SipMessageSender;
import cn.skcks.docking.gb28181.core.sip.utils.SipUtil;
import cn.skcks.docking.gb28181.mocking.core.sip.message.processor.message.request.catalog.CatalogCmdProcessor;
import cn.skcks.docking.gb28181.mocking.core.sip.message.processor.message.request.deviceinfo.DeviceInfoRequestProcessor;
import cn.skcks.docking.gb28181.mocking.core.sip.message.subscribe.SipSubscribe;
import cn.skcks.docking.gb28181.mocking.core.sip.response.SipResponseBuilder;
import gov.nist.javax.sip.message.SIPRequest;
@ -35,6 +36,7 @@ public class MessageRequestProcessor implements MessageProcessor {
private final SipMessageSender sender;
private final CatalogCmdProcessor catalogCmdProcessor;
private final DeviceInfoRequestProcessor deviceInfoRequestProcessor;
private Response okResponse(SIPRequest request){
return SipResponseBuilder.response(request, Response.OK, "OK");
@ -60,6 +62,9 @@ public class MessageRequestProcessor implements MessageProcessor {
if(messageDto.getCmdType().equalsIgnoreCase(CmdType.CATALOG)) {
sender.send(senderIp, okResponse(request));
catalogCmdProcessor.process(request, content);
} else if(messageDto.getCmdType().equalsIgnoreCase("DeviceInfo")){
sender.send(senderIp, okResponse(request));
deviceInfoRequestProcessor.process(request, content);
} else {
Response response = SipResponseBuilder.response(request, Response.NOT_IMPLEMENTED, ResponseStatus.NOT_IMPLEMENTED.getMessage());
sender.send(senderIp, response);

View File

@ -0,0 +1,48 @@
package cn.skcks.docking.gb28181.mocking.core.sip.message.processor.message.request.deviceinfo;
import cn.skcks.docking.gb28181.common.xml.XmlUtils;
import cn.skcks.docking.gb28181.mocking.core.sip.message.processor.message.request.deviceinfo.dto.DeviceInfoRequestDTO;
import cn.skcks.docking.gb28181.mocking.core.sip.message.processor.message.request.deviceinfo.dto.DeviceInfoResponseDTO;
import cn.skcks.docking.gb28181.mocking.core.sip.request.SipRequestBuilder;
import cn.skcks.docking.gb28181.mocking.core.sip.sender.SipSender;
import cn.skcks.docking.gb28181.mocking.orm.mybatis.dynamic.model.MockingDevice;
import cn.skcks.docking.gb28181.mocking.service.device.DeviceService;
import gov.nist.javax.sip.message.SIPRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.sip.header.CallIdHeader;
import javax.sip.header.FromHeader;
@Slf4j
@Component
@RequiredArgsConstructor
public class DeviceInfoRequestProcessor {
private final SipSender sender;
private final DeviceService deviceService;
public void process(SIPRequest request, byte[] content){
DeviceInfoRequestDTO deviceInfoRequestDTO = XmlUtils.parse(content, DeviceInfoRequestDTO.class);
String sn = deviceInfoRequestDTO.getSn();
String deviceId = deviceInfoRequestDTO.getDeviceId();
MockingDevice mockingDevice = deviceService.getDeviceByGbDeviceId(deviceId).orElse(null);
if(mockingDevice == null){
return;
}
DeviceInfoResponseDTO deviceInfoResponseDTO = DeviceInfoResponseDTO.builder()
.sn(sn)
.deviceId(deviceId)
.deviceName(mockingDevice.getName())
.channel(1)
.manufacturer("GB28181-Docking-Platform")
.build();
FromHeader fromHeader = request.getFromHeader();
sender.sendRequest((provider, ip, port)->{
CallIdHeader callIdHeader = provider.getNewCallId();
return SipRequestBuilder.createMessageRequest(mockingDevice,
ip, port, 1, XmlUtils.toXml(deviceInfoResponseDTO), fromHeader.getTag(), callIdHeader);
});
}
}

View File

@ -0,0 +1,16 @@
package cn.skcks.docking.gb28181.mocking.core.sip.message.processor.message.request.deviceinfo.dto;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import lombok.Data;
@JacksonXmlRootElement(localName = "Query")
@Data
public class DeviceInfoRequestDTO {
private String cmdType;
@JacksonXmlProperty(localName = "SN")
private String sn;
@JacksonXmlProperty(localName = "DeviceID")
private String deviceId;
}

View File

@ -0,0 +1,48 @@
package cn.skcks.docking.gb28181.mocking.core.sip.message.processor.message.request.deviceinfo.dto;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@JacksonXmlRootElement(localName = "Response")
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class DeviceInfoResponseDTO {
@Builder.Default
private String cmdType = "DeviceInfo";
@JacksonXmlProperty(localName = "SN")
private String sn;
@JacksonXmlProperty(localName = "DeviceID")
private String deviceId;
private String deviceName;
@Builder.Default
private String Result = "OK";
/**
* 设备生产商
*/
private String manufacturer;
/**
* 设备型号(可选)
*/
private String model;
/**
* 设备固件版本(可选)
*/
private String firmware;
/**
* 视频输入通道数(可选)
*/
private Integer channel;
}