✨ 调整代码策略, 添加AlarmServer
This commit is contained in:
parent
c81be25465
commit
70a34f02e5
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>net.javase.hk</groupId>
|
<groupId>net.javase.hk</groupId>
|
||||||
<artifactId>hk-sup-spring-boot-starter</artifactId>
|
<artifactId>hk-sup-spring-boot-starter</artifactId>
|
||||||
<version>0.0.4</version>
|
<version>0.0.5</version>
|
||||||
<name>hk-sup-spring-boot-starter</name>
|
<name>hk-sup-spring-boot-starter</name>
|
||||||
<description>hk-sup-spring-boot-starter</description>
|
<description>hk-sup-spring-boot-starter</description>
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.javase.hksup.starter.config;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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.CmsServer;
|
||||||
import net.javase.hksup.starter.service.SsServer;
|
import net.javase.hksup.starter.service.SsServer;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
@ -24,6 +25,11 @@ public class HkSupSdkConfiguration {
|
||||||
|
|
||||||
private final ApplicationContext applicationContext;
|
private final ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
@Bean(initMethod = "startServer", destroyMethod = "stopServer")
|
||||||
|
public AlarmServer alarmServer() {
|
||||||
|
return new AlarmServer(applicationContext, hkSupSdkProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Bean(initMethod = "startCmsServer", destroyMethod = "stopCmsServer")
|
@Bean(initMethod = "startCmsServer", destroyMethod = "stopCmsServer")
|
||||||
public CmsServer cmsServer() {
|
public CmsServer cmsServer() {
|
||||||
|
|
|
@ -2,7 +2,11 @@ package net.javase.hksup.starter.config;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import net.javase.hksup.starter.utils.SystemUtil;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HkSupSdkProperties
|
* HkSupSdkProperties
|
||||||
|
@ -93,4 +97,23 @@ public class HkSupSdkProperties {
|
||||||
private String sdkLogPath;
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
182
src/main/java/net/javase/hksup/starter/service/AlarmServer.java
Normal file
182
src/main/java/net/javase/hksup/starter/service/AlarmServer.java
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -30,8 +30,7 @@ public class CmsServer {
|
||||||
|
|
||||||
private final ApplicationContext applicationContext;
|
private final ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
public static HCISUPCMS hciSupCms = null;
|
||||||
public HCISUPCMS hcisupcms = null;
|
|
||||||
private int CmsHandle = -1; //CMS监听句柄
|
private int CmsHandle = -1; //CMS监听句柄
|
||||||
private HCISUPCMS.DEVICE_REGISTER_CB deviceRegisterCb;
|
private HCISUPCMS.DEVICE_REGISTER_CB deviceRegisterCb;
|
||||||
HCISUPCMS.NET_EHOME_CMS_LISTEN_PARAM struCMSListenPara = new HCISUPCMS.NET_EHOME_CMS_LISTEN_PARAM();
|
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.supSdkProperties = supSdkProperties;
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
createSDKInstance();
|
createSDKInstance();
|
||||||
callback = applicationContext.getBeansOfType(CmsServerCallback.class).values().stream().findAny().orElse(null);
|
callback = applicationContext.getBeansOfType(CmsServerCallback.class).values().stream().findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据不同操作系统选择不同的库文件和库路径
|
* 根据不同操作系统选择不同的库文件和库路径
|
||||||
*/
|
*/
|
||||||
private boolean createSDKInstance() {
|
private boolean createSDKInstance() {
|
||||||
if (hcisupcms == null) {
|
if (hciSupCms == null) {
|
||||||
String libPath = libPath();
|
String libPath = libPath();
|
||||||
synchronized (HCISUPCMS.class) {
|
synchronized (HCISUPCMS.class) {
|
||||||
String strDllPath = "";
|
String strDllPath = "";
|
||||||
|
@ -61,7 +60,7 @@ public class CmsServer {
|
||||||
strDllPath = libPath + "libHCISUPCMS.so";
|
strDllPath = libPath + "libHCISUPCMS.so";
|
||||||
}
|
}
|
||||||
log.info("loadLibrary: {}", strDllPath);
|
log.info("loadLibrary: {}", strDllPath);
|
||||||
hcisupcms = (HCISUPCMS) Native.loadLibrary(strDllPath, HCISUPCMS.class);
|
hciSupCms = (HCISUPCMS) Native.loadLibrary(strDllPath, HCISUPCMS.class);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.error("loadLibrary: {}, Error: {}", strDllPath, ex.getMessage());
|
log.error("loadLibrary: {}, Error: {}", strDllPath, ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
|
@ -75,7 +74,7 @@ public class CmsServer {
|
||||||
* cms服务初始化,开启监听
|
* cms服务初始化,开启监听
|
||||||
*/
|
*/
|
||||||
private void cmsInit() {
|
private void cmsInit() {
|
||||||
if (hcisupcms == null) {
|
if (hciSupCms == null) {
|
||||||
if (!createSDKInstance()) {
|
if (!createSDKInstance()) {
|
||||||
throw new RuntimeException("Load CMS SDK fail!");
|
throw new RuntimeException("Load CMS SDK fail!");
|
||||||
}
|
}
|
||||||
|
@ -86,47 +85,47 @@ public class CmsServer {
|
||||||
String strPathCrypto = libPath + "libeay32.dll"; //Linux版本是libcrypto.so库文件的路径
|
String strPathCrypto = libPath + "libeay32.dll"; //Linux版本是libcrypto.so库文件的路径
|
||||||
System.arraycopy(strPathCrypto.getBytes(), 0, ptrByteArrayCrypto.byValue, 0, strPathCrypto.length());
|
System.arraycopy(strPathCrypto.getBytes(), 0, ptrByteArrayCrypto.byValue, 0, strPathCrypto.length());
|
||||||
ptrByteArrayCrypto.write();
|
ptrByteArrayCrypto.write();
|
||||||
hcisupcms.NET_ECMS_SetSDKInitCfg(0, ptrByteArrayCrypto.getPointer());
|
hciSupCms.NET_ECMS_SetSDKInitCfg(0, ptrByteArrayCrypto.getPointer());
|
||||||
|
|
||||||
//设置libssl.so所在路径
|
//设置libssl.so所在路径
|
||||||
HCISUPCMS.BYTE_ARRAY ptrByteArraySsl = new HCISUPCMS.BYTE_ARRAY(256);
|
HCISUPCMS.BYTE_ARRAY ptrByteArraySsl = new HCISUPCMS.BYTE_ARRAY(256);
|
||||||
String strPathSsl = libPath + "ssleay32.dll"; //Linux版本是libssl.so库文件的路径
|
String strPathSsl = libPath + "ssleay32.dll"; //Linux版本是libssl.so库文件的路径
|
||||||
System.arraycopy(strPathSsl.getBytes(), 0, ptrByteArraySsl.byValue, 0, strPathSsl.length());
|
System.arraycopy(strPathSsl.getBytes(), 0, ptrByteArraySsl.byValue, 0, strPathSsl.length());
|
||||||
ptrByteArraySsl.write();
|
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组件库文件夹所在路径
|
//设置HCAapSDKCom组件库文件夹所在路径
|
||||||
HCISUPCMS.BYTE_ARRAY ptrByteArrayCom = new HCISUPCMS.BYTE_ARRAY(256);
|
HCISUPCMS.BYTE_ARRAY ptrByteArrayCom = new HCISUPCMS.BYTE_ARRAY(256);
|
||||||
String strPathCom = libPath + "HCAapSDKCom"; //只支持绝对路径,建议使用英文路径
|
String strPathCom = libPath + "HCAapSDKCom"; //只支持绝对路径,建议使用英文路径
|
||||||
System.arraycopy(strPathCom.getBytes(), 0, ptrByteArrayCom.byValue, 0, strPathCom.length());
|
System.arraycopy(strPathCom.getBytes(), 0, ptrByteArrayCom.byValue, 0, strPathCom.length());
|
||||||
ptrByteArrayCom.write();
|
ptrByteArrayCom.write();
|
||||||
hcisupcms.NET_ECMS_SetSDKLocalCfg(5, ptrByteArrayCom.getPointer());
|
hciSupCms.NET_ECMS_SetSDKLocalCfg(5, ptrByteArrayCom.getPointer());
|
||||||
|
|
||||||
} else if (SystemUtil.isLinux()) {
|
} else if (SystemUtil.isLinux()) {
|
||||||
HCISUPCMS.BYTE_ARRAY ptrByteArrayCrypto = new HCISUPCMS.BYTE_ARRAY(256);
|
HCISUPCMS.BYTE_ARRAY ptrByteArrayCrypto = new HCISUPCMS.BYTE_ARRAY(256);
|
||||||
String strPathCrypto = libPath + "libcrypto.so"; //Linux版本是libcrypto.so库文件的路径
|
String strPathCrypto = libPath + "libcrypto.so"; //Linux版本是libcrypto.so库文件的路径
|
||||||
System.arraycopy(strPathCrypto.getBytes(), 0, ptrByteArrayCrypto.byValue, 0, strPathCrypto.length());
|
System.arraycopy(strPathCrypto.getBytes(), 0, ptrByteArrayCrypto.byValue, 0, strPathCrypto.length());
|
||||||
ptrByteArrayCrypto.write();
|
ptrByteArrayCrypto.write();
|
||||||
hcisupcms.NET_ECMS_SetSDKInitCfg(0, ptrByteArrayCrypto.getPointer());
|
hciSupCms.NET_ECMS_SetSDKInitCfg(0, ptrByteArrayCrypto.getPointer());
|
||||||
|
|
||||||
//设置libssl.so所在路径
|
//设置libssl.so所在路径
|
||||||
HCISUPCMS.BYTE_ARRAY ptrByteArraySsl = new HCISUPCMS.BYTE_ARRAY(256);
|
HCISUPCMS.BYTE_ARRAY ptrByteArraySsl = new HCISUPCMS.BYTE_ARRAY(256);
|
||||||
String strPathSsl = libPath + "libssl.so"; //Linux版本是libssl.so库文件的路径
|
String strPathSsl = libPath + "libssl.so"; //Linux版本是libssl.so库文件的路径
|
||||||
System.arraycopy(strPathSsl.getBytes(), 0, ptrByteArraySsl.byValue, 0, strPathSsl.length());
|
System.arraycopy(strPathSsl.getBytes(), 0, ptrByteArraySsl.byValue, 0, strPathSsl.length());
|
||||||
ptrByteArraySsl.write();
|
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组件库文件夹所在路径
|
//设置HCAapSDKCom组件库文件夹所在路径
|
||||||
HCISUPCMS.BYTE_ARRAY ptrByteArrayCom = new HCISUPCMS.BYTE_ARRAY(256);
|
HCISUPCMS.BYTE_ARRAY ptrByteArrayCom = new HCISUPCMS.BYTE_ARRAY(256);
|
||||||
String strPathCom = libPath + "HCAapSDKCom/"; //只支持绝对路径,建议使用英文路径
|
String strPathCom = libPath + "HCAapSDKCom/"; //只支持绝对路径,建议使用英文路径
|
||||||
System.arraycopy(strPathCom.getBytes(), 0, ptrByteArrayCom.byValue, 0, strPathCom.length());
|
System.arraycopy(strPathCom.getBytes(), 0, ptrByteArrayCom.byValue, 0, strPathCom.length());
|
||||||
ptrByteArrayCom.write();
|
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) {
|
if (beansOfType.size() < 1) {
|
||||||
throw new RuntimeException("not found device register callback implement!");
|
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());
|
System.arraycopy(supSdkProperties.getCmsServerIp().getBytes(), 0, struCMSListenPara.struAddress.szIP, 0, supSdkProperties.getCmsServerIp().length());
|
||||||
struCMSListenPara.struAddress.wPort = Short.parseShort(supSdkProperties.getCmsServerPort().toString());
|
struCMSListenPara.struAddress.wPort = Short.parseShort(supSdkProperties.getCmsServerPort().toString());
|
||||||
struCMSListenPara.fnCB = deviceRegisterCb;
|
struCMSListenPara.fnCB = deviceRegisterCb;
|
||||||
struCMSListenPara.write();
|
struCMSListenPara.write();
|
||||||
//启动监听,接收设备注册信息
|
//启动监听,接收设备注册信息
|
||||||
CmsHandle = hcisupcms.NET_ECMS_StartListen(struCMSListenPara);
|
CmsHandle = hciSupCms.NET_ECMS_StartListen(struCMSListenPara);
|
||||||
if (CmsHandle < -1) {
|
if (CmsHandle < -1) {
|
||||||
log.info("NET_ECMS_StartListen failed, error code: {}", hcisupcms.NET_ECMS_GetLastError());
|
log.info("NET_ECMS_StartListen failed, error code: {}", hciSupCms.NET_ECMS_GetLastError());
|
||||||
hcisupcms.NET_ECMS_Fini();
|
hciSupCms.NET_ECMS_Fini();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String CmsListenInfo = new String(struCMSListenPara.struAddress.szIP).trim() + "_" + struCMSListenPara.struAddress.wPort;
|
String CmsListenInfo = new String(struCMSListenPara.struAddress.szIP).trim() + "_" + struCMSListenPara.struAddress.wPort;
|
||||||
|
@ -177,8 +176,8 @@ public class CmsServer {
|
||||||
try {
|
try {
|
||||||
if (CmsHandle >= 0) {
|
if (CmsHandle >= 0) {
|
||||||
log.info("开始停止CMS注册服务");
|
log.info("开始停止CMS注册服务");
|
||||||
hcisupcms.NET_ECMS_StopListen(CmsHandle);
|
hciSupCms.NET_ECMS_StopListen(CmsHandle);
|
||||||
hcisupcms.NET_ECMS_Fini();
|
hciSupCms.NET_ECMS_Fini();
|
||||||
log.info("停止CMS注册服务成功!");
|
log.info("停止CMS注册服务成功!");
|
||||||
Optional.ofNullable(callback).ifPresent(CmsServerCallback::finishStop);
|
Optional.ofNullable(callback).ifPresent(CmsServerCallback::finishStop);
|
||||||
}
|
}
|
||||||
|
@ -224,8 +223,8 @@ public class CmsServer {
|
||||||
m_struParam2.dwOutSize = iOutSize2;
|
m_struParam2.dwOutSize = iOutSize2;
|
||||||
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
|
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
|
||||||
m_struParam2.write();
|
m_struParam2.write();
|
||||||
if (!hcisupcms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
|
if (!hciSupCms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
|
||||||
log.info("添加人员失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hcisupcms.NET_ECMS_GetLastError());
|
log.info("添加人员失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hciSupCms.NET_ECMS_GetLastError());
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
m_struParam2.read();
|
m_struParam2.read();
|
||||||
|
@ -293,8 +292,8 @@ public class CmsServer {
|
||||||
m_struParam2.dwOutSize = iOutSize2;
|
m_struParam2.dwOutSize = iOutSize2;
|
||||||
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
|
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
|
||||||
m_struParam2.write();
|
m_struParam2.write();
|
||||||
if (!hcisupcms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
|
if (!hciSupCms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
|
||||||
log.info("删除人员失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hcisupcms.NET_ECMS_GetLastError());
|
log.info("删除人员失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hciSupCms.NET_ECMS_GetLastError());
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
m_struParam2.read();
|
m_struParam2.read();
|
||||||
|
@ -370,8 +369,8 @@ public class CmsServer {
|
||||||
m_struParam2.dwOutSize = iOutSize2;
|
m_struParam2.dwOutSize = iOutSize2;
|
||||||
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
|
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
|
||||||
m_struParam2.write();
|
m_struParam2.write();
|
||||||
if (!hcisupcms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
|
if (!hciSupCms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
|
||||||
log.info("查询人员失败,NET_ECMS_ISAPIPassThrough failed, error:{}", hcisupcms.NET_ECMS_GetLastError());
|
log.info("查询人员失败,NET_ECMS_ISAPIPassThrough failed, error:{}", hciSupCms.NET_ECMS_GetLastError());
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
m_struParam2.read();
|
m_struParam2.read();
|
||||||
|
@ -419,8 +418,8 @@ public class CmsServer {
|
||||||
m_struParam2.dwOutSize = iOutSize2;
|
m_struParam2.dwOutSize = iOutSize2;
|
||||||
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
|
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
|
||||||
m_struParam2.write();
|
m_struParam2.write();
|
||||||
if (!hcisupcms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
|
if (!hciSupCms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
|
||||||
log.info("下发门禁人脸失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hcisupcms.NET_ECMS_GetLastError());
|
log.info("下发门禁人脸失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hciSupCms.NET_ECMS_GetLastError());
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
m_struParam2.read();
|
m_struParam2.read();
|
||||||
|
@ -477,8 +476,8 @@ public class CmsServer {
|
||||||
m_struParam2.dwOutSize = iOutSize2;
|
m_struParam2.dwOutSize = iOutSize2;
|
||||||
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
|
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
|
||||||
m_struParam2.write();
|
m_struParam2.write();
|
||||||
if (!hcisupcms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
|
if (!hciSupCms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
|
||||||
log.info("修改门禁人脸失败,NET_ECMS_ISAPIPassThrough failed,error:" + hcisupcms.NET_ECMS_GetLastError());
|
log.info("修改门禁人脸失败,NET_ECMS_ISAPIPassThrough failed,error:" + hciSupCms.NET_ECMS_GetLastError());
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
m_struParam2.read();
|
m_struParam2.read();
|
||||||
|
@ -542,8 +541,8 @@ public class CmsServer {
|
||||||
m_struParam2.dwOutSize = iOutSize2;
|
m_struParam2.dwOutSize = iOutSize2;
|
||||||
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
|
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
|
||||||
m_struParam2.write();
|
m_struParam2.write();
|
||||||
if (!hcisupcms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
|
if (!hciSupCms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
|
||||||
log.info("删除门禁人脸失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hcisupcms.NET_ECMS_GetLastError());
|
log.info("删除门禁人脸失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hciSupCms.NET_ECMS_GetLastError());
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
m_struParam2.read();
|
m_struParam2.read();
|
||||||
|
@ -602,8 +601,8 @@ public class CmsServer {
|
||||||
m_struParam2.dwOutSize = iOutSize2;
|
m_struParam2.dwOutSize = iOutSize2;
|
||||||
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
|
m_struParam2.dwRecvTimeOut = 5000; //接收超时时间,单位毫秒
|
||||||
m_struParam2.write();
|
m_struParam2.write();
|
||||||
if (!hcisupcms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
|
if (!hciSupCms.NET_ECMS_ISAPIPassThrough(loginID, m_struParam2)) {
|
||||||
log.info("查询门禁人脸失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hcisupcms.NET_ECMS_GetLastError());
|
log.info("查询门禁人脸失败,NET_ECMS_ISAPIPassThrough failed,error:{}", hciSupCms.NET_ECMS_GetLastError());
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
m_struParam2.read();
|
m_struParam2.read();
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SsServer
|
* SsServer
|
||||||
|
@ -20,7 +21,7 @@ import java.util.Map;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SsServer {
|
public class SsServer {
|
||||||
|
|
||||||
public HCISUPSS hCEhomeSS = null;
|
public static HCISUPSS hCEhomeSS = null;
|
||||||
String PSS_CLIENT_FILE_PATH_PARAM_NAME = "File-Path"; //图片文件路径
|
String PSS_CLIENT_FILE_PATH_PARAM_NAME = "File-Path"; //图片文件路径
|
||||||
String PSS_CLIENT_VRB_FILENAME_CODE = "Filename-Code";//VRB协议的FilenameCode
|
String PSS_CLIENT_VRB_FILENAME_CODE = "Filename-Code";//VRB协议的FilenameCode
|
||||||
String PSS_CLIENT_KMS_USER_NAME = "KMS-Username"; //KMS图片服务器用户名
|
String PSS_CLIENT_KMS_USER_NAME = "KMS-Username"; //KMS图片服务器用户名
|
||||||
|
@ -30,11 +31,11 @@ public class SsServer {
|
||||||
|
|
||||||
private HCISUPSS.EHomeSSMsgCallBack eHomeSSMsgCallBack;// 信息回调函数(上报)
|
private HCISUPSS.EHomeSSMsgCallBack eHomeSSMsgCallBack;// 信息回调函数(上报)
|
||||||
private HCISUPSS.EHomeSSStorageCallBack eHomeSSStorageCallBack;// 文件保存回调函数(下载)
|
private HCISUPSS.EHomeSSStorageCallBack eHomeSSStorageCallBack;// 文件保存回调函数(下载)
|
||||||
private HCISUPSS.EHomeSSRWCallBackEx eHomeSSRWCallBackEx; //读写扩展回调函数
|
private Optional<HCISUPSS.EHomeSSRWCallBackEx> eHomeSSRWCallBackEx; //读写扩展回调函数
|
||||||
private HCISUPSS.NET_EHOME_SS_LISTEN_PARAM pSSListenParam = new HCISUPSS.NET_EHOME_SS_LISTEN_PARAM();
|
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;
|
int client = -1;
|
||||||
static int iCount = 0;
|
private static int iCount = 0;
|
||||||
byte[] szUrl = new byte[HCISUPSS.MAX_URL_LEN_SS];
|
byte[] szUrl = new byte[HCISUPSS.MAX_URL_LEN_SS];
|
||||||
String url = "";
|
String url = "";
|
||||||
|
|
||||||
|
@ -191,7 +192,7 @@ public class SsServer {
|
||||||
if (beansOfType.size() < 1) {
|
if (beansOfType.size() < 1) {
|
||||||
throw new RuntimeException("not found EHomeSSMsgCallBack implement!");
|
throw new RuntimeException("not found EHomeSSMsgCallBack implement!");
|
||||||
}
|
}
|
||||||
beansOfType.forEach((k, v) -> eHomeSSMsgCallBack = v);
|
eHomeSSMsgCallBack = beansOfType.values().stream().findFirst().get();
|
||||||
}
|
}
|
||||||
pSSListenParam.fnSSMsgCb = eHomeSSMsgCallBack;
|
pSSListenParam.fnSSMsgCb = eHomeSSMsgCallBack;
|
||||||
|
|
||||||
|
@ -201,20 +202,23 @@ public class SsServer {
|
||||||
* 简单功能测试可以使用存储回调(SDK底层使用db数据库自动存取数据,因此会受到db数据库的性能瓶颈影响)
|
* 简单功能测试可以使用存储回调(SDK底层使用db数据库自动存取数据,因此会受到db数据库的性能瓶颈影响)
|
||||||
* 需要自定义URL或者自己读写图片数据,则使用读写扩展回调(推荐)
|
* 需要自定义URL或者自己读写图片数据,则使用读写扩展回调(推荐)
|
||||||
*/
|
*/
|
||||||
//存储信息回调
|
|
||||||
if (eHomeSSStorageCallBack == null) {
|
|
||||||
Map<String, HCISUPSS.EHomeSSStorageCallBack> 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 = applicationContext.getBeansOfType(HCISUPSS.EHomeSSRWCallBackEx.class)
|
||||||
// eHomeSSRWCallBackEx = new cbEHomeSSRWCallBackEx();
|
.values().stream().findFirst();
|
||||||
// }
|
|
||||||
// pSSListenParam.fnSSRWCbEx = eHomeSSRWCallBackEx;
|
if (eHomeSSRWCallBackEx.isPresent()) {
|
||||||
|
pSSListenParam.fnSSRWCbEx = eHomeSSRWCallBackEx.get();
|
||||||
|
} else {
|
||||||
|
//存储信息回调
|
||||||
|
if (eHomeSSStorageCallBack == null) {
|
||||||
|
Map<String, HCISUPSS.EHomeSSStorageCallBack> 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.bySecurityMode = 1;
|
||||||
pSSListenParam.write();
|
pSSListenParam.write();
|
||||||
|
@ -269,7 +273,7 @@ public class SsServer {
|
||||||
log.warn("NET_ESS_ClientSetParam失败\n err: {}", hCEhomeSS.NET_ESS_GetLastError());
|
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());
|
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());
|
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());
|
boolean bCloud_AK = hCEhomeSS.NET_ESS_ClientSetParam(client, PSS_CLIENT_CLOUD_AK_NAME, hkSupSdkProperties.getSzAk());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user