【Thermal】Manually Measuring Temperature

サンプルプログラム

//
// Device Network SDK (Thermal)
// Manually Measure Temperature
// Sample Code of Manually Measuring Temperature
//
#include <stdio.h>
#include <iostream>
#include “Windows.h”
#include “HCNetSDK.h”

using namespace std;

//Macro Definition of temporal resolution
#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)

int iNum=0;
#define ISAPI_OUT_LEN 3 * 1024 * 1024

#define ISAPI_STATUS_LEN  8*1024

void CALLBACK GetManualThermInfoCallback(DWORD dwType, void* lpBuffer, DWORD dwBufLen, void* pUserData)
{
    if (dwType == NET_SDK_CALLBACK_TYPE_DATA)
    {
        LPNET_SDK_MANUAL_THERMOMETRY lpManualThermometry = new NET_SDK_MANUAL_THERMOMETRY;
memcpy(lpManualThermometry, lpBuffer, sizeof(*lpManualThermometry));
        NET_DVR_TIME struAbsTime = {0};
        struAbsTime.dwYear = GET_YEAR(lpManualThermometry->dwAbsTime);
        struAbsTime.dwMonth = GET_MONTH(lpManualThermometry->dwAbsTime);
        struAbsTime.dwDay = GET_DAY(lpManualThermometry->dwAbsTime);
        struAbsTime.dwHour = GET_HOUR(lpManualThermometry->dwAbsTime);
        struAbsTime.dwMinute = GET_MINUTE(lpManualThermometry->dwAbsTime);

struAbsTime.dwSecond = GET_SECOND(lpManualThermometry->dwAbsTime);

        printf(“Manual Temperature Measurement Result: dwChannel[%d]byThermometryUnit[d%]dwAbsTime[%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d]\n”,
            lpManualThermometry->dwChannel, lpManualThermometry->byThermometryUnit, struAbsTime.dwYear,

struAbsTime.dwMonth, struAbsTime.dwDay, struAbsTime.dwHour, struAbsTime.dwMinute, struAbsTime.dwSecond);

        if (lpManualThermometry != NULL)
        {
            delete lpManualThermometry;
            lpManualThermometry = NULL;
        }
    }
    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 main()
{
DWORD dwChannel = 2;  //Thermal imaging channel
    char *m_pOutBuf = new char[ISAPI_OUT_LEN];
memset(m_pOutBuf, 0, ISAPI_OUT_LEN);
    char *m_pStatusBuf = new char[ISAPI_STATUS_LEN];

memset(m_pStatusBuf, 0, ISAPI_STATUS_LEN);

    //—————————————
    //Initialize
NET_DVR_Init();
    //Set connected time and reconnected time
    NET_DVR_SetConnectTime(2000, 1);

NET_DVR_SetReconnect(10000, true);

    //—————————————
    //Register device (it is not required when listening alarm)
    LONG lUserID;
    NET_DVR_DEVICEINFO_V30 struDeviceInfo;
    lUserID = NET_DVR_Login_V30(“10.8.10.199 “, 8000, “admin”, “abcd1234”, &struDeviceInfo);
    if (lUserID < 0)
    {
        printf(“Login error, %d\n”, NET_DVR_GetLastError());
        NET_DVR_Cleanup();
        return;

}

    //Capability sets of manual temperature measurement
    NET_DVR_STD_ABILITY struStdAbility = {0};
    struStdAbility.lpCondBuffer = &dwChannel;
    struStdAbility.dwCondSize = sizeof(DWORD);
    struStdAbility.lpOutBuffer    = m_pOutBuf;
    struStdAbility.dwOutSize      = ISAPI_OUT_LEN;
    struStdAbility.lpStatusBuffer = m_pStatusBuf;

struStdAbility.dwStatusSize   = ISAPI_STATUS_LEN;

    if(!NET_DVR_GetSTDAbility(lUserID,NET_DVR_GET_MANUALTHERM_CAPABILITIES,&struStdAbility))
    {
        printf(“NET_DVR_GET_MANUALTHERM_CAPABILITIES failed, error code: %d\n”, NET_DVR_GetLastError());
    }
    else
    {
        printf(“NET_DVR_GET_MANUALTHERM_CAPABILITIES is successful!”);

}

    //Configure basic parameter of manual temperature measurement
    NET_DVR_STD_CONFIG struStdConfig = {0};
    struStdConfig.lpCondBuffer = &dwChannel;
    struStdConfig.dwCondSize = sizeof(dwChannel);
    struStdConfig.lpInBuffer = NULL;
    struStdConfig.dwInSize = 0;
    NET_SDK_MANUALTHERM_BASICPARAM struManualThermBasicParam = {0};
    struStdConfig.lpOutBuffer = (LPVOID)&struManualThermBasicParam;
    struStdConfig.dwOutSize = sizeof(struManualThermBasicParam);
    struStdConfig.lpStatusBuffer = m_pStatusBuf;
struStdConfig.dwStatusSize = ISAPI_STATUS_LEN;

DWORD dwReturned=0;

    if(!NET_DVR_GetSTDConfig(lUserID,NET_DVR_GET_MANUALTHERM_BASICPARAM,&struStdConfig))
    {
        printf(“NET_DVR_GET_MANUALTHERM_BASICPARAM failed, error code: %d\n”, NET_DVR_GetLastError());
    }
    else
    {
        printf(“NET_DVR_GET_MANUALTHERM_BASICPARAM is successful!”);

}

    struManualThermBasicParam.wDistance = 20; //Distance (m), ranging from 0 to 10000
    struStdConfig.lpInBuffer = (LPVOID)&struManualThermBasicParam;

struStdConfig.dwInSize = sizeof(struManualThermBasicParam);

    if(!NET_DVR_SetSTDConfig(lUserID,NET_DVR_SET_MANUALTHERM_BASICPARAM,&struStdConfig))
    {
        printf(“NET_DVR_SET_MANUALTHERM_BASICPARAM failed, error code: %d\n”, NET_DVR_GetLastError());
    }
    else
    {
        printf(“NET_DVR_SET_MANUALTHERM_BASICPARAM is successful!”);

}

    //Configure rule for manual temperature measurement
    NET_SDK_MANUAL_THERMOMETRY struManualTherm = {0};
    struManualTherm.dwSize = sizeof(struManualTherm);
    struManualTherm.dwChannel = dwChannel;
    struManualTherm.byThermometryUnit = 0; //Temperature unit: 0-Centigrade,1-Fahrenheit, 2-Kelvin
    struManualTherm.struRuleInfo.byRuleID = 1;
    struManualTherm.struRuleInfo.byEnable=1;
    strcpy(struManualTherm.struRuleInfo.szRuleName, “TestName”);
    struManualTherm.struRuleInfo.byRuleCalibType = 0;
    struManualTherm.struRuleInfo.struPointTherm.struPoint.fX = 0.5; //Normalized value, ranging from 0.001 to 1.
    struManualTherm.struRuleInfo.struPointTherm.struPoint.fY = 0.5; //Normalized value, ranging from 0.001 to 1.
    struStdConfig.lpCondBuffer = &dwChannel;
    struStdConfig.dwCondSize = sizeof(dwChannel);
    struStdConfig.lpInBuffer = (LPVOID)&struManualTherm;;

struStdConfig.dwInSize = sizeof(struManualTherm);

    if(!NET_DVR_SetSTDConfig(lUserID,NET_DVR_SET_MANUALTHERM,&struStdConfig))
    {
        printf(“NET_DVR_SET_MANUALTHERM failed, error code: %d\n”, NET_DVR_GetLastError());
    }
    else
    {
        printf(“NET_DVR_SET_MANUALTHERM is successful!”);

}

    //Enable manual temperature measurement
    NET_DVR_REALTIME_THERMOMETRY_COND struThermCond = {0};
    struThermCond.dwSize = sizeof(struThermCond);
    struThermCond.byRuleID = 1;       //Rule ID, 0-Get all rules, the rule ID starts from 1.

struThermCond.dwChan = dwChannel; //Start from 1, 0xffffffff- Get all channels

    LONG ManualHandle = NET_DVR_StartRemoteConfig(lUserID, NET_DVR_GET_MANUALTHERM_INFO, &struThermCond, sizeof(struThermCond), GetManualThermInfoCallback, NULL);
    if (ManualHandle >= 0)
    {
        printf(“NET_DVR_GET_MANUALTHERM_INFO failed, error code: %d\n”, NET_DVR_GetLastError());
    }
    else
    {
        printf(“NET_DVR_GET_MANUALTHERM_INFO is successful!”);

}

    Sleep(5000);  //Wait for receiving manual measurement result
    //Close the handle created by long connection configuration API, and release resource.
    if(!NET_DVR_StopRemoteConfig(ManualHandle))
    {
        printf(“NET_DVR_StopRemoteConfig failed, error code: %d\n”, NET_DVR_GetLastError());

}

    //User logout, if the user is not login, skip this step.

NET_DVR_Logout(lUserID);

    //Release SDK resource

NET_DVR_Cleanup();

    if (m_pOutBuf != NULL)
    {
        delete []m_pOutBuf;
        m_pOutBuf = NULL;

}

    if (m_pStatusBuf != NULL)
    {
        delete []m_pStatusBuf;
        m_pStatusBuf = NULL;
}
    return;
}

関連記事