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

📄 utility.c

📁 一个在Linux下开发的IP摄像头的驱动程序及控制软件
💻 C
字号:
#include "Utility.h"

#define MAX_DEVICE_TO_ACCESS   16


SCODE ServerManagerInitBlock(HANDLE *phServerMgr, HANDLE *phDevice, TCHAR *pszModelName, TSERVER_INFO tServerInfo)
{
	SCODE scRet = S_OK;
	TVersionInfo tVerInfo;
	TSRVMNGR_DEV_PROPERTY tDevProperty;

	// ServerManager version information
	memset(&tVerInfo, 0, sizeof(tVerInfo));
	tVerInfo.wMajor = SRVMNGR_VERSION_MAJOR;
	tVerInfo.wMinor = SRVMNGR_VERSION_MINOR;
	tVerInfo.wBuild = SRVMNGR_VERSION_BUILD;
	tVerInfo.wRevision = SRVMNGR_VERSION_REVISION;

	// 1. Initialize the ServerManager object
	scRet = ServerManager_Initial(phServerMgr, MAX_DEVICE_TO_ACCESS, 0, &tVerInfo);
	if (S_OK != scRet)
	{
		printf("ServerManager_Initial failed: %X\n", scRet);
		return scRet;
	}

	// 2. Create the ServerManager device object
	scRet = ServerManager_CreateDevice(*phServerMgr, phDevice);
	if (S_OK != scRet)
	{
		printf("ServerManager_CreateDevice failed: %X\n", scRet);
		goto Lab_ReleaseHandle;
	}

	memset(&tDevProperty, 0, sizeof(TSRVMNGR_DEV_PROPERTY));
	strcpy(tDevProperty.tServerProperty.szHost, tServerInfo.szHostName);
	strcpy(tDevProperty.tServerProperty.szUserName, tServerInfo.szUserName);
	strcpy(tDevProperty.tServerProperty.szPassword, tServerInfo.szPassWord);
	tDevProperty.tServerProperty.dwHttpPort = tServerInfo.dwHttpPort;
	tDevProperty.tServerProperty.dwTimeout = tServerInfo.dwTimeout;
	tDevProperty.bServerUtlPriority = FALSE;

	// 3. Set the Device Properties
	scRet = ServerManager_SetDeviceProperty(*phDevice, &tDevProperty);
	if (S_OK != scRet)
	{
		printf("ServerManager_SetDeviceProperty failed: %X\n", scRet);
		goto Lab_DeleteDevice;
	}

	// 4. Connect to the server and retrieve the server model in block mode
	scRet = ServerManager_OpenDeviceBlock(*phDevice, pszModelName, MAX_PATH);
	if (S_OK != scRet)
	{
		printf("ServerManager_OpenDeviceBlock failed: %X\n", scRet);
		goto Lab_DeleteDevice;
	}
	else
	{
		printf("Model Name = %s\n", pszModelName);
	}

	return scRet;

	// Release resource
Lab_DeleteDevice:
	ServerManager_DeleteDevice(phDevice);
Lab_ReleaseHandle:
	ServerManager_Release(phServerMgr);

	return scRet;
}

SCODE ServerManagerRelease(HANDLE *phServerMgr, HANDLE *phDevice)
{
	SCODE scRet = S_OK;

	scRet = ServerManager_DeleteDevice(phDevice);
	if (S_OK != scRet)
	{
		printf("ServerManager_DeleteDevice failed: %X\n", scRet);
		return scRet;
	}

	scRet = ServerManager_Release(phServerMgr);
	if (S_OK != scRet)
	{
		printf("ServerManager_Release failed: %X\n", scRet);
		return scRet;
	}

	return scRet;
}

SCODE ParseInputArgument(int argc, char* argv[], TSERVER_INFO *ptServerInfo, ESRVMGR_SAMPLE eSrvMgrSample)
{
	int iCnt;

	memset(ptServerInfo, 0, sizeof(TSERVER_INFO));
	ptServerInfo->dwHttpPort = 0;
	ptServerInfo->dwTimeout = 0;
	ptServerInfo->bRead = FALSE;
	ptServerInfo->tHttpOperation.bPost = FALSE;
	
	for (iCnt = 1; iCnt < argc; iCnt++)
	{
		// Basic commands		
		if (strncmp(argv[iCnt], "-I", 2) == 0 && strlen(argv[iCnt]) > 2)
		{
			// -I[IP/Domain Name]
			strncpy(ptServerInfo->szHostName, &argv[iCnt][2], sizeof(ptServerInfo->szHostName));
		}
		else if (strncmp(argv[iCnt], "-H", 2) == 0 && strlen(argv[iCnt]) > 2)
		{
			// -H[HTTP Port]
			ptServerInfo->dwHttpPort = atoi(&argv[iCnt][2]);
		}
		else if (strncmp(argv[iCnt], "-U", 2) == 0 && strlen(argv[iCnt]) > 2)
		{
			// -U[User Name]
			strncpy(ptServerInfo->szUserName, &argv[iCnt][2], sizeof(ptServerInfo->szUserName));
		}
		else if (strncmp(argv[iCnt], "-P", 2) == 0 && strlen(argv[iCnt]) > 2)
		{
			// -P[Password]
			strncpy(ptServerInfo->szPassWord, & argv[iCnt][2], sizeof(ptServerInfo->szPassWord));
	    }
		else if (strncmp(argv[iCnt], "-T", 2) == 0 && strlen(argv[iCnt]) > 2)
		{
			// -T[Timeout]
			ptServerInfo->dwTimeout = atoi(&argv[iCnt][2]);
	    }
		else if (strncmp(argv[iCnt], "-R", 2) == 0 )
		{
			// -R (Use Read operation. If not being set, use Write operation.)
			ptServerInfo->bRead = true;
		}

		// DIDO extension commands
		if (eSrvMgrSample == eSrvMgrDIDO)
		{
			if (strncmp(argv[iCnt], "-1", 2) == 0 && strlen(argv[iCnt]) > 2)
			{
				// -1[H or L]
				strncpy(&ptServerInfo->acDOStatus[0], &argv[iCnt][2], sizeof(ptServerInfo->acDOStatus[0]));
			}
			else if (strncmp(argv[iCnt], "-2", 2) == 0 && strlen(argv[iCnt]) > 2)
			{
				// -2[H or L]
				strncpy(&ptServerInfo->acDOStatus[1], &argv[iCnt][2], sizeof(ptServerInfo->acDOStatus[1]));
			}
		}

		// HTTP Operation extension commands
		if (eSrvMgrSample == eSrvMgrHTTPOperation)
		{
			if (strncmp(argv[iCnt], "-C", 2) == 0 && strlen(argv[iCnt]) > 2)
			{
				// -C[URL command]
				strncpy(ptServerInfo->tHttpOperation.szUrlCommand, &argv[iCnt][2], sizeof(ptServerInfo->tHttpOperation.szUrlCommand));
			}
			else if (strncmp(argv[iCnt], "-O", 2) == 0 )
			{
				// -O (Use POST method. If not being set, use GET method.)
				ptServerInfo->tHttpOperation.bPost = true;
			}
		}

		// SystemInfo extension commands
		if (eSrvMgrSample == eSrvMgrSystemInfo)
		{
			if (strncmp(argv[iCnt], "-M", 2) == 0 && strlen(argv[iCnt]) > 2)
			{
				// -M[SystemInfo Item]
				strncpy(ptServerInfo->tSystemInfo.szSystemItem, &argv[iCnt][2], sizeof(ptServerInfo->tSystemInfo.szSystemItem));
			}
			else if (strncmp(argv[iCnt], "-N", 2) == 0 && strlen(argv[iCnt]) > 2)
			{
				// -N[Item Content]
				strncpy(ptServerInfo->tSystemInfo.szItemContent, &argv[iCnt][2], sizeof(ptServerInfo->tSystemInfo.szItemContent));
			}
		}

		// UART extension commands
		if (eSrvMgrSample == eSrvMgrUART)
		{
			if (strncmp(argv[iCnt], "-D", 2) == 0 && strlen(argv[iCnt]) > 2)
			{
				// -D[Data]
				strncpy(ptServerInfo->byUARTData, &argv[iCnt][2], sizeof(ptServerInfo->byUARTData));
			}
		}
	}
	if (strlen(ptServerInfo->szHostName) == 0)
	{
		printf("please input IP address\n");
		return -1;
	}

	return S_OK;
}

⌨️ 快捷键说明

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