123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- #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; //规则ID,0代表获取全部规则,具体规则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;
- }
|