SOMS/test/HikTest/MeasureTempreutre.cpp

166 lines
5.8 KiB
C++
Raw Permalink Normal View History

2024-07-15 10:31:26 +08:00
#include "MeasureTempreutre.h"
#include <stdio.h>
#include <iostream>
#include "Windows.h"
#include <HCNetSDK.h>
using namespace std;
#pragma comment(lib, "HCNetSDK.lib")
//ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EAB6A8>
#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("ʵʱ<EFBFBD><EFBFBD><EFBFBD>½<EFBFBD><EFBFBD><EFBFBD>: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);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (struThermometry.byRuleCalibType == 0)
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ:fTemperature[%f]\n", struThermometry.struPointThermCfg.fTemperature);
}
//<2F><>/<2F>߲<EFBFBD><DFB2><EFBFBD>
if ((struThermometry.byRuleCalibType == 1) || (struThermometry.byRuleCalibType == 2))
{
printf("<EFBFBD><EFBFBD>/<2F>߲<EFBFBD><DFB2><EFBFBD><EFBFBD><EFBFBD>Ϣ: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; //<2F>ȳ<EFBFBD><C8B3><EFBFBD>ͨ<EFBFBD><CDA8>
//---------------------------------------
//<2F><>ʼ<EFBFBD><CABC>
NET_DVR_Init();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
NET_DVR_SetConnectTime(2000, 1);
NET_DVR_SetReconnect(10000, true);
//---------------------------------------
//ע<><D7A2><EFBFBD>豸(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD>ע<EFBFBD><D7A2>)
LONG lUserID;
NET_DVR_DEVICEINFO_V30 struDeviceInfo;
string ip = "192.168.81.105";
string user = "admin";
string pwd = "yunda123";
//printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼ip:\n");
//printf("input: ");
//cin >> ip;
////scanf_s("%s", &ip,30);
//printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>:\n");
//printf("input: ");
//cin >> user;
//printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\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("<EFBFBD><EFBFBD>¼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;
}
//<2F><><EFBFBD><EFBFBD>ʵʱ<CAB5>¶ȼ<C2B6><C8BC><EFBFBD>
NET_DVR_REALTIME_THERMOMETRY_COND struThermCond = { 0 };
struThermCond.dwSize = sizeof(struThermCond);
struThermCond.byRuleID = 0; //<2F><><EFBFBD><EFBFBD>ID<49><44>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡȫ<C8A1><C8AB><EFBFBD><EFBFBD><EFBFBD>򣬾<EFBFBD><F2A3ACBE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID<49><44>1<EFBFBD><31>ʼ
struThermCond.dwChan = dwChannel; //<2F><>1<EFBFBD><31>ʼ<EFBFBD><CABC>0xffffffff<66><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡȫ<C8A1><C8AB>ͨ<EFBFBD><CDA8>
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 << "<EFBFBD><EFBFBD>" << i << "<EFBFBD><EFBFBD>" << endl;
////<2F><><EFBFBD><EFBFBD>q<EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD>򣬷<EFBFBD><F2A3ACB7><EFBFBD>һֱ<D2BB><D6B1><EFBFBD><EFBFBD>
//char c = 0;
//while ('q' != c)
//{
// printf("input 'q' to quit\n");
// printf("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>Ԥ<EFBFBD><D4A4>λ\n");
// int flag = -1;
// cin >> flag;
// if (flag > 0)
// {
// bool res = NET_DVR_PTZPreset(lUserID, 39, flag);
// if (res)
// {
// printf("Ԥ<><D4A4>λ<EFBFBD><CEBB><EFBFBD>óɹ<C3B3>\n");
// }
// }
// printf("input: ");
// scanf_s("%c", &c);
//}
Sleep(2000);
//<2F>رճ<D8B1><D5B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ýӿ<C3BD><D3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><C4BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>Դ
if (!NET_DVR_StopRemoteConfig(lHandle))
{
printf("NET_DVR_StopRemoteConfig failed, error code: %d\n", NET_DVR_GetLastError());
}
}
string flag1 = "";
cin >> flag1;
cout << flag1 << endl;
//ע<><D7A2><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>û<EFBFBD>е<EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ
NET_DVR_Logout(lUserID);
//<2F>ͷ<EFBFBD>SDK<44><4B>Դ
NET_DVR_Cleanup();
return;
}