📄 motiondetection.c
字号:
#include <stdlib.h>
//#include "SrvDepResource.h"
#include "Utility.h"
#ifndef _WIN32
#include <sys/time.h>
#endif // _WIN32
TSERVER_INFO g_tServerInfo;
int main(int argc, char* argv[])
{
char szInputBuf[4] = "";
int iChoice, iWndNumber;
TSERVERUTL_MODETECT_INFO atMotionInfo[3];
SCODE scRet;
int i;
if (HandleBasicArgument(argc, argv, &g_tServerInfo) < 0)
return -1;
printf("Choose one operation\n(1) Read Motion Detection Settings, (2) Set Motion Detection Settings:");
szInputBuf[0] = 0;
if (fgets(szInputBuf, 3, stdin) == NULL)
return -1;
if (strlen(szInputBuf) > 0 && szInputBuf[strlen(szInputBuf) - 1] == '\n')
szInputBuf[strlen(szInputBuf) - 1] = 0;
if (szInputBuf[0] == 0)
{
printf("please input correct number\n");
return -1;
}
iChoice = atoi(szInputBuf);
if (iChoice < 1 || iChoice > 2)
{
printf("\nIndex out of range!\n\n");
return -1;
}
memset(atMotionInfo, 0, sizeof(atMotionInfo));
//get montion detection window info
if (iChoice == 1)
{
scRet = MotionGetSet(g_tServerInfo, atMotionInfo, &iWndNumber, TRUE);
if (scRet != 0)
{
printf("get motion rectangle fail with error %X\n", scRet);
return scRet;
}
for (i = 0; i < (int) iWndNumber; i++)
{
if (atMotionInfo[i].bWindowEnabled)
{
if (atMotionInfo[i].bFullSize)
printf("Sensitivity = %d, Percent = %d\n",
atMotionInfo[i].nSensitivity, atMotionInfo[i].nPercent);
else
printf("Windows %d: Name = %s, X = %d, Y = %d, W = %d, H = %d, Sensitivity = %d, Percent = %d\n",
i + 1,
atMotionInfo[i].szName, atMotionInfo[i].nX, atMotionInfo[i].nY,
atMotionInfo[i].nW, atMotionInfo[i].nH,
atMotionInfo[i].nSensitivity, atMotionInfo[i].nPercent);
}
}
printf("\n");
}
else
{
printf("Which windows to set? (1-3) ");
szInputBuf[0] = 0;
if (fgets(szInputBuf, 3, stdin) == NULL)
{
printf("please input correct number\n");
return -1;
}
if (strlen(szInputBuf) > 0 && szInputBuf[strlen(szInputBuf) - 1] == '\n')
szInputBuf[strlen(szInputBuf) - 1] = 0;
if (szInputBuf[0] == 0)
{
printf("please input correct number\n");
return -1;
}
iWndNumber = atoi(szInputBuf);
if (iWndNumber < 1 || iWndNumber > 3)
{
printf("\nIndex out of range!\n\n");
return -1;
}
iWndNumber--;
printf("Type the value settings in sequence:\n\"Name, X, Y, Width, Height, Sensitivity, Percentage\"\n");
printf("(Note, each one in an individual line without comma):\n");
if ((i = scanf("%[a-zA-Z0-9 _-] %d %d %d %d %d %d", atMotionInfo[iWndNumber].szName,
&atMotionInfo[iWndNumber].nX, &atMotionInfo[iWndNumber].nY, &atMotionInfo[iWndNumber].nW,
&atMotionInfo[iWndNumber].nH, &atMotionInfo[iWndNumber].nSensitivity,
&atMotionInfo[iWndNumber].nPercent)) != 7)
{
printf("Incorrect Format %d\n\n", i);
return -1;
}
atMotionInfo[iWndNumber].bWindowEnabled = TRUE;
#ifndef _WIN32
fgets(szInputBuf, 3, stdin);
#else
fflush(stdin);
#endif // _WIN32
scRet = MotionGetSet(g_tServerInfo, atMotionInfo, &iWndNumber, FALSE);
if (scRet != 0)
{
printf("fail to set motion detection info with error %X\n", scRet);
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -