⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nonblocking.c

📁 一个在Linux下开发的IP摄像头的驱动程序及控制软件
💻 C
字号:
#ifdef _WIN32
#include <windows.h> 
#else
#include <sys/time.h>
#endif  _WIN32
#include <stdio.h>
#include "Utility.h"

 
TSERVER_INFO g_tServerInfo;
TSERVERUTL_DEV_PROPERTY tDevProperty;
HANDLE g_hServerUtl;
HANDLE g_hDevice;


int g_iWaitCount;

int DoNonBlockMode();
void __stdcall ServUtlStatusCallback(HANDLE hDevice, DWORD dwContext, DWORD dwStatus,
                           DWORD dwParam1, DWORD dwParam2);


int main(int argc, char* argv[])
{
	if (HandleBasicArgument(argc, argv, &g_tServerInfo) < 0) return -1;

    if (DoNonBlockMode() < 0)
		return -1;

	return 0;
}

int DoNonBlockMode()
{

	char lpszModelName[64]; 
	char szInputBuf[256];
	char szSection[256], szEntry[256];
	char szContent[256];
	int iNum;
	SCODE scRet ;

	if (ServerUtlInit(&g_hServerUtl, &g_hDevice, lpszModelName, g_tServerInfo) < 0)
		return -1;

	// do a while loop to ask user for item to retrieve

	g_iWaitCount = 0; 
	printf("To end this program, please press Enter directly.\n");
	printf("Please select the info index to retrieve (range: %d to %d):",
		eSystemResetSystem, eCamCtrlPatrolName);
		
	memset(szInputBuf,0,sizeof(szInputBuf));
	if (fgets(szInputBuf, 255, stdin) == NULL)
	{
		ServerUtlRelease(&g_hServerUtl, &g_hDevice);
		return -1;
	}

	if (strlen(szInputBuf) > 0 && szInputBuf[strlen(szInputBuf) - 1] == '\n')
		szInputBuf[strlen(szInputBuf) - 1] = 0;

	if (szInputBuf[0] == 0)
	{
		ServerUtlRelease(&g_hServerUtl, &g_hDevice);
		return -1;
	}

	iNum = atoi(szInputBuf);
	if (iNum < eSystemResetSystem || iNum > eCamCtrlPatrolName)
	{
		printf("\nIndex out of range!\n\n");
		ServerUtlRelease(&g_hServerUtl, &g_hDevice);
		return -1;
	}

	scRet = ServerUtl_GetSysInfoSecEntry(g_hDevice, (ESYSTEM_INFO_ID) iNum, szSection, szEntry);
	if (scRet != S_OK)
	{
		printf("\nServer does not support such property!\n");
		ServerUtlRelease(&g_hServerUtl, &g_hDevice);
		return -1;
	}
		
	ServerUtl_GetSysInfoByID(g_hDevice, szContent, (ESYSTEM_INFO_ID) iNum, -1);

	printf("[%s] %s: %s\n\n", szSection, szEntry, szContent);
	printf("set the entry as: ");
	if (fgets(szInputBuf, 255, stdin) == NULL)
	{
		ServerUtlRelease(&g_hServerUtl, &g_hDevice);
		return -1;
	}

	if (strlen(szInputBuf) > 0 && szInputBuf[strlen(szInputBuf) - 1] == '\n')
		szInputBuf[strlen(szInputBuf) - 1] = 0;

	if (szInputBuf[0] == 0)
	{
		ServerUtlRelease(&g_hServerUtl, &g_hDevice);
		return -1;
	}

	scRet = ServerUtl_SetSysInfo(g_hDevice, szInputBuf, szSection, szEntry, -1);
	if (scRet != S_OK)
	{
		printf("set entry vlaue fail\n");
		ServerUtlRelease(&g_hServerUtl, &g_hDevice);
		return -1;
	}	
	if (scRet == S_OK)						//update the remote config. 
	{
		scRet = ServerUtl_UpdateRemoteConfig(g_hDevice, true);		
		if (scRet != S_OK)
		{
			printf("update remote config fail:%d\n",scRet );
			ServerUtlRelease(&g_hServerUtl, &g_hDevice);
			return -1;
		}
	} 
    g_iWaitCount = 0;

	while(g_iWaitCount < 30)
	{
#ifdef _WIN32
		Sleep(1000);
#else
		sleep(1);
#endif  //_WIN32
		g_iWaitCount++;
		printf(".");
	}
 
	ServerUtlRelease(&g_hServerUtl, &g_hDevice);

	return 0;


}

void __stdcall ServUtlStatusCallback(HANDLE hDevice, DWORD dwContext, DWORD dwStatus,
                           DWORD dwParam1, DWORD dwParam2)
{
   printf("callback function Result :%i\n",dwParam1);
   
   g_iWaitCount = 30;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -