📄 motiondetection.c
字号:
/*
* This sample code is written by block mode. If you want to use nonblock mode,
* please reference the HttpOperation_NonBlock sample.
*
*/
#include "Utility.h"
int main(int argc, char* argv[])
{
SCODE scRet = S_OK;
HANDLE hServerMgr = NULL;
HANDLE hDevice = NULL;
TCHAR szModelName[MAX_PATH] = {0};
TSERVER_INFO tServerInfo;
// MotionDetection parameter
int i = 0;
int iWndNumber = 3;
DWORD dwCamNumber = 1; // Index of camera, starting from 1.
TSRVCTRL_MODETECT_INFO atMDInfo[3];
char szInputBuf[MAX_PATH] = {0};
// example Get MotionDetectionInfo input: -I192.168.0.1 -H80 -Uroot -Proot -T30000 -R
// example Set MotionDetectionInfo input: -I192.168.0.1 -H80 -Uroot -Proot -T30000
if (ParseInputArgument(argc, argv, &tServerInfo, eSrvMgrMotionDetection) != S_OK)
{
return 0;
}
// 1. Initialization
scRet = ServerManagerInitBlock(&hServerMgr, &hDevice, szModelName, tServerInfo);
if (S_OK != scRet)
{
printf("ServerManagerInitBlock failed...\n");
return 0;
}
memset(atMDInfo, 0, sizeof(atMDInfo));
// 2. Motion Detection sample
if (tServerInfo.bRead)
{
// Get Motion Detection info
scRet = ServerManager_GetMotionDetectionInfoBlock(hDevice, dwCamNumber, atMDInfo);
if (S_OK == scRet)
{
for (i = 0; i < iWndNumber; i++)
{
if (atMDInfo[i].bWindowEnabled)
{
printf("Windows %d: Name = %s, X = %d, Y = %d, W = %d, H = %d, Sensitivity = %d, Percent = %d\n",
i + 1, atMDInfo[i].szName, atMDInfo[i].nX, atMDInfo[i].nY, atMDInfo[i].nW, atMDInfo[i].nH, atMDInfo[i].nSensitivity, atMDInfo[i].nPercent);
}
}
}
else
{
printf("Get MotionDetectionInfo failed: %X\n", scRet);
}
}
else
{
while (1)
{
printf("\n\nPlease press Enter directly to end this program.\n\n");
// check the input command
printf("Which MotionDetection windows to set? (1-3)\n");
if (fgets(szInputBuf, MAX_PATH, stdin) == NULL)
{
printf("Incorrect input!\n\n");
continue;
}
if (strlen(szInputBuf) > 0 && szInputBuf[strlen(szInputBuf) - 1] == '\n')
{
szInputBuf[strlen(szInputBuf) - 1] = 0;
}
if (szInputBuf[0] == 0)
{
break; // end the rpogram
}
iWndNumber = atoi(szInputBuf);
if (iWndNumber < 1 || iWndNumber > 3)
{
printf("Input value incorrect or out of range!\n\n");
continue;
}
iWndNumber--;
printf("Type the settings in sequence:\n\"Name, X, Y, Width, Height, Sensitivity, Percentage\"\n");
if (fgets(szInputBuf, MAX_PATH, stdin) == NULL)
{
printf("Incorrect input!\n\n");
continue;
}
i = sscanf(szInputBuf,"%s %d %d %d %d %d %d", atMDInfo[iWndNumber].szName, &atMDInfo[iWndNumber].nX, &atMDInfo[iWndNumber].nY,
&atMDInfo[iWndNumber].nW, &atMDInfo[iWndNumber].nH, &atMDInfo[iWndNumber].nSensitivity, &atMDInfo[iWndNumber].nPercent);
if (i != 7)
{
printf("Incorrect Format\n\n");
continue;
}
atMDInfo[iWndNumber].bWindowEnabled = TRUE;
// Set Motion Detection info
scRet = ServerManager_SetMotionDetectionInfoBlock(hDevice, dwCamNumber, atMDInfo, FALSE);
if (S_OK == scRet)
{
printf("Set MotionDetectionInfo success.\n");
}
else
{
printf("Set MotionDetectionInfo failed: %X\n", scRet);
}
}
}
// 3. Release all resource
ServerManagerRelease(&hServerMgr, &hDevice);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -