#include "base/define.h"
#include "stdlib.h"
#include "hardware/gpio_cfg.h"
#include "base/delay.h"
#include "hardware/adc_cfg.h"
#include "hardware/power.h"
#include "base/utility.h"
//#include "usartapp.h"
#include "driver/jqdriver.h"
#include "interface/jqchecker.h"
//#include "database.h"
#include "driver/XTDriver.h"
#include "interface/Basechecker.h"
#include "elec_io.h"



volatile uint16_t jq_adc_test_buf[2048];

static void OutGroup1(uint32_t count,uint32_t delay,uint32_t cycle)
{
	__disable_irq();
	while(count > 0)
	{
		PCout(OUTBH_Pin_Nu) = 1;
		PBout(OUTAH_Pin_Nu) = 1;
		delay_us(delay);
		PBout(OUTBL_Pin_Nu) = 0;
		PBout(OUTAL_Pin_Nu) = 0;
		delay_us(cycle);
		PCout(OUTBH_Pin_Nu) = 0;
		PBout(OUTAH_Pin_Nu) = 0;
		delay_us(delay);
		PBout(OUTBL_Pin_Nu) = 1;
		PBout(OUTAL_Pin_Nu) = 1;
		delay_us(cycle);
		count--;
	}
	__enable_irq();
}
static void GpioTest(int argc, char**argv)
{
	uint32_t io_value = 0;
	uint32_t count = 0,delay,cycle;
	if (argc < 3)
	{
		 goto IO_help_label_;
	}
	if(argc == 3)
	{
			io_value = atoi(argv[2]);
	}

	if (!rt_strcmp(argv[1], "LAVC_M"))
	{
		PAout(LAVC_M_Pin_Nu) = io_value;
	}else if(!rt_strcmp(argv[1], "SEG0"))
	{
		rt_kprintf("Read SEG4 value = %d \n",PCin(SEG0_Pin_Nu));
	}else if(!rt_strcmp(argv[1], "R10_ON"))
	{
		PBout(R10_ON_Pin_Nu) = io_value;
	}else if(!rt_strcmp(argv[1], "R510_ON")){
		PBout(R510_ON_Pin_Nu) = io_value;
	}else if(!rt_strcmp(argv[1], "LED1")){
		PBout(LED1_Pin_Nu) = io_value;
	}else if(!rt_strcmp(argv[1], "IO_APD12")){
		PBout(IO_APD12_Pin_Nu) = io_value;
	}else if(!rt_strcmp(argv[1], "LED2")){
		PBout(LED2_Pin_Nu) = io_value;
	}else if(!rt_strcmp(argv[1], "OUTAL"))
	{
		PBout(OUTAL_Pin_Nu) = io_value;
	}else if(!rt_strcmp(argv[1], "OUTBL"))
	{
		PBout(OUTBL_Pin_Nu) = io_value;
	}else if(!rt_strcmp(argv[1], "OUTAH"))
	{
		PBout(OUTAH_Pin_Nu) = io_value;
	}else if(!rt_strcmp(argv[1], "R100_ON"))
	{
		PCout(R100_ON_Pin_Nu) = io_value;
	}else if(!rt_strcmp(argv[1], "OUTBH"))
	{
		PCout(OUTBH_Pin_Nu) = io_value;
	}
	else if(!rt_strcmp(argv[1], "Power_ON"))
	{
		PCout(POWER_ON_Pin_Nu) = io_value;
	}else if(!rt_strcmp(argv[1], "SEG4"))
	{
		rt_kprintf("Read SEG4 value = %d \n",PCin(SEG4_Pin_Nu));
	}else if(!rt_strcmp(argv[1], "SEG3"))
	{
		rt_kprintf("Read SEG4 value = %d \n",PCin(SEG3_Pin_Nu));
	}else if(!rt_strcmp(argv[1], "SEG1"))
	{
		rt_kprintf("Read SEG4 value = %d \n",PCin(SEG1_Pin_Nu));
	}else if(!rt_strcmp(argv[1], "SEG2"))
	{
		rt_kprintf("Read SEG4 value = %d \n",PCin(SEG2_Pin_Nu));
	}else if(!rt_strcmp(argv[1], "IO_APD22"))
	{
		PCout(IO_APD22_Pin_Nu) = io_value;
	}else if(!rt_strcmp(argv[1], "IO_APD21"))
	{
		PCout(IO_APD21_Pin_Nu) = io_value;
	}else if(!rt_strcmp(argv[1], "IO_APD11"))
	{
		PCout(IO_APD11_Pin_Nu) = io_value;
	}
		
	else if(!rt_strcmp(argv[1], "Group1"))
	{
		
		count = atoi(argv[2]);
		delay = atoi(argv[3]);
		cycle = atoi(argv[4]);
		OutGroup1(count,delay,cycle);
	}
	 else
    {
	IO_help_label_:
			  rt_kprintf("IO [IO_name] 0/1/R \n");
				rt_kprintf("IO Group[number] count delay cycle \n");

    }
}
MSH_CMD_EXPORT_ALIAS(GpioTest,IO,I/O Input Output test);

static void DACTest(int argc, char**argv)
{
	uint32_t da_value = 0;
	if (argc < 3)
	{
		 goto DAC_help_label_;
	}
	if(argc == 3)
	{
			da_value = atoi(argv[2]);
	}
	
	if(!rt_strcmp(argv[1], "C_H_DAC"))
	{
		if(da_value < 125)
		{
			rt_kprintf("C_H_DAC Min value 1400");
		}else{
			C_H_DAC_Set(da_value);
		}
		
	}else if(!rt_strcmp(argv[1], "C_M_DAC"))
	{
		C_M_DAC_Set(da_value);
	}else{
		DAC_help_label_:
			  rt_kprintf("DA [C_H_DAC/C_M_DAC] Value(0~4096) \n");
	}
		
}
MSH_CMD_EXPORT_ALIAS(DACTest,DA,Out DA Voltage);
static void ADCTest(int argc, char**argv)
{
	uint16_t adv;
	uint16_t ul_count = 0;
	if (argc < 2)
	{
		 goto ADC_help_label_;
	}else if(!rt_strcmp(argv[1], "V_LA_M"))
	{
		GetADC1_Value(V_LA_M_CH,&adv,1);
		rt_kprintf("V_LA_M = %d \n",adv);
	}else if(!rt_strcmp(argv[1], "V_LA_H"))
	{
		GetADC1_Value(V_LA_H_CH,&adv,1);
		rt_kprintf("V_LA_H = %d \n",adv);
	}else if(!rt_strcmp(argv[1], "VCC_2V5"))
	{
		GetADC1_Value(VCC_2V5_CH,&adv,1);
		rt_kprintf("VCC_2V5 = %d \n",adv);
	}else if(!rt_strcmp(argv[1], "VCC_1V25"))
	{
		GetADC1_Value(VCC_1V25_CH,&adv,1);
		rt_kprintf("VCC_1V25 = %d \n",adv);
	}else if(!rt_strcmp(argv[1], "RAD_01"))
	{
		GetADC1_Value(RAD_01_CH,&adv,1);
		rt_kprintf("RAD_01 = %d \n",adv);
	}else if(!rt_strcmp(argv[1], "AD_OUTA"))
	{
		GetADC1_Value(AD_OUTA_CH,&adv,1);
		rt_kprintf("AD_OUTA = %d \n",adv);
	}
	else if(!rt_strcmp(argv[1], "AD_OUTB"))
	{
		GetADC1_Value(AD_OUTB_CH,&adv,1);
		rt_kprintf("AD_OUTB = %d \n",adv);
	}
	else if(!rt_strcmp(argv[1], "V_BASE"))
	{
		GetADC1_Value(ADC_Channel_17,&adv,1);
		rt_kprintf("V_BASE = %d \n",adv);
	}else if(!rt_strcmp(argv[1], "TEMP"))
	{
		GetADC1_Value(ADC_Channel_16,&adv,1);
		rt_kprintf("TEMP = %d \n",adv);
	}
	else if(!rt_strcmp(argv[1], "AN_UA"))
	{
		StartADC2Channel(AN_UA_CH,ADC_SPEED_MIDLE);
		rt_kprintf("AN_UA = %d \n",GetADC1_Fast());
	}else if(!rt_strcmp(argv[1], "AN_MAL"))
	{
		StartADC2Channel(AN_MAL_CH,ADC_SPEED_MIDLE);
		rt_kprintf("AN_MAL = %d \n",GetADC1_Fast());
	}
	else if(!rt_strcmp(argv[1], "FMA"))
	{
		JQBUS_OFF;
		rt_kprintf("Close Bus \n");
		delay_ms(1000);
		rt_kprintf("Open Bus \n");
		POWER_ON;
		StartADC2Channel(AN_MAL_CH,ADC_SPEED_HIGH);
		Power_SetSampleCurrentRange(R100_0p2mA_3mA_MC);
		JQBUS_ON;
		delay_ms(1);
		ul_count = 0;
		while(ul_count < 2048)
		{
			jq_adc_test_buf[ul_count++] = GetADC1_Fast();
		}
		ul_count = 0;
		rt_kprintf("Sample data \n");
		while(ul_count < 2048)
		{
			rt_kprintf("%d\t%d\t%d\t%d\n",jq_adc_test_buf[ul_count],jq_adc_test_buf[ul_count+1],jq_adc_test_buf[ul_count+2],jq_adc_test_buf[ul_count+3]);
			ul_count +=4;
		}
	}
	else if(!rt_strcmp(argv[1], "FUA"))
	{
		JQBUS_OFF;
		rt_kprintf("Close Bus \n");
		delay_ms(1000);
		rt_kprintf("Open Bus \n");
		StartADC2Channel(AN_UA_CH,ADC_SPEED_HIGH);
		POWER_ON;
		Power_SetSampleCurrentRange(R10_0p1mA_1p6mA_UC);
		JQBUS_ON;	
		delay_ms(1);
		ul_count = 0;
		while(ul_count < 2048)
		{
			jq_adc_test_buf[ul_count++] = GetADC1_Fast();
		}
		ul_count = 0;
		rt_kprintf("Sample data \n");
		while(ul_count < 2048)
		{
			rt_kprintf("%d\t%d\t%d\t%d\n",jq_adc_test_buf[ul_count],jq_adc_test_buf[ul_count+1],jq_adc_test_buf[ul_count+2],jq_adc_test_buf[ul_count+3]);
			ul_count +=4;
		}
	}
	else{
		ADC_help_label_:
			  rt_kprintf("AD [ChannelName] \n");
				rt_kprintf("AD FUA / FMA \n");
	}

}
MSH_CMD_EXPORT_ALIAS(ADCTest,AD,Get AD Value);



static void PowerTest(int argc, char**argv)
{
	PowerInfo_st infos_st;
	if (argc < 2)
	{
		 goto FB_help_label_;
	}else if(!rt_strcmp(argv[1], "ON"))
	{
		POWER_ON
	}else if(!rt_strcmp(argv[1], "OFF"))
	{
		POWER_OFF
	}
	else if(!rt_strcmp(argv[1], "HV"))
	{
			
		rt_kprintf("POWER HV(10) %d \n" , Power_GetHPowerV());
	}else if(!rt_strcmp(argv[1], "MV"))
	{
		rt_kprintf("POWER MV(10) %d \n" , Power_GetMPowerV());
	}else if(!rt_strcmp(argv[1], "CURRENT")){
		rt_kprintf("CURRENT 0.1uA %d \n" , Power_GetCurrent());
	}else if(!rt_strcmp(argv[1], "SET"))
	{
		infos_st.V_LAH = atoi(argv[2]);
		infos_st.V_LAM = atoi(argv[3]);
		infos_st.V_LAH_DAC = 0;
		infos_st.V_LAM_DAC = 0;
		PowerCalibration(&infos_st);
		if(	infos_st.V_LAH_DAC > 0)
			PowerSetVoltage(&infos_st);
		
	}
	else{
		FB_help_label_:
			  rt_kprintf("POWER  [ ON |HV | MV | CURRENT] \n");
				rt_kprintf("POWER [SET] [HV max 260] [MV ] \n");
	}
}
MSH_CMD_EXPORT_ALIAS(PowerTest ,POWER,  BUS POWER );


extern Checker_RunCfg_st checker_runcfg;
static void CheckerTest(int argc, char**argv)
{
	uint32_t h_power,m_power;
	uint16_t us_array[20];
	uint8_t* puc_buf;
	uint16_t us_temp;
	rt_memset(&checker_runcfg,0,sizeof(Checker_RunCfg_st));
	if(argc > 2)
	{
		checker_runcfg.param_count = argc-2;
		us_temp = 0;
		while(us_temp < checker_runcfg.param_count)
		{
			checker_runcfg.params[us_temp] = atoi(argv[us_temp+2]);
			us_temp++;
		}
	}
	if (argc < 2)
	{
		 goto CH_help_label_;
	}else if(!rt_strcmp(argv[1], "ON")){
		JQBUS_ON
	}else if(!rt_strcmp(argv[1], "OFF")){
		JQBUS_OFF
	}
	else if(!rt_strcmp(argv[1], "H")){
			JQBUS_W_1
		
	}else if(!rt_strcmp(argv[1], "L")){
		JQBUS_W_0
	}else if(!rt_strcmp(argv[1], "CURRENT")){
	
	}else if(!rt_strcmp(argv[1], "PowerPrapare")){

		Checker_PowerPrapare();
		rt_kprintf("PowerPrapare  Excute %d \n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "PowerOn")){
		checker_runcfg.rtv_count = 2;
		JQ_Test_PowerOn();		
		rt_kprintf("PowerOn Excute %d BusV %d Energy %d \n",checker_runcfg.Task_Result[0],checker_runcfg.Test_Rtv[0],checker_runcfg.Test_Rtv[1] );
	}else if(!rt_strcmp(argv[1], "SetBusV")){
		checker_runcfg.rtv_count = 1;
		JQ_Test_SetBusV();		
		rt_kprintf("SetBusV Excute %d  BusV %d \n",checker_runcfg.Task_Result[0],checker_runcfg.Test_Rtv[0] );
	}else if(!rt_strcmp(argv[1], "BaseCur")){
		checker_runcfg.rtv_count = 2;
		JQ_Test_BaseCur();		
		rt_kprintf("BaseCur Excute %d  BusCur1 %d  BusCur2 %d \n",checker_runcfg.Task_Result[0],checker_runcfg.Test_Rtv[0],checker_runcfg.Test_Rtv[1] );
	}	
	else if(!rt_strcmp(argv[1], "ScanUID")){
		checker_runcfg.rtv_count = 8;
		JQ_Test_ScanUID();		
		rt_kprintf("ScanUID excute %d, max_cur %d, max_time %d, min_cur %d, min_time %d  UID\t",\
		checker_runcfg.Task_Result[0],checker_runcfg.Test_Rtv[0],checker_runcfg.Test_Rtv[1],checker_runcfg.Test_Rtv[2],checker_runcfg.Test_Rtv[3]);
		us_temp = 0;
		while(us_temp < 4)
		{
			printf("%02x ",(checker_runcfg.Test_Rtv[us_temp+4]) & 0x0FF);
			printf("%02x ",(checker_runcfg.Test_Rtv[us_temp+4]>>8) & 0x0FF);
			us_temp++;
		}
		printf("\n");
	}else if(!rt_strcmp(argv[1], "ReadChipID")){
		checker_runcfg.rtv_count = 1;
		JQ_Test_ReadChipID();		
		printf("ReadChipID Excute %d  ChipID %04x \n",checker_runcfg.Task_Result[0],checker_runcfg.Test_Rtv[0]);
	}else if(!rt_strcmp(argv[1], "PWCheck")){
		JQ_Test_PWCheck();		
		printf("PWCheck Excute %d \n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "OTPCheck")){
		JQ_Test_OTPCheck();		
		printf("OTPCheck Excute %d \n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "FTCheck")){
		JQ_Test_FTCheck();		
		printf("FTCheck Excute %d \n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "ReadState")){
		checker_runcfg.rtv_count = 1;
		JQ_Test_ReadState();		
		printf("ReadState Excute %d  State %02x\n",checker_runcfg.Task_Result[0],checker_runcfg.Test_Rtv[0]);
	}else if(!rt_strcmp(argv[1], "WriteUserInfo")){
		JQ_Test_WriteUserInfo();		
		printf("WriteUserInfo Excute %d \n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "ChgEnergy")){
		checker_runcfg.rtv_count = 4;
		JQ_Test_ChgEnergy();		
		printf("ReadState Excute %d  Energy_0.1ms %d ",checker_runcfg.Task_Result[0],checker_runcfg.Test_Rtv[0]);
		printf("EndCur_0.1uA %d ",checker_runcfg.Test_Rtv[1]);
		printf("MaxCur_0.1mA %d ",checker_runcfg.Test_Rtv[2]);
		printf("ShakeADV %d \n",checker_runcfg.Test_Rtv[3]);
	}else if(!rt_strcmp(argv[1], "CheckDAC")){
		checker_runcfg.rtv_count = 1;
		JQ_Test_CheckDAC();		
		printf("CheckDAC Excute %d  End_DAC %d \n",checker_runcfg.Task_Result[0],checker_runcfg.Test_Rtv[0]);
	}else if(!rt_strcmp(argv[1], "WaitDelay")){
		checker_runcfg.rtv_count = 1;
		Checker_WaitDelay();		
		printf("CheckDAC Excute %d  End_DAC %d \n",checker_runcfg.Task_Result[0],checker_runcfg.Test_Rtv[0]);
	}else if(!rt_strcmp(argv[1], "SetDelay")){
		JQ_Test_SetDelay();		
		printf("SetDelay Excute %d  \n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "ReadDelay")){
		checker_runcfg.rtv_count = 1;
		JQ_Test_ReadDelay();		
		printf("ReadDelay Excute %d Delay %d \n",checker_runcfg.Task_Result[0],checker_runcfg.Test_Rtv[0]);
	}else if(!rt_strcmp(argv[1], "ClkTrim")){
		JQ_Test_ClkTrim();		
		printf("ClkTrim Excute %d\n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "Discharge")){
		JQ_Test_Discharge();		
		printf("Discharge Excute %d\n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "Reset")){
		JQ_Test_Reset();		
		printf("Reset Excute %d\n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "BootEn")){
		JQ_Test_BootEn();		
		printf("BootEn Excute %d\n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "ClearBoom")){
		JQ_Test_ClearBoom();		
		printf("ClearBoom Excute %d\n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "BoomEnergy")){
		checker_runcfg.rtv_count = 4;
		JQ_Test_BoomEnergy();		
		printf("BoomEnergy Excute %d  Energy_0.1ms %d ",checker_runcfg.Task_Result[0],checker_runcfg.Test_Rtv[0]);
		printf("PlusShakeADV %d ",checker_runcfg.Test_Rtv[1]);
		printf("MaxChgCur_0.1mA %d ",checker_runcfg.Test_Rtv[2]);
		printf("ChgShakeADV %d \n",checker_runcfg.Test_Rtv[3]);
		
			
	}else if(!rt_strcmp(argv[1], "EnCommEndCur")){
		JQ_Test_EnCommEndCur();		
		printf("BootEn Excute %d\n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "GetCommEndCur")){
		checker_runcfg.rtv_count = 1;
		JQ_Test_GetCommEndCur();		
		printf("GetCommEndCur Excute %d  CommCur %d\n",checker_runcfg.Task_Result[0],checker_runcfg.Test_Rtv[0]);
	}else if(!rt_strcmp(argv[1], "PowerOff")){
		JQ_Test_PowerOff();		
		printf("PowerOff Excute %d\n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "WriteOTP")){
		HexStrings2Byte(argv+4,argc-4,(uint8_t*)(&checker_runcfg.params[2]),8);
		JQ_Test_WriteOTP();		
		printf("WriteOTP Excute %d\n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "ReadOTP")){
		us_temp = checker_runcfg.params[1];
		checker_runcfg.rtv_count = (us_temp + 1)/2;
		JQ_Test_ReadOTP();
		printf("ReadOTP Excute %d ReadDatas ",checker_runcfg.Task_Result[0]);
		puc_buf = (uint8_t*)checker_runcfg.Test_Rtv;
		while(us_temp > 0)
		{
			printf("%02x ",*puc_buf++);
			us_temp--;
		}
		printf("\n");
	}else if(!rt_strcmp(argv[1], "WriteBuf2OTP")){
		JQ_Test_WriteBuf2OTP();
		printf("WriteBuf2OTP Excute %d \n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "BindUIDPWD")){
		
		memcpy(us_array,argv[2],strlen(argv[2]));
		UidCode_YM2JQ(checker_runcfg.writeuid,(uint8_t*)us_array);
		m_power = GetPasswordByUidCode((uint8_t*)us_array);
		memcpy(checker_runcfg.writepwd,(uint8_t*)&m_power ,4);
		checker_runcfg.pwd_len = 4;
		checker_runcfg.uid_len = 8;
		JQ_UID_PWD_Bind();
		printf("BindUIDPWD Excute %d \n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "VerifyUIDPWD")){
		JQ_Verify_UID_PWD();
		printf("VerifyUIDPWD Excute %d \n",checker_runcfg.Task_Result[0]);
	}
	
	else if(!rt_strcmp(argv[1], "SetHardVer")){
		HexStrings2Byte(argv+2,argc-2,(uint8_t*)(&boardinfo_un.boardinfo.hard_v),2);
		SaveBoardInfo();
		printf("SetHardVer  %04x\n",boardinfo_un.boardinfo.hard_v);
	}else if(!rt_strcmp(argv[1], "SetRsisDiff")){
		boardinfo_un.boardinfo.resistor_diff = checker_runcfg.params[0];
		SaveBoardInfo();
		printf("SetRsisDiff  %d\n",boardinfo_un.boardinfo.resistor_diff);
	}else if(!rt_strcmp(argv[1], "ReadBoard")){
		LoadBoardInfo();
		printf("BootFlag %08x HardVersion %02x RsistorDiff %d\n",\
		boardinfo_un.boardinfo.bootflag,boardinfo_un.boardinfo.hard_v,boardinfo_un.boardinfo.resistor_diff);
	}else if(!rt_strcmp(argv[1], "ExcuePlan")){
		Ye_RunPlanCheckTest();
	}
	else if(!rt_strcmp(argv[1], "SetWriteBuf")){
		HexStrings2Byte(argv+2,argc-2,Checker_FacBuf+2,CHECKER_FAC_BUF_LEN-2);
		if(argc > CHECKER_FAC_BUF_LEN)
		{
			Checker_FacBuf[0] = CHECKER_FAC_BUF_LEN-2;
		}else{
			Checker_FacBuf[0] = argc-2;
		}
		Checker_FacBuf[1] = CheckCRC_8(Checker_FacBuf+2,Checker_FacBuf[0]);
		printf("SetWriteBuf Excute 0 \n");
	}else if(!rt_strcmp(argv[1], "ResistorSample")){
		checker_runcfg.rtv_count = 1;
		Checker_ResistorSample();
		printf("CheckPWD Excute %d Res(0.01) %d\n",checker_runcfg.Task_Result[0],checker_runcfg.Test_Rtv[0]);
	}else if(!rt_strcmp(argv[1], "CapVoltage")){
		checker_runcfg.rtv_count = 1;
		JQ_Test_CapVoltage();
		printf("CheckPWD Excute %d Res(0.01) %d\n",checker_runcfg.Task_Result[0],checker_runcfg.Test_Rtv[0]);
	}else if(!rt_strcmp(argv[1], "EnOTPW")){
		JQ_Test_EnOTPW();
		printf("EnOTPW Excute %d\n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "WriteVersion")){
		JQ_Test_WriteVersion();
		printf("WriteVersion Excute %d\n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "ReadVersion")){
		checker_runcfg.rtv_count = 1;
		JQ_Test_ReadVersion();
		printf("ReadVersion Excute %d Ver %d\n",checker_runcfg.Task_Result[0],checker_runcfg.Test_Rtv[0]);
	}else if(!rt_strcmp(argv[1], "WriteFacBuff")){
		JQ_Test_WriteFacBuff();
		printf("WriteFacBuff Excute %d\n",checker_runcfg.Task_Result[0]);
	}else if(!rt_strcmp(argv[1], "VerifyFacBuff")){
		JQ_Test_VerifyFacBuff();
		printf("VerifyFacBuff Excute %d ",checker_runcfg.Task_Result[0]);
	}
	
	else{
		CH_help_label_:
		rt_kprintf("CH             [ON | OFF | H | L ] \n");
		rt_kprintf("PowerPrapare   [V1,V2,V3...V10] \n");
		rt_kprintf("PowerOn        [Voltage] [TimeOut] [End_ADC_V] \n");
		rt_kprintf("SetBusV        [Voltage] \n");
		rt_kprintf("BaseCur        \n");
		rt_kprintf("ScanUID        [EN_CommCur] [E_UID_Equal_0] \n");
		rt_kprintf("PWCheck        [EN_PW_0] \n");
		rt_kprintf("ReadChipID     \n");
		rt_kprintf("OTPCheck       [EN_UID_PWD_0] [EN_Delay_Re_0] [EN_Factory_0]\n");
		rt_kprintf("FTCheck        \n");
		rt_kprintf("ReadState      [State_Mask] \n");
		rt_kprintf("WriteUserInfo  [2bytes]  [2bytes]\n");
		rt_kprintf("ChgEnergy      [End_ADV] [Sample_timeout] [End_Cur_0.1] [Wait_Timeout] [Chg_Hold]\n");
		rt_kprintf("CheckDAC       [Bg_DAC]  [End_DAC]\n");
		rt_kprintf("WaitDelay      [Delay_0.1S] [En_Monitor] \n");
		rt_kprintf("SetDelay       [Delay]  \n");
		rt_kprintf("ReadDelay      \n");
		rt_kprintf("ClkTrim        [Cycle_us] [Pluse_count] \n");
		rt_kprintf("Discharge      \n");
		rt_kprintf("Reset          \n");
		rt_kprintf("BoomEnergy   	 [End_ADV] [Plus_Count] [DelaySample_ms]\n");
		rt_kprintf("BootEn         \n");
		rt_kprintf("ClearBoom      \n");
		rt_kprintf("EnCommEndCur   \n");
		rt_kprintf("GetCommEndCur  \n");
		rt_kprintf("PowerOff       \n");
		rt_kprintf("WriteOTP       [OTP_Addr] [Write_Len] [DATA ...]\n");
		rt_kprintf("ReadOTP        [OTP_Addr] [Read_Len] \n");
		rt_kprintf("WriteBuf2OTP   [OTP_Addr] [Buffer_Addr] [WriteLen] \n");
		rt_kprintf("BindUIDPWD   	 [uid_str] \n");
		rt_kprintf("VerifyUIDPWD   \n");
		
		rt_kprintf("SetHardVer     [HardVersion 2Bytes] \n");
		rt_kprintf("SetRsisDiff    [RsistorDiff *100] \n");
		rt_kprintf("ReadBoardInfo  \n");
		rt_kprintf("ExcuePlan  \n");
		rt_kprintf("SetWriteBuf    [HexData...]\n");
		rt_kprintf("ResistorSample [Test_Modle]\n");
		rt_kprintf("CapVoltage 		 [WaitTime 0.1S]\n");
		rt_kprintf("EnOTPW 		 \n");
		rt_kprintf("WriteVersion 	[Product Ver] \n");
		rt_kprintf("ReadVersion 	 \n");
		rt_kprintf("WriteFacBuff 	[otp_addr][buf_bg][w_len] \n");
		rt_kprintf("VerifyFacBuff [otp_addr][buf_bg][r_len] \n");
		
	}
	
}
MSH_CMD_EXPORT_ALIAS(CheckerTest ,JCH,  BUS POWER );





