#include "CommandsDefine.h"
#include "ProjectConfig.h"
#include "AnalogChannelCtrl.h"
#include "AnalogChannelCtrl_2d5g_base.h"
#include "sys.h"
#include "timer.h"
#include "delay.h"
#include "iwdg.h"
#include "DS18B20.h"
#include "iap.h"
#include "Helper.h"
//#include "OuterPanel_LED.h"
//#include "Probe.h"
int  flag = 0;
int port1 = 4;
//int port2 = 7;
int dacid = 1;
//u8 testLed =0;
//u8 ledTestEnable =0;
int main(void)
{
    MainInit();
		Helper_CRC32_Init();	
		//LED_ALL(0xFF);
#ifndef RUNNING_WHERE_AT_BOOT	
		int i=0;
		DS18B20_Get_Temp();
		DS18B20_Get_Temp();
		DAC_AD5675((1<<(16+5))|( unsigned short)(0x7FFF),1);
		DAC_AD5675((1<<(16+5))|( unsigned short)(0x7FFF),2);
		u8 setData1= 0x1f;
		u8 setData2= 0x00;
		for(int i=0; i<MAX_CHANNEL_NUM; i++)
		{			 
			DSA_PE43711(LMH6401_ADDR_TEMPCORRECT_GAIN,setData1,1+i);	
			DSA_PE43711(LMH6401_ADDR_TEMPCORRECT_FREQ,setData2,1+i);				 
		}		
#else
	  iap_WriteBootVersionInfo();
#endif
    while(1)
    {			
			delay_us(50);
			//if(0xff!=flag )
			//{
			    //CD_4094(0,1);
					//CD_4094(0,4);

				//DAC_AD5675((5<<16)|( unsigned short)( flag/3300.0 * (1<<16) ),2);
				//DAC_AD5675((5<<16)|( unsigned short)( flag/3300.0 * (1<<16) ),1);
				//DAC_AD5675((port1<<16)|( unsigned short)( flag/3300.0 * (1<<16) ),dacid);
				//DAC_AD5675((port2<<16)|( unsigned short)( flag/3300.0 * (1<<16) ),dacid);
				//flag = 0xff;
			//}
	 
				//delay_ms(1);
				//continue;
#ifndef RUNNING_WHERE_AT_BOOT	
				if(i%100==0)	
				{
					IWDG_Feed();//喂狗
				}
				
				//delay_ms(50);
				AnalogChCtrl_ProtectProcess();	
        Command_ProcessRequestCmds();
				if(IsChannelSetting==1)	
				{
							continue;
				}		
				if(i>=1000) 
				//if(i>=20*500) //测试7.3
				{
					Timer_ReadBack_ProbeStatus(1);
					DS18B20_Get_Temp();
					/* 测试7.3
					Probes_LedCtrl(testLed); 
					testLed =~testLed; */
					/*
					LED_ALL(ledTestEnable);
					ledTestEnable =~ledTestEnable;
					 */
					i=0;	  
				}
				//TIM3_COUNT_DONE=0;     		
				i++;
#else				
        Command_ProcessRequestCmds();
#endif
    }
}

