|
@@ -11,7 +11,9 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
+import java.nio.ByteBuffer;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -24,22 +26,28 @@ public class HCNetSDKUtil {
|
|
|
private int lUserID = -1; //用户句柄
|
|
|
private FExceptionCallBack_Imp fExceptionCallBack;
|
|
|
private String userDir = System.getProperty("user.dir");
|
|
|
- private String sourceDir = null;
|
|
|
+ private String sourceDir = null;
|
|
|
|
|
|
private List<ChannelInfo> channelInfoList = new ArrayList<>();
|
|
|
+ private Float temperature =-999f;
|
|
|
|
|
|
- /*public static void main(String[] args) throws InterruptedException {
|
|
|
- HCNetSDKUtil hcNetSDKUtil = new HCNetSDKUtil();
|
|
|
- List<ChannelInfo> channelInfos = hcNetSDKUtil.init()
|
|
|
+ public static void main(String[] args) throws InterruptedException {
|
|
|
+ /*HCNetSDKUtil hcNetSDKUtil = new HCNetSDKUtil();*/
|
|
|
+ /*List<ChannelInfo> channelInfos = hcNetSDKUtil.init()
|
|
|
.login("192.168.1.210", 8000, "admin", "jdkj@123")
|
|
|
.readChannelInfo().logout().getChannelInfo();
|
|
|
- log.info(channelInfos.toString());
|
|
|
+ log.info(channelInfos.toString());*/
|
|
|
|
|
|
- Boolean loginConnectStatus = hcNetSDKUtil.init()
|
|
|
+ /*Boolean loginConnectStatus = hcNetSDKUtil.init()
|
|
|
.login("192.168.1.210", 8000, "admin", "jdkj@123")
|
|
|
.logout().getLoginConnectStatus();
|
|
|
- log.info(loginConnectStatus.toString());
|
|
|
- }*/
|
|
|
+ log.info(loginConnectStatus.toString());*/
|
|
|
+
|
|
|
+ /*Float t = hcNetSDKUtil.init()
|
|
|
+ .login("192.168.1.211", 8000, "admin", "jdkj@123")
|
|
|
+ .readTemperature().logout().getTemperature();
|
|
|
+ log.info(t.toString());*/
|
|
|
+ }
|
|
|
|
|
|
public HCNetSDKUtil init(){
|
|
|
if (OsSelect.isLinux()) {
|
|
@@ -85,12 +93,13 @@ public class HCNetSDKUtil {
|
|
|
if (!hCNetSDK.NET_DVR_SetExceptionCallBack_V30(0, 0, fExceptionCallBack, pUser)) {
|
|
|
return this;
|
|
|
}
|
|
|
- log.info("设置异常消息回调成功");
|
|
|
+ //log.info("设置异常消息回调成功");
|
|
|
|
|
|
//启用SDK写日志
|
|
|
hCNetSDK.NET_DVR_SetLogToFile(3, "./HCNetSDKLog", false);
|
|
|
lUserID = -1;
|
|
|
channelInfoList = new ArrayList<>();
|
|
|
+ temperature = -999f;
|
|
|
return this;
|
|
|
}
|
|
|
|
|
@@ -127,10 +136,38 @@ public class HCNetSDKUtil {
|
|
|
return channelInfoList;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ public HCNetSDKUtil readTemperature(){
|
|
|
+ if (lUserID == -1) {
|
|
|
+ log.error("请先注册");
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+ int i = 0;
|
|
|
+ while((temperature < -20f || temperature > 150f) && i < 5){
|
|
|
+ // 最多5次获取正常温度
|
|
|
+ if(i > 0){
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ log.error("多次获取温度睡眠1秒失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ temperature = getAvgTemperature(new HKPoint(80f,45f), 160,90);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ //log.info("中心点的温度是,{}", temperature);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Float getTemperature(){
|
|
|
+ return temperature;
|
|
|
+ }
|
|
|
+
|
|
|
public HCNetSDKUtil logout(){
|
|
|
//程序退出的时候调用注销登录接口,每一台设备分别调用一次
|
|
|
if (hCNetSDK.NET_DVR_Logout(lUserID)) {
|
|
|
- log.info("注销成功");
|
|
|
+ //log.info("注销成功");
|
|
|
}
|
|
|
|
|
|
//释放SDK资源,程序退出时调用,只需要调用一次
|
|
@@ -186,10 +223,10 @@ public class HCNetSDKUtil {
|
|
|
HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();
|
|
|
int iUserID = hCNetSDK.NET_DVR_Login_V30(ip, port, user, psw, m_strDeviceInfo);
|
|
|
if ((iUserID == -1) || (iUserID == 0xFFFFFFFF)) {
|
|
|
- System.out.println("登录失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
|
|
|
+ log.error("登录失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
|
|
|
return iUserID;
|
|
|
} else {
|
|
|
- System.out.println(ip + ":设备登录成功!");
|
|
|
+ //log.info(ip + ":设备登录成功!");
|
|
|
return iUserID;
|
|
|
}
|
|
|
}
|
|
@@ -226,9 +263,9 @@ public class HCNetSDKUtil {
|
|
|
|
|
|
int iUserID = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
|
|
|
if (iUserID == -1) {
|
|
|
- System.out.println("登录失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
|
|
|
+ log.error("登录失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
|
|
|
} else {
|
|
|
- System.out.println(ip + ":设备登录成功!");
|
|
|
+ //log.info(ip + ":设备登录成功!");
|
|
|
}
|
|
|
return iUserID;
|
|
|
}
|
|
@@ -289,4 +326,123 @@ public class HCNetSDKUtil {
|
|
|
return channelInfoList;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private Float getAvgTemperature(HKPoint hkPoint, int sourceWidth, int sourceHeight) {
|
|
|
+ boolean bRet = false;
|
|
|
+ int nErr = 0;
|
|
|
+ int erro;
|
|
|
+ HCNetSDK.NET_DVR_THERMOMETRY_PRESETINFO m_struThermometryInfo = new HCNetSDK.NET_DVR_THERMOMETRY_PRESETINFO();
|
|
|
+ m_struThermometryInfo.dwSize = m_struThermometryInfo.size();
|
|
|
+
|
|
|
+ HCNetSDK.NET_DVR_THERMOMETRY_COND m_struThermometryCond = new HCNetSDK.NET_DVR_THERMOMETRY_COND();
|
|
|
+ m_struThermometryCond.dwSize = m_struThermometryCond.size();
|
|
|
+ m_struThermometryCond.dwChannel = 2;
|
|
|
+ m_struThermometryCond.wPresetNo = 1;
|
|
|
+ m_struThermometryCond.write();
|
|
|
+
|
|
|
+ HCNetSDK.NET_DVR_STD_CONFIG struCfg = new HCNetSDK.NET_DVR_STD_CONFIG();
|
|
|
+ struCfg.lpCondBuffer = m_struThermometryCond.getPointer();
|
|
|
+ struCfg.dwCondSize = m_struThermometryCond.size();
|
|
|
+ struCfg.lpOutBuffer = m_struThermometryInfo.getPointer();
|
|
|
+ struCfg.dwOutSize = m_struThermometryInfo.size();
|
|
|
+
|
|
|
+ HCNetSDK.BYTE_ARRAY m_szStatusBuf = new HCNetSDK.BYTE_ARRAY(4096 * 4);
|
|
|
+ struCfg.lpStatusBuffer = m_szStatusBuf.getPointer();
|
|
|
+ struCfg.dwStatusSize = 4096 * 4;
|
|
|
+ struCfg.byDataType = 0;
|
|
|
+
|
|
|
+ bRet = hCNetSDK.NET_DVR_GetSTDConfig(lUserID, 3624, struCfg);
|
|
|
+ if (!bRet) {
|
|
|
+ nErr = hCNetSDK.NET_DVR_GetLastError();
|
|
|
+ log.error("NET_DVR_GetSTDConfig失败,{}", nErr);
|
|
|
+ return 0f;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_struThermometryInfo.dwSize = m_struThermometryInfo.size();
|
|
|
+ m_struThermometryInfo.wPresetNo = 1;
|
|
|
+ m_struThermometryInfo.struPresetInfo[0] = new HCNetSDK.NET_DVR_THERMOMETRY_PRESETINFO_PARAM();
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].byEnabled = 1;
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].byRuleID = 1;
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].wDistance = 10;
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].fEmissivity = (float) 0.9599;
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].byReflectiveEnabled = 0;
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].fReflectiveTemperature = 20;
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].byRuleCalibType = 2;
|
|
|
+ // m_struThermometryInfo.struPresetInfo[0].szRuleName ="1";
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].byDistanceUnit = 0;
|
|
|
+ // m_struThermometryInfo.struPresetInfo[0].byemissivityMode = 0;
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].struPoint = new HCNetSDK.NET_VCA_POINT();
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].struPoint.fX = 0;
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].struPoint.fY = 0;
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].struPoint.write();
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].struRegion = new HCNetSDK.NET_VCA_POLYGON();
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].struRegion.dwPointNum = 2;
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].struRegion.struPos[0] = new HCNetSDK.NET_VCA_POINT();
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].struRegion.struPos[0].fX = (float) 0.187;
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].struRegion.struPos[0].fY = (float) 0.6119;
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].struRegion.struPos[0].write();
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].struRegion.struPos[1] = new HCNetSDK.NET_VCA_POINT();
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].struRegion.struPos[1].fX = (float) 0.876;
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].struRegion.struPos[1].fY = (float) 0.569;
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].struRegion.struPos[1].write();
|
|
|
+ m_struThermometryInfo.struPresetInfo[0].struRegion.write();
|
|
|
+ m_struThermometryInfo.write();
|
|
|
+ struCfg.lpInBuffer = m_struThermometryInfo.getPointer();
|
|
|
+ struCfg.dwInSize = m_struThermometryInfo.size();
|
|
|
+
|
|
|
+ boolean setSTDConfig = hCNetSDK.NET_DVR_SetSTDConfig(lUserID, 3625, struCfg);
|
|
|
+ if (!setSTDConfig) {
|
|
|
+ nErr = hCNetSDK.NET_DVR_GetLastError();
|
|
|
+ log.error("NET_DVR_SetSTDConfig,{}", nErr);
|
|
|
+ }
|
|
|
+
|
|
|
+ HCNetSDK.NET_DVR_JPEGPICTURE_WITH_APPENDDATA m_strJpegWithAppenData = new HCNetSDK.NET_DVR_JPEGPICTURE_WITH_APPENDDATA();
|
|
|
+ m_strJpegWithAppenData.dwSize = m_strJpegWithAppenData.size();
|
|
|
+ m_strJpegWithAppenData.dwChannel = 2;
|
|
|
+ HCNetSDK.BYTE_ARRAY ptrJpegByte = new HCNetSDK.BYTE_ARRAY(2 * 1024 * 1024);
|
|
|
+ HCNetSDK.BYTE_ARRAY ptrP2PDataByte = new HCNetSDK.BYTE_ARRAY(2 * 1024 * 1024);
|
|
|
+ m_strJpegWithAppenData.pJpegPicBuff = ptrJpegByte.getPointer();
|
|
|
+ m_strJpegWithAppenData.pP2PDataBuff = ptrP2PDataByte.getPointer();
|
|
|
+
|
|
|
+ bRet = hCNetSDK.NET_DVR_CaptureJPEGPicture_WithAppendData(lUserID, 2, m_strJpegWithAppenData);
|
|
|
+ if (bRet) {
|
|
|
+ // 测温数据
|
|
|
+ if (m_strJpegWithAppenData.dwP2PDataLen > 0) {
|
|
|
+ HKPoint point = point2point(hkPoint, sourceWidth, sourceHeight, m_strJpegWithAppenData.dwJpegPicWidth,
|
|
|
+ m_strJpegWithAppenData.dwJpegPicHeight);
|
|
|
+ return getTemperature0(m_strJpegWithAppenData.pP2PDataBuff
|
|
|
+ .getByteBuffer((long) ((m_strJpegWithAppenData.dwJpegPicWidth * point.y + point.x) * 4), 4));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0f;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Float getTemperature0(ByteBuffer byteBuffer) {
|
|
|
+ byte[] byTempData = new byte[4];
|
|
|
+ byteBuffer.get(byTempData);
|
|
|
+
|
|
|
+ int l = byTempData[0];
|
|
|
+ l &= 0xff;
|
|
|
+ l |= ((long) byTempData[1] << 8);
|
|
|
+ l &= 0xffff;
|
|
|
+ l |= ((long) byTempData[2] << 16);
|
|
|
+ l &= 0xffffff;
|
|
|
+ l |= ((long) byTempData[3] << 24);
|
|
|
+ return Float.intBitsToFloat(l);
|
|
|
+ }
|
|
|
+
|
|
|
+ private HKPoint point2point(HKPoint points, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight) {
|
|
|
+ points.x = points.x * sourceWidth / targetWidth;
|
|
|
+ points.y = points.y * sourceHeight / targetHeight;
|
|
|
+
|
|
|
+ points.x = points.x >= targetWidth ? targetWidth : points.x;
|
|
|
+ points.x = points.x < 0 ? 0 : points.x;
|
|
|
+
|
|
|
+ points.y = points.y >= targetHeight ? targetHeight : points.y;
|
|
|
+ points.y = points.y < 0 ? 0 : points.y;
|
|
|
+
|
|
|
+ return points;
|
|
|
+ }
|
|
|
+
|
|
|
}
|