MeasureTempreutre.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #include "MeasureTempreutre.h"
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include "Windows.h"
  5. #include <HCNetSDK.h>
  6. using namespace std;
  7. #pragma comment(lib, "HCNetSDK.lib")
  8. //时间解析宏定义
  9. #define GET_YEAR(_time_) (((_time_)>>26) + 2000)
  10. #define GET_MONTH(_time_) (((_time_)>>22) & 15)
  11. #define GET_DAY(_time_) (((_time_)>>17) & 31)
  12. #define GET_HOUR(_time_) (((_time_)>>12) & 31)
  13. #define GET_MINUTE(_time_) (((_time_)>>6) & 63)
  14. #define GET_SECOND(_time_) (((_time_)>>0) & 63)
  15. void CALLBACK GetThermInfoCallback(DWORD dwType, void* lpBuffer, DWORD dwBufLen, void* pUserData)
  16. {
  17. if (dwType == NET_SDK_CALLBACK_TYPE_DATA)
  18. {
  19. NET_DVR_THERMOMETRY_UPLOAD struThermometry = { 0 };
  20. memcpy(&struThermometry, lpBuffer, sizeof(NET_DVR_THERMOMETRY_UPLOAD));
  21. NET_DVR_TIME struAbsTime = { 0 };
  22. struAbsTime.dwYear = GET_YEAR(struThermometry.dwAbsTime);
  23. struAbsTime.dwMonth = GET_MONTH(struThermometry.dwAbsTime);
  24. struAbsTime.dwDay = GET_DAY(struThermometry.dwAbsTime);
  25. struAbsTime.dwHour = GET_HOUR(struThermometry.dwAbsTime);
  26. struAbsTime.dwMinute = GET_MINUTE(struThermometry.dwAbsTime);
  27. struAbsTime.dwSecond = GET_SECOND(struThermometry.dwAbsTime);
  28. 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",
  29. struThermometry.byRuleID, struThermometry.wPresetNo, struThermometry.byRuleCalibType, struThermometry.byThermometryUnit,
  30. struThermometry.byDataType, struAbsTime.dwYear, struAbsTime.dwMonth, struAbsTime.dwDay, struAbsTime.dwHour, struAbsTime.dwMinute, struAbsTime.dwSecond);
  31. //点测温
  32. if (struThermometry.byRuleCalibType == 0)
  33. {
  34. printf("点测温信息:fTemperature[%f]\n", struThermometry.struPointThermCfg.fTemperature);
  35. }
  36. //框/线测温
  37. if ((struThermometry.byRuleCalibType == 1) || (struThermometry.byRuleCalibType == 2))
  38. {
  39. printf("框/线测温信息:fMaxTemperature[%f]fMinTemperature[%f]fAverageTemperature[%f]fTemperatureDiff[%f]\n",
  40. struThermometry.struLinePolygonThermCfg.fMaxTemperature, struThermometry.struLinePolygonThermCfg.fMinTemperature,
  41. struThermometry.struLinePolygonThermCfg.fAverageTemperature, struThermometry.struLinePolygonThermCfg.fTemperatureDiff);
  42. }
  43. }
  44. else if (dwType == NET_SDK_CALLBACK_TYPE_STATUS)
  45. {
  46. DWORD dwStatus = *(DWORD*)lpBuffer;
  47. if (dwStatus == NET_SDK_CALLBACK_STATUS_SUCCESS)
  48. {
  49. printf("dwStatus:NET_SDK_CALLBACK_STATUS_SUCCESS\n");
  50. }
  51. else if (dwStatus == NET_SDK_CALLBACK_STATUS_FAILED)
  52. {
  53. DWORD dwErrCode = *(DWORD*)((char*)lpBuffer + 4);
  54. printf("NET_DVR_GET_MANUALTHERM_INFO failed, Error code %d\n", dwErrCode);
  55. }
  56. }
  57. }
  58. void MeasureTempreutre::TestMeasureTemp()
  59. {
  60. DWORD dwChannel = 2; //热成像通道
  61. //---------------------------------------
  62. //初始化
  63. NET_DVR_Init();
  64. //设置连接时间与重连时间
  65. NET_DVR_SetConnectTime(2000, 1);
  66. NET_DVR_SetReconnect(10000, true);
  67. //---------------------------------------
  68. //注册设备(监听报警可以不注册)
  69. LONG lUserID;
  70. NET_DVR_DEVICEINFO_V30 struDeviceInfo;
  71. string ip = "192.168.81.105";
  72. string user = "admin";
  73. string pwd = "yunda123";
  74. //printf("请输入登录ip:\n");
  75. //printf("input: ");
  76. //cin >> ip;
  77. ////scanf_s("%s", &ip,30);
  78. //printf("请输入用户名:\n");
  79. //printf("input: ");
  80. //cin >> user;
  81. //printf("请输入密码:\n");
  82. //printf("input: ");
  83. //cin >> pwd;
  84. lUserID = NET_DVR_Login_V30(const_cast<char *>( ip.data()), 8000, const_cast<char*>(user.data()), const_cast<char*>(pwd.data()), &struDeviceInfo);
  85. printf("登录ip: %s\n", ip);
  86. if (lUserID < 0)
  87. {
  88. printf("Login failed, error code: %d\n", NET_DVR_GetLastError());
  89. NET_DVR_Cleanup();
  90. printf("input 'q' to quit\n");
  91. printf("input: ");
  92. int flag;
  93. cin >> flag;
  94. return;
  95. }
  96. //启动实时温度检测
  97. NET_DVR_REALTIME_THERMOMETRY_COND struThermCond = { 0 };
  98. struThermCond.dwSize = sizeof(struThermCond);
  99. struThermCond.byRuleID = 0; //规则ID,0代表获取全部规则,具体规则ID从1开始
  100. struThermCond.dwChan = dwChannel; //从1开始,0xffffffff代表获取全部通道
  101. for (int i = 0; i < 1000; i++)
  102. {
  103. LONG lHandle = NET_DVR_StartRemoteConfig(lUserID, NET_DVR_GET_REALTIME_THERMOMETRY, &struThermCond, sizeof(struThermCond), GetThermInfoCallback, NULL);
  104. if (lHandle < 0)
  105. {
  106. printf("NET_DVR_GET_REALTIME_THERMOMETRY failed, error code: %d\n", NET_DVR_GetLastError());
  107. }
  108. else
  109. {
  110. printf("NET_DVR_GET_REALTIME_THERMOMETRY is successful!");
  111. }
  112. cout << "第" << i << "次" << endl;
  113. ////输入q退出程序,否则一直运行
  114. //char c = 0;
  115. //while ('q' != c)
  116. //{
  117. // printf("input 'q' to quit\n");
  118. // printf("输入数字调用预置位\n");
  119. // int flag = -1;
  120. // cin >> flag;
  121. // if (flag > 0)
  122. // {
  123. // bool res = NET_DVR_PTZPreset(lUserID, 39, flag);
  124. // if (res)
  125. // {
  126. // printf("预置位调用成功\n");
  127. // }
  128. // }
  129. // printf("input: ");
  130. // scanf_s("%c", &c);
  131. //}
  132. Sleep(2000);
  133. //关闭长连接配置接口所创建的句柄,释放资源
  134. if (!NET_DVR_StopRemoteConfig(lHandle))
  135. {
  136. printf("NET_DVR_StopRemoteConfig failed, error code: %d\n", NET_DVR_GetLastError());
  137. }
  138. }
  139. string flag1 = "";
  140. cin >> flag1;
  141. cout << flag1 << endl;
  142. //注销用户,如果前面没有登录,该步骤则不需要
  143. NET_DVR_Logout(lUserID);
  144. //释放SDK资源
  145. NET_DVR_Cleanup();
  146. return;
  147. }