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

📄 clientdemo.cpp

📁 linux DVR 设备 开发包
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		PrintFrameFormatPara(&FrameFormat);	}	else	{		fprintf(stderr, "Get Frame Format Para. failed, errno[%d]\n", NET_DVR_GetLastError());	}}//#include <sys/socket.h>void TestVoiceCom(){	glVoiceHandle = NET_DVR_StartVoiceCom(glUserID, VoiceCallBack, 100);	if(glVoiceHandle < 0)    {        fprintf( stderr, "VoiceStart failed. errno[%d]\n",            NET_DVR_GetLastError() );        return ;    }    usleep(8000);       char SendBuf[80];	int i = 0;	for(i = 0;i<80;i++)		SendBuf[i] = i;    			for(i=0; i<500; i++)	{		if(!NET_DVR_VoiceComSendData(glVoiceHandle,SendBuf,80))        {        	fprintf( stderr, "Voice send data failed. errno[%d]\n",NET_DVR_GetLastError() );        	break;        }        usleep(40*1000);	} 	   	if(NET_DVR_StopVoiceCom(glVoiceHandle))	{		glVoiceHandle = -1;		printf("VoiceCom stopped!!!\n");		}}void GetBMPByTime(NET_DVR_DEVICEINFO *devInfo){	int nRet = -1;	NET_DVR_TIME beginTime;   	beginTime.dwYear = 2005;    beginTime.dwMonth = 4;    beginTime.dwDay = 29;    beginTime.dwHour = 14;    beginTime.dwMinute = 0;    beginTime.dwSecond = 0;    INITINFO InitInfo;	InitInfo.uWidth = 0;	InitInfo.uHeight = 0;	if(!NET_DVR_DrawAreaInit(InitInfo))	{		printf("DrawAreaInit failed\n");		return ;	}		nRet = NET_DVR_GetBMPByTime(glUserID,devInfo->byStartChan, &beginTime, "getbmp.bmp");	if(nRet < 0)	{		fprintf( stderr, "Get BMP file failed. errno[%d]\n",NET_DVR_GetLastError() );	}	else if(nRet == 0)	{		printf("Get BMP file success!\n");	}	else if (nRet == 1)	{		printf("no BMP file in the time!\n");	}		NET_DVR_DrawAreaRelease();}void GetConfigFile(){	if(!NET_DVR_GetConfigFile(glUserID, "config.bin"))	{		printf("Get config file failed!\n");	}	else		{		printf("Get config file success!\n");	}	}void SetConfigFile(){	if(!NET_DVR_SetConfigFile(glUserID, "config.bin"))	{		printf("Set config file failed!\n");	}	else		{		printf("Set config file success!\n");	}}void GetJEPGPicture(NET_DVR_DEVICEINFO *devInfo){	LPNET_DVR_JPEGPARA lpJPEGpara;	lpJPEGpara = new NET_DVR_JPEGPARA;	lpJPEGpara->wPicSize = 0;		/* 0=CIF, 1=QCIF, 2=D1 */	lpJPEGpara->wPicQuality = 0;	/* 图片质量系数 0-最好 1-较好 2-一般 */	if(NET_DVR_CaptureJPEGPicture(glUserID, devInfo->byStartChan, lpJPEGpara, "JPEG.jpg"))	{		printf("Get JPEG file success!\n");	}	else	{		fprintf(stderr, "Get JPEG file failed!, errno[%d]\n", NET_DVR_GetLastError());	}	delete lpJPEGpara;}void PrintString(LPNET_DVR_SHOWSTRING para){	printf("SHOWSTRING ENABLE: %d \n",para->struStringInfo[0].wShowString);	printf("SHOWSTRING: %s \n",para->struStringInfo[0].sString);}void ShowString(NET_DVR_DEVICEINFO *devInfo){	NET_DVR_SHOWSTRING m_stringcfg;	DWORD Bytesreturned;	if(NET_DVR_GetDVRConfig(glUserID, NET_DVR_GET_SHOWSTRING, devInfo->byStartChan, &m_stringcfg, sizeof(NET_DVR_SHOWSTRING),&Bytesreturned))	{		PrintString(&m_stringcfg);		//m_stringcfg.struStringInfo[0].wShowString = 1;		//m_stringcfg.struStringInfo[0].wStringSize = strlen("hello");				/* 该行字符的长度,不能大于44个字符 */		//m_stringcfg.struStringInfo[0].wShowStringTopLeftX = 2;		/* 字符显示位置的x坐标 */		//m_stringcfg.struStringInfo[0].wShowStringTopLeftY = 20;		/* 字符名称显示位置的y坐标 */		//memcpy(m_stringcfg.struStringInfo[0].sString, "hello", strlen("hello"));		if(NET_DVR_SetDVRConfig(glUserID, NET_DVR_SET_SHOWSTRING, devInfo->byStartChan, &m_stringcfg, sizeof(NET_DVR_SHOWSTRING)))		{			printf("Set showstring success\n");		} 		else		{			fprintf(stderr, "Set showstring failed, errno[%d]\n", NET_DVR_GetLastError());		}	} 	else	{		fprintf(stderr, "Get showstring failed, errno[%d]\n", NET_DVR_GetLastError());	}}void PrintDecInfo(LPNET_DVR_DECCFG para){	printf("DECINFO DECCHANNUM: %d \n",para->dwDecChanNum);	printf("DECINFO 0:POOLCHANS: %d \n",para->struDecInfo[0].byPoolChans);	printf("DECINFO 0:0 POOLCHANS: %s \n",para->struDecInfo[0].struchanConInfo[0].sDVRIP);	printf("DECINFO 1:POOLCHANS: %d \n",para->struDecInfo[1].byPoolChans);	printf("DECINFO 1:0 POOLCHANS: %s \n",para->struDecInfo[1].struchanConInfo[0].sDVRIP);}void SetDecInfo(NET_DVR_DEVICEINFO *devInfo){	NET_DVR_DECCFG Decoderinfo;		if(NET_DVR_GetDecInfo(glUserID, devInfo->byStartChan, &Decoderinfo))	{		PrintDecInfo(&Decoderinfo);		/*		Decoderinfo.dwDecChanNum = 2;				Decoderinfo.struDecInfo[0].byPoolChans = 1;				Decoderinfo.struDecInfo[0].byEnablePoll = 0;				Decoderinfo.struDecInfo[0].byPoolTime = 1;				memcpy(Decoderinfo.struDecInfo[0].struchanConInfo[0].sDVRIP, "192.0.1.138", strlen("192.0.1.138"));	/ * DVR IP地址 * /				Decoderinfo.struDecInfo[0].struchanConInfo[0].wDVRPort = 8000;			/ * 端口号 * /				memcpy(Decoderinfo.struDecInfo[0].struchanConInfo[0].sUserName, "admin", strlen("admin"));	/ * 用户名 * /				memcpy(Decoderinfo.struDecInfo[0].struchanConInfo[0].sPassword, "12345", strlen("12345"));	/ * 密码 * /				Decoderinfo.struDecInfo[0].struchanConInfo[0].byChannel = 1;		/ * 通道号 * /				Decoderinfo.struDecInfo[0].struchanConInfo[0].byLinkMode = 0;		/ * 连接模式 * /					Decoderinfo.struDecInfo[0].struchanConInfo[0].byLinkType = 0;		/ * 连接类型 0-主码流 1-子码流 * /								Decoderinfo.struDecInfo[1].byPoolChans = 1;				Decoderinfo.struDecInfo[1].byEnablePoll = 0;				Decoderinfo.struDecInfo[1].byPoolTime = 1;				memcpy(Decoderinfo.struDecInfo[1].struchanConInfo[0].sDVRIP, "192.0.1.17", strlen("192.0.1.17"));	/ * DVR IP地址 * /				Decoderinfo.struDecInfo[1].struchanConInfo[0].wDVRPort = 8000;			/ * 端口号 * /				memcpy(Decoderinfo.struDecInfo[1].struchanConInfo[0].sUserName, "admin", strlen("admin"));	/ * 用户名 * /				memcpy(Decoderinfo.struDecInfo[1].struchanConInfo[0].sPassword, "12345", strlen("12345"));	/ * 密码 * /				Decoderinfo.struDecInfo[1].struchanConInfo[0].byChannel = 1;		/ * 通道号 * /				Decoderinfo.struDecInfo[1].struchanConInfo[0].byLinkMode = 0;		/ * 连接模式 * /					Decoderinfo.struDecInfo[1].struchanConInfo[0].byLinkType = 0;		/ * 连接类型 0-主码流 1-子码流 * /				*/		if(NET_DVR_SetDecInfo(glUserID, devInfo->byStartChan, &Decoderinfo))		{			printf("Set 600XD/F info. success\n");		} 		else		{			fprintf(stderr, "Set 600XD/F info. failed, errno[%d]\n", NET_DVR_GetLastError());		}	}	else	{		fprintf(stderr, "Get 600XD/F info. failed, errno[%d]\n", NET_DVR_GetLastError());	}}void PrintDecTransPrt(LPNET_DVR_PORTCFG para){	printf("DECTRANSPORT 232 ENABLE: %d \n",para->struTransPortInfo[0].dwEnableTransPort);	printf("DECTRANSPORT 232 DECIP: %s \n",para->struTransPortInfo[0].sDecoderIP);	printf("DECTRANSPORT 232 TRNSPORT: %d \n",para->struTransPortInfo[0].wDVRTransPort);	printf("DECTRANSPORT 485 ENABLE: %d \n",para->struTransPortInfo[1].dwEnableTransPort);	printf("DECTRANSPORT 485 DECIP: %s \n",para->struTransPortInfo[1].sDecoderIP);	printf("DECTRANSPORT 485 TRNSPORT: %d \n",para->struTransPortInfo[1].wDVRTransPort);}void DecTransPort(){	NET_DVR_PORTCFG TransPort;		if(NET_DVR_GetDecTransPort(glUserID, &TransPort))	{		PrintDecTransPrt(&TransPort);		/* 数组0表示232 数组1表示485 */		/*		TransPort.struTransPortInfo[0].dwEnableTransPort = 0;/ * 是否启动透明通道 0-不启用 1-启用* /				memcpy(TransPort.struTransPortInfo[0].sDecoderIP, "192.0.1.138", strlen("192.0.1.138"));/ * DVR IP地址 * /				TransPort.struTransPortInfo[0].wDecoderPort = 8000;	/ * 端口号 * /				TransPort.struTransPortInfo[0].wDVRTransPort = 1;	/ * 配置前端DVR是从485/232输出,1表示232串口,2表示485串口 * /				TransPort.struTransPortInfo[1].dwEnableTransPort = 0;/ * 是否启动透明通道 0-不启用 1-启用* /				memcpy(TransPort.struTransPortInfo[1].sDecoderIP, "192.0.1.17", strlen("192.0.1.17"));/ * DVR IP地址 * /				TransPort.struTransPortInfo[1].wDecoderPort = 8000;	/ * 端口号 * /				TransPort.struTransPortInfo[1].wDVRTransPort = 2;	/ * 配置前端DVR是从485/232输出,1表示232串口,2表示485串口 * /				*/		if(NET_DVR_SetDecTransPort(glUserID, &TransPort))		{			printf("Set 600XD/F transport success\n");		} 		else		{			fprintf(stderr, "Set 600XD/F transport failed, errno[%d]\n", NET_DVR_GetLastError());		}	}	else	{		fprintf(stderr, "Get 600XD/F transport failed, errno[%d]\n", NET_DVR_GetLastError());	}}void PrintDVRState(NET_DVR_DEVICEINFO *devInfo, LPNET_DVR_WORKSTATE pworkstate){	int i, j;	printf("device static: %d\n", pworkstate->dwDeviceStatic);	for (i=0; i<devInfo->byDiskNum; i++)		printf( "hdisk %d:\n"				"	volume:%d\tfreespace:%d\thdisk static:0x%x\n",				i,				pworkstate->struHardDiskStatic[i].dwVolume,				pworkstate->struHardDiskStatic[i].dwFreeSpace,				pworkstate->struHardDiskStatic[i].dwHardDiskStatic);	for (i=0; i<devInfo->byChanNum; i++) {		printf( "channel %d:\n"				"	record static:%d\tsignal static:%d\thardware static:%d\n"				"	bit rate:%d\tlink number:%d\n",					i,				pworkstate->struChanStatic[i].byRecordStatic,				pworkstate->struChanStatic[i].bySignalStatic,				pworkstate->struChanStatic[i].byHardwareStatic,				pworkstate->struChanStatic[i].dwBitRate,				pworkstate->struChanStatic[i].dwLinkNum);		for (j=0; j<(int)(pworkstate->struChanStatic[i].dwLinkNum); j++)			printf( "	link number %d:\n"					"		client ip:0x%x\n",					j,					pworkstate->struChanStatic[i].dwClientIP[j]);	}	for (i=0; i<devInfo->byAlarmInPortNum; i++)		printf( "alarm in number %d:\n"			"	static: %d\n",			i,			pworkstate->byAlarmInStatic[i]);	for (i=0; i<devInfo->byAlarmOutPortNum; i++)		printf( "alarm out number %d:\n"			"	static: %d\n",			i,			pworkstate->byAlarmOutStatic[i]);	printf("local display static: %d\n", pworkstate->dwLocalDisplay);}void GetDVRStatus(NET_DVR_DEVICEINFO *devInfo){	NET_DVR_WORKSTATE struworkstate;	if (!NET_DVR_GetDVRWorkState(glUserID, &struworkstate)) {		fprintf(stderr, "errno[%d]\n", NET_DVR_GetLastError());		return;	}	PrintDVRState(devInfo, &struworkstate);	}void dvr_error(char *msg){	fprintf(stderr, "%s: errno[%d]\n", msg, NET_DVR_GetLastError());	exit(0);}void CtrlDVRRecord(NET_DVR_DEVICEINFO *devInfo){	if (!NET_DVR_StartDVRRecord(glUserID, devInfo->byStartChan, 0))		dvr_error("StartDVRecord");	sleep(5);	if (!NET_DVR_StopDVRRecord(glUserID, devInfo->byStartChan))		dvr_error("StopDVRecord");}const char *usageinfo[] = {"######### Usage #############","1. RealPlay.","2. SearchFileList.","3. PlaybackByName.","4. PlaybackByTime.","5. SearchLogFile.","6. GetFileByName.","7. GetFileByTime.","8. SetupAlarmChan.","9. TestUpgrade.","10. Control PTZ.","11. FormatDisk.","12. TestSerial232.","13. TestSerial485.","14. TestRebootDVR.","15. TestShutDownDVR.","16. GetDevicePara.","17. GetNetPara.","18. GetPicturePara.","19. GetCompressPara.","20. GetRecordPara.","21. GetDecoderPara.","22. Get232Para.","23. GetAlarminPara.","24. GetAlarmoutPara.","25. SetDVRTime.","26. GetPreviewPara.","27. VideoOutPara.","28. GetUserPara.","29. GetExceptionPara.","30. GetFrameFormatPara.","31. TestVoiceCom.","32. GetBMPByTime.","33. GetConfigFile.","34. SetConfigFile.","35. Get485Para.","36. GetJEPGPicture.","37. ShowString.","38. SetDecInfo.","39. DecTransPort.","40. invalid.","41. invalid.","42. invalid.","43. invalid.","44. invalid.","45. GetDVRStatus.","46. CtrlDVRRecord","47. invalid.","48. invalid.","49. invalid.","50. GETDDNSCFG.","51. ScaleCFG.","52. ATMPortCFG.","53. TestDVRAlive.","54. SetAlarmOut.","######### End ##############"};  int main(int argc, char *argv[]){	//NET_DVR_LOG dvrlog;		NET_DVR_DEVICEINFO devInfo;	int cmd = 0, usageinfolength;	//char allip[16][16] = {0};	//DWORD dwValidIP;	#ifdef SDK_TEST	char localip[16] = "192.0.5.42";	char serverip[16] = "192.0.7.253";	#else	char localip[16];	char serverip[16];	printf("Please input local ip:\n");	scanf("%s", localip );	printf("Please input server ip:\n");	scanf("%s", serverip );	#endif		//initialization	if(!NET_DVR_Init())	{		printf("HC Clientdemo Init failed\n");		return -1;	}		//NET_DVR_GetLocalIP(allip, &dwValidIP);	//printf("all ip num is %d, ip0 is %s, ip1 is %s\n", dwValidIP, allip[0], allip[1]);	//NET_DVR_SetValidIP(0);	//getchar();#ifdef ANALYZE	AnalyzeDataInit();#endif	if (!NET_DVR_SetConnectTime(5000, 3)) 	{		fprintf(stderr, "%d:errno[%d]\n", __LINE__, NET_DVR_GetLastError());		return -1;	}	//set callback	NET_DVR_SetDVRMessageCallBack(gfMessCallBack, (void*)1);	//start listen	if( !NET_DVR_StartListen(localip, LOCAL_PORT) )	{	    printf("StartListen failed ... LastError[%d]\n", NET_DVR_GetLastError());	    NET_DVR_Cleanup();	    return -1;	}	glUserID = NET_DVR_Login(serverip, PORT, USER_NAME, PASSWD, &devInfo);		if(glUserID < 0) 	{		printf( "Login DVR failed ... LastError[%d]\n", NET_DVR_GetLastError() );			NET_DVR_StopListen();

⌨️ 快捷键说明

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