repo
stringclasses
1k values
file_url
stringlengths
96
373
file_path
stringlengths
11
294
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
6 values
commit_sha
stringclasses
1k values
retrieved_at
stringdate
2026-01-04 14:45:56
2026-01-04 18:30:23
truncated
bool
2 classes
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/AlarmQueryMessageClientHandler.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/AlarmQueryMessageClientHandler.java
package io.github.lunasaw.gbproxy.client.transmit.request.message.handler.query; import javax.sip.RequestEvent; import io.github.lunasaw.gbproxy.client.transmit.cmd.ClientCommandSender; import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract; import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.gb28181.common.entity.notify.DeviceAlarmNotify; import io.github.lunasaw.gb28181.common.entity.query.DeviceAlarmQuery; import org.springframework.stereotype.Component; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageRequestHandler; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; /** * 设备告警查询消息处理器 * 负责处理设备告警查询请求 * * @author luna * @date 2023/10/19 */ @Component @Slf4j @Getter @Setter public class AlarmQueryMessageClientHandler extends MessageClientHandlerAbstract { public static final String CMD_TYPE = "Alarm"; private String cmdType = CMD_TYPE; public AlarmQueryMessageClientHandler(MessageRequestHandler messageRequestHandler) { super(messageRequestHandler); } @Override public String getRootType() { return "Query"; } @Override public void handForEvt(RequestEvent event) { try { DeviceSession deviceSession = getDeviceSession(event); String userId = deviceSession.getUserId(); String sipId = deviceSession.getSipId(); log.debug("处理设备告警查询: userId={}, sipId={}", userId, sipId); // 解析告警查询请求 DeviceAlarmQuery deviceAlarmQuery = parseXml(DeviceAlarmQuery.class); String sn = deviceAlarmQuery.getSn(); // 调用业务处理器获取设备告警信息 DeviceAlarmNotify deviceAlarmNotify = messageRequestHandler.getDeviceAlarmNotify(deviceAlarmQuery); deviceAlarmNotify.setSn(sn); // 发送响应 ClientCommandSender.sendAlarmCommand(deviceSession.getFromDevice(), deviceSession.getToDevice(), deviceAlarmNotify); } catch (Exception e) { log.error("处理设备告警查询时发生异常: event = {}", event, e); } } @Override public String getCmdType() { return cmdType; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/PresetQueryMessageClientHandler.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/PresetQueryMessageClientHandler.java
package io.github.lunasaw.gbproxy.client.transmit.request.message.handler.query; import io.github.lunasaw.gb28181.common.entity.query.PresetQuery; import io.github.lunasaw.gb28181.common.entity.response.PresetQueryResponse; import io.github.lunasaw.gbproxy.client.transmit.cmd.ClientCommandSender; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageRequestHandler; import io.github.lunasaw.sip.common.entity.DeviceSession; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import javax.sip.RequestEvent; /** * 设备预置位查询消息处理器 * 负责处理设备预置位查询请求 * * @author luna */ @Component @Slf4j @Getter @Setter public class PresetQueryMessageClientHandler extends MessageClientHandlerAbstract { public static final String CMD_TYPE = "PresetQuery"; private String cmdType = CMD_TYPE; public PresetQueryMessageClientHandler(MessageRequestHandler messageRequestHandler) { super(messageRequestHandler); } @Override public String getRootType() { return "Query"; } @Override public void handForEvt(RequestEvent event) { try { DeviceSession deviceSession = getDeviceSession(event); String userId = deviceSession.getUserId(); String sipId = deviceSession.getSipId(); log.debug("处理设备预置位查询: userId={}, sipId={}", userId, sipId); // 解析查询请求 PresetQuery presetQuery = parseXml(PresetQuery.class); String sn = presetQuery.getSn(); // 调用业务处理器获取设备预置位信息(需在MessageRequestHandler中扩展方法) PresetQueryResponse presetQueryResponse = messageRequestHandler.getPresetQueryResponse(userId); presetQueryResponse.setSn(sn); // 发送响应 ClientCommandSender.sendPresetQueryResponse(deviceSession.getFromDevice(), deviceSession.getToDevice(), presetQueryResponse); } catch (Exception e) { log.error("处理设备预置位查询时发生异常: event = {}", event, e); } } @Override public String getCmdType() { return cmdType; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/ConfigDownloadMessageHandler.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/ConfigDownloadMessageHandler.java
package io.github.lunasaw.gbproxy.client.transmit.request.message.handler.query; import io.github.lunasaw.gb28181.common.entity.query.DeviceConfigDownload; import io.github.lunasaw.gb28181.common.entity.response.DeviceConfigResponse; import io.github.lunasaw.gbproxy.client.transmit.cmd.ClientCommandSender; import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageRequestHandler; import io.github.lunasaw.sip.common.entity.DeviceSession; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import javax.sip.RequestEvent; /** * 设备配置下载消息处理器 * 负责处理设备配置下载请求 * * @author luna * @date 2023/10/19 */ @Component @Slf4j @Getter @Setter public class ConfigDownloadMessageHandler extends MessageClientHandlerAbstract { public static final String CMD_TYPE = "ConfigDownload"; private String cmdType = CMD_TYPE; public ConfigDownloadMessageHandler(MessageRequestHandler messageRequestHandler) { super(messageRequestHandler); } @Override public String getRootType() { return "Query"; } @Override public void handForEvt(RequestEvent event) { try { DeviceSession deviceSession = getDeviceSession(event); String userId = deviceSession.getUserId(); String sipId = deviceSession.getSipId(); log.debug("处理设备配置下载: userId={}, sipId={}", userId, sipId); // 解析配置下载请求 DeviceConfigDownload deviceConfigDownload = parseXml(DeviceConfigDownload.class); // 调用业务处理器获取设备配置 DeviceConfigResponse deviceConfigResponse = messageRequestHandler.getDeviceConfigResponse(deviceConfigDownload); deviceConfigResponse.setSn(deviceConfigDownload.getSn()); // 发送响应 ClientCommandSender.sendDeviceConfigCommand(deviceSession.getFromDevice(), deviceSession.getToDevice(), deviceConfigResponse); } catch (Exception e) { log.error("处理设备配置下载时发生异常: event = {}", event, e); } } @Override public String getCmdType() { return cmdType; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/DeviceMobileQueryMessageClientHandler.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/DeviceMobileQueryMessageClientHandler.java
package io.github.lunasaw.gbproxy.client.transmit.request.message.handler.query; import io.github.lunasaw.gb28181.common.entity.notify.MobilePositionNotify; import io.github.lunasaw.gb28181.common.entity.query.MobilePositionQuery; import io.github.lunasaw.gbproxy.client.transmit.cmd.ClientCommandSender; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageRequestHandler; import io.github.lunasaw.sip.common.entity.DeviceSession; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import javax.sip.RequestEvent; /** * 设备移动位置查询消息处理器 * * @author luna * @date 2023/10/19 */ @Component @Slf4j @Getter @Setter public class DeviceMobileQueryMessageClientHandler extends MessageClientHandlerAbstract { public static final String CMD_TYPE = "MobilePosition"; private String cmdType = CMD_TYPE; public DeviceMobileQueryMessageClientHandler(MessageRequestHandler messageRequestHandler) { super(messageRequestHandler); } @Override public String getRootType() { return "Query"; } @Override public void handForEvt(RequestEvent event) { try { DeviceSession deviceSession = getDeviceSession(event); MobilePositionQuery deviceMobileQuery = parseXml(MobilePositionQuery.class); // 直接调用业务方法获取完整应答 MobilePositionNotify mobilePositionNotify = messageRequestHandler.getMobilePositionNotify(deviceMobileQuery); // 发送应答 ClientCommandSender.sendMobilePositionNotify(deviceSession.getFromDevice(), deviceSession.getToDevice(), mobilePositionNotify); } catch (Exception e) { log.error("处理设备预置位查询时发生异常: event = {}", event, e); } } @Override public String getCmdType() { return cmdType; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/RecordInfoQueryMessageClientHandler.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/RecordInfoQueryMessageClientHandler.java
package io.github.lunasaw.gbproxy.client.transmit.request.message.handler.query; import io.github.lunasaw.gb28181.common.entity.query.DeviceRecordQuery; import io.github.lunasaw.gb28181.common.entity.response.DeviceRecord; import io.github.lunasaw.gbproxy.client.transmit.cmd.ClientCommandSender; import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageRequestHandler; import io.github.lunasaw.sip.common.entity.DeviceSession; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import javax.sip.RequestEvent; /** * 设备录像信息查询消息处理器 * 负责处理设备录像信息查询请求 * * @author luna * @date 2023/10/19 */ @Component @Slf4j @Getter @Setter public class RecordInfoQueryMessageClientHandler extends MessageClientHandlerAbstract { public static final String CMD_TYPE = "RecordInfo"; private String cmdType = CMD_TYPE; public RecordInfoQueryMessageClientHandler(MessageRequestHandler messageRequestHandler) { super(messageRequestHandler); } @Override public String getRootType() { return "Query"; } @Override public void handForEvt(RequestEvent event) { try { DeviceSession deviceSession = getDeviceSession(event); String userId = deviceSession.getUserId(); String sipId = deviceSession.getSipId(); log.debug("处理设备录像信息查询: userId={}, sipId={}", userId, sipId); // 解析查询请求 DeviceRecordQuery deviceRecordQuery = parseXml(DeviceRecordQuery.class); String sn = deviceRecordQuery.getSn(); // 调用业务处理器获取设备录像信息 DeviceRecord deviceRecord = messageRequestHandler.getDeviceRecord(deviceRecordQuery); deviceRecord.setSn(sn); // 发送响应 log.debug("发送设备录像信息响应: userId={}, sipId={}, sn={}", userId, sipId, sn); ClientCommandSender.sendDeviceRecordCommand(deviceSession.getFromDevice(), deviceSession.getToDevice(), deviceRecord); } catch (Exception e) { log.error("处理设备录像信息查询时发生异常: event = {}", event, e); } } @Override public String getCmdType() { return cmdType; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/DeviceStatusQueryMessageClientHandler.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/DeviceStatusQueryMessageClientHandler.java
package io.github.lunasaw.gbproxy.client.transmit.request.message.handler.query; import io.github.lunasaw.gb28181.common.entity.query.DeviceQuery; import io.github.lunasaw.gb28181.common.entity.response.DeviceStatus; import io.github.lunasaw.gbproxy.client.transmit.cmd.ClientCommandSender; import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageRequestHandler; import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.sip.common.entity.FromDevice; import io.github.lunasaw.sip.common.service.ClientDeviceSupplier; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.sip.RequestEvent; /** * 设备状态查询消息处理器 * 负责处理设备状态查询请求 * * @author luna * @date 2023/10/19 */ @Component @Slf4j @Getter @Setter public class DeviceStatusQueryMessageClientHandler extends MessageClientHandlerAbstract { public static final String CMD_TYPE = "DeviceStatus"; private String cmdType = CMD_TYPE; @Autowired private ClientDeviceSupplier clientDeviceSupplier; public DeviceStatusQueryMessageClientHandler(MessageRequestHandler messageRequestHandler) { super(messageRequestHandler); } @Override public String getRootType() { return "Query"; } @Override public void handForEvt(RequestEvent event) { try { DeviceSession deviceSession = getDeviceSession(event); String userId = deviceSession.getUserId(); String sipId = deviceSession.getSipId(); log.info("处理设备状态查询: userId={}, sipId={}", userId, sipId); // 解析查询请求 DeviceQuery deviceQuery = parseXml(DeviceQuery.class); String sn = deviceQuery.getSn(); // 调用业务处理器获取设备状态 DeviceStatus deviceStatus = messageRequestHandler.getDeviceStatus(userId); deviceStatus.setSn(sn); // 发送响应 FromDevice clientFromDevice = deviceSession.getFromDevice(); if (clientFromDevice == null) { log.warn("客户端设备信息未找到,无法发送设备状态响应: userId={}, sipId={}", userId, sipId); return; } ClientCommandSender.sendDeviceStatusCommand(deviceSession.getFromDevice(), deviceSession.getToDevice(), deviceStatus); } catch (Exception e) { log.error("处理设备状态查询时发生异常: event = {}", event, e); } } @Override public String getCmdType() { return cmdType; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/DeviceInfoQueryMessageClientHandler.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/DeviceInfoQueryMessageClientHandler.java
package io.github.lunasaw.gbproxy.client.transmit.request.message.handler.query; import javax.sip.RequestEvent; import io.github.lunasaw.gbproxy.client.transmit.cmd.ClientCommandSender; import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract; import lombok.Getter; import lombok.Setter; import org.springframework.stereotype.Component; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageRequestHandler; import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.gb28181.common.entity.query.DeviceQuery; import io.github.lunasaw.gb28181.common.entity.response.DeviceInfo; import lombok.extern.slf4j.Slf4j; /** * 设备信息查询消息处理器 * 负责处理设备信息查询请求 * * @author weidian */ @Component @Slf4j @Getter @Setter public class DeviceInfoQueryMessageClientHandler extends MessageClientHandlerAbstract { public static final String CMD_TYPE = "DeviceInfo"; private String cmdType = CMD_TYPE; public DeviceInfoQueryMessageClientHandler(MessageRequestHandler messageRequestHandler) { super(messageRequestHandler); } @Override public String getRootType() { return "Query"; } @Override public void handForEvt(RequestEvent event) { try { DeviceSession deviceSession = getDeviceSession(event); String userId = deviceSession.getUserId(); String sipId = deviceSession.getSipId(); log.debug("处理设备信息查询: userId={}, sipId={}", userId, sipId); // 解析查询请求 DeviceQuery deviceQuery = parseXml(DeviceQuery.class); String sn = deviceQuery.getSn(); // 调用业务处理器获取设备信息 DeviceInfo deviceInfo = messageRequestHandler.getDeviceInfo(userId); deviceInfo.setSn(sn); // 发送响应(使用全局ThreadLocal中的Call-ID) ClientCommandSender.sendDeviceInfoCommand(deviceSession.getFromDevice(), deviceSession.getToDevice(), deviceInfo); } catch (Exception e) { log.error("处理设备信息查询时发生异常: event = {}", event, e); } } @Override public String getCmdType() { return cmdType; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/ConfigDownloadQueryMessageClientHandler.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/query/ConfigDownloadQueryMessageClientHandler.java
package io.github.lunasaw.gbproxy.client.transmit.request.message.handler.query; import io.github.lunasaw.gb28181.common.entity.query.ConfigDownloadQuery; import io.github.lunasaw.gb28181.common.entity.response.ConfigDownloadResponse; import io.github.lunasaw.gbproxy.client.transmit.cmd.ClientCommandSender; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageRequestHandler; import io.github.lunasaw.sip.common.entity.DeviceSession; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import javax.sip.RequestEvent; /** * 设备配置查询消息处理器 * 负责处理设备配置查询请求 * * @author luna */ @Component @Slf4j @Getter @Setter public class ConfigDownloadQueryMessageClientHandler extends MessageClientHandlerAbstract { public static final String CMD_TYPE = "ConfigDownload"; private String cmdType = CMD_TYPE; public ConfigDownloadQueryMessageClientHandler(MessageRequestHandler messageRequestHandler) { super(messageRequestHandler); } @Override public String getRootType() { return "Query"; } @Override public void handForEvt(RequestEvent event) { try { DeviceSession deviceSession = getDeviceSession(event); String userId = deviceSession.getUserId(); String sipId = deviceSession.getSipId(); log.debug("处理设备配置查询: userId={}, sipId={}", userId, sipId); // 解析查询请求 ConfigDownloadQuery configDownloadQuery = parseXml(ConfigDownloadQuery.class); String sn = configDownloadQuery.getSn(); // 调用业务处理器获取设备配置(需在MessageRequestHandler中扩展方法) ConfigDownloadResponse configDownloadResponse = messageRequestHandler.getConfigDownloadResponse(userId, configDownloadQuery.getConfigType()); configDownloadResponse.setSn(sn); // 发送响应 ClientCommandSender.sendConfigDownloadResponse(deviceSession.getFromDevice(), deviceSession.getToDevice(), configDownloadResponse); } catch (Exception e) { log.error("处理设备配置查询时发生异常: event = {}", event, e); } } @Override public String getCmdType() { return cmdType; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/notify/BroadcastNotifyMessageHandler.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/notify/BroadcastNotifyMessageHandler.java
package io.github.lunasaw.gbproxy.client.transmit.request.message.handler.notify; import javax.sip.RequestEvent; import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor; import io.github.lunasaw.sip.common.entity.DeviceSession; import io.github.lunasaw.gb28181.common.entity.notify.DeviceBroadcastNotify; import org.springframework.stereotype.Component; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageRequestHandler; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; /** * 广播通知消息处理器 * 负责处理广播通知请求 * * @author luna * @date 2023/10/19 */ @Component @Slf4j @Getter @Setter public class BroadcastNotifyMessageHandler extends MessageClientHandlerAbstract { public static final String CMD_TYPE = "Broadcast"; private String cmdType = CMD_TYPE; public BroadcastNotifyMessageHandler(MessageRequestHandler messageRequestHandler) { super(messageRequestHandler); } @Override public String getRootType() { return "Notify"; } @Override public void handForEvt(RequestEvent event) { try { DeviceSession deviceSession = getDeviceSession(event); String userId = deviceSession.getUserId(); String sipId = deviceSession.getSipId(); log.debug("处理广播通知: userId={}, sipId={}", userId, sipId); // 解析广播通知 DeviceBroadcastNotify broadcastNotify = parseXml(DeviceBroadcastNotify.class); // 调用业务处理器处理广播通知 messageRequestHandler.broadcastNotify(broadcastNotify); } catch (Exception e) { log.error("处理广播通知时发生异常: event = {}", event, e); } } @Override public String getCmdType() { return cmdType; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/control/DeviceControlMessageHandler.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/control/DeviceControlMessageHandler.java
package io.github.lunasaw.gbproxy.client.transmit.request.message.handler.control; import javax.sip.RequestEvent; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageRequestHandler; import io.github.lunasaw.gb28181.common.entity.control.*; import io.github.lunasaw.sip.common.utils.XmlUtils; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import java.util.List; import java.util.function.BiConsumer; /** * 设备控制消息处理器 * 负责处理设备控制请求 * * @author luna * @date 2023/10/19 */ @Component @Slf4j @Getter @Setter public class DeviceControlMessageHandler extends MessageClientHandlerAbstract { public static final String CMD_TYPE = "DeviceControl"; private String cmdType = CMD_TYPE; @Autowired @Lazy private DeviceControlRequestHandler deviceControlRequestHandler; public DeviceControlMessageHandler(MessageRequestHandler messageRequestHandler) { super(messageRequestHandler); } @Override public String getRootType() { return "Control"; } private static class HandlerEntry<T> { final String xmlTag; final Class<T> clazz; final BiConsumer<DeviceControlRequestHandler, T> handler; HandlerEntry(String xmlTag, Class<T> clazz, BiConsumer<DeviceControlRequestHandler, T> handler) { this.xmlTag = xmlTag; this.clazz = clazz; this.handler = handler; } } private static final List<HandlerEntry<?>> HANDLERS = List.of( new HandlerEntry<>("PTZCmd", DeviceControlPtz.class, (h, c) -> h.handlePtzCmd((DeviceControlPtz) c)), new HandlerEntry<>("TeleBoot", DeviceControlTeleBoot.class, (h, c) -> h.handleTeleBoot((DeviceControlTeleBoot) c)), new HandlerEntry<>("RecordCmd", DeviceControlRecordCmd.class, (h, c) -> h.handleRecordCmd((DeviceControlRecordCmd) c)), new HandlerEntry<>("GuardCmd", DeviceControlGuard.class, (h, c) -> h.handleGuardCmd((DeviceControlGuard) c)), new HandlerEntry<>("AlarmCmd", DeviceControlAlarm.class, (h, c) -> h.handleAlarmCmd((DeviceControlAlarm) c)), new HandlerEntry<>("IFameCmd", DeviceControlIFame.class, (h, c) -> h.handleIFameCmd((DeviceControlIFame) c)), new HandlerEntry<>("DragZoomIn", DeviceControlDragIn.class, (h, c) -> h.handleDragZoomIn((DeviceControlDragIn) c)), new HandlerEntry<>("DragZoomOut", DeviceControlDragOut.class, (h, c) -> h.handleDragZoomOut((DeviceControlDragOut) c)), new HandlerEntry<>("HomePosition", DeviceControlPosition.class, (h, c) -> h.handleHomePosition((DeviceControlPosition) c)) ); @Override public void handForEvt(RequestEvent event) { try { String xmlStr = getXmlStr(); boolean matched = false; for (HandlerEntry<?> entry : HANDLERS) { if (xmlStr.contains("<" + entry.xmlTag + ">")) { Object cmd = XmlUtils.parseObj(xmlStr, entry.clazz); //noinspection unchecked ((BiConsumer<DeviceControlRequestHandler, Object>) entry.handler).accept(deviceControlRequestHandler, cmd); matched = true; break; } } if (!matched) { log.warn("未识别的DeviceControl命令: {}", xmlStr); } } catch (Exception e) { log.error("处理设备控制请求时发生异常: event = {}", event, e); } } @Override public String getCmdType() { return cmdType; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/control/KeepaliveMessageClientHandler.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/control/KeepaliveMessageClientHandler.java
package io.github.lunasaw.gbproxy.client.transmit.request.message.handler.control; import io.github.lunasaw.gb28181.common.entity.control.KeepaliveControl; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageRequestHandler; import io.github.lunasaw.sip.common.entity.DeviceSession; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import javax.sip.RequestEvent; /** * Keepalive消息客户端处理器 * 负责处理Control类型的Keepalive命令 * * @author claude * @date 2025/01/19 */ @Component @Slf4j @Getter @Setter public class KeepaliveMessageClientHandler extends MessageClientHandlerAbstract { public static final String CMD_TYPE = "Keepalive"; private String cmdType = CMD_TYPE; public KeepaliveMessageClientHandler(MessageRequestHandler messageRequestHandler) { super(messageRequestHandler); } @Override public String getRootType() { return "Control"; } @Override public void handForEvt(RequestEvent event) { try { DeviceSession deviceSession = getDeviceSession(event); String userId = deviceSession.getUserId(); String sipId = deviceSession.getSipId(); log.debug("处理Keepalive心跳请求: userId={}, sipId={}", userId, sipId); // 解析心跳请求 KeepaliveControl keepalive = parseXml(KeepaliveControl.class); String sn = keepalive.getSn(); log.debug("收到Keepalive心跳: userId={}, sipId={}, sn={}, status={}", userId, sipId, sn, keepalive.getStatus()); // 调用业务处理器处理心跳 if (messageRequestHandler != null) { // 这里可以根据需要调用业务处理方法 log.info("处理Keepalive心跳成功: deviceId={}, status={}", keepalive.getDeviceId(), keepalive.getStatus()); } } catch (Exception e) { log.error("处理Keepalive心跳请求时发生异常: event = {}", event, e); } } @Override public String getCmdType() { return cmdType; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/control/DeviceControlRequestHandler.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/control/DeviceControlRequestHandler.java
package io.github.lunasaw.gbproxy.client.transmit.request.message.handler.control; import io.github.lunasaw.gb28181.common.entity.control.*; /** * DeviceControl控制命令业务处理器接口 * 负责处理所有DeviceControl相关的控制命令 * * @author luna */ public interface DeviceControlRequestHandler { /** * 处理云台控制命令 */ void handlePtzCmd(DeviceControlPtz ptzCmd); /** * 处理远程启动命令 */ void handleTeleBoot(DeviceControlTeleBoot teleBootCmd); /** * 处理录像控制命令 */ void handleRecordCmd(DeviceControlRecordCmd recordCmd); /** * 处理布防/撤防命令 */ void handleGuardCmd(DeviceControlGuard guardCmd); /** * 处理告警复位命令 */ void handleAlarmCmd(DeviceControlAlarm alarmCmd); /** * 处理强制关键帧命令 */ void handleIFameCmd(DeviceControlIFame iFameCmd); /** * 处理拉框放大命令 */ void handleDragZoomIn(DeviceControlDragIn dragInCmd); /** * 处理拉框缩小命令 */ void handleDragZoomOut(DeviceControlDragOut dragOutCmd); /** * 处理看守位命令 */ void handleHomePosition(DeviceControlPosition homePositionCmd); // 可扩展更多控制命令 }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/control/emums/DeviceControlType.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/message/handler/control/emums/DeviceControlType.java
package io.github.lunasaw.gbproxy.client.transmit.request.message.handler.control.emums; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import lombok.Setter; import org.apache.commons.lang3.StringUtils; import org.springframework.util.ObjectUtils; import io.github.lunasaw.gb28181.common.entity.control.*; import lombok.Getter; import lombok.SneakyThrows; /** * @author luna */ @Getter public enum DeviceControlType { /** * 云台控制 * 上下左右,预置位,扫描,辅助功能,巡航 */ PTZ("PTZCmd", "云台控制", DeviceControlPtz.class, "ptzCmdControl"), /** * 远程启动 */ TELNET_BOOT("TeleBoot", "远程启动", DeviceControlTeleBoot.class, "telnetBootControl"), /** * 录像控制 */ RECORD("RecordCmd", "录像控制", DeviceControlRecordCmd.class, "recordCmdControl"), /** * 布防撤防 */ GUARD("GuardCmd", "布防撤防", DeviceControlGuard.class, "guardCmdControl"), /** * 告警控制 */ ALARM("AlarmCmd", "告警控制", DeviceControlAlarm.class, "alarmCmdControl"), /** * 强制关键帧 */ I_FRAME("IFameCmd", "强制关键帧", DeviceControlIFame.class, "iFameCmdControl"), /** * 拉框放大 */ DRAG_ZOOM_IN("DragZoomIn", "拉框放大", DeviceControlDragIn.class, "dragZoomInControl"), /** * 拉框缩小 */ DRAG_ZOOM_OUT("DragZoomOut", "拉框缩小", DeviceControlDragOut.class, "dragZoomOutControl"), /** * 看守位 */ HOME_POSITION("HomePosition", "看守位", DeviceControlPosition.class, "HomePositionControl"); private static final Map<String, DeviceControlType> MAP = new ConcurrentHashMap<>(); static { // MAP 初始化 for (DeviceControlType deviceControlType : DeviceControlType.values()) { MAP.put(deviceControlType.getVal(), deviceControlType); } } private final String val; private final String desc; private final Class<?> clazz; @Setter private String beanName; DeviceControlType(String val, String desc, Class<?> clazz, String beanName) { this.val = val; this.desc = desc; this.clazz = clazz; this.beanName = beanName; } public static DeviceControlType getDeviceControlTypeFilter(String content) { if (ObjectUtils.isEmpty(content)) { return null; } String key = MAP.keySet().stream().filter(content::contains).findFirst().orElse(StringUtils.EMPTY); return getDeviceControlType(key); } @SneakyThrows public static DeviceControlType getDeviceControlType(String key) { if (key == null) { return null; } if (MAP.containsKey(key)) { return MAP.get(key); } return null; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/bye/DefaultClientByeProcessorClient.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/bye/DefaultClientByeProcessorClient.java
package io.github.lunasaw.gbproxy.client.transmit.request.bye; import io.github.lunasaw.gbproxy.client.transmit.response.bye.ClientByeProcessorHandler; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.stereotype.Component; /** * @author luna * @date 2023/12/29 */ @Component @ConditionalOnMissingBean(ClientByeProcessorHandler.class) public class DefaultClientByeProcessorClient implements ClientByeProcessorHandler { @Override public void closeStream(String callId) { } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/bye/ByeRequestProcessorClient.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/bye/ByeRequestProcessorClient.java
package io.github.lunasaw.gbproxy.client.transmit.request.bye; import io.github.lunasaw.gbproxy.client.transmit.response.bye.ClientByeProcessorHandler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import javax.sip.Dialog; import javax.sip.RequestEvent; import javax.sip.message.Response; import gov.nist.javax.sip.message.SIPRequest; import io.github.lunasaw.sip.common.transmit.ResponseCmd; import io.github.lunasaw.sip.common.transmit.event.request.SipRequestProcessorAbstract; import io.github.lunasaw.sip.common.utils.SipUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import lombok.Getter; import lombok.Setter; /** * 客户端BYE请求处理器 * 负责处理客户端收到的BYE请求,专注于协议层面处理 * * @author luna */ @Component("byeRequestProcessorClient") @Getter @Setter @Slf4j public class ByeRequestProcessorClient extends SipRequestProcessorAbstract { public static final String METHOD = "BYE"; private String method = METHOD; @Autowired @Lazy private ClientByeProcessorHandler clientByeProcessorHandler; /** * 收到Bye请求 处理 * * @param evt */ @Override public void process(RequestEvent evt) { try { SIPRequest request = (SIPRequest) evt.getRequest(); // 协议层面处理:解析SIP消息 String fromUserId = SipUtils.getUserIdFromFromHeader(request); String toUserId = SipUtils.getUserIdFromToHeader(request); String callId = SipUtils.getCallId(request); log.debug("收到BYE请求: from={}, to={}, callId={}", fromUserId, toUserId, callId); // 发送200 OK响应 ResponseCmd.doResponseCmd(Response.OK, evt); // 检查对话状态 Dialog dialog = evt.getDialog(); if (dialog != null) { // 调用业务处理器关闭流 clientByeProcessorHandler.closeStream(dialog.getCallId().getCallId()); } } catch (Exception e) { log.error("处理BYE请求时发生异常: evt = {}", evt, e); // 发送500错误响应 ResponseCmd.doResponseCmd(Response.SERVER_INTERNAL_ERROR, evt); } } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/bye/ByeProcessorHandler.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/bye/ByeProcessorHandler.java
package io.github.lunasaw.gbproxy.client.transmit.request.bye; /** * BYE请求业务处理器接口 * 负责处理BYE请求的业务逻辑 * * @author luna */ public interface ByeProcessorHandler { /** * 关闭流 * * @param callId 呼叫ID */ void closeStream(String callId); }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/info/InfoRequestHandler.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/info/InfoRequestHandler.java
package io.github.lunasaw.gbproxy.client.transmit.request.info; /** * INFO请求业务处理器接口 * 负责处理INFO请求的业务逻辑 * 按照项目规范,使用Handler命名 * * @author luna * @date 2023/10/18 */ public interface InfoRequestHandler { /** * 接收INFO消息 * * @param userId 用户ID * @param content INFO消息内容 */ void receiveInfo(String userId, String content); }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/info/InfoRequestProcessor.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/info/InfoRequestProcessor.java
package io.github.lunasaw.gbproxy.client.transmit.request.info; import javax.sip.RequestEvent; import javax.sip.message.Response; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import gov.nist.javax.sip.message.SIPRequest; import io.github.lunasaw.sip.common.transmit.ResponseCmd; import io.github.lunasaw.sip.common.transmit.event.request.SipRequestProcessorAbstract; import io.github.lunasaw.sip.common.utils.SipUtils; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; /** * 客户端INFO请求处理器 * 负责处理客户端收到的INFO请求,专注于协议层面处理 * 按照SIP处理器业务逻辑分离规范,只负责SIP协议层面的处理,不包含业务逻辑 * * @author luna * @date 2023/10/18 */ @Component("clientInfoRequestProcessor") @Getter @Setter @Slf4j public class InfoRequestProcessor extends SipRequestProcessorAbstract { public static final String METHOD = "INFO"; private String method = METHOD; @Autowired @Lazy private InfoRequestHandler infoRequestHandler; /** * 收到Info请求 处理 * 专注于协议层面处理:消息解析、参数提取、调用业务处理器、响应构建 * * @param evt INFO请求事件 */ @Override public void process(RequestEvent evt) { try { SIPRequest request = (SIPRequest) evt.getRequest(); // 协议层面处理:解析SIP消息 String fromUserId = SipUtils.getUserIdFromFromHeader(request); String toUserId = SipUtils.getUserIdFromToHeader(request); log.debug("收到INFO请求: from={}, to={}", fromUserId, toUserId); // 在客户端看来,收到请求时fromHeader是服务端,toHeader是客户端 String userId = toUserId; String content = new String(request.getRawContent()); // 调用业务处理器接口,不包含具体业务逻辑 infoRequestHandler.receiveInfo(userId, content); // 发送200 OK响应 ResponseCmd.doResponseCmd(Response.OK, evt); } catch (Exception e) { log.error("处理INFO请求时发生异常: evt = {}", evt, e); // 发送500错误响应 ResponseCmd.doResponseCmd(Response.SERVER_INTERNAL_ERROR, e.getMessage(), evt); } } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/info/DefaultClientInfoRequestHandler.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/transmit/request/info/DefaultClientInfoRequestHandler.java
package io.github.lunasaw.gbproxy.client.transmit.request.info; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.stereotype.Component; /** * INFO请求业务处理器默认实现 * 负责处理INFO请求的具体业务逻辑 * 业务接入方可以通过实现InfoRequestHandler接口来自定义业务逻辑 * 按照项目规范,使用Handler命名 * * @author luna * @date 2023/12/29 */ @Slf4j @Component @ConditionalOnMissingBean(InfoRequestHandler.class) public class DefaultClientInfoRequestHandler implements InfoRequestHandler { /** * 接收INFO消息 * 处理INFO请求的具体业务逻辑 * * @param userId 用户ID * @param content INFO消息内容 */ @Override public void receiveInfo(String userId, String content) { log.info("收到INFO消息: userId={}, content={}", userId, content); // 业务接入方可以在这里实现具体的业务逻辑 // 例如:处理设备控制命令、状态更新、配置变更等 } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/entity/SendRtpItem.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/entity/SendRtpItem.java
package io.github.lunasaw.gbproxy.client.entity; import lombok.Data; @Data public class SendRtpItem { /** * 推流ip */ private String ip; /** * 推流端口 */ private int port; /** * 推流标识 */ private String ssrc; /** * 平台id */ private String platformId; /** * 对应设备id */ private String deviceId; /** * 直播流的应用名 */ private String app; /** * 通道id */ private String channelId; /** * 推流状态 * 0 等待设备推流上来 * 1 等待上级平台回复ack * 2 推流中 */ private int status = 0; /** * 设备推流的streamId */ private String streamId; /** * 是否为tcp */ private boolean tcp; /** * 是否为tcp主动模式 */ private boolean tcpActive; /** * 自己推流使用的端口 */ private int localPort; /** * 使用的流媒体 */ private String mediaServerId; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/entity/InviteResponseEntity.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/entity/InviteResponseEntity.java
package io.github.lunasaw.gbproxy.client.entity; import io.github.lunasaw.gb28181.common.entity.enums.InviteSessionNameEnum; import lombok.Getter; import lombok.Setter; import java.util.Random; /** * @author luna * @date 2023/11/6 */ @Getter @Setter public class InviteResponseEntity { /** * 点播类型 */ private InviteSessionNameEnum sessionName; /** * 用户ID */ private String userId; /** * 媒体IP */ private String mediaIp; /** * 本地端口 */ private int localPort; /** * 开始时间 */ private long startTime; /** * 结束时间 */ private long endTime; /** * ssrc */ private String ssrc; public static void main(String[] args) { StringBuffer content = getAckPlayBody("userId", "mediaIp", 0, "ssrc"); System.out.println(content); } public static StringBuffer getAckPlayBackBody(String userId, String mediaIp, int localPort, long startTime, long endTime, String ssrc) { return getAckBody(InviteSessionNameEnum.PLAY_BACK, userId, mediaIp, localPort, startTime, endTime, ssrc); } public static StringBuffer getAckPlayBody(String userId, String mediaIp, int localPort, String ssrc) { return getAckBody(InviteSessionNameEnum.PLAY, userId, mediaIp, localPort, 0, 0, ssrc); } public static StringBuffer getAckBody(InviteSessionNameEnum sessionName, String userId, String mediaIp, int localPort, long startTime, long endTime, String ssrc) { StringBuffer content = new StringBuffer(200); content.append("v=0\r\n"); content.append("o=").append(userId).append(" 0 0 IN IP4 ").append(mediaIp).append("\r\n"); content.append("s=").append(sessionName.getType()).append("\r\n"); content.append("c=IN IP4 ").append(mediaIp).append("\r\n"); if (InviteSessionNameEnum.PLAY_BACK.equals(sessionName)) { content.append("t=").append(startTime).append(" ").append(endTime).append("\r\n"); } else { content.append("t=0 0\r\n"); } if (localPort == 0) { // 非严格模式端口不统一, 增加兼容性,修改为一个不为0的端口 localPort = new Random().nextInt(65535) + 1; } content.append("m=video ").append(localPort).append(" RTP/AVP 96\r\n"); content.append("a=sendonly\r\n"); content.append("a=rtpmap:96 PS/90000\r\n"); content.append("y=").append(ssrc).append("\r\n"); content.append("f=\r\n"); return content; } @Override public String toString() { return getAckBody(sessionName, userId, mediaIp, localPort, startTime, endTime, ssrc).toString(); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/eventbus/event/subscribe/CatalogEvent.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/eventbus/event/subscribe/CatalogEvent.java
package io.github.lunasaw.gbproxy.client.eventbus.event.subscribe; import org.springframework.context.ApplicationEvent; import lombok.Getter; import lombok.Setter; /** * @author luna */ @Getter @Setter public class CatalogEvent extends ApplicationEvent { public CatalogEvent(Object source) { super(source); } /** * 上线 */ public static final String ON = "ON"; /** * 离线 */ public static final String OFF = "OFF"; /** * 视频丢失 */ public static final String VIDEO_LOST = "VIDEO_LOST"; /** * 故障 */ public static final String DEFECT = "DEFECT"; /** * 增加 */ public static final String ADD = "ADD"; /** * 删除 */ public static final String DEL = "DEL"; /** * 更新 */ public static final String UPDATE = "UPDATE"; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/config/SipProxyClientAutoConfig.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/config/SipProxyClientAutoConfig.java
package io.github.lunasaw.gbproxy.client.config; import io.github.lunasaw.gbproxy.client.transmit.request.message.ClientMessageRequestProcessor; import io.github.lunasaw.gbproxy.client.transmit.request.message.MessageClientHandlerAbstract; import io.github.lunasaw.gbproxy.client.transmit.request.subscribe.SubscribeHandlerAbstract; import io.github.lunasaw.gbproxy.client.transmit.request.subscribe.SubscribeRequestProcessor; import jakarta.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeansException; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Component; import java.util.Map; /** * SIP代理客户端自动配置类 * 使用 @DependsOn 确保在所有默认处理器创建完成后再进行处理器注册 * * @author luna * @date 2023/10/16 */ @Slf4j @Component @ComponentScan(basePackages = "io.github.lunasaw.gbproxy.client") public class SipProxyClientAutoConfig implements InitializingBean, ApplicationContextAware { private ApplicationContext applicationContext; @Override public void afterPropertiesSet() { Map<String, MessageClientHandlerAbstract> clientMessageHandlerMap = applicationContext.getBeansOfType(MessageClientHandlerAbstract.class); clientMessageHandlerMap.forEach((k, v) -> ClientMessageRequestProcessor.addHandler(v)); Map<String, SubscribeHandlerAbstract> clientSubscribeHandlerMap = applicationContext.getBeansOfType(SubscribeHandlerAbstract.class); clientSubscribeHandlerMap.forEach((k, v) -> SubscribeRequestProcessor.addHandler(v)); } @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/config/SipClientProperties.java
gb28181-client/src/main/java/io/github/lunasaw/gbproxy/client/config/SipClientProperties.java
package io.github.lunasaw.gbproxy.client.config; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; /** * Voglander SIP客户端配置属性 * * @author luna * @since 2025/8/2 */ @Data @Component @ConfigurationProperties(prefix = "sip.client") public class SipClientProperties { /** * 是否启用客户端 */ private boolean enabled = false; /** * 客户端ID */ private String clientId = "34020000001320000001"; /** * 客户端名称 */ private String clientName = "GB28181-Client"; /** * 保活间隔 */ private String keepAliveInterval = "1m"; /** * 最大重试次数 */ private int maxRetries = 3; /** * 重试延迟 */ private String retryDelay = "5s"; /** * 注册过期时间(秒) */ private int registerExpires = 3600; /** * 客户端IP */ private String domain = "127.0.0.1"; /** * 客户端端口 */ private int port = 5061; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/AuxiliaryControlInstructionTest.java
gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/AuxiliaryControlInstructionTest.java
package io.github.lunasaw.gb28181.common.entity.control.instruction; import io.github.lunasaw.gb28181.common.entity.control.instruction.builder.PTZInstructionBuilder; import io.github.lunasaw.gb28181.common.entity.control.instruction.enums.AuxiliaryControlEnum; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.*; /** * 辅助开关控制指令生成和解析完整测试 * 验证所有辅助开关指令是否按照A.3.7规范正确生成 */ class AuxiliaryControlInstructionTest { @Test @DisplayName("开关开启指令测试") void testSwitchOnInstruction() { // 测试开启雨刷(开关1) PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x001) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_ON, 1) .build(); assertEquals((byte) 0x8C, instruction.getInstructionCode()); assertEquals((byte) 0x01, instruction.getData1()); // 字节5为辅助开关编号 assertEquals(0x001, instruction.getFullAddress()); assertTrue(instruction.isValid()); // 测试开启灯光控制(开关2) PTZInstructionFormat lightOnInstruction = PTZInstructionBuilder.create() .address(0x002) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_ON, 2) .build(); assertEquals((byte) 0x8C, lightOnInstruction.getInstructionCode()); assertEquals((byte) 0x02, lightOnInstruction.getData1()); assertTrue(lightOnInstruction.isValid()); // 测试最大开关编号255 PTZInstructionFormat maxSwitchInstruction = PTZInstructionBuilder.create() .address(0x003) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_ON, 255) .build(); assertEquals((byte) 0x8C, maxSwitchInstruction.getInstructionCode()); assertEquals((byte) 0xFF, maxSwitchInstruction.getData1()); assertTrue(maxSwitchInstruction.isValid()); } @Test @DisplayName("开关关闭指令测试") void testSwitchOffInstruction() { // 测试关闭雨刷(开关1) PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x001) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_OFF, 1) .build(); assertEquals((byte) 0x8D, instruction.getInstructionCode()); assertEquals((byte) 0x01, instruction.getData1()); // 字节5为辅助开关编号 assertEquals(0x001, instruction.getFullAddress()); assertTrue(instruction.isValid()); // 测试关闭加热控制(开关3) PTZInstructionFormat heatingOffInstruction = PTZInstructionBuilder.create() .address(0x004) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_OFF, 3) .build(); assertEquals((byte) 0x8D, heatingOffInstruction.getInstructionCode()); assertEquals((byte) 0x03, heatingOffInstruction.getData1()); assertTrue(heatingOffInstruction.isValid()); // 测试最小开关编号0 PTZInstructionFormat minSwitchInstruction = PTZInstructionBuilder.create() .address(0x005) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_OFF, 0) .build(); assertEquals((byte) 0x8D, minSwitchInstruction.getInstructionCode()); assertEquals((byte) 0x00, minSwitchInstruction.getData1()); assertTrue(minSwitchInstruction.isValid()); } @ParameterizedTest @DisplayName("辅助开关编号范围测试") @ValueSource(ints = {0, 1, 2, 3, 4, 5, 50, 100, 200, 255}) void testSwitchNumberRange(int switchNumber) { // 测试有效开关编号 assertTrue(AuxiliaryControlEnum.isValidSwitchNumber(switchNumber)); // 测试开关开启 PTZInstructionFormat onInstruction = PTZInstructionBuilder.create() .address(0x001) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_ON, switchNumber) .build(); assertEquals((byte) 0x8C, onInstruction.getInstructionCode()); assertEquals((byte) switchNumber, onInstruction.getData1()); assertTrue(onInstruction.isValid()); // 测试开关关闭 PTZInstructionFormat offInstruction = PTZInstructionBuilder.create() .address(0x002) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_OFF, switchNumber) .build(); assertEquals((byte) 0x8D, offInstruction.getInstructionCode()); assertEquals((byte) switchNumber, offInstruction.getData1()); assertTrue(offInstruction.isValid()); } @Test @DisplayName("辅助开关类型测试") void testAuxiliarySwitchTypes() { // 测试预定义的开关类型 assertEquals(AuxiliaryControlEnum.AuxiliarySwitchType.WIPER, AuxiliaryControlEnum.AuxiliarySwitchType.getByValue(1)); assertEquals(AuxiliaryControlEnum.AuxiliarySwitchType.LIGHT, AuxiliaryControlEnum.AuxiliarySwitchType.getByValue(2)); assertEquals(AuxiliaryControlEnum.AuxiliarySwitchType.HEATING, AuxiliaryControlEnum.AuxiliarySwitchType.getByValue(3)); assertEquals(AuxiliaryControlEnum.AuxiliarySwitchType.VENTILATION, AuxiliaryControlEnum.AuxiliarySwitchType.getByValue(4)); assertEquals(AuxiliaryControlEnum.AuxiliarySwitchType.DEFROST, AuxiliaryControlEnum.AuxiliarySwitchType.getByValue(5)); assertEquals(AuxiliaryControlEnum.AuxiliarySwitchType.CUSTOM, AuxiliaryControlEnum.AuxiliarySwitchType.getByValue(0)); // 测试未定义类型返回CUSTOM assertEquals(AuxiliaryControlEnum.AuxiliarySwitchType.CUSTOM, AuxiliaryControlEnum.AuxiliarySwitchType.getByValue(100)); assertEquals(AuxiliaryControlEnum.AuxiliarySwitchType.CUSTOM, AuxiliaryControlEnum.AuxiliarySwitchType.getByValue(-1)); // 验证开关类型描述 assertEquals("雨刷控制", AuxiliaryControlEnum.AuxiliarySwitchType.WIPER.getDescription()); assertEquals("灯光控制", AuxiliaryControlEnum.AuxiliarySwitchType.LIGHT.getDescription()); assertEquals("加热控制", AuxiliaryControlEnum.AuxiliarySwitchType.HEATING.getDescription()); assertEquals("通风控制", AuxiliaryControlEnum.AuxiliarySwitchType.VENTILATION.getDescription()); assertEquals("除霜控制", AuxiliaryControlEnum.AuxiliarySwitchType.DEFROST.getDescription()); assertEquals("自定义控制", AuxiliaryControlEnum.AuxiliarySwitchType.CUSTOM.getDescription()); } @Test @DisplayName("辅助开关指令解析测试") void testAuxiliaryInstructionParsing() { // 创建开启雨刷指令 PTZInstructionFormat originalInstruction = PTZInstructionBuilder.create() .address(0x123) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_ON, 1) .build(); // 序列化为字节数组 byte[] bytes = originalInstruction.toByteArray(); assertEquals(8, bytes.length); // 验证字节数组内容 assertEquals((byte) 0xA5, bytes[0]); // 首字节 assertEquals((byte) 0x8C, bytes[3]); // 指令码 assertEquals((byte) 0x01, bytes[4]); // 开关编号 // 从字节数组重建指令 PTZInstructionFormat parsedInstruction = PTZInstructionFormat.fromByteArray(bytes); // 验证解析结果 assertEquals(originalInstruction.getFullAddress(), parsedInstruction.getFullAddress()); assertEquals(originalInstruction.getInstructionCode(), parsedInstruction.getInstructionCode()); assertEquals(originalInstruction.getData1(), parsedInstruction.getData1()); assertTrue(parsedInstruction.isValid()); // 验证十六进制字符串解析 String hexString = originalInstruction.toHexString(); PTZInstructionFormat parsedFromHex = PTZInstructionFormat.fromHexString(hexString); assertEquals(originalInstruction.getInstructionCode(), parsedFromHex.getInstructionCode()); assertEquals((byte) 0x01, parsedFromHex.getData1()); assertTrue(parsedFromHex.isValid()); } @Test @DisplayName("辅助开关枚举映射测试") void testAuxiliaryEnumMapping() { // 测试指令码到枚举的映射 assertEquals(AuxiliaryControlEnum.SWITCH_ON, AuxiliaryControlEnum.getByCode((byte) 0x8C)); assertEquals(AuxiliaryControlEnum.SWITCH_OFF, AuxiliaryControlEnum.getByCode((byte) 0x8D)); // 测试名称到枚举的映射 assertEquals(AuxiliaryControlEnum.SWITCH_ON, AuxiliaryControlEnum.getByName("开关开")); assertEquals(AuxiliaryControlEnum.SWITCH_OFF, AuxiliaryControlEnum.getByName("开关关")); // 测试无效映射 assertNull(AuxiliaryControlEnum.getByCode((byte) 0x8B)); assertNull(AuxiliaryControlEnum.getByCode((byte) 0x8E)); assertNull(AuxiliaryControlEnum.getByName("无效指令")); } @Test @DisplayName("辅助开关参数验证测试") void testAuxiliaryParameterValidation() { // 测试有效开关编号范围 0-255 assertTrue(AuxiliaryControlEnum.isValidSwitchNumber(0)); assertTrue(AuxiliaryControlEnum.isValidSwitchNumber(1)); assertTrue(AuxiliaryControlEnum.isValidSwitchNumber(255)); assertTrue(AuxiliaryControlEnum.isValidSwitchNumber(128)); // 测试无效开关编号范围 assertFalse(AuxiliaryControlEnum.isValidSwitchNumber(-1)); assertFalse(AuxiliaryControlEnum.isValidSwitchNumber(256)); assertFalse(AuxiliaryControlEnum.isValidSwitchNumber(1000)); } @Test @DisplayName("辅助开关指令格式验证测试") void testAuxiliaryInstructionFormat() { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x100) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_ON, 42) .build(); // 验证指令格式符合A.3.7规范 assertEquals((byte) 0xA5, instruction.getHeader()); assertEquals((byte) 0x8C, instruction.getInstructionCode()); assertEquals((byte) 42, instruction.getData1()); // 字节5为开关编号 // 验证地址编码 assertEquals(0x100, instruction.getFullAddress()); assertEquals((byte) 0x00, instruction.getAddressLow()); assertEquals((byte) 0x01, (instruction.getCombinationCode2() & 0x0F)); assertTrue(instruction.isValid()); } @Test @DisplayName("辅助开关指令异常处理测试") void testAuxiliaryInstructionExceptions() { // 测试无效开关编号 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_ON, -1) .build(); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_OFF, 256) .build(); }); } @Test @DisplayName("辅助开关控制场景测试") void testAuxiliaryControlScenarios() { // 场景1:雨刷控制 PTZInstructionFormat wiperOn = PTZInstructionBuilder.create() .address(0x001) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_ON, 1) .build(); PTZInstructionFormat wiperOff = PTZInstructionBuilder.create() .address(0x001) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_OFF, 1) .build(); assertEquals((byte) 0x8C, wiperOn.getInstructionCode()); assertEquals((byte) 0x8D, wiperOff.getInstructionCode()); assertEquals((byte) 0x01, wiperOn.getData1()); assertEquals((byte) 0x01, wiperOff.getData1()); assertTrue(wiperOn.isValid()); assertTrue(wiperOff.isValid()); // 场景2:灯光控制 PTZInstructionFormat lightOn = PTZInstructionBuilder.create() .address(0x002) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_ON, 2) .build(); PTZInstructionFormat lightOff = PTZInstructionBuilder.create() .address(0x002) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_OFF, 2) .build(); assertEquals((byte) 0x8C, lightOn.getInstructionCode()); assertEquals((byte) 0x8D, lightOff.getInstructionCode()); assertEquals((byte) 0x02, lightOn.getData1()); assertEquals((byte) 0x02, lightOff.getData1()); assertTrue(lightOn.isValid()); assertTrue(lightOff.isValid()); // 场景3:多个辅助设备同时控制(需要发送多个指令) int[] devices = {1, 2, 3, 4, 5}; // 雨刷、灯光、加热、通风、除霜 // 全部开启 for (int device : devices) { PTZInstructionFormat onInstruction = PTZInstructionBuilder.create() .address(0x003) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_ON, device) .build(); assertEquals((byte) 0x8C, onInstruction.getInstructionCode()); assertEquals((byte) device, onInstruction.getData1()); assertTrue(onInstruction.isValid()); } // 全部关闭 for (int device : devices) { PTZInstructionFormat offInstruction = PTZInstructionBuilder.create() .address(0x003) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_OFF, device) .build(); assertEquals((byte) 0x8D, offInstruction.getInstructionCode()); assertEquals((byte) device, offInstruction.getData1()); assertTrue(offInstruction.isValid()); } } @Test @DisplayName("辅助开关指令序列化一致性测试") void testAuxiliarySerializationConsistency() { PTZInstructionFormat original = PTZInstructionBuilder.create() .address(0x3FF) .addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_OFF, 199) .build(); // 测试字节数组序列化 byte[] bytes = original.toByteArray(); PTZInstructionFormat fromBytes = PTZInstructionFormat.fromByteArray(bytes); assertEquals(original.getInstructionCode(), fromBytes.getInstructionCode()); assertEquals(original.getData1(), fromBytes.getData1()); assertEquals(original.getFullAddress(), fromBytes.getFullAddress()); // 测试十六进制序列化 String hex = original.toHexString(); PTZInstructionFormat fromHex = PTZInstructionFormat.fromHexString(hex); assertEquals(original.getInstructionCode(), fromHex.getInstructionCode()); assertEquals(original.getData1(), fromHex.getData1()); assertEquals(original.getFullAddress(), fromHex.getFullAddress()); // 验证所有版本都有效 assertTrue(original.isValid()); assertTrue(fromBytes.isValid()); assertTrue(fromHex.isValid()); } @Test @DisplayName("辅助开关指令功能描述验证") void testAuxiliaryFunctionDescription() { // 验证开关开指令描述包含开关量和模拟量的功能 String onDescription = AuxiliaryControlEnum.SWITCH_ON.getDescription(); assertTrue(onDescription.contains("开关开")); assertTrue(onDescription.contains("模拟量步进数值增加")); // 验证开关关指令描述包含开关量和模拟量的功能 String offDescription = AuxiliaryControlEnum.SWITCH_OFF.getDescription(); assertTrue(offDescription.contains("开关关")); assertTrue(offDescription.contains("模拟量步进数值减少")); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/PTZControlInstructionTest.java
gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/PTZControlInstructionTest.java
package io.github.lunasaw.gb28181.common.entity.control.instruction; import io.github.lunasaw.gb28181.common.entity.control.instruction.builder.PTZInstructionBuilder; import io.github.lunasaw.gb28181.common.entity.control.instruction.enums.PTZControlEnum; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import static org.junit.jupiter.api.Assertions.*; /** * PTZ控制指令生成和解析完整测试 * 验证所有PTZ指令是否按照A.3.2规范正确生成 */ class PTZControlInstructionTest { @Test @DisplayName("PTZ停止指令测试") void testPTZStopInstruction() { // 根据表A.5序号7:字节4=00H,PTZ的所有操作均停止 PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.STOP) .horizontalSpeed(0x00) .verticalSpeed(0x00) .zoomSpeed(0x0) .build(); assertEquals((byte) 0x00, instruction.getInstructionCode()); assertEquals(0x001, instruction.getFullAddress()); assertTrue(instruction.isValid()); // 验证生成的十六进制字符串 String hexString = instruction.toHexString(); assertEquals(16, hexString.length()); assertTrue(hexString.startsWith("A5")); } @Test @DisplayName("PTZ水平方向控制测试") void testPTZHorizontalControl() { // 测试向左移动 - 表A.5序号5 PTZInstructionFormat leftInstruction = PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.PAN_LEFT) .horizontalSpeed(0x40) .verticalSpeed(0x20) .zoomSpeed(0x0) .build(); assertEquals((byte) 0x02, leftInstruction.getInstructionCode()); assertEquals((byte) 0x40, leftInstruction.getData1()); // 水平速度 assertEquals((byte) 0x20, leftInstruction.getData2()); // 垂直速度 assertTrue(leftInstruction.isValid()); // 测试向右移动 - 表A.5序号6 PTZInstructionFormat rightInstruction = PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.PAN_RIGHT) .horizontalSpeed(0x60) .verticalSpeed(0x30) .zoomSpeed(0x0) .build(); assertEquals((byte) 0x01, rightInstruction.getInstructionCode()); assertEquals((byte) 0x60, rightInstruction.getData1()); assertEquals((byte) 0x30, rightInstruction.getData2()); assertTrue(rightInstruction.isValid()); } @Test @DisplayName("PTZ垂直方向控制测试") void testPTZVerticalControl() { // 测试向上移动 - 表A.5序号3 PTZInstructionFormat upInstruction = PTZInstructionBuilder.create() .address(0x002) .addPTZControl(PTZControlEnum.TILT_UP) .horizontalSpeed(0x50) .verticalSpeed(0x80) .zoomSpeed(0x0) .build(); assertEquals((byte) 0x08, upInstruction.getInstructionCode()); assertEquals((byte) 0x50, upInstruction.getData1()); assertEquals((byte) 0x80, upInstruction.getData2()); assertTrue(upInstruction.isValid()); // 测试向下移动 - 表A.5序号4 PTZInstructionFormat downInstruction = PTZInstructionBuilder.create() .address(0x002) .addPTZControl(PTZControlEnum.TILT_DOWN) .horizontalSpeed(0x30) .verticalSpeed(0x70) .zoomSpeed(0x0) .build(); assertEquals((byte) 0x04, downInstruction.getInstructionCode()); assertEquals((byte) 0x30, downInstruction.getData1()); assertEquals((byte) 0x70, downInstruction.getData2()); assertTrue(downInstruction.isValid()); } @Test @DisplayName("PTZ变倍控制测试") void testPTZZoomControl() { // 测试镜头放大 - 表A.5序号2 PTZInstructionFormat zoomInInstruction = PTZInstructionBuilder.create() .address(0x003) .addPTZControl(PTZControlEnum.ZOOM_IN) .horizontalSpeed(0x00) .verticalSpeed(0x00) .zoomSpeed(0x0F) .build(); assertEquals((byte) 0x10, zoomInInstruction.getInstructionCode()); assertEquals((byte) 0x0F, zoomInInstruction.getData3()); assertTrue(zoomInInstruction.isValid()); // 测试镜头缩小 - 表A.5序号1 PTZInstructionFormat zoomOutInstruction = PTZInstructionBuilder.create() .address(0x003) .addPTZControl(PTZControlEnum.ZOOM_OUT) .horizontalSpeed(0x00) .verticalSpeed(0x00) .zoomSpeed(0x0A) .build(); assertEquals((byte) 0x20, zoomOutInstruction.getInstructionCode()); assertEquals((byte) 0x0A, zoomOutInstruction.getData3()); assertTrue(zoomOutInstruction.isValid()); } @Test @DisplayName("PTZ组合控制测试") void testPTZCombinedControl() { // 测试右上移动同时缩小 - 表A.5序号8示例 PTZInstructionFormat combinedInstruction = PTZInstructionBuilder.create() .address(0x004) .addPTZControl(PTZControlEnum.PanDirection.RIGHT, PTZControlEnum.TiltDirection.UP, PTZControlEnum.ZoomDirection.OUT) .horizontalSpeed(0x50) .verticalSpeed(0x60) .zoomSpeed(0x08) .build(); // 验证指令码:右(0x01) + 上(0x08) + 缩小(0x20) = 0x29 assertEquals((byte) 0x29, combinedInstruction.getInstructionCode()); assertEquals((byte) 0x50, combinedInstruction.getData1()); assertEquals((byte) 0x60, combinedInstruction.getData2()); assertEquals((byte) 0x08, combinedInstruction.getData3()); assertTrue(combinedInstruction.isValid()); // 验证方向检查 assertTrue(combinedInstruction.getInstructionCode() != 0); PTZControlEnum controlEnum = PTZControlEnum.getByCode(combinedInstruction.getInstructionCode()); if (controlEnum != null) { assertTrue(controlEnum.hasPanControl()); assertTrue(controlEnum.hasTiltControl()); assertTrue(controlEnum.hasZoomControl()); } } @ParameterizedTest @DisplayName("PTZ指令码映射验证") @CsvSource({ "0x00, STOP, 停止", "0x01, PAN_RIGHT, 向右", "0x02, PAN_LEFT, 向左", "0x04, TILT_DOWN, 向下", "0x08, TILT_UP, 向上", "0x10, ZOOM_IN, 放大", "0x20, ZOOM_OUT, 缩小" }) void testPTZInstructionCodeMapping(String hexCode, String enumName, String description) { byte code = (byte) Integer.parseInt(hexCode.substring(2), 16); PTZControlEnum controlEnum = PTZControlEnum.getByCode(code); assertNotNull(controlEnum, "指令码 " + hexCode + " 应该有对应的枚举"); assertEquals(enumName, controlEnum.name()); assertEquals(description, controlEnum.getName()); } @Test @DisplayName("PTZ指令解析测试") void testPTZInstructionParsing() { // 创建一个标准的右移指令 PTZInstructionFormat originalInstruction = PTZInstructionBuilder.create() .address(0x123) .addPTZControl(PTZControlEnum.PAN_RIGHT) .horizontalSpeed(0x40) .verticalSpeed(0x20) .zoomSpeed(0x0F) .build(); // 序列化为字节数组 byte[] bytes = originalInstruction.toByteArray(); // 从字节数组重建指令 PTZInstructionFormat parsedInstruction = PTZInstructionFormat.fromByteArray(bytes); // 验证解析结果 assertEquals(originalInstruction.getFullAddress(), parsedInstruction.getFullAddress()); assertEquals(originalInstruction.getInstructionCode(), parsedInstruction.getInstructionCode()); assertEquals(originalInstruction.getData1(), parsedInstruction.getData1()); assertEquals(originalInstruction.getData2(), parsedInstruction.getData2()); assertEquals(originalInstruction.getData3(), parsedInstruction.getData3()); assertTrue(parsedInstruction.isValid()); // 验证十六进制字符串解析 String hexString = originalInstruction.toHexString(); PTZInstructionFormat parsedFromHex = PTZInstructionFormat.fromHexString(hexString); assertEquals(originalInstruction.getInstructionCode(), parsedFromHex.getInstructionCode()); assertTrue(parsedFromHex.isValid()); } @Test @DisplayName("PTZ指令速度范围测试") void testPTZSpeedRanges() { // 测试最小速度值 PTZInstructionFormat minSpeedInstruction = PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.PAN_RIGHT) .horizontalSpeed(0x00) .verticalSpeed(0x00) .zoomSpeed(0x0) .build(); assertTrue(minSpeedInstruction.isValid()); // 测试最大速度值 PTZInstructionFormat maxSpeedInstruction = PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.PAN_LEFT) .horizontalSpeed(0xFF) .verticalSpeed(0xFF) .zoomSpeed(0xF) .build(); assertTrue(maxSpeedInstruction.isValid()); assertEquals((byte) 0xFF, maxSpeedInstruction.getData1()); assertEquals((byte) 0xFF, maxSpeedInstruction.getData2()); assertEquals((byte) 0x0F, maxSpeedInstruction.getData3()); } @Test @DisplayName("PTZ校验码计算验证") void testPTZChecksumCalculation() { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.PAN_RIGHT) .horizontalSpeed(0x40) .verticalSpeed(0x20) .zoomSpeed(0x0F) .build(); // 手动计算校验码进行验证 byte[] bytes = instruction.toByteArray(); int calculatedSum = 0; for (int i = 0; i < 7; i++) { calculatedSum += (bytes[i] & 0xFF); } byte expectedChecksum = (byte) (calculatedSum % 256); assertEquals(expectedChecksum, instruction.getChecksum()); assertTrue(instruction.isValid()); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/FIControlInstructionTest.java
gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/FIControlInstructionTest.java
package io.github.lunasaw.gb28181.common.entity.control.instruction; import io.github.lunasaw.gb28181.common.entity.control.instruction.builder.PTZInstructionBuilder; import io.github.lunasaw.gb28181.common.entity.control.instruction.enums.FIControlEnum; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import static org.junit.jupiter.api.Assertions.*; /** * FI(Focus/Iris)控制指令生成和解析完整测试 * 验证所有FI指令是否按照A.3.3规范正确生成 */ class FIControlInstructionTest { @Test @DisplayName("FI停止指令测试") void testFIStopInstruction() { // 根据表A.7序号5:字节4=40H,镜头停止FI的所有动作 PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x001) .addFIControl(FIControlEnum.STOP) .focusSpeed(0x00) .irisSpeed(0x00) .build(); assertEquals((byte) 0x40, instruction.getInstructionCode()); assertEquals(0x001, instruction.getFullAddress()); assertTrue(instruction.isValid()); // 验证FI指令的固定位模式 (Bit7=0, Bit6=1, Bit5=0, Bit4=0) byte instructionCode = instruction.getInstructionCode(); assertEquals(0x40, instructionCode & 0xF0); // 高4位应该是0100 } @Test @DisplayName("光圈控制指令测试") void testIrisControl() { // 测试光圈缩小 - 表A.7序号1 PTZInstructionFormat irisCloseInstruction = PTZInstructionBuilder.create() .address(0x002) .addFIControl(FIControlEnum.IRIS_CLOSE) .focusSpeed(0x00) .irisSpeed(0x80) .build(); assertEquals((byte) 0x48, irisCloseInstruction.getInstructionCode()); assertEquals((byte) 0x00, irisCloseInstruction.getData1()); // 聚焦速度 assertEquals((byte) 0x80, irisCloseInstruction.getData2()); // 光圈速度 assertTrue(irisCloseInstruction.isValid()); // 验证光圈控制位 (Bit3=1) assertTrue((irisCloseInstruction.getInstructionCode() & 0x08) != 0); // 测试光圈放大 - 表A.7序号2 PTZInstructionFormat irisOpenInstruction = PTZInstructionBuilder.create() .address(0x002) .addFIControl(FIControlEnum.IRIS_OPEN) .focusSpeed(0x00) .irisSpeed(0x60) .build(); assertEquals((byte) 0x44, irisOpenInstruction.getInstructionCode()); assertEquals((byte) 0x00, irisOpenInstruction.getData1()); assertEquals((byte) 0x60, irisOpenInstruction.getData2()); assertTrue(irisOpenInstruction.isValid()); // 验证光圈控制位 (Bit2=1) assertTrue((irisOpenInstruction.getInstructionCode() & 0x04) != 0); } @Test @DisplayName("聚焦控制指令测试") void testFocusControl() { // 测试聚焦近 - 表A.7序号3 PTZInstructionFormat focusNearInstruction = PTZInstructionBuilder.create() .address(0x003) .addFIControl(FIControlEnum.FOCUS_NEAR) .focusSpeed(0x90) .irisSpeed(0x00) .build(); assertEquals((byte) 0x42, focusNearInstruction.getInstructionCode()); assertEquals((byte) 0x90, focusNearInstruction.getData1()); // 聚焦速度 assertEquals((byte) 0x00, focusNearInstruction.getData2()); // 光圈速度 assertTrue(focusNearInstruction.isValid()); // 验证聚焦控制位 (Bit1=1) assertTrue((focusNearInstruction.getInstructionCode() & 0x02) != 0); // 测试聚焦远 - 表A.7序号4 PTZInstructionFormat focusFarInstruction = PTZInstructionBuilder.create() .address(0x003) .addFIControl(FIControlEnum.FOCUS_FAR) .focusSpeed(0x70) .irisSpeed(0x00) .build(); assertEquals((byte) 0x41, focusFarInstruction.getInstructionCode()); assertEquals((byte) 0x70, focusFarInstruction.getData1()); assertEquals((byte) 0x00, focusFarInstruction.getData2()); assertTrue(focusFarInstruction.isValid()); // 验证聚焦控制位 (Bit0=1) assertTrue((focusFarInstruction.getInstructionCode() & 0x01) != 0); } @Test @DisplayName("FI组合控制指令测试") void testFICombinedControl() { // 测试光圈缩小+聚焦远组合 - 表A.7序号6 PTZInstructionFormat combinedInstruction = PTZInstructionBuilder.create() .address(0x004) .addFIControl(FIControlEnum.IrisDirection.CLOSE, FIControlEnum.FocusDirection.FAR) .focusSpeed(0x80) .irisSpeed(0x60) .build(); // 验证指令码:基础(0x40) + 光圈缩小(0x08) + 聚焦远(0x01) = 0x49 assertEquals((byte) 0x49, combinedInstruction.getInstructionCode()); assertEquals((byte) 0x80, combinedInstruction.getData1()); // 聚焦速度 assertEquals((byte) 0x60, combinedInstruction.getData2()); // 光圈速度 assertTrue(combinedInstruction.isValid()); // 验证控制类型检查 FIControlEnum controlEnum = FIControlEnum.getByCode(combinedInstruction.getInstructionCode()); if (controlEnum != null) { assertTrue(controlEnum.hasIrisControl()); assertTrue(controlEnum.hasFocusControl()); } // 测试其他组合:光圈放大+聚焦近 PTZInstructionFormat anotherCombination = PTZInstructionBuilder.create() .address(0x005) .addFIControl(FIControlEnum.IrisDirection.OPEN, FIControlEnum.FocusDirection.NEAR) .focusSpeed(0x50) .irisSpeed(0x70) .build(); // 基础(0x40) + 光圈放大(0x04) + 聚焦近(0x02) = 0x46 assertEquals((byte) 0x46, anotherCombination.getInstructionCode()); assertTrue(anotherCombination.isValid()); } @ParameterizedTest @DisplayName("FI指令码映射验证") @CsvSource({ "0x40, STOP, 停止", "0x41, FOCUS_FAR, 聚焦远", "0x42, FOCUS_NEAR, 聚焦近", "0x44, IRIS_OPEN, 光圈放大", "0x48, IRIS_CLOSE, 光圈缩小" }) void testFIInstructionCodeMapping(String hexCode, String enumName, String description) { byte code = (byte) Integer.parseInt(hexCode.substring(2), 16); FIControlEnum controlEnum = FIControlEnum.getByCode(code); assertNotNull(controlEnum, "指令码 " + hexCode + " 应该有对应的枚举"); assertEquals(enumName, controlEnum.name()); assertEquals(description, controlEnum.getName()); } @Test @DisplayName("FI指令解析测试") void testFIInstructionParsing() { // 创建一个光圈放大指令 PTZInstructionFormat originalInstruction = PTZInstructionBuilder.create() .address(0x123) .addFIControl(FIControlEnum.IRIS_OPEN) .focusSpeed(0x70) .irisSpeed(0x90) .build(); // 序列化为字节数组 byte[] bytes = originalInstruction.toByteArray(); assertEquals(8, bytes.length); // 从字节数组重建指令 PTZInstructionFormat parsedInstruction = PTZInstructionFormat.fromByteArray(bytes); // 验证解析结果 assertEquals(originalInstruction.getFullAddress(), parsedInstruction.getFullAddress()); assertEquals(originalInstruction.getInstructionCode(), parsedInstruction.getInstructionCode()); assertEquals(originalInstruction.getData1(), parsedInstruction.getData1()); assertEquals(originalInstruction.getData2(), parsedInstruction.getData2()); assertTrue(parsedInstruction.isValid()); // 验证十六进制字符串解析 String hexString = originalInstruction.toHexString(); PTZInstructionFormat parsedFromHex = PTZInstructionFormat.fromHexString(hexString); assertEquals(originalInstruction.getInstructionCode(), parsedFromHex.getInstructionCode()); assertTrue(parsedFromHex.isValid()); } @Test @DisplayName("FI指令速度范围测试") void testFISpeedRanges() { // 测试最小速度值 PTZInstructionFormat minSpeedInstruction = PTZInstructionBuilder.create() .address(0x001) .addFIControl(FIControlEnum.IRIS_OPEN) .focusSpeed(0x00) .irisSpeed(0x00) .build(); assertTrue(minSpeedInstruction.isValid()); assertEquals((byte) 0x00, minSpeedInstruction.getData1()); assertEquals((byte) 0x00, minSpeedInstruction.getData2()); // 测试最大速度值 PTZInstructionFormat maxSpeedInstruction = PTZInstructionBuilder.create() .address(0x001) .addFIControl(FIControlEnum.FOCUS_NEAR) .focusSpeed(0xFF) .irisSpeed(0xFF) .build(); assertTrue(maxSpeedInstruction.isValid()); assertEquals((byte) 0xFF, maxSpeedInstruction.getData1()); assertEquals((byte) 0xFF, maxSpeedInstruction.getData2()); } @Test @DisplayName("FI指令位模式验证") void testFIBitPatterns() { // 验证FI指令的固定位模式 for (FIControlEnum fiControl : FIControlEnum.values()) { byte code = fiControl.getInstructionCode(); // Bit7应该为0, Bit6应该为1, Bit5和Bit4应该为0 assertEquals(0, (code >> 7) & 1, "Bit7应该为0"); assertEquals(1, (code >> 6) & 1, "Bit6应该为1"); assertEquals(0, (code >> 5) & 1, "Bit5应该为0"); assertEquals(0, (code >> 4) & 1, "Bit4应该为0"); } } @Test @DisplayName("FI方向枚举测试") void testFIDirectionEnums() { // 测试光圈方向枚举 assertEquals(FIControlEnum.IrisDirection.CLOSE, FIControlEnum.IRIS_CLOSE.getIrisDirection()); assertEquals(FIControlEnum.IrisDirection.OPEN, FIControlEnum.IRIS_OPEN.getIrisDirection()); assertEquals(FIControlEnum.IrisDirection.NONE, FIControlEnum.STOP.getIrisDirection()); // 测试聚焦方向枚举 assertEquals(FIControlEnum.FocusDirection.NEAR, FIControlEnum.FOCUS_NEAR.getFocusDirection()); assertEquals(FIControlEnum.FocusDirection.FAR, FIControlEnum.FOCUS_FAR.getFocusDirection()); assertEquals(FIControlEnum.FocusDirection.NONE, FIControlEnum.STOP.getFocusDirection()); } @Test @DisplayName("FI指令互斥性验证") void testFIMutualExclusion() { // 验证Bit3和Bit2不应同时为1(光圈控制互斥) // 验证Bit1和Bit0不应同时为1(聚焦控制互斥) for (FIControlEnum fiControl : FIControlEnum.values()) { byte code = fiControl.getInstructionCode(); // 检查光圈控制位互斥性 boolean bit3 = (code & 0x08) != 0; boolean bit2 = (code & 0x04) != 0; assertFalse(bit3 && bit2, "光圈控制的Bit3和Bit2不应同时为1"); // 检查聚焦控制位互斥性 boolean bit1 = (code & 0x02) != 0; boolean bit0 = (code & 0x01) != 0; assertFalse(bit1 && bit0, "聚焦控制的Bit1和Bit0不应同时为1"); } } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/PTZInstructionSystemTest.java
gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/PTZInstructionSystemTest.java
package io.github.lunasaw.gb28181.common.entity.control.instruction; import io.github.lunasaw.gb28181.common.entity.control.instruction.builder.PTZInstructionBuilder; import io.github.lunasaw.gb28181.common.entity.control.instruction.crypto.PTZInstructionCrypto; import io.github.lunasaw.gb28181.common.entity.control.instruction.enums.*; import io.github.lunasaw.gb28181.common.entity.control.instruction.manager.PTZInstructionManager; import io.github.lunasaw.gb28181.common.entity.control.instruction.serializer.PTZInstructionSerializer; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import javax.crypto.SecretKey; import java.nio.ByteBuffer; import static org.junit.jupiter.api.Assertions.*; /** * PTZ指令系统单元测试 */ class PTZInstructionSystemTest { private PTZInstructionFormat testInstruction; private final int testAddress = 0x123; private final byte testInstructionCode = 0x01; private final byte testData1 = 0x10; private final byte testData2 = 0x20; private final byte testData3 = 0x0F; @BeforeEach void setUp() { testInstruction = new PTZInstructionFormat(testAddress, testInstructionCode, testData1, testData2, testData3); } @Test @DisplayName("PTZ指令格式基础功能测试") void testPTZInstructionFormat() { // 测试基础属性 assertEquals((byte) 0xA5, testInstruction.getHeader()); assertEquals(testAddress, testInstruction.getFullAddress()); assertEquals(testInstructionCode, testInstruction.getInstructionCode()); assertEquals(testData1, testInstruction.getData1()); assertEquals(testData2, testInstruction.getData2()); assertEquals(testData3, testInstruction.getData3()); // 测试字节数组转换 byte[] bytes = testInstruction.toByteArray(); assertEquals(8, bytes.length); assertEquals((byte) 0xA5, bytes[0]); // 测试十六进制字符串转换 String hexString = testInstruction.toHexString(); assertEquals(16, hexString.length()); assertTrue(hexString.startsWith("A5")); // 测试指令有效性验证 assertTrue(testInstruction.isValid()); // 测试从字节数组重建 PTZInstructionFormat rebuilt = PTZInstructionFormat.fromByteArray(bytes); assertEquals(testInstruction.getFullAddress(), rebuilt.getFullAddress()); assertEquals(testInstruction.getInstructionCode(), rebuilt.getInstructionCode()); // 测试从十六进制字符串重建 PTZInstructionFormat fromHex = PTZInstructionFormat.fromHexString(hexString); assertEquals(testInstruction.getFullAddress(), fromHex.getFullAddress()); } @Test @DisplayName("PTZ控制指令枚举测试") void testPTZControlEnum() { // 测试基础枚举查找 assertEquals(PTZControlEnum.STOP, PTZControlEnum.getByCode((byte) 0x00)); assertEquals(PTZControlEnum.PAN_RIGHT, PTZControlEnum.getByCode((byte) 0x01)); assertEquals(PTZControlEnum.PAN_LEFT, PTZControlEnum.getByCode((byte) 0x02)); assertEquals(PTZControlEnum.TILT_UP, PTZControlEnum.getByCode((byte) 0x08)); // 测试方向检查 assertTrue(PTZControlEnum.PAN_LEFT.hasPanControl()); assertTrue(PTZControlEnum.TILT_UP.hasTiltControl()); assertTrue(PTZControlEnum.ZOOM_IN.hasZoomControl()); // 测试方向获取 assertEquals(PTZControlEnum.PanDirection.LEFT, PTZControlEnum.PAN_LEFT.getPanDirection()); assertEquals(PTZControlEnum.TiltDirection.UP, PTZControlEnum.TILT_UP.getTiltDirection()); assertEquals(PTZControlEnum.ZoomDirection.IN, PTZControlEnum.ZOOM_IN.getZoomDirection()); } @Test @DisplayName("FI控制指令枚举测试") void testFIControlEnum() { // 测试基础枚举查找 assertEquals(FIControlEnum.STOP, FIControlEnum.getByCode((byte) 0x40)); assertEquals(FIControlEnum.IRIS_OPEN, FIControlEnum.getByCode((byte) 0x44)); assertEquals(FIControlEnum.FOCUS_NEAR, FIControlEnum.getByCode((byte) 0x42)); // 测试控制类型检查 assertTrue(FIControlEnum.IRIS_OPEN.hasIrisControl()); assertTrue(FIControlEnum.FOCUS_NEAR.hasFocusControl()); // 测试方向获取 assertEquals(FIControlEnum.IrisDirection.OPEN, FIControlEnum.IRIS_OPEN.getIrisDirection()); assertEquals(FIControlEnum.FocusDirection.NEAR, FIControlEnum.FOCUS_NEAR.getFocusDirection()); } @Test @DisplayName("预置位控制指令枚举测试") void testPresetControlEnum() { // 测试基础枚举查找 assertEquals(PresetControlEnum.SET_PRESET, PresetControlEnum.getByCode((byte) 0x81)); assertEquals(PresetControlEnum.CALL_PRESET, PresetControlEnum.getByCode((byte) 0x82)); assertEquals(PresetControlEnum.DELETE_PRESET, PresetControlEnum.getByCode((byte) 0x83)); // 测试预置位号验证 assertTrue(PresetControlEnum.isValidPresetNumber(1)); assertTrue(PresetControlEnum.isValidPresetNumber(255)); assertFalse(PresetControlEnum.isValidPresetNumber(0)); assertFalse(PresetControlEnum.isValidPresetNumber(256)); } @Test @DisplayName("Builder模式测试") void testPTZInstructionBuilder() { // 测试PTZ控制构建 PTZInstructionFormat ptzInstruction = PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.PAN_RIGHT) .horizontalSpeed(0x40) .verticalSpeed(0x20) .build(); assertEquals(0x001, ptzInstruction.getFullAddress()); assertEquals((byte) 0x01, ptzInstruction.getInstructionCode()); assertEquals((byte) 0x40, ptzInstruction.getData1()); assertEquals((byte) 0x20, ptzInstruction.getData2()); // 测试FI控制构建 PTZInstructionFormat fiInstruction = PTZInstructionBuilder.create() .address(0x002) .addFIControl(FIControlEnum.IRIS_OPEN) .focusSpeed(0x80) .irisSpeed(0x60) .build(); assertEquals(0x002, fiInstruction.getFullAddress()); assertEquals((byte) 0x44, fiInstruction.getInstructionCode()); // 测试预置位控制构建 PTZInstructionFormat presetInstruction = PTZInstructionBuilder.create() .address(0x003) .addPresetControl(PresetControlEnum.SET_PRESET, 10) .build(); assertEquals(0x003, presetInstruction.getFullAddress()); assertEquals((byte) 0x81, presetInstruction.getInstructionCode()); assertEquals((byte) 0x00, presetInstruction.getData1()); assertEquals((byte) 10, presetInstruction.getData2()); // 测试组合PTZ控制 PTZInstructionFormat combinedInstruction = PTZInstructionBuilder.create() .address(0x004) .addPTZControl(PTZControlEnum.PanDirection.RIGHT, PTZControlEnum.TiltDirection.UP, PTZControlEnum.ZoomDirection.IN) .horizontalSpeed(0x50) .verticalSpeed(0x30) .zoomSpeed(0x0A) .build(); assertEquals((byte) 0x19, combinedInstruction.getInstructionCode()); // 0x01 + 0x08 + 0x10 } @Test @DisplayName("序列化功能测试") void testSerialization() { // 测试字节数组序列化 byte[] bytes = PTZInstructionSerializer.serializeToBytes(testInstruction); assertEquals(8, bytes.length); PTZInstructionFormat deserialized = PTZInstructionSerializer.deserializeFromBytes(bytes); assertEquals(testInstruction.getFullAddress(), deserialized.getFullAddress()); // 测试十六进制序列化 String hex = PTZInstructionSerializer.serializeToHex(testInstruction); assertEquals(16, hex.length()); PTZInstructionFormat fromHex = PTZInstructionSerializer.deserializeFromHex(hex); assertEquals(testInstruction.getInstructionCode(), fromHex.getInstructionCode()); // 测试Base64序列化 String base64 = PTZInstructionSerializer.serializeToBase64(testInstruction); assertNotNull(base64); assertFalse(base64.isEmpty()); PTZInstructionFormat fromBase64 = PTZInstructionSerializer.deserializeFromBase64(base64); assertEquals(testInstruction.getData1(), fromBase64.getData1()); // 测试ByteBuffer序列化 ByteBuffer buffer = PTZInstructionSerializer.serializeToByteBuffer(testInstruction); assertEquals(8, buffer.remaining()); PTZInstructionFormat fromBuffer = PTZInstructionSerializer.deserializeFromByteBuffer(buffer); assertEquals(testInstruction.getData2(), fromBuffer.getData2()); } @Test @DisplayName("加密解密功能测试") void testCrypto() { // 测试AES-GCM加密 SecretKey aesKey = PTZInstructionCrypto.generateAESKey(256); assertNotNull(aesKey); byte[] encrypted = PTZInstructionCrypto.encryptAESGCM(testInstruction, aesKey); assertNotNull(encrypted); assertTrue(encrypted.length > 8); // 应该包含IV和认证标签 PTZInstructionFormat decrypted = PTZInstructionCrypto.decryptAESGCM(encrypted, aesKey); assertEquals(testInstruction.getFullAddress(), decrypted.getFullAddress()); assertEquals(testInstruction.getInstructionCode(), decrypted.getInstructionCode()); // 测试XOR加密 byte[] xorKey = PTZInstructionCrypto.generateRandomKey(8); byte[] xorEncrypted = PTZInstructionCrypto.encryptXOR(testInstruction, xorKey); assertEquals(8, xorEncrypted.length); PTZInstructionFormat xorDecrypted = PTZInstructionCrypto.decryptXOR(xorEncrypted, xorKey); assertEquals(testInstruction.getData3(), xorDecrypted.getData3()); // 测试哈希计算 byte[] md5Hash = PTZInstructionCrypto.calculateMD5Hash(testInstruction); assertEquals(16, md5Hash.length); byte[] sha256Hash = PTZInstructionCrypto.calculateSHA256Hash(testInstruction); assertEquals(32, sha256Hash.length); // 测试完整性验证 assertTrue(PTZInstructionCrypto.verifyIntegrity(testInstruction, md5Hash, "MD5")); assertTrue(PTZInstructionCrypto.verifyIntegrity(testInstruction, sha256Hash, "SHA-256")); } @Test @DisplayName("指令管理器测试") void testInstructionManager() { // 测试指令类型识别 assertEquals(PTZInstructionManager.InstructionType.PTZ_CONTROL, PTZInstructionManager.getInstructionType((byte) 0x01)); assertEquals(PTZInstructionManager.InstructionType.FI_CONTROL, PTZInstructionManager.getInstructionType((byte) 0x40)); assertEquals(PTZInstructionManager.InstructionType.PRESET_CONTROL, PTZInstructionManager.getInstructionType((byte) 0x81)); // 测试枚举获取 assertEquals(PTZControlEnum.PAN_RIGHT, PTZInstructionManager.getPTZControlEnum((byte) 0x01)); assertEquals(FIControlEnum.STOP, PTZInstructionManager.getFIControlEnum((byte) 0x40)); assertEquals(PresetControlEnum.SET_PRESET, PTZInstructionManager.getPresetControlEnum((byte) 0x81)); // 测试指令码支持检查 assertTrue(PTZInstructionManager.isSupportedInstructionCode((byte) 0x01)); assertTrue(PTZInstructionManager.isSupportedInstructionCode((byte) 0x40)); assertFalse(PTZInstructionManager.isSupportedInstructionCode((byte) 0xFF)); // 测试描述信息获取 String description = PTZInstructionManager.getInstructionDescription((byte) 0x01); assertNotNull(description); assertFalse(description.isEmpty()); // 测试统计信息 PTZInstructionManager.InstructionStatistics stats = PTZInstructionManager.getStatistics(); assertNotNull(stats); assertTrue(stats.getTotalCount() > 0); assertTrue(stats.getCountsByType().size() > 0); } @Test @DisplayName("错误处理测试") void testErrorHandling() { // 测试无效地址 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create().address(0x1000).build(); // 超出范围 }); // 测试无效预置位号 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addPresetControl(PresetControlEnum.SET_PRESET, 0) // 无效预置位号 .build(); }); // 测试无效字节数组 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionFormat.fromByteArray(new byte[]{0x01, 0x02}); // 长度不足 }); // 测试无效十六进制字符串 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionFormat.fromHexString("A5F0"); // 长度不足 }); // 测试XOR密钥长度 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionCrypto.encryptXOR(testInstruction, new byte[]{0x01}); // 密钥长度错误 }); } @Test @DisplayName("指令兼容性测试") void testInstructionCompatibility() { // 测试与现有PtzUtils的兼容性 // 创建一个PTZ右移指令 PTZInstructionFormat rightInstruction = PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.PAN_RIGHT) .horizontalSpeed(0x40) .verticalSpeed(0x20) .zoomSpeed(0x0F) .build(); // 验证指令格式符合规范 assertTrue(rightInstruction.isValid()); assertEquals((byte) 0xA5, rightInstruction.getHeader()); assertEquals((byte) 0x01, rightInstruction.getInstructionCode()); // 右移指令码 // 测试十六进制输出格式与现有系统兼容 String hexString = rightInstruction.toHexString(); assertTrue(hexString.startsWith("A5")); assertEquals(16, hexString.length()); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/CruiseControlInstructionTest.java
gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/CruiseControlInstructionTest.java
package io.github.lunasaw.gb28181.common.entity.control.instruction; import io.github.lunasaw.gb28181.common.entity.control.instruction.builder.PTZInstructionBuilder; import io.github.lunasaw.gb28181.common.entity.control.instruction.enums.CruiseControlEnum; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.*; /** * 巡航控制指令生成和解析完整测试 * 验证所有巡航指令是否按照A.3.5规范正确生成 */ class CruiseControlInstructionTest { @Test @DisplayName("加入巡航点指令测试") void testAddCruisePointInstruction() { // 测试向巡航组1添加预置位3 PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x001) .addCruiseControl(CruiseControlEnum.ADD_CRUISE_POINT, 1, 3) .build(); assertEquals((byte) 0x84, instruction.getInstructionCode()); assertEquals((byte) 0x01, instruction.getData1()); // 字节5为巡航组号 assertEquals((byte) 0x03, instruction.getData2()); // 字节6为预置位号 assertEquals(0x001, instruction.getFullAddress()); assertTrue(instruction.isValid()); // 测试边界值:巡航组255,预置位255 PTZInstructionFormat maxInstruction = PTZInstructionBuilder.create() .address(0x002) .addCruiseControl(CruiseControlEnum.ADD_CRUISE_POINT, 255, 255) .build(); assertEquals((byte) 0x84, maxInstruction.getInstructionCode()); assertEquals((byte) 0xFF, maxInstruction.getData1()); assertEquals((byte) 0xFF, maxInstruction.getData2()); assertTrue(maxInstruction.isValid()); } @Test @DisplayName("删除巡航点指令测试") void testDeleteCruisePointInstruction() { // 测试删除巡航组2的预置位5 PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x003) .addCruiseControl(CruiseControlEnum.DELETE_CRUISE_POINT, 2, 5) .build(); assertEquals((byte) 0x85, instruction.getInstructionCode()); assertEquals((byte) 0x02, instruction.getData1()); // 字节5为巡航组号 assertEquals((byte) 0x05, instruction.getData2()); // 字节6为预置位号 assertTrue(instruction.isValid()); // 测试删除整条巡航(字节6为00H) PTZInstructionFormat deleteEntireInstruction = PTZInstructionBuilder.create() .address(0x004) .addCruiseControl(CruiseControlEnum.DELETE_CRUISE_POINT, 3, 0) .build(); assertEquals((byte) 0x85, deleteEntireInstruction.getInstructionCode()); assertEquals((byte) 0x03, deleteEntireInstruction.getData1()); assertEquals((byte) 0x00, deleteEntireInstruction.getData2()); // 删除整条巡航 assertTrue(deleteEntireInstruction.isValid()); } @Test @DisplayName("设置巡航速度指令测试") void testSetCruiseSpeedInstruction() { // 测试设置巡航组1速度为100(数据分布:低8位=100,高4位=0) PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x005) .addCruiseControl(CruiseControlEnum.SET_CRUISE_SPEED, 1, 1, 100) .build(); assertEquals((byte) 0x86, instruction.getInstructionCode()); assertEquals((byte) 0x01, instruction.getData1()); // 字节5为巡航组号 assertEquals((byte) 100, instruction.getData2()); // 字节6为速度低8位 assertEquals((byte) 0x00, instruction.getData3()); // 字节7高4位为速度高4位(0) assertTrue(instruction.isValid()); // 测试大速度值:4095(0xFFF)= 低8位0xFF + 高4位0x0F PTZInstructionFormat maxSpeedInstruction = PTZInstructionBuilder.create() .address(0x006) .addCruiseControl(CruiseControlEnum.SET_CRUISE_SPEED, 2, 1, 4095) .build(); assertEquals((byte) 0x86, maxSpeedInstruction.getInstructionCode()); assertEquals((byte) 0x02, maxSpeedInstruction.getData1()); assertEquals((byte) 0xFF, maxSpeedInstruction.getData2()); // 4095 & 0xFF = 255 assertEquals((byte) 0x0F, maxSpeedInstruction.getData3()); // (4095 >> 8) & 0x0F = 15 assertTrue(maxSpeedInstruction.isValid()); } @Test @DisplayName("设置巡航停留时间指令测试") void testSetCruiseStayTimeInstruction() { // 测试设置巡航组3停留时间为60秒 PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x007) .addCruiseControl(CruiseControlEnum.SET_CRUISE_STAY_TIME, 3, 1, 60) .build(); assertEquals((byte) 0x87, instruction.getInstructionCode()); assertEquals((byte) 0x03, instruction.getData1()); // 字节5为巡航组号 assertEquals((byte) 60, instruction.getData2()); // 字节6为时间低8位 assertEquals((byte) 0x00, instruction.getData3()); // 字节7高4位为时间高4位 assertTrue(instruction.isValid()); // 测试大时间值:1800秒(0x708)= 低8位0x08 + 高4位0x07 PTZInstructionFormat longTimeInstruction = PTZInstructionBuilder.create() .address(0x008) .addCruiseControl(CruiseControlEnum.SET_CRUISE_STAY_TIME, 4, 1, 1800) .build(); assertEquals((byte) 0x87, longTimeInstruction.getInstructionCode()); assertEquals((byte) 0x04, longTimeInstruction.getData1()); assertEquals((byte) 0x08, longTimeInstruction.getData2()); // 1800 & 0xFF = 8 assertEquals((byte) 0x07, longTimeInstruction.getData3()); // (1800 >> 8) & 0x0F = 7 assertTrue(longTimeInstruction.isValid()); } @Test @DisplayName("开始巡航指令测试") void testStartCruiseInstruction() { // 测试开始巡航组5 PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x009) .addCruiseControl(CruiseControlEnum.START_CRUISE, 5) .build(); assertEquals((byte) 0x88, instruction.getInstructionCode()); assertEquals((byte) 0x05, instruction.getData1()); // 字节5为巡航组号 assertEquals((byte) 0x00, instruction.getData2()); // 字节6为00H assertEquals(0x009, instruction.getFullAddress()); assertTrue(instruction.isValid()); // 测试开始巡航组0 PTZInstructionFormat zeroGroupInstruction = PTZInstructionBuilder.create() .address(0x00A) .addCruiseControl(CruiseControlEnum.START_CRUISE, 0) .build(); assertEquals((byte) 0x88, zeroGroupInstruction.getInstructionCode()); assertEquals((byte) 0x00, zeroGroupInstruction.getData1()); assertEquals((byte) 0x00, zeroGroupInstruction.getData2()); assertTrue(zeroGroupInstruction.isValid()); } @ParameterizedTest @DisplayName("巡航组号范围测试") @ValueSource(ints = {0, 1, 50, 100, 200, 255}) void testCruiseGroupNumberRange(int groupNumber) { // 测试有效巡航组号 assertTrue(CruiseControlEnum.isValidGroupNumber(groupNumber)); // 测试开始巡航 PTZInstructionFormat startInstruction = PTZInstructionBuilder.create() .address(0x001) .addCruiseControl(CruiseControlEnum.START_CRUISE, groupNumber) .build(); assertEquals((byte) 0x88, startInstruction.getInstructionCode()); assertEquals((byte) groupNumber, startInstruction.getData1()); assertTrue(startInstruction.isValid()); } @ParameterizedTest @DisplayName("预置位号范围测试") @ValueSource(ints = {1, 25, 50, 100, 200, 255}) void testPresetNumberRange(int presetNumber) { // 测试有效预置位号 assertTrue(CruiseControlEnum.isValidPresetNumber(presetNumber)); // 测试加入巡航点 PTZInstructionFormat addInstruction = PTZInstructionBuilder.create() .address(0x001) .addCruiseControl(CruiseControlEnum.ADD_CRUISE_POINT, 1, presetNumber) .build(); assertEquals((byte) 0x84, addInstruction.getInstructionCode()); assertEquals((byte) presetNumber, addInstruction.getData2()); assertTrue(addInstruction.isValid()); } @Test @DisplayName("巡航指令解析测试") void testCruiseInstructionParsing() { // 创建设置巡航速度指令 PTZInstructionFormat originalInstruction = PTZInstructionBuilder.create() .address(0x123) .addCruiseControl(CruiseControlEnum.SET_CRUISE_SPEED, 10, 20, 500) .build(); // 序列化为字节数组 byte[] bytes = originalInstruction.toByteArray(); assertEquals(8, bytes.length); // 验证字节数组内容 assertEquals((byte) 0xA5, bytes[0]); // 首字节 assertEquals((byte) 0x86, bytes[3]); // 指令码 assertEquals((byte) 10, bytes[4]); // 巡航组号 assertEquals((byte) (500 & 0xFF), bytes[5]); // 速度低8位 // 从字节数组重建指令 PTZInstructionFormat parsedInstruction = PTZInstructionFormat.fromByteArray(bytes); // 验证解析结果 assertEquals(originalInstruction.getFullAddress(), parsedInstruction.getFullAddress()); assertEquals(originalInstruction.getInstructionCode(), parsedInstruction.getInstructionCode()); assertEquals(originalInstruction.getData1(), parsedInstruction.getData1()); assertEquals(originalInstruction.getData2(), parsedInstruction.getData2()); assertEquals(originalInstruction.getData3(), parsedInstruction.getData3()); assertTrue(parsedInstruction.isValid()); // 验证十六进制字符串解析 String hexString = originalInstruction.toHexString(); PTZInstructionFormat parsedFromHex = PTZInstructionFormat.fromHexString(hexString); assertEquals(originalInstruction.getInstructionCode(), parsedFromHex.getInstructionCode()); assertTrue(parsedFromHex.isValid()); } @Test @DisplayName("巡航指令枚举映射测试") void testCruiseEnumMapping() { // 测试指令码到枚举的映射 assertEquals(CruiseControlEnum.ADD_CRUISE_POINT, CruiseControlEnum.getByCode((byte) 0x84)); assertEquals(CruiseControlEnum.DELETE_CRUISE_POINT, CruiseControlEnum.getByCode((byte) 0x85)); assertEquals(CruiseControlEnum.SET_CRUISE_SPEED, CruiseControlEnum.getByCode((byte) 0x86)); assertEquals(CruiseControlEnum.SET_CRUISE_STAY_TIME, CruiseControlEnum.getByCode((byte) 0x87)); assertEquals(CruiseControlEnum.START_CRUISE, CruiseControlEnum.getByCode((byte) 0x88)); // 测试名称到枚举的映射 assertEquals(CruiseControlEnum.ADD_CRUISE_POINT, CruiseControlEnum.getByName("加入巡航点")); assertEquals(CruiseControlEnum.DELETE_CRUISE_POINT, CruiseControlEnum.getByName("删除巡航点")); assertEquals(CruiseControlEnum.START_CRUISE, CruiseControlEnum.getByName("开始巡航")); // 测试无效映射 assertNull(CruiseControlEnum.getByCode((byte) 0x83)); assertNull(CruiseControlEnum.getByCode((byte) 0x89)); assertNull(CruiseControlEnum.getByName("无效指令")); } @Test @DisplayName("巡航参数验证测试") void testCruiseParameterValidation() { // 测试有效参数范围 assertTrue(CruiseControlEnum.isValidGroupNumber(0)); assertTrue(CruiseControlEnum.isValidGroupNumber(255)); assertTrue(CruiseControlEnum.isValidPresetNumber(1)); assertTrue(CruiseControlEnum.isValidPresetNumber(255)); assertTrue(CruiseControlEnum.isValidSpeed(0)); assertTrue(CruiseControlEnum.isValidSpeed(4095)); assertTrue(CruiseControlEnum.isValidStayTime(0)); assertTrue(CruiseControlEnum.isValidStayTime(4095)); // 测试无效参数范围 assertFalse(CruiseControlEnum.isValidGroupNumber(-1)); assertFalse(CruiseControlEnum.isValidGroupNumber(256)); assertFalse(CruiseControlEnum.isValidPresetNumber(0)); assertFalse(CruiseControlEnum.isValidPresetNumber(256)); assertFalse(CruiseControlEnum.isValidSpeed(-1)); assertFalse(CruiseControlEnum.isValidSpeed(4096)); assertFalse(CruiseControlEnum.isValidStayTime(-1)); assertFalse(CruiseControlEnum.isValidStayTime(4096)); } @Test @DisplayName("巡航指令数据编码测试") void testCruiseDataEncoding() { // 测试12位数据的编码(速度和时间) int[] testValues = {0, 1, 255, 256, 1023, 2048, 4095}; for (int value : testValues) { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x001) .addCruiseControl(CruiseControlEnum.SET_CRUISE_SPEED, 1, 1, value) .build(); // 验证数据编码 byte expectedLow = (byte) (value & 0xFF); byte expectedHigh = (byte) ((value >> 8) & 0x0F); assertEquals(expectedLow, instruction.getData2()); assertEquals(expectedHigh, instruction.getData3()); assertTrue(instruction.isValid()); // 验证数据解码 int decodedValue = (instruction.getData2() & 0xFF) | ((instruction.getData3() & 0x0F) << 8); assertEquals(value, decodedValue); } } @Test @DisplayName("巡航指令异常处理测试") void testCruiseInstructionExceptions() { // 测试无效巡航组号 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addCruiseControl(CruiseControlEnum.START_CRUISE, -1) .build(); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addCruiseControl(CruiseControlEnum.START_CRUISE, 256) .build(); }); // 测试无效预置位号 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addCruiseControl(CruiseControlEnum.ADD_CRUISE_POINT, 1, 0) .build(); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addCruiseControl(CruiseControlEnum.ADD_CRUISE_POINT, 1, 256) .build(); }); // 测试无效速度或时间 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addCruiseControl(CruiseControlEnum.SET_CRUISE_SPEED, 1, 1, -1) .build(); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addCruiseControl(CruiseControlEnum.SET_CRUISE_SPEED, 1, 1, 4096) .build(); }); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/PTZInstructionBoundaryAndExceptionTest.java
gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/PTZInstructionBoundaryAndExceptionTest.java
package io.github.lunasaw.gb28181.common.entity.control.instruction; import io.github.lunasaw.gb28181.common.entity.control.instruction.builder.PTZInstructionBuilder; import io.github.lunasaw.gb28181.common.entity.control.instruction.enums.*; import io.github.lunasaw.gb28181.common.entity.control.instruction.serializer.PTZInstructionSerializer; import io.github.lunasaw.gb28181.common.entity.control.instruction.crypto.PTZInstructionCrypto; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.*; /** * PTZ指令系统边界值和异常情况完整测试 * 验证所有边界条件和异常处理 */ class PTZInstructionBoundaryAndExceptionTest { @Test @DisplayName("地址边界值测试") void testAddressBoundaryValues() { // 测试最小有效地址 PTZInstructionFormat minInstruction = PTZInstructionBuilder.create() .address(0x000) .addPTZControl(PTZControlEnum.STOP) .build(); assertEquals(0x000, minInstruction.getFullAddress()); assertTrue(minInstruction.isValid()); // 测试最大有效地址 PTZInstructionFormat maxInstruction = PTZInstructionBuilder.create() .address(0xFFF) .addPTZControl(PTZControlEnum.STOP) .build(); assertEquals(0xFFF, maxInstruction.getFullAddress()); assertTrue(maxInstruction.isValid()); // 测试广播地址(0x000) PTZInstructionFormat broadcastInstruction = PTZInstructionBuilder.create() .address(0x000) .addPTZControl(PTZControlEnum.PAN_LEFT) .build(); assertEquals(0x000, broadcastInstruction.getFullAddress()); assertTrue(broadcastInstruction.isValid()); } @Test @DisplayName("地址超出范围异常测试") void testAddressOutOfRangeExceptions() { // 测试负数地址 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(-1) .addPTZControl(PTZControlEnum.STOP) .build(); }); // 测试超出范围地址 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x1000) // 超出0xFFF .addPTZControl(PTZControlEnum.STOP) .build(); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0xFFFF) // 远超范围 .addPTZControl(PTZControlEnum.STOP) .build(); }); } @ParameterizedTest @DisplayName("速度参数边界值测试") @ValueSource(ints = {0x00, 0x01, 0x7F, 0x80, 0xFE, 0xFF}) void testSpeedBoundaryValues(int speed) { // 测试水平速度边界值 PTZInstructionFormat horizontalSpeedInstruction = PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.PAN_RIGHT) .horizontalSpeed(speed) .build(); assertEquals((byte) speed, horizontalSpeedInstruction.getData1()); assertTrue(horizontalSpeedInstruction.isValid()); // 测试垂直速度边界值 PTZInstructionFormat verticalSpeedInstruction = PTZInstructionBuilder.create() .address(0x002) .addPTZControl(PTZControlEnum.TILT_UP) .verticalSpeed(speed) .build(); assertEquals((byte) speed, verticalSpeedInstruction.getData2()); assertTrue(verticalSpeedInstruction.isValid()); } @Test @DisplayName("速度参数异常测试") void testSpeedParameterExceptions() { // 测试水平速度超出范围 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.PAN_RIGHT) .horizontalSpeed(-1) .build(); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.PAN_RIGHT) .horizontalSpeed(0x100) .build(); }); // 测试垂直速度超出范围 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.TILT_UP) .verticalSpeed(-1) .build(); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.TILT_UP) .verticalSpeed(0x100) .build(); }); // 测试变倍速度超出范围 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.ZOOM_IN) .zoomSpeed(-1) .build(); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.ZOOM_IN) .zoomSpeed(0x10) .build(); }); } @Test @DisplayName("预置位号边界值和异常测试") void testPresetNumberBoundaryAndExceptions() { // 测试最小有效预置位号 PTZInstructionFormat minPresetInstruction = PTZInstructionBuilder.create() .address(0x001) .addPresetControl(PresetControlEnum.SET_PRESET, 1) .build(); assertEquals((byte) 1, minPresetInstruction.getData2()); assertTrue(minPresetInstruction.isValid()); // 测试最大有效预置位号 PTZInstructionFormat maxPresetInstruction = PTZInstructionBuilder.create() .address(0x001) .addPresetControl(PresetControlEnum.SET_PRESET, 255) .build(); assertEquals((byte) 0xFF, maxPresetInstruction.getData2()); assertTrue(maxPresetInstruction.isValid()); // 测试无效预置位号(0号预留) assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addPresetControl(PresetControlEnum.SET_PRESET, 0) .build(); }); // 测试超出范围预置位号 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addPresetControl(PresetControlEnum.SET_PRESET, 256) .build(); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addPresetControl(PresetControlEnum.SET_PRESET, -1) .build(); }); } @Test @DisplayName("12位数据边界值测试") void testTwelveBitDataBoundaryValues() { // 测试巡航速度最小值 PTZInstructionFormat minSpeedInstruction = PTZInstructionBuilder.create() .address(0x001) .addCruiseControl(CruiseControlEnum.SET_CRUISE_SPEED, 1, 1, 0) .build(); assertEquals((byte) 0x00, minSpeedInstruction.getData2()); assertEquals((byte) 0x00, minSpeedInstruction.getData3()); assertTrue(minSpeedInstruction.isValid()); // 测试巡航速度最大值(4095 = 0xFFF) PTZInstructionFormat maxSpeedInstruction = PTZInstructionBuilder.create() .address(0x001) .addCruiseControl(CruiseControlEnum.SET_CRUISE_SPEED, 1, 1, 4095) .build(); assertEquals((byte) 0xFF, maxSpeedInstruction.getData2()); // 低8位 assertEquals((byte) 0x0F, maxSpeedInstruction.getData3()); // 高4位 assertTrue(maxSpeedInstruction.isValid()); // 测试扫描速度边界值 PTZInstructionFormat scanSpeedInstruction = PTZInstructionBuilder.create() .address(0x002) .addScanSpeedControl(1, 4095) .build(); assertEquals((byte) 0xFF, scanSpeedInstruction.getData2()); assertEquals((byte) 0x0F, scanSpeedInstruction.getData3()); assertTrue(scanSpeedInstruction.isValid()); } @Test @DisplayName("12位数据异常测试") void testTwelveBitDataExceptions() { // 测试巡航速度超出范围 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addCruiseControl(CruiseControlEnum.SET_CRUISE_SPEED, 1, 1, -1) .build(); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addCruiseControl(CruiseControlEnum.SET_CRUISE_SPEED, 1, 1, 4096) .build(); }); // 测试巡航停留时间超出范围 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addCruiseControl(CruiseControlEnum.SET_CRUISE_STAY_TIME, 1, 1, -1) .build(); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addCruiseControl(CruiseControlEnum.SET_CRUISE_STAY_TIME, 1, 1, 4096) .build(); }); // 测试扫描速度超出范围 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addScanSpeedControl(1, -1) .build(); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addScanSpeedControl(1, 4096) .build(); }); } @Test @DisplayName("序列化异常测试") void testSerializationExceptions() { // 测试空指令序列化 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionSerializer.serializeToBytes(null); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionSerializer.serializeToHex(null); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionSerializer.serializeToBase64(null); }); // 测试无效字节数组反序列化 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionSerializer.deserializeFromBytes(null); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionSerializer.deserializeFromBytes(new byte[]{}); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionSerializer.deserializeFromBytes(new byte[]{0x01, 0x02}); // 长度不足 }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionSerializer.deserializeFromBytes(new byte[10]); // 长度过长 }); // 测试无效十六进制字符串反序列化 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionSerializer.deserializeFromHex(null); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionSerializer.deserializeFromHex(""); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionSerializer.deserializeFromHex("A5F0"); // 长度不足 }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionSerializer.deserializeFromHex("A5F001020304050607080910"); // 长度过长 }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionSerializer.deserializeFromHex("G5F00102030405060708"); // 无效字符 }); // 测试无效Base64字符串反序列化 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionSerializer.deserializeFromBase64(null); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionSerializer.deserializeFromBase64(""); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionSerializer.deserializeFromBase64("Invalid@Base64!"); }); } @Test @DisplayName("加密异常测试") void testEncryptionExceptions() { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.STOP) .build(); // 测试空指令加密 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionCrypto.encryptXOR(null, new byte[8]); }); // 测试无效密钥长度 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionCrypto.encryptXOR(instruction, null); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionCrypto.encryptXOR(instruction, new byte[7]); // 密钥长度不足 }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionCrypto.encryptXOR(instruction, new byte[9]); // 密钥长度过长 }); // 测试XOR解密异常 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionCrypto.decryptXOR(null, new byte[8]); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionCrypto.decryptXOR(new byte[8], null); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionCrypto.decryptXOR(new byte[7], new byte[8]); // 数据长度不正确 }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionCrypto.decryptXOR(new byte[8], new byte[7]); // 密钥长度不正确 }); } @Test @DisplayName("指令格式异常测试") void testInstructionFormatExceptions() { // 测试从无效字节数组创建指令 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionFormat.fromByteArray(null); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionFormat.fromByteArray(new byte[]{}); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionFormat.fromByteArray(new byte[7]); // 长度不足 }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionFormat.fromByteArray(new byte[9]); // 长度过长 }); // 测试从无效十六进制字符串创建指令 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionFormat.fromHexString(null); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionFormat.fromHexString("A5F0010203"); // 长度不足 }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionFormat.fromHexString("A5F0010203040506070809"); // 长度过长 }); } @Test @DisplayName("Builder模式空值异常测试") void testBuilderNullExceptions() { // 测试空控制枚举 assertThrows(NullPointerException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addPTZControl((PTZControlEnum) null) .build(); }); assertThrows(NullPointerException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addFIControl((FIControlEnum) null) .build(); }); assertThrows(NullPointerException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addPresetControl(null, 1) .build(); }); assertThrows(NullPointerException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addCruiseControl(null, 1) .build(); }); // 测试空方向枚举 assertThrows(NullPointerException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addPTZControl(null, PTZControlEnum.TiltDirection.UP, PTZControlEnum.ZoomDirection.IN) .build(); }); assertThrows(NullPointerException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addFIControl(null, FIControlEnum.FocusDirection.NEAR) .build(); }); } @Test @DisplayName("极端数据组合测试") void testExtremeDataCombinations() { // 测试所有最大值组合 PTZInstructionFormat maxValuesInstruction = PTZInstructionBuilder.create() .address(0xFFF) .addPTZControl(PTZControlEnum.PAN_RIGHT_TILT_UP_ZOOM_OUT) .horizontalSpeed(0xFF) .verticalSpeed(0xFF) .zoomSpeed(0x0F) .build(); assertEquals(0xFFF, maxValuesInstruction.getFullAddress()); assertEquals((byte) 0xFF, maxValuesInstruction.getData1()); assertEquals((byte) 0xFF, maxValuesInstruction.getData2()); assertEquals((byte) 0x0F, maxValuesInstruction.getData3()); assertTrue(maxValuesInstruction.isValid()); // 测试所有最小值组合 PTZInstructionFormat minValuesInstruction = PTZInstructionBuilder.create() .address(0x000) .addPTZControl(PTZControlEnum.STOP) .horizontalSpeed(0x00) .verticalSpeed(0x00) .zoomSpeed(0x00) .build(); assertEquals(0x000, minValuesInstruction.getFullAddress()); assertEquals((byte) 0x00, minValuesInstruction.getData1()); assertEquals((byte) 0x00, minValuesInstruction.getData2()); assertEquals((byte) 0x00, minValuesInstruction.getData3()); assertTrue(minValuesInstruction.isValid()); // 测试混合边界值 PTZInstructionFormat mixedBoundaryInstruction = PTZInstructionBuilder.create() .address(0x800) // 中间值 .addCruiseControl(CruiseControlEnum.SET_CRUISE_SPEED, 255, 1, 4095) .build(); assertEquals(0x800, mixedBoundaryInstruction.getFullAddress()); assertEquals((byte) 0xFF, mixedBoundaryInstruction.getData1()); // 巡航组号最大值 assertEquals((byte) 0xFF, mixedBoundaryInstruction.getData2()); // 速度低8位 assertEquals((byte) 0x0F, mixedBoundaryInstruction.getData3()); // 速度高4位 assertTrue(mixedBoundaryInstruction.isValid()); } @Test @DisplayName("内存和性能边界测试") void testMemoryAndPerformanceBoundaries() { // 测试大量指令创建和序列化 for (int i = 0; i < 1000; i++) { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(i % 0x1000) .addPTZControl(PTZControlEnum.values()[i % PTZControlEnum.values().length]) .horizontalSpeed(i % 256) .verticalSpeed((i * 2) % 256) .zoomSpeed((i * 3) % 16) .build(); assertTrue(instruction.isValid()); // 测试序列化性能 String hex = instruction.toHexString(); assertEquals(16, hex.length()); // 测试反序列化 PTZInstructionFormat reconstructed = PTZInstructionFormat.fromHexString(hex); assertTrue(reconstructed.isValid()); assertEquals(instruction.getInstructionCode(), reconstructed.getInstructionCode()); } } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/PresetControlInstructionTest.java
gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/PresetControlInstructionTest.java
package io.github.lunasaw.gb28181.common.entity.control.instruction; import io.github.lunasaw.gb28181.common.entity.control.instruction.builder.PTZInstructionBuilder; import io.github.lunasaw.gb28181.common.entity.control.instruction.enums.PresetControlEnum; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.*; /** * 预置位控制指令生成和解析完整测试 * 验证所有预置位指令是否按照A.3.4规范正确生成 */ class PresetControlInstructionTest { @Test @DisplayName("设置预置位指令测试") void testSetPresetInstruction() { // 测试设置预置位1 PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x001) .addPresetControl(PresetControlEnum.SET_PRESET, 1) .build(); assertEquals((byte) 0x81, instruction.getInstructionCode()); assertEquals((byte) 0x00, instruction.getData1()); // 字节5固定为00H assertEquals((byte) 0x01, instruction.getData2()); // 字节6为预置位号 assertEquals(0x001, instruction.getFullAddress()); assertTrue(instruction.isValid()); // 测试设置预置位255(最大值) PTZInstructionFormat maxPresetInstruction = PTZInstructionBuilder.create() .address(0x002) .addPresetControl(PresetControlEnum.SET_PRESET, 255) .build(); assertEquals((byte) 0x81, maxPresetInstruction.getInstructionCode()); assertEquals((byte) 0x00, maxPresetInstruction.getData1()); assertEquals((byte) 0xFF, maxPresetInstruction.getData2()); // 255 = 0xFF assertTrue(maxPresetInstruction.isValid()); } @Test @DisplayName("调用预置位指令测试") void testCallPresetInstruction() { // 测试调用预置位5 PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x003) .addPresetControl(PresetControlEnum.CALL_PRESET, 5) .build(); assertEquals((byte) 0x82, instruction.getInstructionCode()); assertEquals((byte) 0x00, instruction.getData1()); // 字节5固定为00H assertEquals((byte) 0x05, instruction.getData2()); // 字节6为预置位号 assertEquals(0x003, instruction.getFullAddress()); assertTrue(instruction.isValid()); // 测试调用预置位128(中间值) PTZInstructionFormat midPresetInstruction = PTZInstructionBuilder.create() .address(0x004) .addPresetControl(PresetControlEnum.CALL_PRESET, 128) .build(); assertEquals((byte) 0x82, midPresetInstruction.getInstructionCode()); assertEquals((byte) 0x00, midPresetInstruction.getData1()); assertEquals((byte) 0x80, midPresetInstruction.getData2()); // 128 = 0x80 assertTrue(midPresetInstruction.isValid()); } @Test @DisplayName("删除预置位指令测试") void testDeletePresetInstruction() { // 测试删除预置位10 PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x005) .addPresetControl(PresetControlEnum.DELETE_PRESET, 10) .build(); assertEquals((byte) 0x83, instruction.getInstructionCode()); assertEquals((byte) 0x00, instruction.getData1()); // 字节5固定为00H assertEquals((byte) 0x0A, instruction.getData2()); // 字节6为预置位号 assertEquals(0x005, instruction.getFullAddress()); assertTrue(instruction.isValid()); // 测试删除预置位200 PTZInstructionFormat highPresetInstruction = PTZInstructionBuilder.create() .address(0x006) .addPresetControl(PresetControlEnum.DELETE_PRESET, 200) .build(); assertEquals((byte) 0x83, highPresetInstruction.getInstructionCode()); assertEquals((byte) 0x00, highPresetInstruction.getData1()); assertEquals((byte) 0xC8, highPresetInstruction.getData2()); // 200 = 0xC8 assertTrue(highPresetInstruction.isValid()); } @ParameterizedTest @DisplayName("预置位号范围测试") @ValueSource(ints = {1, 50, 100, 150, 200, 255}) void testPresetNumberRange(int presetNumber) { // 测试有效预置位号 assertTrue(PresetControlEnum.isValidPresetNumber(presetNumber)); // 测试设置预置位 PTZInstructionFormat setInstruction = PTZInstructionBuilder.create() .address(0x001) .addPresetControl(PresetControlEnum.SET_PRESET, presetNumber) .build(); assertEquals((byte) 0x81, setInstruction.getInstructionCode()); assertEquals((byte) presetNumber, setInstruction.getData2()); assertTrue(setInstruction.isValid()); // 测试调用预置位 PTZInstructionFormat callInstruction = PTZInstructionBuilder.create() .address(0x002) .addPresetControl(PresetControlEnum.CALL_PRESET, presetNumber) .build(); assertEquals((byte) 0x82, callInstruction.getInstructionCode()); assertEquals((byte) presetNumber, callInstruction.getData2()); assertTrue(callInstruction.isValid()); // 测试删除预置位 PTZInstructionFormat deleteInstruction = PTZInstructionBuilder.create() .address(0x003) .addPresetControl(PresetControlEnum.DELETE_PRESET, presetNumber) .build(); assertEquals((byte) 0x83, deleteInstruction.getInstructionCode()); assertEquals((byte) presetNumber, deleteInstruction.getData2()); assertTrue(deleteInstruction.isValid()); } @Test @DisplayName("预置位指令解析测试") void testPresetInstructionParsing() { // 创建设置预置位指令 PTZInstructionFormat originalInstruction = PTZInstructionBuilder.create() .address(0x123) .addPresetControl(PresetControlEnum.SET_PRESET, 42) .build(); // 序列化为字节数组 byte[] bytes = originalInstruction.toByteArray(); assertEquals(8, bytes.length); // 验证字节数组内容 assertEquals((byte) 0xA5, bytes[0]); // 首字节 assertEquals((byte) 0x81, bytes[3]); // 指令码 assertEquals((byte) 0x00, bytes[4]); // 数据1固定00H assertEquals((byte) 42, bytes[5]); // 预置位号 // 从字节数组重建指令 PTZInstructionFormat parsedInstruction = PTZInstructionFormat.fromByteArray(bytes); // 验证解析结果 assertEquals(originalInstruction.getFullAddress(), parsedInstruction.getFullAddress()); assertEquals(originalInstruction.getInstructionCode(), parsedInstruction.getInstructionCode()); assertEquals(originalInstruction.getData1(), parsedInstruction.getData1()); assertEquals(originalInstruction.getData2(), parsedInstruction.getData2()); assertTrue(parsedInstruction.isValid()); // 验证十六进制字符串解析 String hexString = originalInstruction.toHexString(); PTZInstructionFormat parsedFromHex = PTZInstructionFormat.fromHexString(hexString); assertEquals(originalInstruction.getInstructionCode(), parsedFromHex.getInstructionCode()); assertEquals((byte) 42, parsedFromHex.getData2()); assertTrue(parsedFromHex.isValid()); } @Test @DisplayName("预置位指令枚举映射测试") void testPresetEnumMapping() { // 测试指令码到枚举的映射 assertEquals(PresetControlEnum.SET_PRESET, PresetControlEnum.getByCode((byte) 0x81)); assertEquals(PresetControlEnum.CALL_PRESET, PresetControlEnum.getByCode((byte) 0x82)); assertEquals(PresetControlEnum.DELETE_PRESET, PresetControlEnum.getByCode((byte) 0x83)); // 测试名称到枚举的映射 assertEquals(PresetControlEnum.SET_PRESET, PresetControlEnum.getByName("设置预置位")); assertEquals(PresetControlEnum.CALL_PRESET, PresetControlEnum.getByName("调用预置位")); assertEquals(PresetControlEnum.DELETE_PRESET, PresetControlEnum.getByName("删除预置位")); // 测试无效映射 assertNull(PresetControlEnum.getByCode((byte) 0x80)); assertNull(PresetControlEnum.getByCode((byte) 0x84)); assertNull(PresetControlEnum.getByName("无效指令")); } @Test @DisplayName("预置位号验证测试") void testPresetNumberValidation() { // 测试有效范围 1-255 assertTrue(PresetControlEnum.isValidPresetNumber(1)); assertTrue(PresetControlEnum.isValidPresetNumber(255)); assertTrue(PresetControlEnum.isValidPresetNumber(128)); // 测试无效范围 assertFalse(PresetControlEnum.isValidPresetNumber(0)); // 0号预留 assertFalse(PresetControlEnum.isValidPresetNumber(256)); // 超出范围 assertFalse(PresetControlEnum.isValidPresetNumber(-1)); // 负数 assertFalse(PresetControlEnum.isValidPresetNumber(1000)); // 远超范围 } @Test @DisplayName("预置位指令格式验证测试") void testPresetInstructionFormat() { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x100) .addPresetControl(PresetControlEnum.CALL_PRESET, 99) .build(); // 验证指令格式符合A.3.4规范 assertEquals((byte) 0xA5, instruction.getHeader()); assertEquals((byte) 0x82, instruction.getInstructionCode()); assertEquals((byte) 0x00, instruction.getData1()); // 字节5固定为00H assertEquals((byte) 99, instruction.getData2()); // 字节6为预置位号1-255 assertEquals((byte) 0x00, instruction.getData3()); // 字节7高4位为0(预置位指令不使用) // 验证地址编码 assertEquals(0x100, instruction.getFullAddress()); assertEquals((byte) 0x00, instruction.getAddressLow()); assertEquals((byte) 0x01, (instruction.getCombinationCode2() & 0x0F)); assertTrue(instruction.isValid()); } @Test @DisplayName("预置位指令边界值测试") void testPresetBoundaryValues() { // 测试最小有效预置位号 PTZInstructionFormat minInstruction = PTZInstructionBuilder.create() .address(0x001) .addPresetControl(PresetControlEnum.SET_PRESET, 1) .build(); assertEquals((byte) 0x01, minInstruction.getData2()); assertTrue(minInstruction.isValid()); // 测试最大有效预置位号 PTZInstructionFormat maxInstruction = PTZInstructionBuilder.create() .address(0x001) .addPresetControl(PresetControlEnum.SET_PRESET, 255) .build(); assertEquals((byte) 0xFF, maxInstruction.getData2()); assertTrue(maxInstruction.isValid()); // 测试无效预置位号应抛出异常 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addPresetControl(PresetControlEnum.SET_PRESET, 0) .build(); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addPresetControl(PresetControlEnum.SET_PRESET, 256) .build(); }); } @Test @DisplayName("预置位指令序列化一致性测试") void testPresetSerializationConsistency() { PTZInstructionFormat original = PTZInstructionBuilder.create() .address(0x2FF) .addPresetControl(PresetControlEnum.DELETE_PRESET, 177) .build(); // 测试字节数组序列化 byte[] bytes = original.toByteArray(); PTZInstructionFormat fromBytes = PTZInstructionFormat.fromByteArray(bytes); assertEquals(original.getInstructionCode(), fromBytes.getInstructionCode()); assertEquals(original.getData2(), fromBytes.getData2()); assertEquals(original.getFullAddress(), fromBytes.getFullAddress()); // 测试十六进制序列化 String hex = original.toHexString(); PTZInstructionFormat fromHex = PTZInstructionFormat.fromHexString(hex); assertEquals(original.getInstructionCode(), fromHex.getInstructionCode()); assertEquals(original.getData2(), fromHex.getData2()); assertEquals(original.getFullAddress(), fromHex.getFullAddress()); // 验证所有版本都有效 assertTrue(original.isValid()); assertTrue(fromBytes.isValid()); assertTrue(fromHex.isValid()); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/PTZInstructionFormatValidationTest.java
gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/PTZInstructionFormatValidationTest.java
package io.github.lunasaw.gb28181.common.entity.control.instruction; import io.github.lunasaw.gb28181.common.entity.control.instruction.builder.PTZInstructionBuilder; import io.github.lunasaw.gb28181.common.entity.control.instruction.enums.*; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.*; /** * PTZ指令格式验证完整测试 * 验证指令格式是否严格按照A.3.1规范实现 */ class PTZInstructionFormatValidationTest { @Test @DisplayName("指令首字节验证测试") void testInstructionHeader() { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.STOP) .build(); // 验证首字节固定为A5H assertEquals((byte) 0xA5, instruction.getHeader()); assertEquals(PTZInstructionFormat.INSTRUCTION_HEADER, instruction.getHeader()); // 验证字节数组第一个字节 byte[] bytes = instruction.toByteArray(); assertEquals((byte) 0xA5, bytes[0]); // 验证十六进制字符串以A5开头 String hexString = instruction.toHexString(); assertTrue(hexString.startsWith("A5")); } @Test @DisplayName("组合码1验证测试") void testCombinationCode1() { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.PAN_RIGHT) .build(); // 验证版本信息为0(本标准版本1.0) assertEquals(PTZInstructionFormat.VERSION, 0x0); // 手动计算校验位验证 byte header = instruction.getHeader(); int headerHigh = (header >> 4) & 0x0F; // A5H的高4位 = AH = 10 int headerLow = header & 0x0F; // A5H的低4位 = 5H = 5 int versionInfo = PTZInstructionFormat.VERSION; // 版本信息 = 0 int expectedCheckBit = (headerHigh + headerLow + versionInfo) % 16; // (10 + 5 + 0) % 16 = 15 = FH byte combinationCode1 = instruction.getCombinationCode1(); int actualVersionInfo = (combinationCode1 >> 4) & 0x0F; int actualCheckBit = combinationCode1 & 0x0F; assertEquals(versionInfo, actualVersionInfo); assertEquals(expectedCheckBit, actualCheckBit); } @ParameterizedTest @DisplayName("地址编码验证测试") @ValueSource(ints = {0x000, 0x001, 0x123, 0x456, 0x789, 0xABC, 0xFFF}) void testAddressEncoding(int address) { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(address) .addPTZControl(PTZControlEnum.STOP) .build(); // 验证完整地址 assertEquals(address, instruction.getFullAddress()); // 验证地址低8位(字节3) byte expectedAddressLow = (byte) (address & 0xFF); assertEquals(expectedAddressLow, instruction.getAddressLow()); // 验证地址高4位(字节7低4位) byte expectedAddressHigh = (byte) ((address >> 8) & 0x0F); assertEquals(expectedAddressHigh, (instruction.getCombinationCode2() & 0x0F)); // 验证字节数组中的地址编码 byte[] bytes = instruction.toByteArray(); assertEquals(expectedAddressLow, bytes[2]); // 字节3 assertEquals(expectedAddressHigh, (bytes[6] & 0x0F)); // 字节7低4位 assertTrue(instruction.isValid()); } @Test @DisplayName("指令码验证测试") void testInstructionCode() { // 测试各种指令码 PTZControlEnum[] ptzControls = { PTZControlEnum.STOP, PTZControlEnum.PAN_LEFT, PTZControlEnum.PAN_RIGHT, PTZControlEnum.TILT_UP, PTZControlEnum.TILT_DOWN, PTZControlEnum.ZOOM_IN, PTZControlEnum.ZOOM_OUT }; for (PTZControlEnum control : ptzControls) { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x001) .addPTZControl(control) .build(); assertEquals(control.getInstructionCode(), instruction.getInstructionCode()); // 验证字节数组中的指令码(字节4) byte[] bytes = instruction.toByteArray(); assertEquals(control.getInstructionCode(), bytes[3]); assertTrue(instruction.isValid()); } // 测试FI指令码 FIControlEnum[] fiControls = { FIControlEnum.STOP, FIControlEnum.IRIS_OPEN, FIControlEnum.IRIS_CLOSE, FIControlEnum.FOCUS_NEAR, FIControlEnum.FOCUS_FAR }; for (FIControlEnum control : fiControls) { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x002) .addFIControl(control) .build(); assertEquals(control.getInstructionCode(), instruction.getInstructionCode()); // 验证字节数组中的指令码(字节4) byte[] bytes = instruction.toByteArray(); assertEquals(control.getInstructionCode(), bytes[3]); assertTrue(instruction.isValid()); } } @Test @DisplayName("数据字节验证测试") void testDataBytes() { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x123) .addPTZControl(PTZControlEnum.PAN_RIGHT) .horizontalSpeed(0x40) .verticalSpeed(0x80) .zoomSpeed(0x0F) .build(); // 验证数据1(字节5) assertEquals((byte) 0x40, instruction.getData1()); // 验证数据2(字节6) assertEquals((byte) 0x80, instruction.getData2()); // 验证数据3(字节7高4位) assertEquals((byte) 0x0F, instruction.getData3()); // 验证字节数组中的数据 byte[] bytes = instruction.toByteArray(); assertEquals((byte) 0x40, bytes[4]); // 字节5 assertEquals((byte) 0x80, bytes[5]); // 字节6 assertEquals((byte) 0x0F, (bytes[6] >> 4) & 0x0F); // 字节7高4位 assertTrue(instruction.isValid()); } @Test @DisplayName("组合码2验证测试") void testCombinationCode2() { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x3A7) // 地址高4位=3, 低8位=A7 .addPTZControl(PTZControlEnum.ZOOM_IN) .zoomSpeed(0x0C) // 数据3=C .build(); // 验证组合码2 = (数据3 << 4) | 地址高4位 = (C << 4) | 3 = C3H byte expectedCombinationCode2 = (byte) ((0x0C << 4) | (0x3A7 >> 8)); assertEquals(expectedCombinationCode2, instruction.getCombinationCode2()); // 验证字节数组中的组合码2(字节7) byte[] bytes = instruction.toByteArray(); assertEquals(expectedCombinationCode2, bytes[6]); // 验证数据3和地址高4位的提取 assertEquals((byte) 0x0C, instruction.getData3()); assertEquals(0x3A7, instruction.getFullAddress()); assertTrue(instruction.isValid()); } @Test @DisplayName("校验码计算验证测试") void testChecksumCalculation() { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x123) .addPTZControl(PTZControlEnum.PAN_RIGHT) .horizontalSpeed(0x40) .verticalSpeed(0x80) .zoomSpeed(0x0F) .build(); // 手动计算校验码 byte[] bytes = instruction.toByteArray(); int sum = 0; for (int i = 0; i < 7; i++) { sum += (bytes[i] & 0xFF); } byte expectedChecksum = (byte) (sum % 256); // 验证校验码 assertEquals(expectedChecksum, instruction.getChecksum()); assertEquals(expectedChecksum, bytes[7]); // 字节8 assertTrue(instruction.isValid()); } @Test @DisplayName("指令长度验证测试") void testInstructionLength() { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x001) .addPTZControl(PTZControlEnum.STOP) .build(); // 验证字节数组长度固定为8 byte[] bytes = instruction.toByteArray(); assertEquals(8, bytes.length); // 验证十六进制字符串长度固定为16 String hexString = instruction.toHexString(); assertEquals(16, hexString.length()); assertTrue(instruction.isValid()); } @Test @DisplayName("指令有效性验证测试") void testInstructionValidation() { // 创建有效指令 PTZInstructionFormat validInstruction = PTZInstructionBuilder.create() .address(0x100) .addPTZControl(PTZControlEnum.PAN_LEFT) .horizontalSpeed(0x60) .build(); assertTrue(validInstruction.isValid()); // 测试首字节错误的情况 byte[] invalidBytes = validInstruction.toByteArray(); invalidBytes[0] = (byte) 0xB5; // 错误的首字节 PTZInstructionFormat invalidInstruction = PTZInstructionFormat.fromByteArray(invalidBytes); assertFalse(invalidInstruction.isValid()); // 测试校验码错误的情况 byte[] wrongChecksumBytes = validInstruction.toByteArray(); wrongChecksumBytes[7] = (byte) 0x00; // 错误的校验码 PTZInstructionFormat wrongChecksumInstruction = PTZInstructionFormat.fromByteArray(wrongChecksumBytes); assertFalse(wrongChecksumInstruction.isValid()); } @Test @DisplayName("指令重计算校验码测试") void testRecalculateChecksum() { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x200) .addFIControl(FIControlEnum.IRIS_OPEN) .irisSpeed(0x90) .build(); assertTrue(instruction.isValid()); // 保存原始校验码 byte originalChecksum = instruction.getChecksum(); // 重新计算校验码 instruction.recalculateChecksum(); // 验证校验码未改变(因为指令本身没有修改) assertEquals(originalChecksum, instruction.getChecksum()); assertTrue(instruction.isValid()); } @Test @DisplayName("边界地址值验证测试") void testBoundaryAddressValues() { // 测试最小地址 0x000 PTZInstructionFormat minAddressInstruction = PTZInstructionBuilder.create() .address(0x000) .addPTZControl(PTZControlEnum.STOP) .build(); assertEquals(0x000, minAddressInstruction.getFullAddress()); assertTrue(minAddressInstruction.isValid()); // 测试最大地址 0xFFF PTZInstructionFormat maxAddressInstruction = PTZInstructionBuilder.create() .address(0xFFF) .addPTZControl(PTZControlEnum.STOP) .build(); assertEquals(0xFFF, maxAddressInstruction.getFullAddress()); assertTrue(maxAddressInstruction.isValid()); // 验证地址编码 assertEquals((byte) 0xFF, maxAddressInstruction.getAddressLow()); assertEquals((byte) 0x0F, (maxAddressInstruction.getCombinationCode2() & 0x0F)); } @Test @DisplayName("指令格式一致性验证测试") void testInstructionFormatConsistency() { // 创建各种类型的指令 PTZInstructionFormat[] instructions = { // PTZ指令 PTZInstructionBuilder.create().address(0x001).addPTZControl(PTZControlEnum.PAN_RIGHT).build(), // FI指令 PTZInstructionBuilder.create().address(0x002).addFIControl(FIControlEnum.IRIS_OPEN).build(), // 预置位指令 PTZInstructionBuilder.create().address(0x003).addPresetControl(PresetControlEnum.SET_PRESET, 10).build(), // 巡航指令 PTZInstructionBuilder.create().address(0x004).addCruiseControl(CruiseControlEnum.START_CRUISE, 1).build(), // 扫描指令 PTZInstructionBuilder.create().address(0x005).addScanControl(ScanControlEnum.START_AUTO_SCAN, 1, ScanControlEnum.ScanOperationType.START).build(), // 辅助开关指令 PTZInstructionBuilder.create().address(0x006).addAuxiliaryControl(AuxiliaryControlEnum.SWITCH_ON, 1).build() }; for (PTZInstructionFormat instruction : instructions) { // 验证所有指令都符合基本格式要求 assertEquals((byte) 0xA5, instruction.getHeader()); assertEquals(8, instruction.toByteArray().length); assertEquals(16, instruction.toHexString().length()); assertTrue(instruction.isValid()); // 验证序列化/反序列化一致性 byte[] bytes = instruction.toByteArray(); PTZInstructionFormat reconstructed = PTZInstructionFormat.fromByteArray(bytes); assertEquals(instruction.getFullAddress(), reconstructed.getFullAddress()); assertEquals(instruction.getInstructionCode(), reconstructed.getInstructionCode()); assertTrue(reconstructed.isValid()); // 验证十六进制序列化/反序列化一致性 String hex = instruction.toHexString(); PTZInstructionFormat fromHex = PTZInstructionFormat.fromHexString(hex); assertEquals(instruction.getInstructionCode(), fromHex.getInstructionCode()); assertTrue(fromHex.isValid()); } } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/ScanControlInstructionTest.java
gb28181-common/src/test/java/io/github/lunasaw/gb28181/common/entity/control/instruction/ScanControlInstructionTest.java
package io.github.lunasaw.gb28181.common.entity.control.instruction; import io.github.lunasaw.gb28181.common.entity.control.instruction.builder.PTZInstructionBuilder; import io.github.lunasaw.gb28181.common.entity.control.instruction.enums.ScanControlEnum; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.*; /** * 扫描控制指令生成和解析完整测试 * 验证所有扫描指令是否按照A.3.6规范正确生成 */ class ScanControlInstructionTest { @Test @DisplayName("开始自动扫描指令测试") void testStartAutoScanInstruction() { // 测试开始扫描组1的自动扫描 PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x001) .addScanControl(ScanControlEnum.START_AUTO_SCAN, 1, ScanControlEnum.ScanOperationType.START) .build(); assertEquals((byte) 0x89, instruction.getInstructionCode()); assertEquals((byte) 0x01, instruction.getData1()); // 字节5为扫描组号 assertEquals((byte) 0x00, instruction.getData2()); // 字节6为操作类型(开始=00H) assertEquals(0x001, instruction.getFullAddress()); assertTrue(instruction.isValid()); // 测试扫描组255 PTZInstructionFormat maxGroupInstruction = PTZInstructionBuilder.create() .address(0x002) .addScanControl(ScanControlEnum.START_AUTO_SCAN, 255, ScanControlEnum.ScanOperationType.START) .build(); assertEquals((byte) 0x89, maxGroupInstruction.getInstructionCode()); assertEquals((byte) 0xFF, maxGroupInstruction.getData1()); assertEquals((byte) 0x00, maxGroupInstruction.getData2()); assertTrue(maxGroupInstruction.isValid()); } @Test @DisplayName("设置扫描边界指令测试") void testSetScanBoundaryInstruction() { // 测试设置左边界 PTZInstructionFormat leftBoundaryInstruction = PTZInstructionBuilder.create() .address(0x003) .addScanControl(ScanControlEnum.SET_LEFT_BOUNDARY, 2, ScanControlEnum.ScanOperationType.SET_LEFT_BOUNDARY) .build(); assertEquals((byte) 0x89, leftBoundaryInstruction.getInstructionCode()); assertEquals((byte) 0x02, leftBoundaryInstruction.getData1()); // 扫描组号 assertEquals((byte) 0x01, leftBoundaryInstruction.getData2()); // 操作类型(左边界=01H) assertTrue(leftBoundaryInstruction.isValid()); // 测试设置右边界 PTZInstructionFormat rightBoundaryInstruction = PTZInstructionBuilder.create() .address(0x004) .addScanControl(ScanControlEnum.SET_RIGHT_BOUNDARY, 3, ScanControlEnum.ScanOperationType.SET_RIGHT_BOUNDARY) .build(); assertEquals((byte) 0x89, rightBoundaryInstruction.getInstructionCode()); assertEquals((byte) 0x03, rightBoundaryInstruction.getData1()); // 扫描组号 assertEquals((byte) 0x02, rightBoundaryInstruction.getData2()); // 操作类型(右边界=02H) assertTrue(rightBoundaryInstruction.isValid()); } @Test @DisplayName("设置扫描速度指令测试") void testSetScanSpeedInstruction() { // 测试设置扫描组1速度为150 PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x005) .addScanSpeedControl(1, 150) .build(); assertEquals((byte) 0x8A, instruction.getInstructionCode()); assertEquals((byte) 0x01, instruction.getData1()); // 字节5为扫描组号 assertEquals((byte) 150, instruction.getData2()); // 字节6为速度低8位 assertEquals((byte) 0x00, instruction.getData3()); // 字节7高4位为速度高4位(0) assertTrue(instruction.isValid()); // 测试大速度值:2048(0x800)= 低8位0x00 + 高4位0x08 PTZInstructionFormat highSpeedInstruction = PTZInstructionBuilder.create() .address(0x006) .addScanSpeedControl(5, 2048) .build(); assertEquals((byte) 0x8A, highSpeedInstruction.getInstructionCode()); assertEquals((byte) 0x05, highSpeedInstruction.getData1()); assertEquals((byte) 0x00, highSpeedInstruction.getData2()); // 2048 & 0xFF = 0 assertEquals((byte) 0x08, highSpeedInstruction.getData3()); // (2048 >> 8) & 0x0F = 8 assertTrue(highSpeedInstruction.isValid()); // 测试最大速度值:4095(0xFFF) PTZInstructionFormat maxSpeedInstruction = PTZInstructionBuilder.create() .address(0x007) .addScanSpeedControl(10, 4095) .build(); assertEquals((byte) 0x8A, maxSpeedInstruction.getInstructionCode()); assertEquals((byte) 0x0A, maxSpeedInstruction.getData1()); assertEquals((byte) 0xFF, maxSpeedInstruction.getData2()); // 4095 & 0xFF = 255 assertEquals((byte) 0x0F, maxSpeedInstruction.getData3()); // (4095 >> 8) & 0x0F = 15 assertTrue(maxSpeedInstruction.isValid()); } @ParameterizedTest @DisplayName("扫描组号范围测试") @ValueSource(ints = {0, 1, 50, 100, 200, 255}) void testScanGroupNumberRange(int groupNumber) { // 测试有效扫描组号 assertTrue(ScanControlEnum.isValidGroupNumber(groupNumber)); // 测试开始扫描 PTZInstructionFormat startInstruction = PTZInstructionBuilder.create() .address(0x001) .addScanControl(ScanControlEnum.START_AUTO_SCAN, groupNumber, ScanControlEnum.ScanOperationType.START) .build(); assertEquals((byte) 0x89, startInstruction.getInstructionCode()); assertEquals((byte) groupNumber, startInstruction.getData1()); assertTrue(startInstruction.isValid()); // 测试设置扫描速度 PTZInstructionFormat speedInstruction = PTZInstructionBuilder.create() .address(0x002) .addScanSpeedControl(groupNumber, 100) .build(); assertEquals((byte) 0x8A, speedInstruction.getInstructionCode()); assertEquals((byte) groupNumber, speedInstruction.getData1()); assertTrue(speedInstruction.isValid()); } @Test @DisplayName("扫描操作类型测试") void testScanOperationTypes() { // 测试所有操作类型 ScanControlEnum.ScanOperationType[] types = { ScanControlEnum.ScanOperationType.START, ScanControlEnum.ScanOperationType.SET_LEFT_BOUNDARY, ScanControlEnum.ScanOperationType.SET_RIGHT_BOUNDARY }; int[] expectedValues = {0x00, 0x01, 0x02}; for (int i = 0; i < types.length; i++) { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x001) .addScanControl(ScanControlEnum.START_AUTO_SCAN, 1, types[i]) .build(); assertEquals((byte) expectedValues[i], instruction.getData2()); assertTrue(instruction.isValid()); // 测试反向查找 assertEquals(types[i], ScanControlEnum.ScanOperationType.getByValue(expectedValues[i])); } // 测试无效操作类型 assertNull(ScanControlEnum.ScanOperationType.getByValue(0x03)); assertNull(ScanControlEnum.ScanOperationType.getByValue(-1)); } @Test @DisplayName("扫描指令解析测试") void testScanInstructionParsing() { // 创建设置扫描速度指令 PTZInstructionFormat originalInstruction = PTZInstructionBuilder.create() .address(0x123) .addScanSpeedControl(20, 777) .build(); // 序列化为字节数组 byte[] bytes = originalInstruction.toByteArray(); assertEquals(8, bytes.length); // 验证字节数组内容 assertEquals((byte) 0xA5, bytes[0]); // 首字节 assertEquals((byte) 0x8A, bytes[3]); // 指令码 assertEquals((byte) 20, bytes[4]); // 扫描组号 assertEquals((byte) (777 & 0xFF), bytes[5]); // 速度低8位 // 从字节数组重建指令 PTZInstructionFormat parsedInstruction = PTZInstructionFormat.fromByteArray(bytes); // 验证解析结果 assertEquals(originalInstruction.getFullAddress(), parsedInstruction.getFullAddress()); assertEquals(originalInstruction.getInstructionCode(), parsedInstruction.getInstructionCode()); assertEquals(originalInstruction.getData1(), parsedInstruction.getData1()); assertEquals(originalInstruction.getData2(), parsedInstruction.getData2()); assertEquals(originalInstruction.getData3(), parsedInstruction.getData3()); assertTrue(parsedInstruction.isValid()); // 验证十六进制字符串解析 String hexString = originalInstruction.toHexString(); PTZInstructionFormat parsedFromHex = PTZInstructionFormat.fromHexString(hexString); assertEquals(originalInstruction.getInstructionCode(), parsedFromHex.getInstructionCode()); assertTrue(parsedFromHex.isValid()); } @Test @DisplayName("扫描指令枚举映射测试") void testScanEnumMapping() { // 测试指令码到枚举的映射(注意:START_AUTO_SCAN、SET_LEFT_BOUNDARY、SET_RIGHT_BOUNDARY都使用0x89) assertEquals(ScanControlEnum.START_AUTO_SCAN, ScanControlEnum.getByCode((byte) 0x89)); assertEquals(ScanControlEnum.SET_SCAN_SPEED, ScanControlEnum.getByCode((byte) 0x8A)); // 测试名称到枚举的映射 assertEquals(ScanControlEnum.START_AUTO_SCAN, ScanControlEnum.getByName("开始自动扫描")); assertEquals(ScanControlEnum.SET_LEFT_BOUNDARY, ScanControlEnum.getByName("设置左边界")); assertEquals(ScanControlEnum.SET_RIGHT_BOUNDARY, ScanControlEnum.getByName("设置右边界")); assertEquals(ScanControlEnum.SET_SCAN_SPEED, ScanControlEnum.getByName("设置扫描速度")); // 测试无效映射 assertNull(ScanControlEnum.getByCode((byte) 0x8B)); assertNull(ScanControlEnum.getByName("无效指令")); } @Test @DisplayName("扫描参数验证测试") void testScanParameterValidation() { // 测试有效参数范围 assertTrue(ScanControlEnum.isValidGroupNumber(0)); assertTrue(ScanControlEnum.isValidGroupNumber(255)); assertTrue(ScanControlEnum.isValidSpeed(0)); assertTrue(ScanControlEnum.isValidSpeed(4095)); // 测试无效参数范围 assertFalse(ScanControlEnum.isValidGroupNumber(-1)); assertFalse(ScanControlEnum.isValidGroupNumber(256)); assertFalse(ScanControlEnum.isValidSpeed(-1)); assertFalse(ScanControlEnum.isValidSpeed(4096)); } @Test @DisplayName("扫描速度数据编码测试") void testScanSpeedDataEncoding() { // 测试12位速度数据的编码 int[] testSpeeds = {0, 1, 255, 256, 1024, 2048, 4095}; for (int speed : testSpeeds) { PTZInstructionFormat instruction = PTZInstructionBuilder.create() .address(0x001) .addScanSpeedControl(1, speed) .build(); // 验证速度编码 byte expectedLow = (byte) (speed & 0xFF); byte expectedHigh = (byte) ((speed >> 8) & 0x0F); assertEquals(expectedLow, instruction.getData2()); assertEquals(expectedHigh, instruction.getData3()); assertTrue(instruction.isValid()); // 验证速度解码 int decodedSpeed = (instruction.getData2() & 0xFF) | ((instruction.getData3() & 0x0F) << 8); assertEquals(speed, decodedSpeed); } } @Test @DisplayName("扫描指令异常处理测试") void testScanInstructionExceptions() { // 测试无效扫描组号 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addScanControl(ScanControlEnum.START_AUTO_SCAN, -1, ScanControlEnum.ScanOperationType.START) .build(); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addScanControl(ScanControlEnum.START_AUTO_SCAN, 256, ScanControlEnum.ScanOperationType.START) .build(); }); // 测试无效速度 assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addScanSpeedControl(1, -1) .build(); }); assertThrows(IllegalArgumentException.class, () -> { PTZInstructionBuilder.create() .address(0x001) .addScanSpeedControl(1, 4096) .build(); }); } @Test @DisplayName("扫描指令组合使用测试") void testScanInstructionCombination() { // 模拟完整的扫描设置流程 // 1. 设置左边界 PTZInstructionFormat setLeftBoundary = PTZInstructionBuilder.create() .address(0x001) .addScanControl(ScanControlEnum.SET_LEFT_BOUNDARY, 1, ScanControlEnum.ScanOperationType.SET_LEFT_BOUNDARY) .build(); // 2. 设置右边界 PTZInstructionFormat setRightBoundary = PTZInstructionBuilder.create() .address(0x001) .addScanControl(ScanControlEnum.SET_RIGHT_BOUNDARY, 1, ScanControlEnum.ScanOperationType.SET_RIGHT_BOUNDARY) .build(); // 3. 设置扫描速度 PTZInstructionFormat setSpeed = PTZInstructionBuilder.create() .address(0x001) .addScanSpeedControl(1, 300) .build(); // 4. 开始扫描 PTZInstructionFormat startScan = PTZInstructionBuilder.create() .address(0x001) .addScanControl(ScanControlEnum.START_AUTO_SCAN, 1, ScanControlEnum.ScanOperationType.START) .build(); // 验证所有指令都有效 assertTrue(setLeftBoundary.isValid()); assertTrue(setRightBoundary.isValid()); assertTrue(setSpeed.isValid()); assertTrue(startScan.isValid()); // 验证指令码 assertEquals((byte) 0x89, setLeftBoundary.getInstructionCode()); assertEquals((byte) 0x89, setRightBoundary.getInstructionCode()); assertEquals((byte) 0x8A, setSpeed.getInstructionCode()); assertEquals((byte) 0x89, startScan.getInstructionCode()); // 验证操作类型区分 assertEquals((byte) 0x01, setLeftBoundary.getData2()); assertEquals((byte) 0x02, setRightBoundary.getData2()); assertEquals((byte) 0x00, startScan.getData2()); // 验证扫描组号一致性 assertEquals((byte) 0x01, setLeftBoundary.getData1()); assertEquals((byte) 0x01, setRightBoundary.getData1()); assertEquals((byte) 0x01, setSpeed.getData1()); assertEquals((byte) 0x01, startScan.getData1()); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/package-info.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/package-info.java
/** * SIP协议交互模型 一般一端发起的模型,另一端需要xml解析 * * @author luna * 2021/8/18 */ package io.github.lunasaw.gb28181.common.entity;
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/DeviceAlarm.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/DeviceAlarm.java
package io.github.lunasaw.gb28181.common.entity; import java.util.Date; import lombok.Data; /** * "报警信息" * * @author lin */ @Data public class DeviceAlarm { /** * 数据库id */ private String id; /** * 设备Id */ private String deviceId; /** * 报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级警情 */ private String alarmPriority; /** * 报警方式 , 1为电话报警, 2为设备报警, 3为短信报警, 4为 GPS报警, 5为视频报警, 6为设备故障报警, * 7其他报警;可以为直接组合如12为电话报警或 设备报警- */ private String alarmMethod; /** * 报警时间 */ private Date alarmTime; /** * 报警内容描述 */ private String alarmDescription; /** * 经度 */ private double longitude; /** * 纬度 */ private double latitude; /** * 报警类型, * 报警方式为2时,不携带 AlarmType为默认的报警设备报警, * 携带 AlarmType取值及对应报警类型如下: * 1-视频丢失报警; * 2-设备防拆报警; * 3-存储设备磁盘满报警; * 4-设备高温报警; * 5-设备低温报警。 * 报警方式为5时,取值如下: * 1-人工视频报警; * 2-运动目标检测报警; * 3-遗留物检测报警; * 4-物体移除检测报警; * 5-绊线检测报警; * 6-入侵检测报警; * 7-逆行检测报警; * 8-徘徊检测报警; * 9-流量统计报警; * 10-密度检测报警; * 11-视频异常检测报警; * 12-快速移动报警。 * 报警方式为6时,取值下: * 1-存储设备磁盘故障报警; * 2-存储设备风扇故障报警。 */ private String alarmType; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/PresetQuery.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/PresetQuery.java
package io.github.lunasaw.gb28181.common.entity.query; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import jakarta.xml.bind.annotation.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 A.2.4 g)设备预置位查询 * <pre> * <Query> * <CmdType>PresetQuery</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * </Query> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Query") @XmlAccessorType(XmlAccessType.FIELD) public class PresetQuery extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "PresetQuery"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/package-info.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/package-info.java
/** * Contains classes that represent XML elements. * 包含设备查询的实体类的xml bean * * @author luna * @date 2023/11/20 */ package io.github.lunasaw.gb28181.common.entity.query;
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/DeviceStatusQuery.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/DeviceStatusQuery.java
package io.github.lunasaw.gb28181.common.entity.query; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import jakarta.xml.bind.annotation.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 A.2.4 a)设备状态查询请求 * <pre> * <Query> * <CmdType>DeviceStatus</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * </Query> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Query") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceStatusQuery extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "DeviceStatus"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/DeviceQuery.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/DeviceQuery.java
package io.github.lunasaw.gb28181.common.entity.query; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlRootElement; import io.github.lunasaw.gb28181.common.entity.base.DeviceBase; import lombok.Getter; import lombok.Setter; /** * <?xml version="1.0" encoding="UTF-8"?> * <Query> * <CmdType>Catalog</CmdType> * <SN>123</SN> * <DeviceID>123</DeviceID> * </Query> * @author luna */ @Getter @Setter @XmlRootElement(name = "Query") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceQuery extends DeviceBase { public DeviceQuery() { } public DeviceQuery(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/CatalogQuery.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/CatalogQuery.java
package io.github.lunasaw.gb28181.common.entity.query; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import jakarta.xml.bind.annotation.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 A.2.4 b)设备目录信息查询请求 * <pre> * <Query> * <CmdType>Catalog</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * <StartTime>2023-01-01T00:00:00</StartTime> * <EndTime>2023-12-31T23:59:59</EndTime> * </Query> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Query") @XmlAccessorType(XmlAccessType.FIELD) public class CatalogQuery extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "Catalog"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "StartTime") private String startTime; @XmlElement(name = "EndTime") private String endTime; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/DeviceInfoQuery.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/DeviceInfoQuery.java
package io.github.lunasaw.gb28181.common.entity.query; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import jakarta.xml.bind.annotation.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 A.2.4 c)设备信息查询请求 * <pre> * <Query> * <CmdType>DeviceInfo</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * </Query> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Query") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceInfoQuery extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "DeviceInfo"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/TalkQuery.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/TalkQuery.java
package io.github.lunasaw.gb28181.common.entity.query; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import jakarta.xml.bind.annotation.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 语音对讲查询 * <p> * 语音对讲功能实现中心用户与前端用户之间的一对一语音对讲功能。 * 语音对讲功能由两个独立的流程组合实现: * a)通过9.2的实时视音频点播功能,中心用户获得前端设备的实时视音频媒体流; * b)通过9.12的语音广播功能,中心用户向前端对讲设备发送实时音频媒体流。 * </p> * <pre> * <Query> * <CmdType>Talk</CmdType> * <SN>123</SN> * <DeviceID>34020000001360000001</DeviceID> * <TargetID>34020000001370000001</TargetID> * </Query> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Query") @XmlAccessorType(XmlAccessType.FIELD) public class TalkQuery extends XmlBean { /** * 命令类型:语音对讲(必选) */ @XmlElement(name = "CmdType") private final String cmdType = "Talk"; /** * 命令序列号(必选) */ @XmlElement(name = "SN") private String sn; /** * 语音输入设备的设备编码(必选) */ @XmlElement(name = "DeviceID") private String deviceId; /** * 语音输出设备的设备编码(必选) */ @XmlElement(name = "TargetID") private String targetId; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/DeviceRecordQuery.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/DeviceRecordQuery.java
package io.github.lunasaw.gb28181.common.entity.query; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import com.luna.common.date.DateUtils; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import lombok.Getter; import lombok.Setter; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.Locale; /** * <?xml version="1.0" encoding="UTF-8"?> * <Query> * <CmdType>RecordInfo</CmdType> * <SN>sn</SN> * <DeviceID>channelId</DeviceID> * <StartTime>DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(startTime)</StartTime> * <EndTime> DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(endTime)</EndTime> * <Secrecy> secrecy </Secrecy> * <Type>type</Type> * </Query> * * @author luna */ @Getter @Setter @XmlRootElement(name = "Query") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceRecordQuery extends XmlBean { @XmlElement(name = "CmdType") public String cmdType; @XmlElement(name = "SN") public String sn; @XmlElement(name = "DeviceID") public String deviceId; @XmlElement(name = "StartTime") public String startTime; @XmlElement(name = "EndTime") public String endTime; @XmlElement(name = "Secrecy") public String secrecy; /** * 大华NVR要求必须增加一个值为all的文本元素节点Type * * all(time 或 alarm 或 manual 或 all) */ @XmlElement(name = "Type") public String type; public DeviceRecordQuery() {} public DeviceRecordQuery(String cmdType, String sn, String deviceId) { this.cmdType = cmdType; this.sn = sn; this.deviceId = deviceId; } public static void main(String[] args) { DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault()).withZone(ZoneId.of("Asia/Shanghai")); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).withZone(ZoneId.of("Asia/Shanghai")); String format = dateTimeFormatter.format(formatter.parse("2023-11-11 10:10:10")); System.out.println(format); String s = DateUtils.formatTime(DateUtils.ISO8601_PATTERN, new Date()); System.out.println(s); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/AlarmQuery.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/AlarmQuery.java
package io.github.lunasaw.gb28181.common.entity.query; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import jakarta.xml.bind.annotation.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 A.2.4 e)报警查询 * <pre> * <Query> * <CmdType>Alarm</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * <StartAlarmPriority>0</StartAlarmPriority> * <EndAlarmPriority>4</EndAlarmPriority> * <AlarmMethod>12</AlarmMethod> * <AlarmType>1</AlarmType> * <StartAlarmTime>2023-01-01T00:00:00</StartAlarmTime> * <EndAlarmTime>2023-12-31T23:59:59</EndAlarmTime> * </Query> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Query") @XmlAccessorType(XmlAccessType.FIELD) public class AlarmQuery extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "Alarm"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "StartAlarmPriority") private String startAlarmPriority; @XmlElement(name = "EndAlarmPriority") private String endAlarmPriority; @XmlElement(name = "AlarmMethod") private String alarmMethod; @XmlElement(name = "AlarmType") private String alarmType; @XmlElement(name = "StartAlarmTime") private String startAlarmTime; @XmlElement(name = "EndAlarmTime") private String endAlarmTime; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/RecordInfoQuery.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/RecordInfoQuery.java
package io.github.lunasaw.gb28181.common.entity.query; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import jakarta.xml.bind.annotation.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 A.2.4 d)文件目录检索请求 * <pre> * <Query> * <CmdType>RecordInfo</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * <StartTime>2023-01-01T00:00:00</StartTime> * <EndTime>2023-12-31T23:59:59</EndTime> * <FilePath>/path/to/file</FilePath> * <Address>上海</Address> * <Secrecy>0</Secrecy> * <Type>all</Type> * <RecorderID>recorder1</RecorderID> * <IndistinctQuery>0</IndistinctQuery> * </Query> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Query") @XmlAccessorType(XmlAccessType.FIELD) public class RecordInfoQuery extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "RecordInfo"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "StartTime") private String startTime; @XmlElement(name = "EndTime") private String endTime; @XmlElement(name = "FilePath") private String filePath; @XmlElement(name = "Address") private String address; @XmlElement(name = "Secrecy") private Integer secrecy; @XmlElement(name = "Type") private String type; @XmlElement(name = "RecorderID") private String recorderId; @XmlElement(name = "IndistinctQuery") private String indistinctQuery; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/DeviceAlarmQuery.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/DeviceAlarmQuery.java
package io.github.lunasaw.gb28181.common.entity.query; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import lombok.Getter; import lombok.Setter; /** * <?xml version="1.0" encoding="UTF-8"?> * <Query> * <CmdType>Alarm</CmdType> * <SN>217408</SN> * <DeviceID>123</DeviceID> * <StartAlarmPriority>12312</StartAlarmPriority> * <EndAlarmPriority>123</EndAlarmPriority> * <AlarmMethod>alarmMethod</AlarmMethod> * <AlarmType>alarmType</AlarmType> * <StartAlarmTime>startTime</StartAlarmTime> * <EndAlarmTime>endTime</EndAlarmTime> * </Query> * * @author luna */ @Getter @Setter @XmlRootElement(name = "Query") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceAlarmQuery extends XmlBean { @XmlElement(name = "CmdType") public String cmdType; @XmlElement(name = "SN") public String sn; @XmlElement(name = "DeviceID") public String deviceId; @XmlElement(name = "StartTime") public String startTime; @XmlElement(name = "EndTime") public String endTime; @XmlElement(name = "StartAlarmPriority") public String startAlarmPriority; /** * */ @XmlElement(name = "endAlarmPriority") public String endAlarmPriority; @XmlElement(name = "AlarmType") public String alarmType; @XmlElement(name = "AlarmMethod") public String alarmMethod; public DeviceAlarmQuery() {} public DeviceAlarmQuery(String cmdType, String sn, String deviceId) { this.cmdType = cmdType; this.sn = sn; this.deviceId = deviceId; } public static void main(String[] args) { } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/DeviceConfigDownload.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/DeviceConfigDownload.java
package io.github.lunasaw.gb28181.common.entity.query; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import io.github.lunasaw.gb28181.common.entity.base.DeviceBase; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * * <?xml version="1.0" encoding="UTF-8"?> * <Control> * <CmdType>DeviceConfig</CmdType> * <SN>150959</SN> * <DeviceID>channelId</DeviceID> * <BasicParam> * <Name>name</Name> * <Expiration>30</Expiration> * <HeartBeatInterval>300</HeartBeatInterval> * <HeartBeatCount>300</HeartBeatCount> * </BasicParam> * </Control> * * @author luna */ @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Query") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceConfigDownload extends DeviceBase { /** * 查询配置参数类型(必选),可查询的配 置 类 型 包 括 * 基 本 参 数 配 置:BasicParam, * 视 频 参数范围:VideoParamOpt,SVAC * 编 码 配 置:SVACEncodeConfig,SVAC * 解 码 配 置:SVACDe-codeConfig。 * 可同时查询多个配置类型,各类型以“/”分隔,可返回与查询 * SN 值相同的多个响应,每个响应对应一个配置类型 */ @XmlElement(name = "ConfigType") public String configType; public DeviceConfigDownload(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/MobilePositionQuery.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/MobilePositionQuery.java
package io.github.lunasaw.gb28181.common.entity.query; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import jakarta.xml.bind.annotation.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 A.2.4 h)移动设备位置数据查询 * <pre> * <Query> * <CmdType>MobilePosition</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * <Interval>5</Interval> * </Query> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Query") @XmlAccessorType(XmlAccessType.FIELD) public class MobilePositionQuery extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "MobilePosition"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "Interval") private Integer interval; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/DeviceMobileQuery.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/DeviceMobileQuery.java
package io.github.lunasaw.gb28181.common.entity.query; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import lombok.Getter; import lombok.Setter; /** * 设备移动位置查询 * @author luna */ @Getter @Setter @XmlRootElement(name = "Query") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceMobileQuery extends XmlBean { @XmlElement(name = "CmdType") public String cmdType; @XmlElement(name = "SN") public String sn; @XmlElement(name = "DeviceID") public String deviceId; @XmlElement(name = "interval") private String Interval; public DeviceMobileQuery() { } public DeviceMobileQuery(String cmdType, String sn, String deviceId) { this.cmdType = cmdType; this.sn = sn; this.deviceId = deviceId; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/ConfigDownloadQuery.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/query/ConfigDownloadQuery.java
package io.github.lunasaw.gb28181.common.entity.query; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import jakarta.xml.bind.annotation.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 A.2.4 f)设备配置查询 * <pre> * <Query> * <CmdType>ConfigDownload</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * <ConfigType>BasicParam/VideoParamOpt</ConfigType> * </Query> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Query") @XmlAccessorType(XmlAccessType.FIELD) public class ConfigDownloadQuery extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "ConfigDownload"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "ConfigType") private String configType; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/base/package-info.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/base/package-info.java
/** * Base classes for SIP entities. * 包含设备基础的实体类的xml bean * * @author luna * @date 2023/11/20 */ package io.github.lunasaw.gb28181.common.entity.base;
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/base/DeviceBase.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/base/DeviceBase.java
package io.github.lunasaw.gb28181.common.entity.base; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import lombok.Getter; import lombok.Setter; /** * @author luna */ @Getter @Setter @XmlAccessorType(XmlAccessType.FIELD) public abstract class DeviceBase extends XmlBean { @XmlElement(name = "CmdType") private String cmdType; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; public DeviceBase() { } public DeviceBase(String cmdType, String sn, String deviceId) { this.cmdType = cmdType; this.sn = sn; this.deviceId = deviceId; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/xml/package-info.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/xml/package-info.java
/** * Contains classes that represent XML elements. * * @author luna * @date 2023/11/20 */ package io.github.lunasaw.gb28181.common.entity.xml;
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/xml/XmlBean.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/xml/XmlBean.java
package io.github.lunasaw.gb28181.common.entity.xml; import java.io.StringReader; import java.io.StringWriter; import jakarta.xml.bind.JAXBContext; import jakarta.xml.bind.Marshaller; import jakarta.xml.bind.Unmarshaller; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import lombok.*; /** * @author luna * @date 2023/10/12 */ @Getter @Setter @XmlAccessorType(XmlAccessType.NONE) @AllArgsConstructor @NoArgsConstructor public class XmlBean { /** * 字符集, 支持 UTF-8 与 GB2312 */ private String charset = "UTF-8"; @SneakyThrows @Override public String toString() { JAXBContext jaxbContext = JAXBContext.newInstance(this.getClass()); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, charset); StringWriter writer = new StringWriter(); marshaller.marshal(this, writer); return writer.toString(); } @SneakyThrows public static <T> Object parseObj(String xmlStr, Class<T> clazz) { JAXBContext jaxbContext = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); return unmarshaller.unmarshal(new StringReader(xmlStr)); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/utils/PtzCmdEnum.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/utils/PtzCmdEnum.java
package io.github.lunasaw.gb28181.common.entity.utils; import java.util.HashMap; import java.util.Map; /** * 枚举类,表示不同的云台控制命令 */ public enum PtzCmdEnum { // 向左移动 LEFT("left", 2), // 向右移动 RIGHT("right", 1), // 向上移动 UP("up", 8), // 向下移动 DOWN("down", 4), // 向左上移动 UPLEFT("upleft", 10), // 向右上移动 UPRIGHT("upright", 9), // 向左下移动 DOWNLEFT("downleft", 6), // 向右下移动 DOWNRIGHT("downright", 5), // 放大 ZOOMIN("zoomin", 16), // 缩小 ZOOMOUT("zoomout", 32); // 命令的字符串表示 private String command; // 命令的数值编码 private int cmdCode; // 构造方法,私有化 private PtzCmdEnum(String command, int cmdCode) { this.command = command; this.cmdCode = cmdCode; } // 获取命令的字符串表示 public String getCommand() { return command; } // 获取命令的数值编码 public int getCmdCode() { return cmdCode; } // 用于存储命令和枚举值的映射关系 private static Map<String, PtzCmdEnum> map = new HashMap<>(); // 静态代码块,初始化映射关系 static { for (PtzCmdEnum e : PtzCmdEnum.values()) { map.put(e.getCommand(), e); } } // 根据命令的字符串表示,获取对应的枚举值 public static PtzCmdEnum getByCommand(String command) { return map.get(command); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/utils/PtzUtils.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/utils/PtzUtils.java
package io.github.lunasaw.gb28181.common.entity.utils; public class PtzUtils { public static String getPtzCmd(String ptzCmd, int speed) { return getPtzCmd(PtzCmdEnum.getByCommand(ptzCmd), speed); } public static String getPtzCmd(PtzCmdEnum ptzCmdEnum, int speed) { return getPtzCmd(ptzCmdEnum.getCmdCode(), speed, speed, speed); } /** * 获取控制命令代码 * * @param cmdCode 命令code * @param horizonSpeed 水平速度 * @param verticalSpeed 垂直速度 * @param zoomSpeed 缩放速度 * @return */ public static String getPtzCmd(int cmdCode, int horizonSpeed, int verticalSpeed, int zoomSpeed) { StringBuilder builder = new StringBuilder("A50F01"); String strTmp = String.format("%02X", cmdCode); builder.append(strTmp, 0, 2); strTmp = String.format("%02X", horizonSpeed); builder.append(strTmp, 0, 2); strTmp = String.format("%02X", verticalSpeed); builder.append(strTmp, 0, 2); //优化zoom变倍速率 if ((zoomSpeed > 0) && (zoomSpeed < 16)) { zoomSpeed = 16; } strTmp = String.format("%X", zoomSpeed); builder.append(strTmp, 0, 1).append("0"); //计算校验码 int checkCode = (0XA5 + 0X0F + 0X01 + cmdCode + horizonSpeed + verticalSpeed + (zoomSpeed & 0XF0)) % 0X100; strTmp = String.format("%02X", checkCode); builder.append(strTmp, 0, 2); return builder.toString(); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/utils/GbUtil.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/utils/GbUtil.java
package io.github.lunasaw.gb28181.common.entity.utils; import org.springframework.util.StringUtils; /** * @author weidian */ public class GbUtil { public static String generateGbCode(Long id) { return generateGbCode("127.0.0.1", id); } public static String generateGbCode(String ip, Long id) { if (StringUtils.isEmpty(ip) || null == id) { return null; } // 将nvrId转成10位数字 return getAreaCodeByIp(ip) + String.format("%010d", id); } public static String generateGbCode(String ip, String id) { if (StringUtils.isEmpty(ip) || null == id) { return null; } // 将nvrId转成10位数字 return getAreaCodeByIp(ip) + id; } public static String getAreaCodeByIp(String ip) { /** * 33010602 (浙江杭州西湖区) 01(社区) 118 (NVR设备) 7(internel) 000001 (设备编码) * * 33010602011187000001 */ return "3301060201"; } public static void main(String[] args) { System.out.println(generateGbCode("111", 2345L)); } public static String getAreaByGbCode(String GbCode) { return StringUtils.isEmpty(GbCode) || GbCode.length() < 10 ? null : GbCode.substring(0, 10); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/DeviceOtherUpdateNotify.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/DeviceOtherUpdateNotify.java
package io.github.lunasaw.gb28181.common.entity.notify; import java.util.List; import jakarta.xml.bind.annotation.*; import org.assertj.core.util.Lists; import io.github.lunasaw.gb28181.common.entity.base.DeviceBase; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * <?xml version="1.0" encoding="UTF-8"?> * <Notify> * <CmdType>Catalog</CmdType> * <SN>422214</SN> * <DeviceID>device_001</DeviceID> * <SumNum>1</SumNum> * <DeviceList Num="1"> * <Item> * <DeviceID>33010602011187000001</DeviceID> * <Event>Event</Event> * </Item> * </DeviceList> * </Notify> * * @author luna */ @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Notify") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceOtherUpdateNotify extends DeviceBase { @XmlElement(name = "SumNum") private int sumNum; @XmlElement(name = "Item") @XmlElementWrapper(name = "DeviceList") private List<OtherItem> deviceItemList; @Getter @Setter @XmlRootElement(name = "Item") @XmlAccessorType(XmlAccessType.FIELD) public static class OtherItem { @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "Event") private String event; } public DeviceOtherUpdateNotify(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); } public static void main(String[] args) { DeviceOtherUpdateNotify deviceUpdateNotify = new DeviceOtherUpdateNotify(); deviceUpdateNotify.setDeviceItemList(Lists.newArrayList()); deviceUpdateNotify.setSumNum(1); System.out.println(deviceUpdateNotify); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/package-info.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/package-info.java
/** * Contains all the SIP NOTIFY message related classes. * 包含设备通知的实体类的xml bean * * @author luna * @date 2023/11/20 */ package io.github.lunasaw.gb28181.common.entity.notify;
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/MediaStatusNotify.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/MediaStatusNotify.java
package io.github.lunasaw.gb28181.common.entity.notify; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import io.github.lunasaw.gb28181.common.entity.base.DeviceBase; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * <?xml version="1.0" encoding="UTF-8"?> * <Notify> * <CmdType>MediaStatus</CmdType> * <SN>226063</SN> * <DeviceID>12312</DeviceID> * <NotifyType>121</NotifyType> * </Notify> * @author luna */ @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Notify") @XmlAccessorType(XmlAccessType.FIELD) public class MediaStatusNotify extends DeviceBase { @XmlElement(name = "NotifyType") private String notifyType; public MediaStatusNotify(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/DeviceKeepLiveNotify.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/DeviceKeepLiveNotify.java
package io.github.lunasaw.gb28181.common.entity.notify; import io.github.lunasaw.gb28181.common.entity.base.DeviceBase; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * <?xml version="1.0" encoding="UTF-8"?> * <Notify> * <CmdType>Keepalive</CmdType> * <SN>340917</SN> * <DeviceID>parentPlatform.getDeviceGBId()</DeviceID> * <Status>OK</Status> * </Notify> * * @author luna */ @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Notify") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceKeepLiveNotify extends DeviceBase { @XmlElement(name = "CmdType") private String cmdType = "Keepalive"; @XmlElement(name = "Status") public String status; public DeviceKeepLiveNotify(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); } public static void main(String[] args) { DeviceKeepLiveNotify deviceKeepLiveNotify = new DeviceKeepLiveNotify(); deviceKeepLiveNotify.setStatus("OK"); System.out.println(deviceKeepLiveNotify); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/DeviceUpdateItem.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/DeviceUpdateItem.java
package io.github.lunasaw.gb28181.common.entity.notify; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import io.github.lunasaw.gb28181.common.entity.response.DeviceCatalog; import lombok.Getter; import lombok.Setter; /** * @author luna * @date 2023/10/15 */ @Getter @Setter @XmlRootElement(name = "Item") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceUpdateItem extends DeviceCatalog { @XmlElement(name = "Event") private String event; public static void main(String[] args) { } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/DeviceAlarmNotify.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/DeviceAlarmNotify.java
package io.github.lunasaw.gb28181.common.entity.notify; import com.luna.common.date.DateUtils; import io.github.lunasaw.gb28181.common.entity.enums.CmdTypeEnum; import io.github.lunasaw.gb28181.common.entity.response.DeviceItem; import io.github.lunasaw.gb28181.common.entity.DeviceAlarm; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * <?xml version="1.0" encoding="UTF-8"?> * <Notify> * <CmdType>Alarm</CmdType> * <SN>744523</SN> * <DeviceID>2133</DeviceID> * <AlarmPriority>AlarmPriority</AlarmPriority> * <AlarmMethod>deviceAlarm.getAlarmMethod()</AlarmMethod> * <AlarmTime>DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(deviceAlarm.getAlarmTime())</AlarmTime> * <AlarmDescription>deviceAlarm.getAlarmDescription() </AlarmDescription> * <Longitude>deviceAlarm.getLongitude()</Longitude> * <Latitude>deviceAlarm.getLatitude() </Latitude> * <info> * <AlarmType>deviceAlarm.getAlarmType() </AlarmType> * </info> * </Notify> * * @author luna */ @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Notify") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceAlarmNotify extends XmlBean { @XmlElement(name = "CmdType") public String cmdType = CmdTypeEnum.ALARM.getType(); @XmlElement(name = "SN") public String sn; @XmlElement(name = "DeviceID") public String deviceId; @XmlElement(name = "AlarmPriority") public String alarmPriority; @XmlElement(name = "AlarmMethod") public String alarmMethod; /** * ISO8601 */ @XmlElement(name = "AlarmTime") public String alarmTime; /** * 经度 */ @XmlElement(name = "Longitude") public String longitude; /** * 纬度 */ @XmlElement(name = "Latitude") public String latitude; @XmlElement(name = "Info") private AlarmInfo info; public DeviceAlarmNotify(String cmdType, String sn, String deviceId) { this.cmdType = cmdType; this.sn = sn; this.deviceId = deviceId; } public static void main(String[] args) { DeviceAlarmNotify deviceCatalog = new DeviceAlarmNotify(); deviceCatalog.setDeviceId("123"); DeviceItem deviceItem = new DeviceItem(); deviceItem.setAddress("!23"); System.out.println(deviceCatalog); } public DeviceAlarmNotify setAlarm(DeviceAlarm deviceAlarm) { setAlarmPriority(deviceAlarm.getAlarmPriority()); setAlarmMethod(deviceAlarm.getAlarmMethod()); setAlarmTime(DateUtils.formatTime(DateUtils.ISO8601_PATTERN, deviceAlarm.getAlarmTime())); setLongitude(String.valueOf(deviceAlarm.getLongitude())); setLatitude(String.valueOf(deviceAlarm.getLatitude())); setInfo(new AlarmInfo(deviceAlarm.getAlarmType())); return this; } @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Info") @XmlAccessorType(XmlAccessType.FIELD) public static class AlarmInfo { @XmlElement(name = "AlarmType") public String alarmType; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/MobilePositionNotify.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/MobilePositionNotify.java
package io.github.lunasaw.gb28181.common.entity.notify; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import io.github.lunasaw.gb28181.common.entity.base.DeviceBase; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * <?xml version="1.0" encoding="UTF-8"?> * <Notify> * <CmdType>MobilePosition</CmdType> * <SN>383451</SN> * <DeviceID>123</DeviceID> * <Time>gpsMsgInfo.getTime() </Time> * <Longitude> gpsMsgInfo.getLng() </Longitude> * <Latitude>gpsMsgInfo.getLat() </Latitude> * <Speed>gpsMsgInfo.getSpeed()</Speed> * <Direction>gpsMsgInfo.getDirection()</Direction> * <Altitude>gpsMsgInfo.getAltitude()</Altitude> * </Notify> * * @author luna */ @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Notify") @XmlAccessorType(XmlAccessType.FIELD) public class MobilePositionNotify extends DeviceBase { /** * 产生通知时间(必选) */ @XmlElement(name = "Time") private String time; /** * 经度(必选)- GB28181标准要求double类型 */ @XmlElement(name = "Longitude") private Double longitude; /** * 纬度(必选)- GB28181标准要求double类型 */ @XmlElement(name = "Latitude") private Double latitude; /** * 速度,单位:km/h(可选)- GB28181标准要求double类型 */ @XmlElement(name = "Speed") private Double speed; /** * 方向,取值为当前摄像头方向与正北方的顺时针夹角,取值范围0°~360°,单位:(°)(可选) * GB28181标准要求double类型 */ @XmlElement(name = "Direction") private Double direction; /** * 海拔高度,单位:m(可选)- GB28181标准要求double类型 */ @XmlElement(name = "Altitude") private Double altitude; public MobilePositionNotify(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/KeepaliveNotify.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/KeepaliveNotify.java
package io.github.lunasaw.gb28181.common.entity.notify; import jakarta.xml.bind.annotation.*; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import java.util.List; /** * GB28181协议 A.2.5 a)状态信息报送 * <pre> * <Notify> * <CmdType>Keepalive</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * <Status>OK</Status> * <Info> * <DeviceID>34020000001320000002</DeviceID> * <DeviceID>34020000001320000003</DeviceID> * </Info> * </Notify> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Notify") @XmlAccessorType(XmlAccessType.FIELD) public class KeepaliveNotify extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "Keepalive"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "Status") private String status; @XmlElementWrapper(name = "Info") @XmlElement(name = "DeviceID") private List<String> infoDeviceIds; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/DeviceBroadcastNotify.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/DeviceBroadcastNotify.java
package io.github.lunasaw.gb28181.common.entity.notify; import io.github.lunasaw.gb28181.common.entity.base.DeviceBase; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 A.2.5 d)语音广播通知 * <p> * 语音广播功能实现用户通过语音输入设备向前端语音输出设备的语音广播。 * </p> * <pre> * <Notify> * <CmdType>Broadcast</CmdType> * <SN>992</SN> * <SourceID>31010400001360000001</SourceID> * <TargetID>31010403001370002272</TargetID> * </Notify> * </pre> * @author luna */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Notify") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceBroadcastNotify extends DeviceBase { /** * 语音输入设备的设备编码(必选) */ @XmlElement(name = "SourceID") private String sourceId; /** * 语音输出设备的设备编码(必选) */ @XmlElement(name = "TargetID") private String targetId; public DeviceBroadcastNotify(String cmdType, String sn, String deviceId, String sourceId, String targetId) { super(cmdType, sn, deviceId); this.sourceId = sourceId; this.targetId = targetId; } /** * 兼容性构造函数 * @deprecated 请使用完整的构造函数 */ @Deprecated public DeviceBroadcastNotify(String type, String fromUserId, String toUserId) { super(type, null, null); this.sourceId = fromUserId; this.targetId = toUserId; } /** * 兼容性构造函数 * @deprecated 请使用完整的构造函数 */ @Deprecated public DeviceBroadcastNotify(String cmdType, String sourceId, String targetId, String deviceId) { super(cmdType, null, deviceId); this.sourceId = sourceId; this.targetId = targetId; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/DeviceUpdateNotify.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/notify/DeviceUpdateNotify.java
package io.github.lunasaw.gb28181.common.entity.notify; import jakarta.xml.bind.annotation.*; import io.github.lunasaw.gb28181.common.entity.base.DeviceBase; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.assertj.core.util.Lists; import java.util.List; /** * <?xml version="1.0" encoding="UTF-8"?> * <Notify> * <CmdType>Catalog</CmdType> * <SN>422214</SN> * <DeviceID>device_001</DeviceID> * <SumNum>1</SumNum> * <DeviceList Num="1"> * <Item> * <DeviceID>33010602011187000001</DeviceID> * <Name>Channel 1</Name> * <ParentID></ParentID> * <Parental>0</Parental> * <Manufacturer>ABC Inc.</Manufacturer> * <Secrecy></Secrecy> * <RegisterWay>1</RegisterWay> * <Status>ON</Status> * <Model>Model 123</Model> * <Owner> John Doe</Owner> * <CivilCode>123456</CivilCode> * <Address>123 Main St.</Address> * <Event>Event</Event> * </Item> * </DeviceList> * </Notify> * @author luna */ @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Notify") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceUpdateNotify extends DeviceBase { @XmlElement(name = "SumNum") private int sumNum; @XmlElement(name = "Item") @XmlElementWrapper(name = "DeviceList") private List<DeviceUpdateItem> deviceItemList; public DeviceUpdateNotify(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); } public static void main(String[] args) { DeviceUpdateNotify deviceUpdateNotify = new DeviceUpdateNotify(); deviceUpdateNotify.setDeviceId("123123"); DeviceUpdateItem deviceUpdateItem = new DeviceUpdateItem(); deviceUpdateItem.setDeviceId("33010602011187000001"); deviceUpdateItem.setName("Channel 1"); deviceUpdateItem.setParentId(null); deviceUpdateItem.setParental(0); deviceUpdateItem.setManufacturer("ABC Inc."); deviceUpdateItem.setSecrecy(0); deviceUpdateItem.setRegisterWay(1); deviceUpdateItem.setStatus("ON"); deviceUpdateItem.setModel("model"); deviceUpdateItem.setOwner("John Dow"); deviceUpdateItem.setCivilCode("123456"); deviceUpdateItem.setEvent("event"); deviceUpdateNotify.setDeviceItemList(Lists.newArrayList(deviceUpdateItem)); deviceUpdateNotify.setSumNum(1); System.out.println(deviceUpdateNotify); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceSubscribe.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceSubscribe.java
package io.github.lunasaw.gb28181.common.entity.response; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import io.github.lunasaw.gb28181.common.entity.base.DeviceBase; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * <?xml version="1.0" encoding="UTF-8"?> * <Response> * <CmdType>Catalog</CmdType> * <SN>sn</SN> * <DeviceID>channelId</DeviceID> * <Result>OK</Result> * </Response> * * @author luna */ @Getter @Setter @NoArgsConstructor @XmlRootElement(name = "Response") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceSubscribe extends DeviceBase { /** * OK */ @XmlElement(name = "Result") private String Result = "OK"; public DeviceSubscribe(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/TalkResponse.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/TalkResponse.java
package io.github.lunasaw.gb28181.common.entity.response; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import jakarta.xml.bind.annotation.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 语音对讲应答 * <p> * 语音对讲功能的应答响应,表示对讲请求的处理结果。 * </p> * <pre> * <Response> * <CmdType>Talk</CmdType> * <SN>123</SN> * <DeviceID>34020000001360000001</DeviceID> * <Result>OK</Result> * </Response> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Response") @XmlAccessorType(XmlAccessType.FIELD) public class TalkResponse extends XmlBean { /** * 命令类型:语音对讲(必选) */ @XmlElement(name = "CmdType") private final String cmdType = "Talk"; /** * 命令序列号(必选) */ @XmlElement(name = "SN") private String sn; /** * 语音输出设备的设备编码(必选) */ @XmlElement(name = "DeviceID") private String deviceId; /** * 执行结果标志(必选) * OK - 对讲建立成功 * ERROR - 对讲建立失败 */ @XmlElement(name = "Result") private String result; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceConfigResponse.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceConfigResponse.java
package io.github.lunasaw.gb28181.common.entity.response; import jakarta.xml.bind.annotation.*; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 A.2.6 i)设备配置应答 * <pre> * <Response> * <CmdType>DeviceConfig</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * <Result>OK</Result> * </Response> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Response") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceConfigResponse extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "DeviceConfig"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "Result") private String result; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceInfoResponse.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceInfoResponse.java
package io.github.lunasaw.gb28181.common.entity.response; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import jakarta.xml.bind.annotation.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import java.util.List; /** * GB28181协议 A.2.6 f)设备信息查询应答 * <pre> * <Response> * <CmdType>DeviceInfo</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * <DeviceName>摄像头1</DeviceName> * <Result>OK</Result> * <Manufacturer>海康</Manufacturer> * <Model>DS-2CD3T</Model> * <Firmware>V5.5.0</Firmware> * <Channel>4</Channel> * <Info>扩展信息</Info> * </Response> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Response") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceInfoResponse extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "DeviceInfo"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "DeviceName") private String deviceName; @XmlElement(name = "Result") private String result; @XmlElement(name = "Manufacturer") private String manufacturer; @XmlElement(name = "Model") private String model; @XmlElement(name = "Firmware") private String firmware; @XmlElement(name = "Channel") private Integer channel; @XmlElement(name = "Info") private List<String> info; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/package-info.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/package-info.java
/** * Contains all the response classes. * 包含设备响应的实体类的xml bean * * @author luna * @date 2023/11/20 */ package io.github.lunasaw.gb28181.common.entity.response;
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/BroadcastResponse.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/BroadcastResponse.java
package io.github.lunasaw.gb28181.common.entity.response; import jakarta.xml.bind.annotation.*; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 A.2.6 1)语音广播应答 * <pre> * <Response> * <CmdType>Broadcast</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * <Result>OK</Result> * </Response> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Response") @XmlAccessorType(XmlAccessType.FIELD) public class BroadcastResponse extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "Broadcast"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "Result") private String result; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceCatalog.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceCatalog.java
package io.github.lunasaw.gb28181.common.entity.response; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import lombok.Getter; import lombok.Setter; /** * @author luna * @date 2023/10/15 */ @Getter @Setter @XmlRootElement(name = "Item") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceCatalog extends XmlBean { /** * 设备/区域/系(必选) * 通道ID */ @XmlElement(name = "DeviceID") private String deviceId; /** * 设备/区域/系(必选) */ @XmlElement(name = "Name") private String name; /** * 当为设备时,设备厂商(必选) */ @XmlElement(name = "Manufacturer") private String manufacturer; /** * 当为设备时,设备型号(必选) */ @XmlElement(name = "Model") private String model; /** * 当为设备时,设备归属(必选) */ @XmlElement(name = "Owner") private String owner; /** * 行政区域(必选) */ @XmlElement(name = "CivilCode") private String civilCode; /** * 当为设备时,安装地址(必选) */ @XmlElement(name = "Address") private String address; /** * 当为设备时,是否有子设备 (必选)1有,0没有 */ @XmlElement(name = "Parental") private int parental = 0; /** * 父设备/区域/系统ID(必选) */ @XmlElement(name = "ParentID") private String parentId; /** * 信令安全模式(可选)缺省为0:不采用;2:S/MIME 签名方式;3:S/ MIME加密签名同时采用方式;4:数字摘要方式 */ @XmlElement(name = "SafetyWay") private int safetyWay = 0; /** * 注册方式(必选)缺省为1;1:符合IETFRFC3261标准的认证注册模 式;2:基于口令的双向认证注册模式;3:基于数字证书的双向认证注册模式 */ @XmlElement(name = "RegisterWay") private int registerWay = 1; /** * 设备状态(必选) */ @XmlElement(name = "Status") private String status; /** * 保密属性(必选)缺省为0 :不涉密,1:涉密 */ @XmlElement(name = "Secrecy") private int secrecy = 0; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceStatusResponse.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceStatusResponse.java
package io.github.lunasaw.gb28181.common.entity.response; import jakarta.xml.bind.annotation.*; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 A.2.6 g)设备状态信息查询应答 * <pre> * <Response> * <CmdType>DeviceStatus</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * <Result>OK</Result> * <Online>ONLINE</Online> * <Status>OK</Status> * <Reason>无</Reason> * <Encode>ON</Encode> * <Record>OFF</Record> * <DeviceTime>2023-12-01T10:30:00</DeviceTime> * </Response> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Response") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceStatusResponse extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "DeviceStatus"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "Result") private String result; @XmlElement(name = "Online") private String online; @XmlElement(name = "Status") private String status; @XmlElement(name = "Reason") private String reason; @XmlElement(name = "Encode") private String encode; @XmlElement(name = "Record") private String record; @XmlElement(name = "DeviceTime") private String deviceTime; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceControlResponse.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceControlResponse.java
package io.github.lunasaw.gb28181.common.entity.response; import jakarta.xml.bind.annotation.*; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 A.2.6 a)设备控制应答 * <pre> * <Response> * <CmdType>DeviceControl</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * <Result>OK</Result> * </Response> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Response") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceControlResponse extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "DeviceControl"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "Result") private String result; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceRecord.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceRecord.java
package io.github.lunasaw.gb28181.common.entity.response; import java.util.List; import io.github.lunasaw.gb28181.common.entity.enums.CmdTypeEnum; import jakarta.xml.bind.annotation.*; import io.github.lunasaw.gb28181.common.entity.base.DeviceBase; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * <?xml version="1.0" encoding="UTF-8"?> * <Response> * <CmdType>RecordInfo</CmdType> * <SN>740143</SN> * <DeviceID>33010602010002719420</DeviceID> * <SumNum>130</SumNum> * <RecordList Num="130"> * <Item> * <DeviceID>null</DeviceID> * <Name>null</Name> * <StartTime>2023-10-16T00:05:00</StartTime> * <EndTime>2023-10-16T00:10:03</EndTime> * <Secrecy>0</Secrecy> * <Type>null</Type> * <FileSize>6245911</FileSize> * <FilePath>/home/www/ZLMediaKit/release/linux/Debug/www/record/onvif/037a00020053fafd470f__D01_CH01_Main/2023-10-16/000500-001003.mp4</FilePath> * </Item> * </RecordList> * </Response> * * @author luna */ @Getter @Setter @NoArgsConstructor @XmlRootElement(name = "Response") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceRecord extends DeviceBase { @XmlElement(name = "CmdType") private String cmdType = CmdTypeEnum.RECORD_INFO.getType(); /** * 总数 */ @XmlElement(name = "SumNum") private int sumNum; /** * "ONLINE":"OFFLINE" */ @XmlElement(name = "Item") @XmlElementWrapper(name = "RecordList") private List<RecordItem> recordList; public DeviceRecord(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); } @Getter @Setter @XmlRootElement(name = "Item") @XmlAccessorType(XmlAccessType.FIELD) public static class RecordItem { @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "Name") private String name; /** * ISO8601格式 */ @XmlElement(name = "StartTime") private String startTime; /** * ISO8601格式 */ @XmlElement(name = "EndTime") private String endTime; @XmlElement(name = "Secrecy") private String secrecy; @XmlElement(name = "Type") private String type; @XmlElement(name = "FileSize") private String fileSize; @XmlElement(name = "FilePath") private String filePath; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/PresetQueryResponse.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/PresetQueryResponse.java
package io.github.lunasaw.gb28181.common.entity.response; import jakarta.xml.bind.annotation.*; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import java.util.List; /** * GB28181协议 A.2.6 k)设备预置位查询应答 * <pre> * <Response> * <CmdType>PresetQuery</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * <PresetList Num="2"> * <Item> * <PresetID>1</PresetID> * <PresetName>预置位1</PresetName> * </Item> * <Item> * <PresetID>2</PresetID> * <PresetName>预置位2</PresetName> * </Item> * </PresetList> * </Response> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Response") @XmlAccessorType(XmlAccessType.FIELD) public class PresetQueryResponse extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "PresetQuery"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "PresetList") private PresetList presetList; @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlAccessorType(XmlAccessType.FIELD) public static class PresetList { @XmlAttribute(name = "Num") private Integer num; @XmlElement(name = "Item") private List<PresetItem> items; } @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlAccessorType(XmlAccessType.FIELD) public static class PresetItem { @XmlElement(name = "PresetID") private String presetId; @XmlElement(name = "PresetName") private String presetName; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DevicePresetResponse.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DevicePresetResponse.java
package io.github.lunasaw.gb28181.common.entity.response; import java.util.List; import jakarta.xml.bind.annotation.*; import io.github.lunasaw.gb28181.common.entity.base.DeviceBase; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import org.assertj.core.util.Lists; /** * <?xml version="1.0" encoding="UTF-8"?> * <Response> * <CmdType>DeviceStatus</CmdType> * <SN>sn</SN> * <DeviceID>channelId</DeviceID> * <Result>OK</Result> * <Online>statusStr</Online> * <Status>OK</Status> * </Response> * * @author luna */ @Getter @Setter @NoArgsConstructor @XmlRootElement(name = "Response") @XmlAccessorType(XmlAccessType.FIELD) public class DevicePresetResponse extends DeviceBase { /** * 当前配置的预置位记录,当未配置预置位时不填写 */ @XmlElement(name = "Item") @XmlElementWrapper(name = "PresetList") private List<PresetItem> presetList; @Getter @Setter @XmlRootElement(name = "Item") @XmlAccessorType(XmlAccessType.FIELD) public static class PresetItem { /** * 预置位编码(必选) */ @XmlElement(name = "PresetID") private String presetID; /** * 预置位名称(必选) */ @XmlElement(name = "PresetName") private String presetName; /** * 列表项个数,当未配置预置位时取值为0(必选) */ @XmlElement(name = "Num") private String num; } public DevicePresetResponse(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); } public static void main(String[] args) { DevicePresetResponse response = new DevicePresetResponse("DevicePreset", "150959", "channelId"); PresetItem presetItem = new PresetItem(); presetItem.setPresetID("1"); presetItem.setPresetName("name"); response.setPresetList(Lists.newArrayList(presetItem)); System.out.println(response); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/RecordInfoResponse.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/RecordInfoResponse.java
package io.github.lunasaw.gb28181.common.entity.response; import jakarta.xml.bind.annotation.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import java.util.List; /** * GB28181协议 A.2.6 h)文件目录检索应答 * <pre> * <Response> * <CmdType>RecordInfo</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * <Name>摄像头1</Name> * <SumNum>2</SumNum> * <RecordList Num="2"> * <Item>...</Item> * <Item>...</Item> * </RecordList> * </Response> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Response") @XmlAccessorType(XmlAccessType.FIELD) public class RecordInfoResponse { @XmlElement(name = "CmdType") private final String cmdType = "RecordInfo"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "Name") private String name; @XmlElement(name = "SumNum") private Integer sumNum; @XmlElement(name = "RecordList") private RecordList recordList; @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlAccessorType(XmlAccessType.FIELD) public static class RecordList { @XmlAttribute(name = "Num") private Integer num; @XmlElement(name = "Item") private List<RecordItem> items; } @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlAccessorType(XmlAccessType.FIELD) public static class RecordItem { // 录像项字段,按实际协议补充 @XmlElement(name = "RecordID") private String recordId; @XmlElement(name = "Name") private String name; @XmlElement(name = "FilePath") private String filePath; @XmlElement(name = "Address") private String address; @XmlElement(name = "StartTime") private String startTime; @XmlElement(name = "EndTime") private String endTime; @XmlElement(name = "Secrecy") private Integer secrecy; @XmlElement(name = "Type") private String type; @XmlElement(name = "RecorderID") private String recorderId; @XmlElement(name = "FileSize") private Long fileSize; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceItem.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceItem.java
package io.github.lunasaw.gb28181.common.entity.response; import jakarta.xml.bind.annotation.*; import io.github.lunasaw.gb28181.common.entity.enums.DeviceGbType; import org.apache.commons.lang3.StringUtils; import com.luna.common.check.Assert; import com.luna.common.date.DateUtils; import com.luna.common.os.SystemInfoUtil; import lombok.Getter; import lombok.Setter; /** * toString 使用父类方法 * @author luna */ @Getter @Setter @XmlRootElement(name = "Item") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceItem extends DeviceCatalog { /** * 业务分组 */ @XmlElement(name = "BusinessGroupID") private String businessGroupId; /** * 警区(可选) */ @XmlElement(name = "Block") private String block; /** * 证书序列号(有证书的设备必选) */ @XmlElement(name = "CertNum") private String certNum; /** * 证书有效标识(有证书的设备必选) 缺省为0;证书有效标识:0:无效 1: 有效 */ @XmlElement(name = "Certifiable") private int certifiable = 0; /** * 无效原因码(有证书且证书无效的设备必选) */ @XmlElement(name = "ErrCode") private Integer errCode; /** * 证书终止有效期(有证书的设备必选) */ @XmlElement(name = "EndTime") private String endTime; /** * 设备/区域/系统IP地址(可选) */ @XmlElement(name = "IPAddress") private String ipAddress; /** * 设备/区域/系统端口(可选) */ @XmlElement(name = "Port") private Integer port; /** * 设备口令(可选) */ @XmlElement(name = "Password") private String password; /** * 云台类型(可选) 1-球机;2-半球;3-固定枪机;4-遥控枪机 */ @XmlElement(name = "PTZType") private Integer ptzType; /** * 经度(可选) */ @XmlElement(name = "Longitude") private Double longitude; /** * 纬度(可选) */ @XmlElement(name = "Latitude") private Double latitude; /** * 摄像机位置类型扩展(可选) * 1-省际检查站、2-党政机关、3-车站码头、4-中心广场、5-体育场馆、6-商业中心、 * 7-宗教场所、8-校园周边、9-治安复杂区域、10-交通干线。当目录项为摄像机时可选。 */ @XmlElement(name = "PositionType") private Integer positionType; /** * 摄像机安装位置室外、室内属性(可选) * 1-室外、2-室内。当目录项为摄像机时可选,缺省为1。 */ @XmlElement(name = "RoomType") private Integer roomType; /** * 摄像机用途属性(可选) * 1-治安、2-交通、3-重点。当目录项为摄像机时可选。 */ @XmlElement(name = "UseType") private Integer useType; /** * 摄像机补光属性(可选) * 1-无补光、2-红外补光、3-白光补光。当目录项为摄像机时可选,缺省为1。 */ @XmlElement(name = "SupplyLightType") private Integer supplyLightType; /** * 摄像机监视方位属性(可选) * 1-东、2-西、3-南、4-北、5-东南、6-东北、7-西南、8-西北。 * 当目录项为摄像机时且为固定摄像机或设置看守位摄像机时可选。 */ @XmlElement(name = "DirectionType") private Integer directionType; /** * 摄像机支持的分辨率(可选) * 格式应符合"幅面*高度[/帧率]"格式。当目录项为摄像机时可选。 */ @XmlElement(name = "Resolution") private String resolution; /** * 下载倍数(可选) * 可选项,取值0为不下载;其他值表示下载的倍数。 */ @XmlElement(name = "DownloadSpeed") private String downloadSpeed; /** * SVC时域可支持的空域层数(可选) * 可选项,缺省为空。 */ @XmlElement(name = "SVCSpaceSupportMode") private Integer svcSpaceSupportMode; /** * SVC时域可支持的时域层数(可选) * 可选项,缺省为空。 */ @XmlElement(name = "SVCTimeSupportMode") private Integer svcTimeSupportMode; public static DeviceItem getInstanceExample(String deviceId) { Assert.notNull(deviceId, "设备ID不能为空"); Assert.isTrue(deviceId.length() == 20, "设备ID长度必须为20位"); DeviceItem deviceItem = new DeviceItem(); deviceItem.setName("Camera"); deviceItem.setManufacturer("Lunasaw"); String substring = deviceId.substring(10, 13); DeviceGbType deviceGbType = DeviceGbType.fromCode(Integer.parseInt(substring)); deviceItem.setBlock("block"); deviceItem.setCertifiable(0); deviceItem.setErrCode(500); deviceItem.setEndTime(DateUtils.formatTime(DateUtils.ISO8601_PATTERN, DateUtils.parseDate("2099-01-01 01:01:01"))); deviceItem.setSecrecy(0); deviceItem.setSafetyWay(0); deviceItem.setIpAddress(SystemInfoUtil.getNoLoopbackIP()); deviceItem.setPort(8116); deviceItem.setPassword("luna"); deviceItem.setPtzType(3); deviceItem.setStatus("ok"); deviceItem.setLongitude(121.472644); deviceItem.setLatitude(31.231706); if (DeviceGbType.CENTER_SERVER.equals(deviceGbType)) { deviceItem.setRegisterWay(1); deviceItem.setSecrecy(0); } if (DeviceGbType.VIRTUAL_ORGANIZATION_DIRECTORY.equals(deviceGbType)) { deviceItem.setParentId("0"); } else { // 业务分组/虚拟组织/行政区划 不设置以下属性 deviceItem.setModel("Model-2312"); deviceItem.setOwner("luna"); if (StringUtils.isNotBlank(deviceId)) { deviceItem.setCivilCode(deviceId.substring(0, 6)); } deviceItem.setAddress("上海市xxx区xxx街道"); } if (DeviceGbType.CENTER_SIGNAL_CONTROL_SERVER.equals(deviceGbType)) { deviceItem.setParentId("0"); deviceItem.setBusinessGroupId("0"); } return deviceItem; } public static void main(String[] args) throws Exception { DeviceItem deviceItem = new DeviceItem(); deviceItem.setDeviceId("12312312"); System.out.println(deviceItem); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceResponse.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceResponse.java
package io.github.lunasaw.gb28181.common.entity.response; import java.util.List; import jakarta.xml.bind.annotation.*; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import org.assertj.core.util.Lists; import io.github.lunasaw.gb28181.common.entity.base.DeviceBase; import lombok.Getter; import lombok.Setter; /** * <?xml version="1.0"?> * <Response> * <CmdType>Catalog</CmdType> * <SN>${SN}</SN> * <DeviceID>${DEVICE_ID}</DeviceID> * <SumNum>1</SumNum> * <DeviceList> * <Item> * <DeviceID>33010602011187000002</DeviceID> * <Name>Camera</Name> * <Manufacturer>海康</Manufacturer> * <Model>Model</Model> * <Owner>Owner</Owner> * <CivilCode>CivilCode</CivilCode> * <Block>Block</Block> * <Address>上海市五角场合生汇</Address> * <Parental>0</Parental> * <ParentID>${DEVICE_ID}</ParentID> * <SafetyWay>0</SafetyWay> * <RegisterWay>1</RegisterWay> * <CertNum>CertNum1</CertNum> * <Certifiable>0</Certifiable> * <ErrCode>400</ErrCode> * <EndTime>2010-11-11T19:46:17</EndTime> * <Secrecy>0</Secrecy> * <IPAddress>172.19.128.50</IPAddress> * <Port>5060</Port> * <Password>Password1</Password> * <PTZType>1</PTZType> * <Status>Status1</Status> * <Longitude>171.4</Longitude> * <Latitude>34.2</Latitude> * </Item> * </DeviceList> * </Response> * @author luna */ @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Response") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceResponse extends DeviceBase { @XmlElement(name = "SumNum") private int sumNum; @XmlElement(name = "Name") private String name; @XmlElement(name = "Item") @XmlElementWrapper(name = "DeviceList") private List<DeviceItem> deviceItemList; /** * 兼容性方法:设置设备列表 * * @param deviceItems 设备项列表 */ public void setDeviceList(List<DeviceItem> deviceItems) { this.deviceItemList = deviceItems; } /** * 兼容性方法:获取设备列表 * * @return 设备项列表 */ public List<DeviceItem> getDeviceList() { return this.deviceItemList; } public DeviceResponse(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); } public static void main(String[] args) { DeviceResponse deviceResponse = new DeviceResponse(); DeviceItem deviceItem = DeviceItem.getInstanceExample("33010602011187000001"); deviceResponse.setDeviceItemList(Lists.newArrayList(deviceItem, deviceItem)); System.out.println(deviceResponse); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceInfo.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceInfo.java
package io.github.lunasaw.gb28181.common.entity.response; import io.github.lunasaw.gb28181.common.entity.enums.CmdTypeEnum; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import io.github.lunasaw.gb28181.common.entity.base.DeviceBase; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * @author luna */ @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Response") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceInfo extends DeviceBase { @XmlElement(name = "CmdType") private String cmdType = CmdTypeEnum.DEVICE_INFO.getType(); @XmlElement(name = "DeviceName") private String deviceName; @XmlElement(name = "Result") private String result; /** * 设备生产商 */ @XmlElement(name = "Manufacturer") private String manufacturer; /** * 设备型号(可选) */ @XmlElement(name = "Model") private String model; /** * 设备固件版本(可选) */ @XmlElement(name = "Firmware") private String firmware; /** * 视频输入通道数(可选) */ @XmlElement(name = "Channel") private int channel; public DeviceInfo(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); } public static void main(String[] args) { DeviceInfo deviceInfo = new DeviceInfo(); Object o = DeviceInfo.parseObj("<Response>\n" + " <CmdType>DeviceInfo</CmdType>\n" + " <SN>1</SN>\n" + " <DeviceID>34020000001320000001</DeviceID>\n" + " <Result>OK</Result>\n" + " <DeviceName>34020000001320000001</DeviceName>\n" + " <Manufacturer>HIK</Manufacturer>\n" + " <Model>DS-2CD2T20FD-I5</Model>\n" + " <Firmware>V5.5.82 build 180314</Firmware>\n" + " <Channel>1</Channel>\n" + "</Response>", DeviceInfo.class); System.out.println(o); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/CatalogResultResponse.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/CatalogResultResponse.java
package io.github.lunasaw.gb28181.common.entity.response; import jakarta.xml.bind.annotation.*; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 A.2.6 d/e)目录信息查询收到应答 * <pre> * <Response> * <CmdType>Catalog</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * <Result>OK</Result> * </Response> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Response") @XmlAccessorType(XmlAccessType.FIELD) public class CatalogResultResponse extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "Catalog"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "Result") private String result; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceStatus.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/DeviceStatus.java
package io.github.lunasaw.gb28181.common.entity.response; import io.github.lunasaw.gb28181.common.entity.enums.CmdTypeEnum; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import io.github.lunasaw.gb28181.common.entity.base.DeviceBase; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * <?xml version="1.0" encoding="UTF-8"?> * <Response> * <CmdType>DeviceStatus</CmdType> * <SN>sn</SN> * <DeviceID>channelId</DeviceID> * <Result>OK</Result> * <Online>ONLINE</Online> * <Status>OK</Status> * </Response> * * @author luna */ @Getter @Setter @NoArgsConstructor @XmlRootElement(name = "Response") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceStatus extends DeviceBase { @XmlElement(name = "CmdType") private String cmdType = CmdTypeEnum.DEVICE_STATUS.getType(); /** * OK */ @XmlElement(name = "Result") private String Result = "OK"; /** * "ONLINE":"OFFLINE" */ @XmlElement(name = "Online") private String Online = "ONLINE"; /** * OK */ @XmlElement(name = "Status") private String status = "OK"; public DeviceStatus(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/ConfigDownloadResponse.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/ConfigDownloadResponse.java
package io.github.lunasaw.gb28181.common.entity.response; import jakarta.xml.bind.annotation.*; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 A.2.6 j)设备配置查询应答 * <pre> * <Response> * <CmdType>ConfigDownload</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * <Result>OK</Result> * <BasicParam>...</BasicParam> * <VideoParamOpt>...</VideoParamOpt> * <SVACEncodeConfig>...</SVACEncodeConfig> * <SVACDecodeConfig>...</SVACDecodeConfig> * </Response> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Response") @XmlAccessorType(XmlAccessType.FIELD) public class ConfigDownloadResponse extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "ConfigDownload"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "Result") private String result; @XmlElement(name = "BasicParam") private String basicParam; @XmlElement(name = "VideoParamOpt") private String videoParamOpt; @XmlElement(name = "SVACEncodeConfig") private String svacEncodeConfig; @XmlElement(name = "SVACDecodeConfig") private String svacDecodeConfig; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/AlarmResponse.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/response/AlarmResponse.java
package io.github.lunasaw.gb28181.common.entity.response; import jakarta.xml.bind.annotation.*; import io.github.lunasaw.gb28181.common.entity.xml.XmlBean; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 A.2.6 b)报警通知应答 * <pre> * <Response> * <CmdType>Alarm</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * <Result>OK</Result> * </Response> * </pre> */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Response") @XmlAccessorType(XmlAccessType.FIELD) public class AlarmResponse extends XmlBean { @XmlElement(name = "CmdType") private final String cmdType = "Alarm"; @XmlElement(name = "SN") private String sn; @XmlElement(name = "DeviceID") private String deviceId; @XmlElement(name = "Result") private String result; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DragZoom.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DragZoom.java
package io.github.lunasaw.gb28181.common.entity.control; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlAccessorType(XmlAccessType.FIELD) public class DragZoom { @XmlElement(name = "Length") public String length; @XmlElement(name = "Width") public String width; @XmlElement(name = "MidPointX") public String midPointX; @XmlElement(name = "MidPointY") public String midPointY; @XmlElement(name = "LengthX") public String lengthX; @XmlElement(name = "LengthY") public String lengthY; }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceControlGuard.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceControlGuard.java
package io.github.lunasaw.gb28181.common.entity.control; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * @author luna */ @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Control") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceControlGuard extends DeviceControlBase { @XmlElement(name = "GuardCmd") public String guardCmd; public DeviceControlGuard(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); this.setControlType("GuardCmd"); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceControlAlarm.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceControlAlarm.java
package io.github.lunasaw.gb28181.common.entity.control; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * * /** * <?xml version="1.0" encoding="UTF-8"?> * <Control> * <CmdType>DeviceControl</CmdType> * <SN>179173</SN> * <DeviceID>213</DeviceID> * <AlarmCmd>ResetAlarm</AlarmCmd> * <Info> * <AlarmMethod>123</AlarmMethod> * <AlarmType>alarmType</AlarmType> * </Info> * </Control> * * @author luna */ @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Control") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceControlAlarm extends DeviceControlBase { @XmlElement(name = "AlarmCmd") public String alarmCmd; @XmlElement(name = "Info") public AlarmInfo alarmInfo; public DeviceControlAlarm(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); this.setControlType("AlarmCmd"); } public static void main(String[] args) { DeviceControlAlarm alarm = new DeviceControlAlarm(); alarm.setCmdType("DeviceControl"); alarm.setSn("179173"); alarm.setDeviceId("123"); alarm.setAlarmCmd("ResetAlarm"); AlarmInfo alarmInfo = new AlarmInfo(); alarmInfo.setAlarmMethod("!231"); alarmInfo.setAlarmType("alarmType"); alarm.setAlarmInfo(alarmInfo); System.out.println(alarm); } @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Info") @XmlAccessorType(XmlAccessType.FIELD) public static class AlarmInfo { @XmlElement(name = "AlarmMethod") public String alarmMethod; @XmlElement(name = "AlarmType") public String alarmType; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceControlRecordCmd.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceControlRecordCmd.java
package io.github.lunasaw.gb28181.common.entity.control; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * @author luna */ @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Control") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceControlRecordCmd extends DeviceControlBase { @XmlElement(name = "RecordCmd") private String recordCmd; public DeviceControlRecordCmd(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); this.setControlType("RecordCmd"); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/package-info.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/package-info.java
/** * Contains classes that represent SIP control entities. * 包含设备控制的实体类的xml bean * * @author luna * @date 2023/11/20 */ package io.github.lunasaw.gb28181.common.entity.control;
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/KeepaliveControl.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/KeepaliveControl.java
package io.github.lunasaw.gb28181.common.entity.control; import jakarta.xml.bind.annotation.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * GB28181协议 Control类型的Keepalive命令 * <pre> * <Control> * <CmdType>Keepalive</CmdType> * <SN>123</SN> * <DeviceID>34020000001320000001</DeviceID> * <Status>OK</Status> * </Control> * </pre> * * @author claude * @date 2025/01/19 */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor @XmlRootElement(name = "Control") @XmlAccessorType(XmlAccessType.FIELD) public class KeepaliveControl extends ControlBase { @XmlElement(name = "Status") private String status; public KeepaliveControl(String sn, String deviceId, String status) { super("Keepalive", sn, deviceId); this.status = status; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/ControlBase.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/ControlBase.java
package io.github.lunasaw.gb28181.common.entity.control; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlRootElement; import lombok.Getter; import lombok.Setter; /** * @author luna */ @Getter @Setter @XmlAccessorType(XmlAccessType.FIELD) public abstract class ControlBase extends DeviceControlBase { public ControlBase() { } public ControlBase(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceControlBase.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceControlBase.java
package io.github.lunasaw.gb28181.common.entity.control; import io.github.lunasaw.gb28181.common.entity.base.DeviceBase; import lombok.Getter; import lombok.Setter; import jakarta.xml.bind.annotation.XmlElement; /** * @author luna */ @Getter @Setter public abstract class DeviceControlBase extends DeviceBase { @XmlElement(name = "ControlType") private String controlType; public DeviceControlBase() { } public DeviceControlBase(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceControlDragOut.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceControlDragOut.java
package io.github.lunasaw.gb28181.common.entity.control; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * <?xml version="1.0" encoding="UTF-8"?> * <Control> * <CmdType>DeviceControl</CmdType> * <SN>331004</SN> * <DeviceID>1231</DeviceID> * <DragZoomOut> * <Length>dragZoom.getLength()</Length> * <Width>dragZoom.getWidth()</Width> * <MidPointX>ragZoom.getMidPointX()</MidPointX> * <MidPointY> dragZoom.getMidPointY()</MidPointY> * <LengthX>ragZoom.getLengthX()</LengthX> * <LengthY> dragZoom.getLengthY()</LengthY> * </DragZoomOut> * </Control> * * @author luna */ @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Control") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceControlDragOut extends DeviceControlBase { /** * 缩小 */ @XmlElement(name = "DragZoomOut") private DragZoom dragZoomOut; public DeviceControlDragOut(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); this.setControlType("DragZoomOut"); } public static void main(String[] args) { DeviceControlDragOut deviceControlDrag = new DeviceControlDragOut(); deviceControlDrag.setDragZoomOut(new DragZoom("1", "2", "3", "4", "5", "6")); System.out.println(deviceControlDrag); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceConfigControl.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceConfigControl.java
package io.github.lunasaw.gb28181.common.entity.control; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * * <?xml version="1.0" encoding="UTF-8"?> * <Control> * <CmdType>DeviceConfig</CmdType> * <SN>150959</SN> * <DeviceID>channelId</DeviceID> * <BasicParam> * <Name>name</Name> * <Expiration>30</Expiration> * <HeartBeatInterval>300</HeartBeatInterval> * <HeartBeatCount>300</HeartBeatCount> * </BasicParam> * </Control> * * @author luna */ @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Control") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceConfigControl extends DeviceControlBase { @XmlElement(name = "BasicParam") private BasicParam basicParam; public DeviceConfigControl(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); this.setControlType("BasicParam"); } @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "BasicParam") @XmlAccessorType(XmlAccessType.FIELD) public static class BasicParam { @XmlElement(name = "Name") private String name; @XmlElement(name = "Expiration") private String expiration; @XmlElement(name = "HeartBeatInterval") private String heartBeatInterval; @XmlElement(name = "HeartBeatCount") private String heartBeatCount; } public static void main(String[] args) { DeviceConfigControl alarm = new DeviceConfigControl(); alarm.setCmdType("DeviceControl"); alarm.setSn("179173"); alarm.setDeviceId("123"); BasicParam basicParam = new BasicParam(); basicParam.setExpiration("30"); basicParam.setHeartBeatCount("31"); basicParam.setHeartBeatInterval("300"); basicParam.setName("QWWQ"); alarm.setBasicParam(basicParam); System.out.println(alarm); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceControlIFame.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceControlIFame.java
package io.github.lunasaw.gb28181.common.entity.control; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import lombok.*; /** * @author luna */ @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Control") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceControlIFame extends DeviceControlBase { @XmlElement(name = "IFameCmd") public String iFameCmd; public DeviceControlIFame(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); this.setControlType("IFameCmd"); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceControlPtz.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceControlPtz.java
package io.github.lunasaw.gb28181.common.entity.control; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * @author luna */ @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Control") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceControlPtz extends DeviceControlBase { @XmlElement(name = "Info") private PtzInfo ptzInfo; @XmlElement(name = "PTZCmd") private String ptzCmd; public DeviceControlPtz(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); this.setControlType("GuardCmd"); } @Getter @Setter @XmlRootElement(name = "Info") @XmlAccessorType(XmlAccessType.FIELD) public static class PtzInfo { @XmlElement(name = "ControlPriority") public Integer controlPriority = 5; } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false
lunasaw/gb28181-proxy
https://github.com/lunasaw/gb28181-proxy/blob/540577abe2124425b68b6288de9e9fc341b1f1fc/gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceControlDragIn.java
gb28181-common/src/main/java/io/github/lunasaw/gb28181/common/entity/control/DeviceControlDragIn.java
package io.github.lunasaw.gb28181.common.entity.control; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; /** * <?xml version="1.0" encoding="UTF-8"?> * <Control> * <CmdType>DeviceControl</CmdType> * <SN>331004</SN> * <DeviceID>1231</DeviceID> * <DragZoomIn> * <Length>dragZoom.getLength()</Length> * <Width>dragZoom.getWidth()</Width> * <MidPointX>ragZoom.getMidPointX()</MidPointX> * <MidPointY> dragZoom.getMidPointY()</MidPointY> * <LengthX>ragZoom.getLengthX()</LengthX> * <LengthY> dragZoom.getLengthY()</LengthY> * </DragZoomIn> * </Control> * * @author luna */ @Getter @Setter @AllArgsConstructor @NoArgsConstructor @XmlRootElement(name = "Control") @XmlAccessorType(XmlAccessType.FIELD) public class DeviceControlDragIn extends DeviceControlBase { /** * 放大 */ @XmlElement(name = "DragZoomIn") private DragZoom dragZoomIn; public DeviceControlDragIn(String cmdType, String sn, String deviceId) { super(cmdType, sn, deviceId); this.setControlType("DragZoomIn"); } }
java
Apache-2.0
540577abe2124425b68b6288de9e9fc341b1f1fc
2026-01-05T02:36:27.870323Z
false