From 70a34f02e5650050a8ea822459a4a9ecadb131f4 Mon Sep 17 00:00:00 2001
From: Frank <3224536684@qq.com>
Date: Thu, 21 Sep 2023 16:42:56 +0800
Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E8=B0=83=E6=95=B4=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81=E7=AD=96=E7=95=A5,=20=E6=B7=BB=E5=8A=A0AlarmServer?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 2 +-
.../starter/config/HkSupSdkConfiguration.java | 6 +
.../starter/config/HkSupSdkProperties.java | 23 +++
.../hksup/starter/service/AlarmServer.java | 182 ++++++++++++++++++
.../hksup/starter/service/CmsServer.java | 69 ++++---
.../hksup/starter/service/SsServer.java | 42 ++--
6 files changed, 269 insertions(+), 55 deletions(-)
create mode 100644 src/main/java/net/javase/hksup/starter/service/AlarmServer.java
diff --git a/pom.xml b/pom.xml
index 5671212..dce69cd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
net.javase.hk
hk-sup-spring-boot-starter
- 0.0.4
+ 0.0.5
hk-sup-spring-boot-starter
hk-sup-spring-boot-starter
diff --git a/src/main/java/net/javase/hksup/starter/config/HkSupSdkConfiguration.java b/src/main/java/net/javase/hksup/starter/config/HkSupSdkConfiguration.java
index ef6e702..1e0c0ee 100644
--- a/src/main/java/net/javase/hksup/starter/config/HkSupSdkConfiguration.java
+++ b/src/main/java/net/javase/hksup/starter/config/HkSupSdkConfiguration.java
@@ -2,6 +2,7 @@ package net.javase.hksup.starter.config;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import net.javase.hksup.starter.service.AlarmServer;
import net.javase.hksup.starter.service.CmsServer;
import net.javase.hksup.starter.service.SsServer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -24,6 +25,11 @@ public class HkSupSdkConfiguration {
private final ApplicationContext applicationContext;
+ @Bean(initMethod = "startServer", destroyMethod = "stopServer")
+ public AlarmServer alarmServer() {
+ return new AlarmServer(applicationContext, hkSupSdkProperties);
+ }
+
@Bean(initMethod = "startCmsServer", destroyMethod = "stopCmsServer")
public CmsServer cmsServer() {
diff --git a/src/main/java/net/javase/hksup/starter/config/HkSupSdkProperties.java b/src/main/java/net/javase/hksup/starter/config/HkSupSdkProperties.java
index 8ed09f9..c029d6c 100644
--- a/src/main/java/net/javase/hksup/starter/config/HkSupSdkProperties.java
+++ b/src/main/java/net/javase/hksup/starter/config/HkSupSdkProperties.java
@@ -2,7 +2,11 @@ package net.javase.hksup.starter.config;
import lombok.Getter;
import lombok.Setter;
+import net.javase.hksup.starter.utils.SystemUtil;
import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.util.StringUtils;
+
+import java.io.File;
/**
* HkSupSdkProperties
@@ -93,4 +97,23 @@ public class HkSupSdkProperties {
private String sdkLogPath;
+ /**
+ * lib根目录
+ */
+ public String libPath() {
+ String libPath = getLibPath();
+ if (!StringUtils.hasText(libPath)) {
+ return SystemUtil.userDir() + File.separator + "lib" + File.separator;
+ }
+ return libPath.endsWith(File.separator) ? libPath : libPath + File.separator;
+ }
+
+ /**
+ * 日志根目录
+ */
+ public String logPath() {
+ String logPath = getSdkLogPath();
+ return StringUtils.hasText(logPath) ? logPath : SystemUtil.userDir() + File.separator + "EHomeSDKLog";
+ }
+
}
diff --git a/src/main/java/net/javase/hksup/starter/service/AlarmServer.java b/src/main/java/net/javase/hksup/starter/service/AlarmServer.java
new file mode 100644
index 0000000..b4aff79
--- /dev/null
+++ b/src/main/java/net/javase/hksup/starter/service/AlarmServer.java
@@ -0,0 +1,182 @@
+package net.javase.hksup.starter.service;
+
+import com.sun.jna.Native;
+import lombok.extern.slf4j.Slf4j;
+import net.javase.hksup.starter.config.HkSupSdkProperties;
+import net.javase.hksup.starter.sdk.HCISUPAlarm;
+import net.javase.hksup.starter.sdk.HCISUPCMS;
+import net.javase.hksup.starter.utils.SystemUtil;
+import org.springframework.context.ApplicationContext;
+
+/**
+ * AlarmServer
+ *
+ * @author Frank
+ */
+@Slf4j
+public class AlarmServer {
+
+ private final HkSupSdkProperties hkSupSdkProperties;
+
+ private final ApplicationContext applicationContext;
+
+ public static HCISUPAlarm hcEHomeAlarm = null;
+ private int alarmHandle = -1; //Alarm监听句柄
+ private HCISUPAlarm.EHomeMsgCallBack cbEHomeMsgCallBack;
+ private HCISUPAlarm.NET_EHOME_ALARM_LISTEN_PARAM netEhomeAlarmListenParam = new HCISUPAlarm.NET_EHOME_ALARM_LISTEN_PARAM();
+
+ public AlarmServer(ApplicationContext applicationContext, HkSupSdkProperties hkSupSdkProperties) {
+ this.hkSupSdkProperties = hkSupSdkProperties;
+ this.applicationContext = applicationContext;
+ createSDKInstance();
+ }
+
+ /**
+ * 初始化CMS服务
+ */
+ void startServer() {
+ try {
+ alarmInit();
+ startAlarmListen();
+ } catch (Exception ex) {
+ log.error("启动Alarm服务失败: " + ex.getMessage(), ex);
+ }
+ }
+
+ /**
+ * 停止CMS服务,回收资源
+ */
+ void stopServer() {
+ try {
+ if (alarmHandle >= 0) {
+ log.info("开始停止Alarm报警服务");
+ hcEHomeAlarm.NET_EALARM_StopListen(alarmHandle);
+ hcEHomeAlarm.NET_EALARM_Fini();
+ log.info("停止Alarm报警服务成功!");
+ }
+ } catch (Exception ex) {
+ log.error("停止Alarm报警服务失败: " + ex.getMessage(), ex);
+ }
+ }
+
+
+ /**
+ * 根据不同操作系统选择不同的库文件和库路径
+ */
+ private boolean createSDKInstance() {
+ if (hcEHomeAlarm == null) {
+ synchronized (HCISUPAlarm.class) {
+ String strDllPath = "";
+ try {
+ SystemUtil.jnaDebugLoad(hkSupSdkProperties.getJnaDebug());
+ if (SystemUtil.isWindows())
+ //win系统加载库路径(路径不要带中文)
+ strDllPath = hkSupSdkProperties.libPath() + "HCISUPAlarm.dll";
+ else if (SystemUtil.isLinux())
+ //Linux系统加载库路径(路径不要带中文)
+ strDllPath = hkSupSdkProperties.libPath() + "libHCISUPAlarm.so";
+ hcEHomeAlarm = (HCISUPAlarm) Native.loadLibrary(strDllPath, HCISUPAlarm.class);
+ } catch (Exception ex) {
+ log.info("loadLibrary: " + strDllPath + " Error: " + ex.getMessage());
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ private void alarmInit() {
+ if (hcEHomeAlarm == null) {
+ if (!createSDKInstance()) {
+ throw new RuntimeException("Load CMS SDK fail");
+ }
+ }
+ if (SystemUtil.isWindows()) {
+ HCISUPCMS.BYTE_ARRAY ptrByteArrayCrypto = new HCISUPCMS.BYTE_ARRAY(256);
+ String strPathCrypto = hkSupSdkProperties.libPath() + "libeay32.dll"; //Linux版本是libcrypto.so库文件的路径
+ System.arraycopy(strPathCrypto.getBytes(), 0, ptrByteArrayCrypto.byValue, 0, strPathCrypto.length());
+ ptrByteArrayCrypto.write();
+ hcEHomeAlarm.NET_EALARM_SetSDKInitCfg(0, ptrByteArrayCrypto.getPointer());
+
+ //设置libssl.so所在路径
+ HCISUPCMS.BYTE_ARRAY ptrByteArraySsl = new HCISUPCMS.BYTE_ARRAY(256);
+ String strPathSsl = hkSupSdkProperties.libPath() + "ssleay32.dll"; //Linux版本是libssl.so库文件的路径
+ System.arraycopy(strPathSsl.getBytes(), 0, ptrByteArraySsl.byValue, 0, strPathSsl.length());
+ ptrByteArraySsl.write();
+ hcEHomeAlarm.NET_EALARM_SetSDKInitCfg(1, ptrByteArraySsl.getPointer());
+
+ //报警服务初始化
+ boolean bRet = hcEHomeAlarm.NET_EALARM_Init();
+ if (!bRet) {
+ log.warn("NET_EALARM_Init failed!");
+ }
+ //设置HCAapSDKCom组件库文件夹所在路径
+ HCISUPCMS.BYTE_ARRAY ptrByteArrayCom = new HCISUPCMS.BYTE_ARRAY(256);
+ String strPathCom = hkSupSdkProperties.libPath() + "HCAapSDKCom"; //只支持绝对路径,建议使用英文路径
+ System.arraycopy(strPathCom.getBytes(), 0, ptrByteArrayCom.byValue, 0, strPathCom.length());
+ ptrByteArrayCom.write();
+ hcEHomeAlarm.NET_EALARM_SetSDKLocalCfg(5, ptrByteArrayCom.getPointer());
+ } else if (SystemUtil.isLinux()) {
+ HCISUPCMS.BYTE_ARRAY ptrByteArrayCrypto = new HCISUPCMS.BYTE_ARRAY(256);
+ String strPathCrypto = hkSupSdkProperties.libPath() + "libcrypto.so"; //Linux版本是libcrypto.so库文件的路径
+ System.arraycopy(strPathCrypto.getBytes(), 0, ptrByteArrayCrypto.byValue, 0, strPathCrypto.length());
+ ptrByteArrayCrypto.write();
+ hcEHomeAlarm.NET_EALARM_SetSDKInitCfg(0, ptrByteArrayCrypto.getPointer());
+
+ //设置libssl.so所在路径
+ HCISUPCMS.BYTE_ARRAY ptrByteArraySsl = new HCISUPCMS.BYTE_ARRAY(256);
+ String strPathSsl = hkSupSdkProperties.libPath() + "libssl.so"; //Linux版本是libssl.so库文件的路径
+ System.arraycopy(strPathSsl.getBytes(), 0, ptrByteArraySsl.byValue, 0, strPathSsl.length());
+ ptrByteArraySsl.write();
+ hcEHomeAlarm.NET_EALARM_SetSDKInitCfg(1, ptrByteArraySsl.getPointer());
+ //报警服务初始化
+ boolean bRet = hcEHomeAlarm.NET_EALARM_Init();
+ if (!bRet) {
+ log.warn("NET_EALARM_Init failed!");
+ }
+ //设置HCAapSDKCom组件库文件夹所在路径
+ HCISUPCMS.BYTE_ARRAY ptrByteArrayCom = new HCISUPCMS.BYTE_ARRAY(256);
+ String strPathCom = hkSupSdkProperties.libPath() + "HCAapSDKCom/"; //只支持绝对路径,建议使用英文路径
+ System.arraycopy(strPathCom.getBytes(), 0, ptrByteArrayCom.byValue, 0, strPathCom.length());
+ ptrByteArrayCom.write();
+ hcEHomeAlarm.NET_EALARM_SetSDKLocalCfg(5, ptrByteArrayCom.getPointer());
+ }
+
+ //启用SDK写日志
+ boolean logToFile = hcEHomeAlarm.NET_EALARM_SetLogToFile(3, hkSupSdkProperties.logPath(), false);
+ }
+
+ /**
+ * 开启报警服务监听
+ */
+ private void startAlarmListen() {
+ if (cbEHomeMsgCallBack == null) {
+ cbEHomeMsgCallBack = applicationContext.getBeansOfType(HCISUPAlarm.EHomeMsgCallBack.class).values().stream().findFirst().orElse(null);
+ if (cbEHomeMsgCallBack == null) {
+ throw new RuntimeException("not found EHomeMsgCallBack implement!");
+ }
+ }
+ System.arraycopy(hkSupSdkProperties.getAlarmServerListenIp().getBytes(), 0, netEhomeAlarmListenParam.struAddress.szIP, 0, hkSupSdkProperties.getAlarmServerListenIp().length());
+ if (Short.parseShort(hkSupSdkProperties.getAlarmServerType().toString()) == 2) {
+ netEhomeAlarmListenParam.struAddress.wPort = Short.parseShort(hkSupSdkProperties.getAlarmServerListenTcpPort().toString());
+ netEhomeAlarmListenParam.byProtocolType = 2; //协议类型:0- TCP,1- UDP, 2-MQTT
+ } else {
+ netEhomeAlarmListenParam.struAddress.wPort = Short.parseShort(hkSupSdkProperties.getAlarmServerListenUdpPort().toString());
+ netEhomeAlarmListenParam.byProtocolType = 1; //协议类型:0- TCP,1- UDP, 2-MQTT
+ }
+ netEhomeAlarmListenParam.fnMsgCb = cbEHomeMsgCallBack;
+ netEhomeAlarmListenParam.byUseCmsPort = 0; //是否复用CMS端口:0- 不复用,非0- 复用
+ netEhomeAlarmListenParam.write();
+
+ //启动报警服务器监听
+ alarmHandle = hcEHomeAlarm.NET_EALARM_StartListen(netEhomeAlarmListenParam);
+ if (alarmHandle < 0) {
+ log.info("NET_EALARM_StartListen failed, error:" + hcEHomeAlarm.NET_EALARM_GetLastError());
+ hcEHomeAlarm.NET_EALARM_Fini();
+ } else {
+ String AlarmListenInfo = new String(netEhomeAlarmListenParam.struAddress.szIP).trim() + "_" + netEhomeAlarmListenParam.struAddress.wPort;
+ log.info("报警服务器:{}, NET_EALARM_StartListen succeed", AlarmListenInfo);
+ }
+ }
+
+}
diff --git a/src/main/java/net/javase/hksup/starter/service/CmsServer.java b/src/main/java/net/javase/hksup/starter/service/CmsServer.java
index 27ad3ff..863d8d3 100644
--- a/src/main/java/net/javase/hksup/starter/service/CmsServer.java
+++ b/src/main/java/net/javase/hksup/starter/service/CmsServer.java
@@ -30,8 +30,7 @@ public class CmsServer {
private final ApplicationContext applicationContext;
-
- public HCISUPCMS hcisupcms = null;
+ public static HCISUPCMS hciSupCms = null;
private int CmsHandle = -1; //CMS监听句柄
private HCISUPCMS.DEVICE_REGISTER_CB deviceRegisterCb;
HCISUPCMS.NET_EHOME_CMS_LISTEN_PARAM struCMSListenPara = new HCISUPCMS.NET_EHOME_CMS_LISTEN_PARAM();
@@ -42,14 +41,14 @@ public class CmsServer {
this.supSdkProperties = supSdkProperties;
this.applicationContext = applicationContext;
createSDKInstance();
- callback = applicationContext.getBeansOfType(CmsServerCallback.class).values().stream().findAny().orElse(null);
+ callback = applicationContext.getBeansOfType(CmsServerCallback.class).values().stream().findFirst().orElse(null);
}
/**
* 根据不同操作系统选择不同的库文件和库路径
*/
private boolean createSDKInstance() {
- if (hcisupcms == null) {
+ if (hciSupCms == null) {
String libPath = libPath();
synchronized (HCISUPCMS.class) {
String strDllPath = "";
@@ -61,7 +60,7 @@ public class CmsServer {
strDllPath = libPath + "libHCISUPCMS.so";
}
log.info("loadLibrary: {}", strDllPath);
- hcisupcms = (HCISUPCMS) Native.loadLibrary(strDllPath, HCISUPCMS.class);
+ hciSupCms = (HCISUPCMS) Native.loadLibrary(strDllPath, HCISUPCMS.class);
} catch (Exception ex) {
log.error("loadLibrary: {}, Error: {}", strDllPath, ex.getMessage());
return false;
@@ -75,7 +74,7 @@ public class CmsServer {
* cms服务初始化,开启监听
*/
private void cmsInit() {
- if (hcisupcms == null) {
+ if (hciSupCms == null) {
if (!createSDKInstance()) {
throw new RuntimeException("Load CMS SDK fail!");
}
@@ -86,47 +85,47 @@ public class CmsServer {
String strPathCrypto = libPath + "libeay32.dll"; //Linux版本是libcrypto.so库文件的路径
System.arraycopy(strPathCrypto.getBytes(), 0, ptrByteArrayCrypto.byValue, 0, strPathCrypto.length());
ptrByteArrayCrypto.write();
- hcisupcms.NET_ECMS_SetSDKInitCfg(0, ptrByteArrayCrypto.getPointer());
+ hciSupCms.NET_ECMS_SetSDKInitCfg(0, ptrByteArrayCrypto.getPointer());
//设置libssl.so所在路径
HCISUPCMS.BYTE_ARRAY ptrByteArraySsl = new HCISUPCMS.BYTE_ARRAY(256);
String strPathSsl = libPath + "ssleay32.dll"; //Linux版本是libssl.so库文件的路径
System.arraycopy(strPathSsl.getBytes(), 0, ptrByteArraySsl.byValue, 0, strPathSsl.length());
ptrByteArraySsl.write();
- hcisupcms.NET_ECMS_SetSDKInitCfg(1, ptrByteArraySsl.getPointer());
+ hciSupCms.NET_ECMS_SetSDKInitCfg(1, ptrByteArraySsl.getPointer());
//注册服务初始化
- boolean binit = hcisupcms.NET_ECMS_Init();
+ boolean binit = hciSupCms.NET_ECMS_Init();
//设置HCAapSDKCom组件库文件夹所在路径
HCISUPCMS.BYTE_ARRAY ptrByteArrayCom = new HCISUPCMS.BYTE_ARRAY(256);
String strPathCom = libPath + "HCAapSDKCom"; //只支持绝对路径,建议使用英文路径
System.arraycopy(strPathCom.getBytes(), 0, ptrByteArrayCom.byValue, 0, strPathCom.length());
ptrByteArrayCom.write();
- hcisupcms.NET_ECMS_SetSDKLocalCfg(5, ptrByteArrayCom.getPointer());
+ hciSupCms.NET_ECMS_SetSDKLocalCfg(5, ptrByteArrayCom.getPointer());
} else if (SystemUtil.isLinux()) {
HCISUPCMS.BYTE_ARRAY ptrByteArrayCrypto = new HCISUPCMS.BYTE_ARRAY(256);
String strPathCrypto = libPath + "libcrypto.so"; //Linux版本是libcrypto.so库文件的路径
System.arraycopy(strPathCrypto.getBytes(), 0, ptrByteArrayCrypto.byValue, 0, strPathCrypto.length());
ptrByteArrayCrypto.write();
- hcisupcms.NET_ECMS_SetSDKInitCfg(0, ptrByteArrayCrypto.getPointer());
+ hciSupCms.NET_ECMS_SetSDKInitCfg(0, ptrByteArrayCrypto.getPointer());
//设置libssl.so所在路径
HCISUPCMS.BYTE_ARRAY ptrByteArraySsl = new HCISUPCMS.BYTE_ARRAY(256);
String strPathSsl = libPath + "libssl.so"; //Linux版本是libssl.so库文件的路径
System.arraycopy(strPathSsl.getBytes(), 0, ptrByteArraySsl.byValue, 0, strPathSsl.length());
ptrByteArraySsl.write();
- hcisupcms.NET_ECMS_SetSDKInitCfg(1, ptrByteArraySsl.getPointer());
+ hciSupCms.NET_ECMS_SetSDKInitCfg(1, ptrByteArraySsl.getPointer());
//注册服务初始化
- boolean binit = hcisupcms.NET_ECMS_Init();
+ boolean binit = hciSupCms.NET_ECMS_Init();
//设置HCAapSDKCom组件库文件夹所在路径
HCISUPCMS.BYTE_ARRAY ptrByteArrayCom = new HCISUPCMS.BYTE_ARRAY(256);
String strPathCom = libPath + "HCAapSDKCom/"; //只支持绝对路径,建议使用英文路径
System.arraycopy(strPathCom.getBytes(), 0, ptrByteArrayCom.byValue, 0, strPathCom.length());
ptrByteArrayCom.write();
- hcisupcms.NET_ECMS_SetSDKLocalCfg(5, ptrByteArrayCom.getPointer());
+ hciSupCms.NET_ECMS_SetSDKLocalCfg(5, ptrByteArrayCom.getPointer());
}
- hcisupcms.NET_ECMS_SetLogToFile(3, logPath(), false);
+ hciSupCms.NET_ECMS_SetLogToFile(3, logPath(), false);
}
/**
@@ -138,17 +137,17 @@ public class CmsServer {
if (beansOfType.size() < 1) {
throw new RuntimeException("not found device register callback implement!");
}
- beansOfType.forEach((k, v) -> deviceRegisterCb = v);
+ deviceRegisterCb = beansOfType.values().stream().findFirst().get();
}
System.arraycopy(supSdkProperties.getCmsServerIp().getBytes(), 0, struCMSListenPara.struAddress.szIP, 0, supSdkProperties.getCmsServerIp().length());
struCMSListenPara.struAddress.wPort = Short.parseShort(supSdkProperties.getCmsServerPort().toString());
struCMSListenPara.fnCB = deviceRegisterCb;
struCMSListenPara.write();
//启动监听,接收设备注册信息
- CmsHandle = hcisupcms.NET_ECMS_StartListen(struCMSListenPara);
+ CmsHandle = hciSupCms.NET_ECMS_StartListen(struCMSListenPara);
if (CmsHandle < -1) {
- log.info("NET_ECMS_StartListen failed, error code: {}", hcisupcms.NET_ECMS_GetLastError());
- hcisupcms.NET_ECMS_Fini();
+ log.info("NET_ECMS_StartListen failed, error code: {}", hciSupCms.NET_ECMS_GetLastError());
+ hciSupCms.NET_ECMS_Fini();
return;
}
String CmsListenInfo = new String(struCMSListenPara.struAddress.szIP).trim() + "_" + struCMSListenPara.struAddress.wPort;
@@ -177,8 +176,8 @@ public class CmsServer {
try {
if (CmsHandle >= 0) {
log.info("开始停止CMS注册服务");
- hcisupcms.NET_ECMS_StopListen(CmsHandle);
- hcisupcms.NET_ECMS_Fini();
+ hciSupCms.NET_ECMS_StopListen(CmsHandle);
+ hciSupCms.NET_ECMS_Fini();
log.info("停止CMS注册服务成功!");
Optional.ofNullable(callback).ifPresent(CmsServerCallback::finishStop);
}
@@ -224,8 +223,8 @@ public class CmsServer {
m_struParam2.dwOutSize = iOutSize2;
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
m_struParam2.write();
- if (!hcisupcms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
- log.info("添加人员失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hcisupcms.NET_ECMS_GetLastError());
+ if (!hciSupCms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
+ log.info("添加人员失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hciSupCms.NET_ECMS_GetLastError());
return null;
} else {
m_struParam2.read();
@@ -293,8 +292,8 @@ public class CmsServer {
m_struParam2.dwOutSize = iOutSize2;
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
m_struParam2.write();
- if (!hcisupcms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
- log.info("删除人员失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hcisupcms.NET_ECMS_GetLastError());
+ if (!hciSupCms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
+ log.info("删除人员失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hciSupCms.NET_ECMS_GetLastError());
return null;
} else {
m_struParam2.read();
@@ -370,8 +369,8 @@ public class CmsServer {
m_struParam2.dwOutSize = iOutSize2;
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
m_struParam2.write();
- if (!hcisupcms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
- log.info("查询人员失败,NET_ECMS_ISAPIPassThrough failed, error:{}", hcisupcms.NET_ECMS_GetLastError());
+ if (!hciSupCms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
+ log.info("查询人员失败,NET_ECMS_ISAPIPassThrough failed, error:{}", hciSupCms.NET_ECMS_GetLastError());
return null;
} else {
m_struParam2.read();
@@ -419,8 +418,8 @@ public class CmsServer {
m_struParam2.dwOutSize = iOutSize2;
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
m_struParam2.write();
- if (!hcisupcms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
- log.info("下发门禁人脸失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hcisupcms.NET_ECMS_GetLastError());
+ if (!hciSupCms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
+ log.info("下发门禁人脸失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hciSupCms.NET_ECMS_GetLastError());
return null;
} else {
m_struParam2.read();
@@ -477,8 +476,8 @@ public class CmsServer {
m_struParam2.dwOutSize = iOutSize2;
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
m_struParam2.write();
- if (!hcisupcms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
- log.info("修改门禁人脸失败,NET_ECMS_ISAPIPassThrough failed,error:" + hcisupcms.NET_ECMS_GetLastError());
+ if (!hciSupCms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
+ log.info("修改门禁人脸失败,NET_ECMS_ISAPIPassThrough failed,error:" + hciSupCms.NET_ECMS_GetLastError());
return null;
} else {
m_struParam2.read();
@@ -542,8 +541,8 @@ public class CmsServer {
m_struParam2.dwOutSize = iOutSize2;
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
m_struParam2.write();
- if (!hcisupcms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
- log.info("删除门禁人脸失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hcisupcms.NET_ECMS_GetLastError());
+ if (!hciSupCms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
+ log.info("删除门禁人脸失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hciSupCms.NET_ECMS_GetLastError());
return null;
} else {
m_struParam2.read();
@@ -602,8 +601,8 @@ public class CmsServer {
m_struParam2.dwOutSize = iOutSize2;
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
m_struParam2.write();
- if (!hcisupcms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
- log.info("查询门禁人脸失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hcisupcms.NET_ECMS_GetLastError());
+ if (!hciSupCms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
+ log.info("查询门禁人脸失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hciSupCms.NET_ECMS_GetLastError());
return null;
} else {
m_struParam2.read();
diff --git a/src/main/java/net/javase/hksup/starter/service/SsServer.java b/src/main/java/net/javase/hksup/starter/service/SsServer.java
index 1581ee3..99c5eec 100644
--- a/src/main/java/net/javase/hksup/starter/service/SsServer.java
+++ b/src/main/java/net/javase/hksup/starter/service/SsServer.java
@@ -11,6 +11,7 @@ import org.springframework.util.StringUtils;
import java.io.File;
import java.util.Map;
+import java.util.Optional;
/**
* SsServer
@@ -20,7 +21,7 @@ import java.util.Map;
@Slf4j
public class SsServer {
- public HCISUPSS hCEhomeSS = null;
+ public static HCISUPSS hCEhomeSS = null;
String PSS_CLIENT_FILE_PATH_PARAM_NAME = "File-Path"; //图片文件路径
String PSS_CLIENT_VRB_FILENAME_CODE = "Filename-Code";//VRB协议的FilenameCode
String PSS_CLIENT_KMS_USER_NAME = "KMS-Username"; //KMS图片服务器用户名
@@ -30,11 +31,11 @@ public class SsServer {
private HCISUPSS.EHomeSSMsgCallBack eHomeSSMsgCallBack;// 信息回调函数(上报)
private HCISUPSS.EHomeSSStorageCallBack eHomeSSStorageCallBack;// 文件保存回调函数(下载)
- private HCISUPSS.EHomeSSRWCallBackEx eHomeSSRWCallBackEx; //读写扩展回调函数
+ private Optional eHomeSSRWCallBackEx; //读写扩展回调函数
private HCISUPSS.NET_EHOME_SS_LISTEN_PARAM pSSListenParam = new HCISUPSS.NET_EHOME_SS_LISTEN_PARAM();
- public static int ssHandle = -1; //存储服务监听句柄
+ private int ssHandle = -1; //存储服务监听句柄
int client = -1;
- static int iCount = 0;
+ private static int iCount = 0;
byte[] szUrl = new byte[HCISUPSS.MAX_URL_LEN_SS];
String url = "";
@@ -191,7 +192,7 @@ public class SsServer {
if (beansOfType.size() < 1) {
throw new RuntimeException("not found EHomeSSMsgCallBack implement!");
}
- beansOfType.forEach((k, v) -> eHomeSSMsgCallBack = v);
+ eHomeSSMsgCallBack = beansOfType.values().stream().findFirst().get();
}
pSSListenParam.fnSSMsgCb = eHomeSSMsgCallBack;
@@ -201,20 +202,23 @@ public class SsServer {
* 简单功能测试可以使用存储回调(SDK底层使用db数据库自动存取数据,因此会受到db数据库的性能瓶颈影响)
* 需要自定义URL或者自己读写图片数据,则使用读写扩展回调(推荐)
*/
- //存储信息回调
- if (eHomeSSStorageCallBack == null) {
- Map beansOfType = applicationContext.getBeansOfType(HCISUPSS.EHomeSSStorageCallBack.class);
- if (beansOfType.size() < 1) {
- throw new RuntimeException("not found eHomeSSStorageCallBack implement!");
- }
- beansOfType.forEach((k, v) -> eHomeSSStorageCallBack = v);
- }
- pSSListenParam.fnSStorageCb = eHomeSSStorageCallBack;
//读写扩展回调
-// if (eHomeSSRWCallBackEx == null) {
-// eHomeSSRWCallBackEx = new cbEHomeSSRWCallBackEx();
-// }
-// pSSListenParam.fnSSRWCbEx = eHomeSSRWCallBackEx;
+ eHomeSSRWCallBackEx = applicationContext.getBeansOfType(HCISUPSS.EHomeSSRWCallBackEx.class)
+ .values().stream().findFirst();
+
+ if (eHomeSSRWCallBackEx.isPresent()) {
+ pSSListenParam.fnSSRWCbEx = eHomeSSRWCallBackEx.get();
+ } else {
+ //存储信息回调
+ if (eHomeSSStorageCallBack == null) {
+ Map beansOfType = applicationContext.getBeansOfType(HCISUPSS.EHomeSSStorageCallBack.class);
+ if (beansOfType.size() < 1) {
+ throw new RuntimeException("not found eHomeSSStorageCallBack implement!");
+ }
+ eHomeSSStorageCallBack = beansOfType.values().stream().findFirst().get();
+ }
+ pSSListenParam.fnSStorageCb = eHomeSSStorageCallBack;
+ }
pSSListenParam.bySecurityMode = 1;
pSSListenParam.write();
@@ -269,7 +273,7 @@ public class SsServer {
log.warn("NET_ESS_ClientSetParam失败\n err: {}", hCEhomeSS.NET_ESS_GetLastError());
}
boolean bKMS_PassWord = hCEhomeSS.NET_ESS_ClientSetParam(client, "SS_CLIENT_KMS_PASSWIRD", hkSupSdkProperties.getKmsPassword());
- if(!bKMS_PassWord) {
+ if (!bKMS_PassWord) {
log.warn("NET_ESS_ClientSetParam失败\n err: {}", hCEhomeSS.NET_ESS_GetLastError());
}
boolean bCloud_AK = hCEhomeSS.NET_ESS_ClientSetParam(client, PSS_CLIENT_CLOUD_AK_NAME, hkSupSdkProperties.getSzAk());