#define GLOBALS_APP_SCI
#include "../App_Headers/includes.h"

/*-------------------------------------------------------------------------
* Function Name  : App_SCI_Proc
* Description    : 串口数据处理
* Input          : None
* Output         : None
* Return         : None
* onther         : 
--------------------------------------------------------------------------*/
void App_SCI_Proc(void)
{
    if(CarFlag.FlagBits.RS232RV_Full == Enable)
    {
        CarFlag.FlagBits.RS232RV_Full = Disable;
        App_CopyRam((INT8U *)&SciFrame,(INT8U *)SCIRV,SCI_LEN);
        if(SCIRV[2] == 1)   //车速
        {
            SCIRV[0] = 0xeb;
            SCIRV[1] = 0x90;
            SCIRV[2] = 0x55;
            SCIRV[3] = 0x01;
            SCIRV[4] = 0x02;//上传
            SCIRV[5] = 0x00; 
            SCIRV[6] = 0x21;

           
            SCIRV[40] = App_CreateCheckSun((INT8U*)&SCIRV[7],SCIRV[2],33);
            SCIRV[41] = 0x55;
            SCIRV[42] = 0xaa;
            Api_SCI_Trans_Bytes((INT8U *)SCIRV,43);
        }
        if(SCIRV[2] == 2)   //转速
        {
            SCIRV[0] = 0xeb;
            SCIRV[1] = 0x90;
            SCIRV[2] = 0x55;
            SCIRV[3] = 0x02;
            SCIRV[4] = 0x02;//上传
            SCIRV[5] = 0x00; 
            SCIRV[6] = 0x21;

           
            SCIRV[40] = App_CreateCheckSun((INT8U*)&SCIRV[7],SCIRV[2],33);
            SCIRV[41] = 0x55;
            SCIRV[42] = 0xaa;
            Api_SCI_Trans_Bytes((INT8U *)SCIRV,43);
        } 
        if(SCIRV[2] == 3)   //水温
        {
            SCIRV[0] = 0xeb;
            SCIRV[1] = 0x90;
            SCIRV[2] = 0x55;
            SCIRV[3] = 0x03;
            SCIRV[4] = 0x02;//上传
            SCIRV[5] = 0x00; 
            SCIRV[6] = 0x21;

           
            SCIRV[40] = App_CreateCheckSun((INT8U*)&SCIRV[7],SCIRV[2],33);
            SCIRV[41] = 0x55;
            SCIRV[42] = 0xaa;
            Api_SCI_Trans_Bytes((INT8U *)SCIRV,43);
        }  
        if(SCIRV[2] == 4)   //燃油
        {
            SCIRV[0] = 0xeb;
            SCIRV[1] = 0x90;
            SCIRV[2] = 0x55;
            SCIRV[3] = 0x04;
            SCIRV[4] = 0x02;//上传
            SCIRV[5] = 0x00; 
            SCIRV[6] = 0x21;


           
            SCIRV[40] = App_CreateCheckSun((INT8U*)&SCIRV[7],SCIRV[2],33);
            SCIRV[41] = 0x55;
            SCIRV[42] = 0xaa;
            Api_SCI_Trans_Bytes((INT8U *)SCIRV,43);
        } 
        if(SCIRV[2] == 11)   //速比
        {
            SCIRV[0] = 0xeb;
            SCIRV[1] = 0x90;
            SCIRV[2] = 0x55;
            SCIRV[3] = 0x0b;
            SCIRV[4] = 0x02;//上传
            SCIRV[5] = 0x00; 
            SCIRV[6] = 0x21;

            App_CopyRam((INT8U *)&SCIRV[7],(INT8U *)&Radio.VehRadio,6);
           
            SCIRV[40] = App_CreateCheckSun((INT8U*)&SCIRV[7],SCIRV[2],33);
            SCIRV[41] = 0x55;
            SCIRV[42] = 0xaa;
            Api_SCI_Trans_Bytes((INT8U *)SCIRV,43);
        } 
        if(SCIRV[2] == 12)   //电压
        {
            SCIRV[0] = 0xeb;
            SCIRV[1] = 0x90;
            SCIRV[2] = 0x55;
            SCIRV[3] = 0x0c;
            SCIRV[4] = 0x02;//上传
            SCIRV[5] = 0x00; 
            SCIRV[6] = 0x21;
            //Veh
            SCIRV[7] = 0;//ADEveArry.TmpEven
            SCIRV[8] = 0;
            //Rev
            SCIRV[9] = 0;
            SCIRV[10] = 0;
            //tmp
            SCIRV[11] = 0;
            SCIRV[12] = 0;
            //fuel
            SCIRV[13] = 0;
            SCIRV[14] = 0;
                                                            
            SCIRV[40] = App_CreateCheckSun((INT8U*)&SCIRV[7],SCIRV[2],33);
            SCIRV[41] = 0x55;
            SCIRV[42] = 0xaa;
            Api_SCI_Trans_Bytes((INT8U *)SCIRV,43);
        }                    
        if(SciFrame.Dir == DownLoad)
        {

            switch(SciFrame.Frame_Type)
            {

                    
                case VehType:                
                  	check = App_CreateCheckSun((INT8U*)SciFrame.Frame_Data,SciFrame.Frame_Check,33);
                  	if(check == SciFrame.Frame_CheckSun)
                  	{
                  	    SCIRV[0] = 0xeb;
                  	    SCIRV[1] = 0x90;
                  	    SCIRV[2] = 0x01;
                  	    SCIRV[3] = 0x55;
                  	    SCIRV[4] = 0xaa;
                  	    Api_SCI_Trans_Bytes((INT8U *)SCIRV,5);
                  	}                  	                    
                    break; 
                case RevType:                
                  	check = App_CreateCheckSun((INT8U*)SciFrame.Frame_Data,SciFrame.Frame_Check,33);
                  	if(check == SciFrame.Frame_CheckSun)
                  	{
                  	    SCIRV[0] = 0xeb;
                  	    SCIRV[1] = 0x90;
                  	    SCIRV[2] = 0x02;
                  	    SCIRV[3] = 0x55;
                  	    SCIRV[4] = 0xaa;
                  	    Api_SCI_Trans_Bytes((INT8U *)SCIRV,5);
                  	}                  	                    
                    break;  
                case TmpType:                
                  	check = App_CreateCheckSun((INT8U*)SciFrame.Frame_Data,SciFrame.Frame_Check,33);
                  	if(check == SciFrame.Frame_CheckSun)
                  	{

                  	    SCIRV[0] = 0xeb;
                  	    SCIRV[1] = 0x90;
                  	    SCIRV[2] = 0x03;
                  	    SCIRV[3] = 0x55;
                  	    SCIRV[4] = 0xaa;
                  	    Api_SCI_Trans_Bytes((INT8U *)SCIRV,5);
                  	}                  	                    
                    break; 
                case FueType:                
                  	check = App_CreateCheckSun((INT8U*)SciFrame.Frame_Data,SciFrame.Frame_Check,33);
                  	if(check == SciFrame.Frame_CheckSun)
                  	{

                  	    SCIRV[0] = 0xeb;
                  	    SCIRV[1] = 0x90;
                  	    SCIRV[2] = 0x04;
                  	    SCIRV[3] = 0x55;
                  	    SCIRV[4] = 0xaa;
                  	    Api_SCI_Trans_Bytes((INT8U *)SCIRV,5);
                  	}                  	                    
                    break;  
                case RadioType:                
                  	check = App_CreateCheckSun((INT8U*)SciFrame.Frame_Data,SciFrame.Frame_Check,33);
                  	if(check == SciFrame.Frame_CheckSun)
                  	{
                  	    Radio.bFlag = SciFrame.Frame_Check;
                  	    App_CopyRam((INT8U *)&Radio.VehRadio,(INT8U *)&SciFrame.Frame_Data[0],2);
                  	    App_CopyRam((INT8U *)&Radio.VehNum,(INT8U *)&SciFrame.Frame_Data[2],2);
                  	    App_CopyRam((INT8U *)&Radio.RevRadio,(INT8U *)&SciFrame.Frame_Data[4],2);
                  	    
                  	    Radio.bCheckSun = App_CreateCheckSun((INT8U*)&Radio.VehRadio,Radio.bFlag,6);
                  	    
                  	    SCIRV[0] = 0xeb;
                  	    SCIRV[1] = 0x90;
                  	    SCIRV[2] = 0x0b;
                  	    SCIRV[3] = 0x55;
                  	    SCIRV[4] = 0xaa;
                  	    Api_SCI_Trans_Bytes((INT8U *)SCIRV,5);
                  	    _FEED_COP();

                        bReturn = Api_DFlashEraseSector(DFLASH_RADIO_ADDR);   
                        bReturn = Api_DFalshProgram(DFLASH_RADIO_ADDR,PAGE_LEN,(INT16U*)&Radio);
                  	}                  	                    
                    break; 
                case AccType:                
                  	check = App_CreateCheckSun((INT8U*)SciFrame.Frame_Data,SciFrame.Frame_Check,33);
                  	if(check == SciFrame.Frame_CheckSun)
                  	{
                
                  	}                  	                    
                    break;                                                                                                                 
                default:
                    ;
            }
        }
        SciFrame.Frame_Head[0] = null;
        SciFrame.Frame_Data[0] = null;
        SciFrame.Frame_Data[1] = null;
        SciFrame.Frame_Type = null;
        SciFrame.Dir = null;
        SCIRV[4] = null;
    }
}