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

📄 consolesample.c

📁 一个在Linux下开发的IP摄像头的驱动程序及控制软件
💻 C
📖 第 1 页 / 共 5 页
字号:
		szInputBuf[0] = 0;
		fgets(szInputBuf, 255, stdin);
		if (strlen(szInputBuf) > 0 && szInputBuf[strlen(szInputBuf) - 1] == '\n')
			szInputBuf[strlen(szInputBuf) - 1] = 0;

		if (szInputBuf[0] == 0)
			break;

		nNum = atoi(szInputBuf);
		if (nNum < eSystemResetSystem || nNum > eCamCtrlPatrolName)
		{
			printf("\nIndex out of range!\n\n");
			continue;
		}

		scRet = ServerUtl_GetSysInfoSecEntry(hDevice, (ESYSTEM_INFO_ID) nNum, szSection, szEntry);
		if (scRet != S_OK)
		{
			printf("\nServer does not support such property!\n\n");
			continue;
		}

		ServerUtl_GetSysInfoByID(hDevice, szContent, (ESYSTEM_INFO_ID) nNum, 0);

		printf("[%s] %s: %s\n\n", szSection, szEntry, szContent);
	}


	ServerUtl_DeleteDevice(hDevice);
	ServerUtl_Release(&hSrvUtl);


	return 0;
}

int TestDIDO()
{
	HANDLE hSrvUtl;
	HANDLE hDevice;
	char lpszModelName[64]; 
	char szInputBuf[256];
	DIDOSTATUS atDIDO[4];

	int nNum;
	int i;
	SCODE scRet;
	TSrvDepResource_ServerInfo srvInfo;

	if (ServerUtlConnectToServer(&hSrvUtl, &hDevice, lpszModelName) < 0)
		return -1;

	SrvDepResource_GetParamForServer(lpszModelName, &srvInfo);

	// do a while loop to ask user for item to retrieve
	while (1)
	{
		printf("To end this program, please press Enter directly.\n");
		printf("Choose one operation\n(1) Get DI, (2) Set DO :");

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

		if (szInputBuf[0] == 0)
			break;

		nNum = atoi(szInputBuf);
		if (nNum < 1 || nNum > 2)
		{
			printf("\nIndex out of range!\n\n");
			continue;
		}

		if (nNum == 1)
		{
			// get DI from server
			scRet = ServerUtl_GetDIStatus(hDevice, &atDIDO[0], &atDIDO[1], &atDIDO[2], &atDIDO[3], FALSE);
			if (scRet != S_OK)
			{
				printf("\nServerUtl_GetDIStatus failed %X\n\n", scRet);
				continue;
			}

			printf("DI(s) =");
			for (i = 0; i < (int) srvInfo.dwDiNum; i++)
			{
				if (i != 0)
					printf(", ");
				printf("%d(%s)", i + 1, atDIDO[i]==DIDO_HIGH?"H":"L");
			}

			printf("\n\n");
			continue;
		}

		nNum = 0;

		if (srvInfo.dwDoNum > 1)
		{
			while (1)
			{
				printf("Which DO to set? (%d - %d or %d means all)",
					0, srvInfo.dwDoNum - 1, srvInfo.dwDoNum);

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

				if (szInputBuf[0] == 0)
				{
					ServerUtl_DeleteDevice(hDevice);
					ServerUtl_Release(&hSrvUtl);
					return -1;
				}

				nNum = atoi(szInputBuf);
				if (nNum < 0 || nNum > (int) srvInfo.dwDoNum)
				{
					printf("Out of range!\n");
					continue;
				}

				break;
			}
		}

		while (1)
		{
			printf("Value set to? (L or H)");
			szInputBuf[0] = 0;
			fgets(szInputBuf, 255, stdin);
			if (strlen(szInputBuf) > 0 && szInputBuf[strlen(szInputBuf) - 1] == '\n')
				szInputBuf[strlen(szInputBuf) - 1] = 0;

			if (szInputBuf[0] == 0)
			{
				ServerUtl_DeleteDevice(hDevice);
				ServerUtl_Release(&hSrvUtl);
				return -1;
			}
			
			if (szInputBuf[0] == 'l' || szInputBuf[0] == 'L' || szInputBuf[0] == '0')
				atDIDO[0] = DIDO_LOW;
			else if (szInputBuf[0] == 'h' || szInputBuf[0] == 'H' || szInputBuf[0] == '1')
				atDIDO[0] = DIDO_HIGH;
			else
			{
				printf("Input value incorrect!\n");
				continue;
			}

			break;
		}

		atDIDO[1] = DIDO_NONE;
		if (nNum == srvInfo.dwDoNum)
			atDIDO[1] = atDIDO[0];
		else if (nNum > 0)
		{
			atDIDO[1] = atDIDO[0];
			atDIDO[0] = DIDO_NONE;
		}

		scRet = ServerUtl_SetDOLevel(hDevice, atDIDO[0], atDIDO[1], FALSE);
		if (scRet != S_OK)
		{
			printf("\nServerUtl_SetDOLevel failed %X\n\n", scRet);
			continue;
		}

		printf("DO set OK!\n\n");
	}


	ServerUtl_DeleteDevice(hDevice);
	ServerUtl_Release(&hSrvUtl);


	return 0;
}

int TestPTZ()
{
	HANDLE hSrvUtl;
	HANDLE hDevice;
	char lpszModelName[64]; 
	char szInputBuf[256];
	PTZCOMMANDS ptzCmd;

	int nNum;
	SCODE scRet;
	TSrvDepResource_ServerInfo srvInfo;

	if (ServerUtlConnectToServer(&hSrvUtl, &hDevice, lpszModelName) < 0)
		return -1;

	SrvDepResource_GetParamForServer(lpszModelName, &srvInfo);

	// do a while loop to ask user for item to retrieve
	while (1)
	{
		printf("To end this program, please press Enter directly.\n");
		printf("Choose one operation\n(1) Left, (2) Right, (3) Up, (4) Down, (5) Home, (6) Zoom in, (7) Zoom out\n");
		printf("(8) Focus Far, (9) Focus Near, (A) Focus Auto, (B) Auto Pan, (C) Auto Partol\n");
		printf("(D) Stop Pan/Tilt, (E) Iris Open, (F) Iris Close, (G) Iris Auto:");

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

		if (szInputBuf[0] == 0)
			break;

		nNum = 0;

		if (szInputBuf[0] <= '9')
			nNum = atoi(szInputBuf);
		else
		{
			if (szInputBuf[0] >= 'A' && szInputBuf[0] <= 'Z')
				nNum = szInputBuf[0] - 'A' + 10;
			else if (szInputBuf[0] >= 'a' && szInputBuf[0] <= 'z')
				nNum = szInputBuf[0] - 'a' + 10;
		}

		if (nNum < 1 || nNum > 16)
		{
			printf("\nInput value incorrect or out of range!\n\n");
			continue;
		}

		switch (nNum)
		{
		case 1:
			ptzCmd = SERVERUTL_PTZ_MOVE_LEFT;
			break;
		case 2:
			ptzCmd = SERVERUTL_PTZ_MOVE_RIGHT;
			break;
		case 3:
			ptzCmd = SERVERUTL_PTZ_MOVE_UP;
			break;
		case 4:
			ptzCmd = SERVERUTL_PTZ_MOVE_DOWN;
			break;
		case 5:
			ptzCmd = SERVERUTL_PTZ_MOVE_HOME;
			break;
		case 6:
			ptzCmd = SERVERUTL_PTZ_ZOOM_TELE;
			break;
		case 7:
			ptzCmd = SERVERUTL_PTZ_ZOOM_WIDE;
			break;
		case 8:
			ptzCmd = SERVERUTL_PTZ_FOCUS_NEAR;
			break;
		case 9:
			ptzCmd = SERVERUTL_PTZ_FOCUS_FAR;
			break;
		case 10:
			ptzCmd = SERVERUTL_PTZ_FOCUS_AUTO;
			break;
		case 11:
			ptzCmd = SERVERUTL_AUTO_PAN;
			break;
		case 12:
			ptzCmd = SERVERUTL_AUTO_PATROL;
			break;
		case 13:
			ptzCmd = SERVERUTL_AUTO_STOP;
			break;
		case 14:
			ptzCmd = SERVERUTL_IRIS_OPEN;
			break;
		case 15:
			ptzCmd = SERVERUTL_IRIS_CLOSE;
			break;
		case 16:
			ptzCmd = SERVERUTL_IRIS_AUTO;
			break;
		}

		nNum = 0;
		if (srvInfo.dwDoNum > 1)
		{
			while (1)
			{
				printf("Which camera to set? (%d - %d)",
					0, srvInfo.dwCamNum - 1, srvInfo.dwCamNum);

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

				if (szInputBuf[0] == 0)
				{
					ServerUtl_DeleteDevice(hDevice);
					ServerUtl_Release(&hSrvUtl);
					return -1;
				}

				nNum = atoi(szInputBuf);
				if (nNum < 0 || nNum >= (int) srvInfo.dwCamNum)
				{
					printf("Out of range!\n");
					continue;
				}

				break;
			}
		}

		// get DI from server
		scRet = ServerUtl_SendPTZCommand(hDevice, nNum, ptzCmd, NULL, FALSE);
		if (scRet != S_OK)
		{
			printf("ServerUtl_SendPTZCommand failed %X\n\n", scRet);
			continue;
		}

		printf("ServerUtl_SendPTZCommand OK!\n\n");
	}


	ServerUtl_DeleteDevice(hDevice);
	ServerUtl_Release(&hSrvUtl);


	return 0;
}

int TestUart()
{
	HANDLE hSrvUtl;
	HANDLE hDevice;
	char lpszModelName[64]; 
	char szInputBuf[256];
	char szReadWriteBuf[256];

	int nNum, nPort;
	SCODE scRet;
	TSrvDepResource_ServerInfo srvInfo;

	if (ServerUtlConnectToServer(&hSrvUtl, &hDevice, lpszModelName) < 0)
		return -1;

	SrvDepResource_GetParamForServer(lpszModelName, &srvInfo);

	// do a while loop to ask user for item to retrieve
	while (1)
	{
		printf("To end this program, please press Enter directly.\n");
		printf("Choose one operation\n(1) Read Uart, (2) Set Uart :");

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

		if (szInputBuf[0] == 0)
			break;

		nNum = atoi(szInputBuf);
		if (nNum < 1 || nNum > 2)
		{
			printf("\nIndex out of range!\n\n");
			continue;
		}

		nPort = 0;
		if (srvInfo.dwComNum > 1)
		{
			while (1)
			{
				printf("Which COM port to set? (%d - %d)",
					0, srvInfo.dwComNum - 1, srvInfo.dwComNum);

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

				if (szInputBuf[0] == 0)
				{
					ServerUtl_DeleteDevice(hDevice);
					ServerUtl_Release(&hSrvUtl);
					return -1;
				}

				nNum = atoi(szInputBuf);		
				if (nNum < 0 || nNum >= (int) srvInfo.dwComNum)
				{
					printf("Out of range!\n");
					continue;
				}

				break;
			}
		}

		if (nNum == 1)
		{
			time_t t1, t2;
			long lMilliSec1, lMilliSec2;
#ifndef _WIN32
			struct timeval tv;
			struct timezone tz;

			gettimeofday(&tv, &tz);

			t1 = tv.tv_sec;
			lMilliSec1 = (long)tv.tv_usec / 1000;
#else
			SYSTEMTIME stNow;
			time(&t1);
			GetLocalTime(&stNow);
			lMilliSec1 = (long) stNow.wMilliseconds;
#endif // 
			scRet = ServerUtl_UartRead(hDevice, nPort, szReadWriteBuf, 10, 
								g_bFlushUart, g_nTimeout, FALSE);
#ifndef _WIN32
			gettimeofday(&tv, &tz);

			t2 = tv.tv_sec;
			lMilliSec2 = (long)tv.tv_usec / 1000;
#else
			time(&t2);
			GetLocalTime(&stNow);
			lMilliSec2 = (long) stNow.wMilliseconds;
#endif // 

			lMilliSec2 -= lMilliSec1;
			t2 -= t1;
			if (lMilliSec2 < 0)
			{
				lMilliSec2 += 1000;
				t2--;
			}

			printf("Total spent time = %d.%03d\n", t2, lMilliSec2);

			if (scRet != S_OK)
			{
				printf("ServerUtl_UartRead failed %X\n\n", scRet);
				continue;
			}

			printf("Read from COM %d(Len = %d): %s\n\n", nPort, strlen(szReadWriteBuf), szReadWriteBuf);
			continue;
		}

		while (1)
		{
			printf("Value set to? (Less than 128 characters)");
			szReadWriteBuf[0] = 0;
			fgets(szReadWriteBuf, 128, stdin);
			if (strlen(szReadWriteBuf) > 0 && szReadWriteBuf[strlen(szReadWriteBuf) - 1] == '\n')
				szReadWriteBuf[strlen(szReadWriteBuf) - 1] = 0;

			if (szReadWriteBuf[0] == 0)
			{
				ServerUtl_DeleteDevice(hDevice);
				ServerUtl_Release(&hSrvUtl);
				return -1;
			}
			
			break;
		}

		scRet = ServerUtl_UartWrite(hDevice, nPort, szReadWriteBuf, FALSE);

		if (scRet != S_OK)
		{
			printf("ServerUtl_UartWrite failed %X\n\n", scRet);
			continue;
		}

		printf("Uart Write OK for length %d!\n\n", strlen(szReadWriteBuf));
	}


⌨️ 快捷键说明

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