【People Counting】Searching History Data

サンプルプログラム

//
// Device Network SDK (People Counting)
// Search Data and Report
// 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;
}

関連記事