Configure Authentication Mode Control Schedule

You can configure the week or holiday schedule to regularly control the authentication modes (e.g., by card, by card+password, by fingerprint, by fingerprint+card, and so on) in some specific time periods.

  • 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 Authentication Mode Control Schedule

  1. Optional: Call NET_DVR_GetDeviceAbility, specify the capability type dwAbilityType to "ACS_ABILITY", set the input buffer (pInBuf) to XML_Desc_AcsAbility for getting the access control capability to check if configuring authentication mode control schedule is supported.

    The capability is returned in the message XML_AcsAbility by the output pointer (pOutBuf).

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

    Otherwise, configuring authentication mode control schedule is not supported, please end this task.

  2. Perform one of the following operations to set week or holiday schedule for authentication mode control.
      1. Call NET_DVR_GetDVRConfig with NET_DVR_GET_VERIFY_WEEK_PLAN (command No.: 2124) to get the existing week schedule configurations for reference.

        Note:

        The week schedule parameters are returned in the structure NET_DVR_WEEK_PLAN_CFG by output buffer (lpOutBuffer).

      2. Call NET_DVR_SetDVRConfig with NET_DVR_SET_VERIFY_WEEK_PLAN (command No.: 2125) and set the input buffer (lpInBuffer) to NET_DVR_WEEK_PLAN_CFG for setting the week schedule.

      1. Call NET_DVR_GetDVRConfig with NET_DVR_GET_VERIFY_HOLIDAY_PLAN (command No.: 2128) to get the existing holiday schedule configurations for reference.

        Note:

        The holiday schedule parameters are returned in the structure NET_DVR_HOLIDAY_PLAN_CFG by output buffer (lpOutBuffer).

      2. Call NET_DVR_SetDVRConfig with NET_DVR_SET_VERIFY_HOLIDAY_PLAN (command No.: 2129) and set the input buffer (lpInBuffer) to NET_DVR_HOLIDAY_PLAN_CFG for setting the holiday schedule.

      3. Call NET_DVR_GetDVRConfig with NET_DVR_GET_VERIFY_HOLIDAY_GROUP (command No.: 2132) to get the existing holiday group configurations for reference.

        Note:

        The holiday group parameters are returned in the structure NET_DVR_HOLIDAY_GROUP_CFG by output buffer (lpOutBuffer).

      4. Call NET_DVR_SetDVRConfig with NET_DVR_SET_VERIFY_HOLIDAY_GROUP (command No.: 2133) and set the input buffer (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_VERIFY_PLAN_TEMPLATE (command No.: 2136) to get the existing schedule template configurations for reference.
    Note:

    The schedule template parameters are returned in the structure NET_DVR_PLAN_TEMPLATE by output buffer (lpOutBuffer).

  4. Call NET_DVR_SetDVRConfig with NET_DVR_SET_VERIFY_PLAN_TEMPLATE (command No.: 2137) and set the input buffer (lpInBuffer) to NET_DVR_PLAN_TEMPLATE for setting the schedule template.
  5. Optional: Call NET_DVR_GetDVRConfig with NET_DVR_GET_CARD_READER_PLAN (command No.: 2142) to get the existing authentication mode control schedule configurations for reference.
    Note:

    The authentication mode control schedule parameters are returned in the structure NET_DVR_CARD_READER_PLAN by output buffer (lpOutBuffer).

  6. Call NET_DVR_SetDVRConfig NET_DVR_SET_CARD_READER_PLAN (command No.: 2143) and set the input buffer (lpInBuffer) to NET_DVR_CARD_READER_PLAN for linking the configured template to the authentication mode control schedule and finishing the configuration.

Sample Code for Configuring Authentication Mode 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 card reader authentication mode schedule, template 1 linked to card reader 1
	NET_DVR_CARD_READER_PLAN struCardReaderPlan = {0};
	struCardReaderPlan.dwSize = sizeof(struCardReaderPlan);
	struCardReaderPlan.dwTemplateNo = 1;//Schedule template 1
	BOOL bRet1 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_CARD_READER_PLAN, 1, \
		&struCardReaderPlan, sizeof(struCardReaderPlan));
	if (!bRet1)
	{
		printf("Setting card reader authentication mode schedule failed, error:%d.\n", NET_DVR_GetLastError());
		NET_DVR_Logout(lUserID);
		NET_DVR_Cleanup();
		return;
	}

	//Set card reader authentication mode schedule template 1, template 1 links to week schedule 1 and holiday group 1
	CString	m_csTemplateName = "card reader authentication mode 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 = 2;//Week schedule No.2
	struPlanTem.dwHolidayGroupNo[0] = 2;//Holiday group No.2, up to 16 holiday groups can be linked to each schedule

	BOOL bRet2 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_VERIFY_PLAN_TEMPLATE, 1, \
		&struPlanTem, sizeof(struPlanTem));
	if (!bRet2)
	{
		printf("Setting card reader authentication mode schedule template failed, error:%d.\n", NET_DVR_GetLastError());
		NET_DVR_Logout(lUserID);
		NET_DVR_Cleanup();
		return;
	}

	//Set week schedule 2 for card reader authentication mode
	NET_DVR_WEEK_PLAN_CFG struWeekPlan2 = {0};
	struWeekPlan2.dwSize = sizeof(struWeekPlan2);
	struWeekPlan2.byEnable = 1;//Enable week schedule

	NET_DVR_SINGLE_PLAN_SEGMENT struSinglePlanSegment = {0};
	LPNET_DVR_SINGLE_PLAN_SEGMENT lpPlanSegment = &struSinglePlanSegment;
	struSinglePlanSegment.byEnable = 1;
	struSinglePlanSegment.byVerifyMode = 4;//Authentication mode: 0-invalid, 1-sleepy, 2-card+password, 3-card, 
                                               //4-card or password, 5-fingerprint, 6-fingerprint+password, 7-fingerprint or card,
                                               //8-fingerprint+card, 9-fingerprint+card+password
	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 authentication modes for each time period
	Here only takes setting one period for each day*/

	for (int iDate = 0; iDate<MAX_DAYS; iDate++)
	{
		memcpy(&struWeekPlan2.struPlanCfg[iDate][0], lpPlanSegment, sizeof(struSinglePlanSegment));
	}

	BOOL bRet3 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_VERIFY_WEEK_PLAN, 2, \
		&struWeekPlan2, sizeof(struWeekPlan2));
	if (!bRet3)
	{
		printf("Setting week schedule for card reader authentication mode failed,error:%d.\n", NET_DVR_GetLastError());
		NET_DVR_Logout(lUserID);
		NET_DVR_Cleanup();
		return;
	}

	//Set holiday group for card reader authentication mode
	CString	m_csGroupName = "Holiday group 2";
	NET_DVR_HOLIDAY_GROUP_CFG struHolidayGroup2 = {0};
	struHolidayGroup2.dwSize = sizeof(struHolidayGroup2);
	struHolidayGroup2.byEnable = 1;
	strncpy((char *)struHolidayGroup2.byGroupName, (LPCTSTR)m_csGroupName, HOLIDAY_GROUP_NAME_LEN);
	struHolidayGroup2.dwHolidayPlanNo[0] = 2;//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_VERIFY_HOLIDAY_GROUP, 2, \
		&struHolidayGroup2, sizeof(struHolidayGroup2));
	if (!bRet4)
	{
		printf("设Setting holiday group for card reader authentication mode failed, error:%d.\n", NET_DVR_GetLastError());
		NET_DVR_Logout(lUserID);
		NET_DVR_Cleanup();
		return;
	}

	//Set holiday schedule for card reader authentication mode
	NET_DVR_HOLIDAY_PLAN_CFG struHolidayPlan2 = {0};
	struHolidayPlan2.dwSize = sizeof(struHolidayPlan2);
	struHolidayPlan2.byEnable = 1;
	struHolidayPlan2.struBeginDate.wYear = 2017;//Holiday start date
	struHolidayPlan2.struBeginDate.byMonth = 10;
	struHolidayPlan2.struBeginDate.byDay = 1;
	struHolidayPlan2.struEndDate.wYear = 2017;//Holiday end date
	struHolidayPlan2.struEndDate.byMonth = 10;
	struHolidayPlan2.struEndDate.byDay = 7;
	//Copy the week schedule parameters to holiday schedule of card reader authentication mode
	memcpy(struHolidayPlan2.struPlanCfg, struWeekPlan2.struPlanCfg, sizeof(NET_DVR_SINGLE_PLAN_SEGMENT)*MAX_DAYS*MAX_TIMESEGMENT_V30);

	BOOL bRet5 = NET_DVR_SetDVRConfig(lUserID, NET_DVR_SET_VERIFY_HOLIDAY_PLAN, 2, \
		&struHolidayPlan2, sizeof(struHolidayPlan2));
	if (!bRet5)
	{
		printf("Setting holiday schedule for card reader authentication mode 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.