Search Data and Report

or devices with local storage, the people counting data will be stored locally after enabling people counting function. You can set condition to search the stored data and get the different types of reports according to the configured condition.

  • Make sure you have called NET_DVR_Init to initialize the integration environment.

  • Make sure you have called NET_DVR_Login_V40 to log in to the device.

Figure 1 Programming Flow of Searching Data and Report
Note:
  • For rear-end devices, to check if searching people counting statistics of multiple channels is supported, you can call NET_DVR_GetDeviceAbility and specify the capability type as "DEVICE_SOFTHARDWARE_ABILITY" (macro definition value: 0x001) to get the software and hardware capability (XML_BasicCapability). If supports, the node <isSupportMultiChannelSearch> will be returned and its value is "true".

  • For front-end devices, to check if searching people counting statistics of multiple channels is supported, you can call NET_DVR_GetDeviceAbility, specify the capability type (dwAbilityType) as "DEVICE_ABILITY_INFO" (macro definition value: 0x011), and set the input buffer pointer (pInBuf) to XML_Desc_VcaChanAbility. If supports, the node <isSupportMultiChannelSearch> will be returned and its value is "true".

  • To check if searching people counting statistics of different time periods is supported, you can call NET_DVR_STDXMLConfig to pass through the request URL: GET /ISAPI/ContentMgmt/capabilities for getting storage configuration capability. If supports, the node <isSupportCountingSearchByUTC> will be returned and its value is "true".

  1. Call NET_DVR_StartRemoteConfig with NET_DVR_GET_PDC_RESULT (command No.: 5089) and specify IpInBuff to NET_DVR_PDC_QUERY_COND) for setting up persistent connection and start searching.
  2. Call NET_DVR_GetNextRemoteConfig to get the search results one by one.
    Note:

    If 1000 (One result is found) and 1001 (Searching) returned, you should call this API repeatedly; if 1002 (Ended) or 1003 (Exception) is returned, you should stop calling this API.

    The search results are returned in the structure NET_DVR_PDC_RESULT by lpOutBuff.

  3. Call NET_DVR_StopRemoteConfig to disconnect the persistent connection.

Sample Code for Searching History Data

#include <stdio.h>
#include <iostream>
#include "Windows.h"
#include "HCNetSDK.h"
using namespace std;

void main() {
    //---------------------------------------
    // Initialize
    NET_DVR_Init();
    //Set connection time and reconnection time
    NET_DVR_SetConnectTime(2000, 1);
    NET_DVR_SetReconnect(10000, true);

    //---------------------------------------
    // Log in to device.
    LONG lUserID;

    //Login parameters, including device IP address, user name, password, and so on.
    NET_DVR_USER_LOGIN_INFO struLoginInfo = {0};
    struLoginInfo.bUseAsynLogin = 0; //Synchronous login mode
    strcpy(struLoginInfo.sDeviceAddress, "192.0.0.64"); //IP address
    struLoginInfo.wPort = 8000; //Service port
    strcpy(struLoginInfo.sUserName, "admin"); //User name
    strcpy(struLoginInfo.sPassword, "abcd1234"); //Password
  
    //Device information, output parameter
    NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {0};

    lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40);
    if (lUserID < 0)
    {
        printf("Login failed, error code: %d\n", NET_DVR_GetLastError());
        NET_DVR_Cleanup();
        return;
    }
  
    NET_DVR_PDC_QUERY_COND m_struPdcResultCond={0};
    m_struPdcResultCond.dwSize = sizeof(m_struPdcResultCond);//Condition for searching people counting data
    m_struPdcResultCond.dwChannel = 1; //Device channel No.

    //Start time
    m_struPdcResultCond.struStartTime.wYear = 2016;
    m_struPdcResultCond.struStartTime.byMonth = 9;
    m_struPdcResultCond.struStartTime.byDay = 5;
    m_struPdcResultCond.struStartTime.byHour = 00;
    m_struPdcResultCond.struStartTime.byMinute = 00;
    m_struPdcResultCond.struStartTime.bySecond = 00;

    //End time 
    m_struPdcResultCond.struEndTime.wYear = 2016;
    m_struPdcResultCond.struEndTime.byMonth = 9;
    m_struPdcResultCond.struEndTime.byDay = 11;
    m_struPdcResultCond.struEndTime.byHour = 23;
    m_struPdcResultCond.struEndTime.byMinute = 59;
    m_struPdcResultCond.struEndTime.bySecond = 59;

    m_struPdcResultCond.byReportType = 2; //Search type: 0-Invalid, 1-Daily Report, 2-Weekly Report, 3- Monthly Report, 4-Annual Report

    LONG m_lHandle = NET_DVR_StartRemoteConfig(lUserID, NET_DVR_GET_PDC_RESULT, &m_struPdcResultCond, sizeof(m_struPdcResultCond), NULL, NULL);
    if (m_lHandle >= 0)
    {
        LONG iNextRet = 0;
        NET_DVR_PDC_RESULT m_struPdcResult = {0};
        while(true)
        {
            iNextRet = NET_DVR_GetNextRemoteConfig(m_lHandle, &m_struPdcResult, sizeof(NET_DVR_PDC_RESULT)); 
            if (iNextRet == NET_SDK_GET_NEXT_STATUS_SUCCESS) //Data is found.
            {
                printf("StartTime[%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d]EndTime[%4.4d%2.2d%2.2d%2.2d%2.2d%2.2d]dwEnterNum[%d]dwLeaveNum[%d]\n",\
                m_struPdcResult.struStartTime.wYear, m_struPdcResult.struStartTime.byMonth, m_struPdcResult.struStartTime.byDay,\
                m_struPdcResult.struStartTime.byHour, m_struPdcResult.struStartTime.byMinute, m_struPdcResult.struStartTime.bySecond,\
                m_struPdcResult.struEndTime.wYear, m_struPdcResult.struEndTime.byMonth, m_struPdcResult.struEndTime.byDay, \
                m_struPdcResult.struEndTime.byHour, m_struPdcResult.struEndTime.byMinute, m_struPdcResult.struEndTime.bySecond);
            }
            else
            {
                if (iNextRet == NET_SDK_GET_NETX_STATUS_NEED_WAIT) //Wait for the device to send data
                {
                    Sleep(5);
                    continue;
                }
                if (iNextRet == NET_SDK_GET_NEXT_STATUS_FINISH) //All data found.
                {
                    printf("People counting data search ended.\n");
                    break;
                }
                else if(iNextRet == NET_SDK_GET_NEXT_STATUS_FAILED) //Search exception.
                {
                    printf("Search exception.\n");
                    break;
                }
                else
                {
                    printf("Unknown status.\n");
                    break;
                }
            }

        }
    }
    else
    {
        printf("Search failed. Error code: %d\n",NET_DVR_GetLastError());
    }

    if (m_lHandle >= 0)
    {
        if (!NET_DVR_StopRemoteConfig(m_lHandle))
        {
            printf("Stopping searching people counting data failed.Error code: %d\n",NET_DVR_GetLastError());
        }
    }
  
    //Log out
    NET_DVR_Logout(lUserID);
    //Release SDK resource
    NET_DVR_Cleanup();
    return;
}

Call NET_DVR_Logout and NET_DVR_Cleanup to log out and release resources.