Configure Access Permission Control Schedule

To regularly control the access permissions for managing the accessible time duration (by default, it is 24 hours) of some important access control points, you can configure the week or holiday schedules.

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

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

Figure 1 Programming Flow of Configuring Access Permission Control Schedule

  1. Call NET_DVR_GetDeviceAbility, specify dwAbilityType to "ACS_ABILITY", set pInBuf to XML_Desc_AcsAbility for getting the access control capability to check if configuring access permission control schedule is supported.

    The capability is returned in the message XML_AcsAbility by pOutBuf.

    If the node <CardRightPlan> is returned, it indicates that configuring access permission control schedule is supported, and you can continue to perform the following steps.

    Otherwise, configuring access permission control schedule is not supported, please end this task.

  2. Perform one of the following operations to set week or holiday schedule for access permission control.
      1. Call NET_DVR_GetDVRConfig with "NET_DVR_GET_CARD_RIGHT_WEEK_PLAN" (command No.: 2126) to get default or configured week schedule configurations for reference.

        Note:

        The week schedule parameters are returned in the structure NET_DVR_WEEK_PLAN_CFG by lpOutBuffer.

      2. Call NET_DVR_SetDVRConfig with "NET_DVR_SET_CARD_RIGHT_WEEK_PLAN" (command No.: 2127) and set lpInBuffer to NET_DVR_WEEK_PLAN_CFG for setting the week schedule.

      1. Call NET_DVR_GetDVRConfig with "NET_DVR_GET_CARD_RIGHT_HOLIDAY_PLAN" (command No.: 2130) to get default or configured holiday schedule configurations for reference.

        Note:

        The holiday schedule parameters are returned in the structure NET_DVR_HOLIDAY_PLAN_CFG by lpOutBuffer.

      2. Call NET_DVR_SetDVRConfig with "NET_DVR_SET_CARD_RIGHT_HOLIDAY_PLAN" (command No.: 2131) and set lpInBuffer to NET_DVR_HOLIDAY_PLAN_CFG for setting the week schedule.

      3. Call NET_DVR_GetDVRConfig with "NET_DVR_GET_CARD_RIGHT_HOLIDAY_GROUP" (command No.: 2134) to get default or configured holiday group configurations for reference.

        Note:

        The holiday group parameters are returned in the structure NET_DVR_HOLIDAY_GROUP_CFG by lpOutBuffer.

      4. Call NET_DVR_SetDVRConfig with "NET_DVR_SET_CARD_RIGHT_HOLIDAY_GROUP" (command No.: 2135) and set lpInBuffer to NET_DVR_HOLIDAY_GROUP_CFG for adding the configured holiday schedule to a holiday group.

  3. Optional: Call NET_DVR_GetDVRConfig with "NET_DVR_GET_CARD_RIGHT_PLAN_TEMPLATE" (command No.: 2138) to get default or configured schedule template configurations for reference.
    Note:

    The schedule template parameters are returned in the structure NET_DVR_PLAN_TEMPLATE by lpOutBuffer.

  4. Call NET_DVR_SetDVRConfig with "NET_DVR_SET_CARD_RIGHT_PLAN_TEMPLATE" (command No.: 2139) and set lpInBuffer to NET_DVR_PLAN_TEMPLATE for setting the schedule template.
    Note:

    The configured schedule template can be directly linked to person ID when applying person information. And the linked person can get the access permission configured in the template.

Sample Code for Configuring Access Permission 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 access permission schedule template, when issuing card, link to this template
	
	CString	m_csTemplateName = "Access permission 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 bRet1 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_CARD_RIGHT_PLAN_TEMPLATE, 1, \
		&struPlanTem, sizeof(struPlanTem));
	if (!bRet1)
	{
		printf("Setting access permission schedule template failed, error:%d.\n", NET_DVR_GetLastError());
		NET_DVR_Logout(lUserID);
		NET_DVR_Cleanup();
		return;
	}

	//Set week schedule 1 for access permission
	NET_DVR_WEEK_PLAN_CFG struWeekPlan = {0};
	struWeekPlan.dwSize = sizeof(struWeekPlan);
	struWeekPlan.byEnable = 1;//Enable week schedule
	
	NET_DVR_SINGLE_PLAN_SEGMENT struSinglePlanSegment = {0};
	LPNET_DVR_SINGLE_PLAN_SEGMENT lpPlanSegment = &struSinglePlanSegment;
	struSinglePlanSegment.byEnable = 1;
	
	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. 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 bRet2 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_CARD_RIGHT_WEEK_PLAN, 1, \
		&struWeekPlan, sizeof(struWeekPlan));
	if (!bRet2)
	{
		printf("Setting week schedule for access permission failed, error:%d.\n", NET_DVR_GetLastError());
		NET_DVR_Logout(lUserID);
		NET_DVR_Cleanup();
		return;
	}

	//Set holiday group for access permission
	CString	m_csGroupName = "access permission 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 bRet3 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_CARD_RIGHT_HOLIDAY_GROUP, 1, \
		&struHolidayGroup1, sizeof(struHolidayGroup1));
	if (!bRet3)
	{
		printf("设Setting holiday group for access permission failed, error:%d.\n", NET_DVR_GetLastError());
		NET_DVR_Logout(lUserID);
		NET_DVR_Cleanup();
		return;
	}

	//Set holiday schedule for access permission
	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 access permission
	memcpy(struHolidayPlan.struPlanCfg, struWeekPlan.struPlanCfg, sizeof(NET_DVR_SINGLE_PLAN_SEGMENT)*MAX_DAYS*MAX_TIMESEGMENT_V30);
	
	BOOL bRet4 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_CARD_RIGHT_HOLIDAY_PLAN, 1, \
		&struHolidayPlan, sizeof(struHolidayPlan));
	if (!bRet4)
	{
		printf("Setting holiday schedule for access permission 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;
}

Call NET_DVR_Logout and NET_DVR_Cleanup to log out and release the resource.