【Person-Based Access Control】Configuring Door Control Schedule
サンプルプログラム
//
// Device Network SDK (Person-Based Access Control)
// Schedule Settings
// Configure Door Control Schedule
//
//
#include <stdio.h>
#include <iostream>
#include <afx.h>
#include “Windows.h”
#include “HCNetSDK.h”
using namespace std;
void main()
{
//—————————————
//Initialize
NET_DVR_Init();
//Set connection timeout and reconnection function
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.168.1.64”); //Device IP address
struLoginInfo.wPort = 8000; //Device service port number
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;
}
//—————————————
//Set door status schedule, template 1 linked to door 1
NET_DVR_DOOR_STATUS_PLAN struDoorStatusPlan = {0};
struDoorStatusPlan.dwSize = sizeof(struDoorStatusPlan);
struDoorStatusPlan.dwTemplateNo = 1;//Schedule template 1
BOOL bRet1 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_DOOR_STATUS_PLAN, 1, \
&struDoorStatusPlan, sizeof(struDoorStatusPlan));
if (!bRet1)
{
printf(“Setting door status schedule failed, error:%d.\n”, NET_DVR_GetLastError());
NET_DVR_Logout(lUserID);
NET_DVR_Cleanup();
return;
}
//Set door status schedule template 1, template 1 links to week schedule 1 and holiday group 1
CStringm_csTemplateName = “door status schedule template 1”;
NET_DVR_PLAN_TEMPLATE struPlanTem = {0};
struPlanTem.dwSize = sizeof(struPlanTem);
struPlanTem.byEnable = 1;//Enable or not: 0-No, 1-Yes
strncpy((char *)struPlanTem.byTemplateName, (LPCTSTR)m_csTemplateName, TEMPLATE_NAME_LEN);
struPlanTem.dwWeekPlanNo = 1;//Week schedule No.1
struPlanTem.dwHolidayGroupNo[0] = 1;//Holiday group No.1, up to 16 holiday groups can be linked to each schedule
//struPlanTem.dwHolidayGroupNo[1] = 2;//Holiday group No.2
BOOL bRet2 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_DOOR_STATUS_PLAN_TEMPLATE, 1, \
&struPlanTem, sizeof(struPlanTem));
if (!bRet2)
{
printf(“Setting door status schedule template failed, error:%d.\n”, NET_DVR_GetLastError());
NET_DVR_Logout(lUserID);
NET_DVR_Cleanup();
return;
}
//Set week schedule 1 for door status
NET_DVR_WEEK_PLAN_CFG struWeekPlan = {0};
struWeekPlan.dwSize = sizeof(struWeekPlan);
struWeekPlan.byEnable = 1;//Enable week scheudle
NET_DVR_SINGLE_PLAN_SEGMENT struSinglePlanSegment = {0};
LPNET_DVR_SINGLE_PLAN_SEGMENT lpPlanSegment = &struSinglePlanSegment;
struSinglePlanSegment.byEnable = 1;
struSinglePlanSegment.byDoorStatus = 3;//Door status: 0-invalid, 1-sleepy, 2-remain open, 3-remain closed.
struSinglePlanSegment.struTimeSegment.struBeginTime.byHour = 0;//Start time
struSinglePlanSegment.struTimeSegment.struBeginTime.byMinute = 0;
struSinglePlanSegment.struTimeSegment.struBeginTime.bySecond = 0;
struSinglePlanSegment.struTimeSegment.struEndTime.byHour = 23;//End time
struSinglePlanSegment.struTimeSegment.struEndTime.byMinute = 59;
struSinglePlanSegment.struTimeSegment.struEndTime.bySecond = 59;
/*Up to 8 time periods can be set for each day, and you can set different statuses for each time period Here only takes setting one period for each day*/
for (int iDate = 0; iDate<MAX_DAYS; iDate++)
{
memcpy(&struWeekPlan.struPlanCfg[iDate][0], lpPlanSegment, sizeof(struSinglePlanSegment));
}
BOOL bRet3 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_WEEK_PLAN_CFG, 1, \
&struWeekPlan, sizeof(struWeekPlan));
if (!bRet3)
{
printf(“Setting week schedule for door status failed, error:%d.\n”, NET_DVR_GetLastError());
NET_DVR_Logout(lUserID);
NET_DVR_Cleanup();
return;
}
//Set holiday group for door status
CStringm_csGroupName = “door status holiday group 1”;
NET_DVR_HOLIDAY_GROUP_CFG struHolidayGroup1 = {0};
struHolidayGroup1.dwSize = sizeof(struHolidayGroup1);
struHolidayGroup1.byEnable = 1;
strncpy((char *)struHolidayGroup1.byGroupName, (LPCTSTR)m_csGroupName, HOLIDAY_GROUP_NAME_LEN);
struHolidayGroup1.dwHolidayPlanNo[0] = 1;//Holiday group 1 links to holiday schedule 1,
//up to 16 holiday schedules can be linked to one holiday group
BOOL bRet4 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_DOOR_STATUS_HOLIDAY_GROUP, 1, \
&struHolidayGroup1, sizeof(struHolidayGroup1));
if (!bRet4)
{
printf(“Setting holiday group for door status failed, error:%d.\n”, NET_DVR_GetLastError());
NET_DVR_Logout(lUserID);
NET_DVR_Cleanup();
return;
}
//Set holiday schedule for door status
NET_DVR_HOLIDAY_PLAN_CFG struHolidayPlan = {0};
struHolidayPlan.dwSize = sizeof(struHolidayPlan);
struHolidayPlan.byEnable = 1;
struHolidayPlan.struBeginDate.wYear = 2017;//Holiday start date
struHolidayPlan.struBeginDate.byMonth = 10;
struHolidayPlan.struBeginDate.byDay = 1;
struHolidayPlan.struEndDate.wYear = 2017;//Holiday end date
struHolidayPlan.struEndDate.byMonth = 10;
struHolidayPlan.struEndDate.byDay = 7;
//Copy the week schedule parameters to holiday schedule of door status
memcpy(struHolidayPlan.struPlanCfg, struWeekPlan.struPlanCfg, sizeof(NET_DVR_SINGLE_PLAN_SEGMENT)*MAX_DAYS*MAX_TIMESEGMENT_V30);
BOOL bRet5 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_DOOR_STATUS_HOLIDAY_PLAN, 1, \
&struHolidayPlan, sizeof(struHolidayPlan));
if (!bRet5)
{
printf(“Setting holiday schedule for door status failed, error:%d.\n”, NET_DVR_GetLastError());
NET_DVR_Logout(lUserID);
NET_DVR_Cleanup();
return;
}
//—————————————
//Exit
Sleep(5000);
//Log out
NET_DVR_Logout(lUserID);
//Release SDK resource
NET_DVR_Cleanup();
return;
}