SOMS/test/HikTest/MeasureTempreutre.cpp
2024-07-15 10:31:26 +08:00

166 lines
5.8 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "MeasureTempreutre.h"
#include <stdio.h>
#include <iostream>
#include "Windows.h"
#include <HCNetSDK.h>
using namespace std;
#pragma comment(lib, "HCNetSDK.lib")
//时间解析宏定义
#define GET_YEAR(_time_) (((_time_)>>26) + 2000)
#define GET_MONTH(_time_) (((_time_)>>22) & 15)
#define GET_DAY(_time_) (((_time_)>>17) & 31)
#define GET_HOUR(_time_) (((_time_)>>12) & 31)
#define GET_MINUTE(_time_) (((_time_)>>6) & 63)
#define GET_SECOND(_time_) (((_time_)>>0) & 63)
void CALLBACK GetThermInfoCallback(DWORD dwType, void* lpBuffer, DWORD dwBufLen, void* pUserData)
{
if (dwType == NET_SDK_CALLBACK_TYPE_DATA)
{
NET_DVR_THERMOMETRY_UPLOAD struThermometry = { 0 };
memcpy(&struThermometry, lpBuffer, sizeof(NET_DVR_THERMOMETRY_UPLOAD));
NET_DVR_TIME struAbsTime = { 0 };
struAbsTime.dwYear = GET_YEAR(struThermometry.dwAbsTime);
struAbsTime.dwMonth = GET_MONTH(struThermometry.dwAbsTime);
struAbsTime.dwDay = GET_DAY(struThermometry.dwAbsTime);
struAbsTime.dwHour = GET_HOUR(struThermometry.dwAbsTime);
struAbsTime.dwMinute = GET_MINUTE(struThermometry.dwAbsTime);
struAbsTime.dwSecond = GET_SECOND(struThermometry.dwAbsTime);
printf("实时测温结果:byRuleID[%d]wPresetNo[%d]byRuleCalibType[%d]byThermometryUnit[%d]byDataType[%d]dwAbsTime[%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d]\n",
struThermometry.byRuleID, struThermometry.wPresetNo, struThermometry.byRuleCalibType, struThermometry.byThermometryUnit,
struThermometry.byDataType, struAbsTime.dwYear, struAbsTime.dwMonth, struAbsTime.dwDay, struAbsTime.dwHour, struAbsTime.dwMinute, struAbsTime.dwSecond);
//点测温
if (struThermometry.byRuleCalibType == 0)
{
printf("点测温信息:fTemperature[%f]\n", struThermometry.struPointThermCfg.fTemperature);
}
//框/线测温
if ((struThermometry.byRuleCalibType == 1) || (struThermometry.byRuleCalibType == 2))
{
printf("框/线测温信息:fMaxTemperature[%f]fMinTemperature[%f]fAverageTemperature[%f]fTemperatureDiff[%f]\n",
struThermometry.struLinePolygonThermCfg.fMaxTemperature, struThermometry.struLinePolygonThermCfg.fMinTemperature,
struThermometry.struLinePolygonThermCfg.fAverageTemperature, struThermometry.struLinePolygonThermCfg.fTemperatureDiff);
}
}
else if (dwType == NET_SDK_CALLBACK_TYPE_STATUS)
{
DWORD dwStatus = *(DWORD*)lpBuffer;
if (dwStatus == NET_SDK_CALLBACK_STATUS_SUCCESS)
{
printf("dwStatus:NET_SDK_CALLBACK_STATUS_SUCCESS\n");
}
else if (dwStatus == NET_SDK_CALLBACK_STATUS_FAILED)
{
DWORD dwErrCode = *(DWORD*)((char*)lpBuffer + 4);
printf("NET_DVR_GET_MANUALTHERM_INFO failed, Error code %d\n", dwErrCode);
}
}
}
void MeasureTempreutre::TestMeasureTemp()
{
DWORD dwChannel = 2; //热成像通道
//---------------------------------------
//初始化
NET_DVR_Init();
//设置连接时间与重连时间
NET_DVR_SetConnectTime(2000, 1);
NET_DVR_SetReconnect(10000, true);
//---------------------------------------
//注册设备(监听报警可以不注册)
LONG lUserID;
NET_DVR_DEVICEINFO_V30 struDeviceInfo;
string ip = "192.168.81.105";
string user = "admin";
string pwd = "yunda123";
//printf("请输入登录ip:\n");
//printf("input: ");
//cin >> ip;
////scanf_s("%s", &ip,30);
//printf("请输入用户名:\n");
//printf("input: ");
//cin >> user;
//printf("请输入密码:\n");
//printf("input: ");
//cin >> pwd;
lUserID = NET_DVR_Login_V30(const_cast<char *>( ip.data()), 8000, const_cast<char*>(user.data()), const_cast<char*>(pwd.data()), &struDeviceInfo);
printf("登录ip: %s\n", ip);
if (lUserID < 0)
{
printf("Login failed, error code: %d\n", NET_DVR_GetLastError());
NET_DVR_Cleanup();
printf("input 'q' to quit\n");
printf("input: ");
int flag;
cin >> flag;
return;
}
//启动实时温度检测
NET_DVR_REALTIME_THERMOMETRY_COND struThermCond = { 0 };
struThermCond.dwSize = sizeof(struThermCond);
struThermCond.byRuleID = 0; //规则ID0代表获取全部规则具体规则ID从1开始
struThermCond.dwChan = dwChannel; //从1开始0xffffffff代表获取全部通道
for (int i = 0; i < 1000; i++)
{
LONG lHandle = NET_DVR_StartRemoteConfig(lUserID, NET_DVR_GET_REALTIME_THERMOMETRY, &struThermCond, sizeof(struThermCond), GetThermInfoCallback, NULL);
if (lHandle < 0)
{
printf("NET_DVR_GET_REALTIME_THERMOMETRY failed, error code: %d\n", NET_DVR_GetLastError());
}
else
{
printf("NET_DVR_GET_REALTIME_THERMOMETRY is successful!");
}
cout << "" << i << "" << endl;
////输入q退出程序否则一直运行
//char c = 0;
//while ('q' != c)
//{
// printf("input 'q' to quit\n");
// printf("输入数字调用预置位\n");
// int flag = -1;
// cin >> flag;
// if (flag > 0)
// {
// bool res = NET_DVR_PTZPreset(lUserID, 39, flag);
// if (res)
// {
// printf("预置位调用成功\n");
// }
// }
// printf("input: ");
// scanf_s("%c", &c);
//}
Sleep(2000);
//关闭长连接配置接口所创建的句柄,释放资源
if (!NET_DVR_StopRemoteConfig(lHandle))
{
printf("NET_DVR_StopRemoteConfig failed, error code: %d\n", NET_DVR_GetLastError());
}
}
string flag1 = "";
cin >> flag1;
cout << flag1 << endl;
//注销用户,如果前面没有登录,该步骤则不需要
NET_DVR_Logout(lUserID);
//释放SDK资源
NET_DVR_Cleanup();
return;
}