#include "../XNetSDKTest.h"
#include "XNetSDKSyn.h"
#include "Camera_Param.h"
#include "Camera_ParamEx.h"

USE_NS_NETSDK_CFG

int TestCameraConfig()
{
	printf("%s\r\n", __FUNCTION__);
	char c = 0;
	int nRet = 0;
	while((c = getchar()) != 'q')
	{
		switch(c)
		{	
			//通用相机参数
		case 'a':
			{
				///获取相机参数
				char szOutBuffer[4096] = {0};
				char outbuffer[100] = {0};
				int len = 0;
				int  nInOutSize = sizeof(szOutBuffer);
				nRet =XSDK_DevGetChnConfigSyn(g_hDevice, 0, JK_Camera_Param, szOutBuffer, &nInOutSize, 4000, EXCMD_CONFIG_GET);
				
				XSDK_CFG::Camera_Param se;
				se.SetName("Camera.Param.[0]");
				se.Parse(szOutBuffer);

				//白平衡
				printf("White balance = %x\r\n", se.WhiteBalance.Value());

				//IRCUT
				printf("IRCUT = %d\r\n", se.IRCUTMode.Value());

				//镜像
				printf("PictureMirror = %x\r\n", se.PictureMirror.Value());

				//白天降噪等级
				printf("Day_nfLevel = %d\r\n", se.Day_nfLevel.Value());

				//晚上降噪等级
				printf("Night_nfLevel = %d\r\n", se.Night_nfLevel.Value());

				//设置相机参数
				if(nRet >= 0)
				{
					se.Day_nfLevel.SetValue(1);
					const char *pCfg = se.ToString();
					nRet = XSDK_DevSetChnConfigSyn(g_hDevice, 0, JK_Camera_Param, pCfg, strlen(pCfg), outbuffer, &len, 5000, EXCMD_CONFIG_SET);

					if(nRet >= 0)
					{
						printf("Set Success!\r\n");
					}
				}
				
			}
			break;
			//相机参数扩展版
		case 'b':
			{
				///获取相机参数
				char szOutBuffer[4096] = {0};
				char outbuffer[100] = {0};
				int len = 0;
				int  nInOutSize = sizeof(szOutBuffer);
				nRet =XSDK_DevGetChnConfigSyn(g_hDevice, 0, JK_Camera_ParamEx, szOutBuffer, &nInOutSize, 4000, EXCMD_CONFIG_GET);

				XSDK_CFG::Camera_ParamEx se;
				se.SetName("Camera.ParamEx.[0]");
				se.Parse(szOutBuffer);

				//宽动态
				printf("BroadTrends AutoGain = %d, Gain = %d\r\n", se.mBroadTrends.AutoGain.Value(), se.mBroadTrends.Gain.Value());

				//设置相机参数
				if(nRet >= 0)
				{
					se.mBroadTrends.AutoGain.SetValue(1);
					const char *pCfg = se.ToString();
					nRet = XSDK_DevSetChnConfigSyn(g_hDevice, 0, JK_Camera_ParamEx, pCfg, strlen(pCfg), outbuffer, &len, 5000, EXCMD_CONFIG_SET);

					if(nRet >= 0)
					{
						printf("Set Success!\r\n");
					}
				}

			}
			break;
		}
	}
	
	return 0;
}


