#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>

#include "main.h"
#include "Bluecell_operate.h"
#include "PE43711.h"
#include "eeprom.h"




/***************************************************************************************/
/*                                  Extern Function                                    */
/***************************************************************************************/
extern uint32_t ShutdownCnt_Get(uint8_t index);
extern void ShutdownCnt_Set(uint8_t index,uint8_t val);

extern void PE43711_atten_ctrl(PE43711_st ATT ,uint8_t data);
extern void Uart1_Data_Send(uint8_t* data,uint16_t size);
extern HAL_StatusTypeDef EEPROM_M24C08_Zerowrite(uint8_t devid,uint16_t Address);
extern uint8_t Chksum_Create(uint8_t *data);
extern uint16_t CRC16_Generate(uint8_t* buf_ptr, int len);
extern uint8_t MBIC_APIFLASH_Func(uint8_t* data,uint32_t size);
extern void MBIC_Bootloader_FirmwareUpdate(uint8_t* data);
extern uint8_t* MBIC_HeaderMergeFunction(uint8_t* data,uint16_t Length );
extern void PE43711_atten_ctrl2(PE43711_st* ATT ,uint8_t data);
extern void PE43711_UL4_atten_ctrl(uint8_t data);



/***************************************************************************************/
/*                                  Extern Valuable                                    */
/***************************************************************************************/
extern volatile bool     AlarmTimerOnSet;
extern volatile bool     AlarmTimerOffSet;
extern volatile uint32_t AlarmTimerOnCnt;
extern volatile uint32_t AlarmTimerOffCnt;

extern volatile uint32_t AGC_On_AlarmTimerCnt[AGC_Alarm_DL_Index_MAX];
extern volatile uint32_t AGC_Off_AlarmTimerCnt[AGC_Alarm_DL_Index_MAX];

extern volatile uint32_t DET_DL_Normal_Shutdown_On_AlarmTimerCnt[DET_Alarm_UL_Index_MAX] ;
extern volatile uint32_t DET_UL_Normal_Shutdown_On_AlarmTimerCnt[DET_Alarm_UL_Index_MAX] ;

extern ALL_PE43711_st ALL_ATT;
extern volatile uint16_t ADC1valuearray[4][ADC_AVERAGECNT];
extern volatile uint16_t ADC3valuearray[5][ADC_AVERAGECNT];
extern volatile uint16_t ADC1Desc_valuearray[4][ADC_AVERAGECNT];
extern volatile uint16_t ADC3Desc_valuearray[5][ADC_AVERAGECNT];

extern volatile uint32_t LedTimerCnt;
extern volatile uint32_t AdcTimerCnt;
extern volatile uint32_t DET_UL_On_AlarmTimerCnt[DET_Alarm_UL_Index_MAX];
extern volatile uint32_t DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL_Index_MAX];
extern volatile uint32_t DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL_Index_MAX];
extern volatile uint32_t DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL_Index_MAX];
extern volatile uint32_t DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL_Index_MAX];
extern volatile uint32_t DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL_Index_MAX];
extern volatile uint32_t ALC_On_AlarmTimerCnt[ALC_Alarm_UL_Index_MAX];
extern volatile uint32_t ALC_Off_AlarmTimerCnt[ALC_Alarm_UL_Index_MAX];
extern volatile uint32_t DET_UL_Shutdown_On_AlarmTimerCnt[DET_Alarm_UL_Index_MAX];
extern volatile uint32_t DET_UL_Shutdown_Off_AlarmTimerCnt[DET_Alarm_UL_Index_MAX];
extern volatile uint32_t DET_DL_Shutdown_On_AlarmTimerCnt[DET_Alarm_DL_Index_MAX];
extern volatile uint32_t DET_DL_Shutdown_Off_AlarmTimerCnt[DET_Alarm_DL_Index_MAX];
extern uint8_t* MBIC_UL_ShutdownCount;
extern uint8_t* MBIC_DL_ShutdownCount;
extern uint8_t* PrevMBIC_UL_ShutdownCount;
extern uint8_t* PrevMBIC_DL_ShutdownCount;

extern volatile uint32_t Alarm_Temp_TimerOffCnt ;
extern volatile uint32_t Alarm_Temp_TimerOnCnt ;

extern volatile uint32_t Alarm_DL_Level_TimerOffCnt ;
extern volatile uint32_t Alarm_DL_Level_TimerOnCnt ;

extern volatile uint32_t Alarm_UL_Level_TimerOffCnt ;
extern volatile uint32_t Alarm_UL_Level_TimerOnCnt ;

extern volatile uint32_t SelfTestLifeCnt[4];
extern volatile uint32_t ADC_100ms_Cnt;

extern volatile uint32_t HFR_ADC1value[ADC1_CNT];
extern volatile uint32_t HFR_ADC3value[ADC3_CNT];

volatile uint8_t Selftest_DL_PrevAttenSave[8] = {0,};
volatile uint8_t Selftest_UL_PrevAttenSave[8] = {0,};
uint8_t TempShutdown_DL_SaveData[4] = {false,};
uint8_t TempShutdown_UL_SaveData[4] = {false,};    

extern volatile uint32_t AlarmReport_TimerCnt;
extern uint8_t Led_ToggleCntSet;

/***************************************************************************************/
/*                                  Function                                           */
/***************************************************************************************/

double AutoControl_ADC_Compare(double CurrentAdc,uint8_t* CompareAdc,uint8_t size,int8_t* RefTable_Data);
void Bluecell_StructCpy(uint8_t* dst,uint8_t* src,uint16_t size);
void DataStatusSet(void);
void Alarm_Check();
double TableAtteGuarantee(uint8_t* Table,double AttenValue);
double PE43711_Double(uint8_t high_bit,uint8_t low_bit);
double Bluecell_TestPro(double value );
double AGC_AutoControl_ADC_Compare(double CurrentAdc,uint8_t* CompareAdc,uint8_t size,int8_t* RefTable_Data);
void ALC_Alarm_TimerSet(uint8_t num,int16_t threshold,int16_t CurrDet,int16_t CurrAtten,int16_t MainAtten);
void Carrier_ONOFF(uint8_t val);
void DL_Path_OnOff(uint8_t Index,uint8_t value,uint8_t* path,uint8_t* PrevAtten,uint8_t* retrycnt,uint8_t* PrevRetryCnt);
void Factory_Set();
void SelfTest_Ctrl(uint8_t num,uint8_t val,uint8_t* selftest,uint8_t* DL_Atten,uint8_t* UL_Atten);
void TimeSetting(uint8_t* data);
void Temp_Shutdown_ONOFF(uint8_t val);

void UL_Path_OnOff(uint8_t Index,uint8_t value,uint8_t* path,uint8_t* PrevAtten,uint8_t* retrycnt,uint8_t* PrevRetryCnt);
/***************************************************************************************/
/*                                  Valuable                                           */
/***************************************************************************************/

#define ALAMASK_DEFAULT 1
#define Temp_THREADHOLD_DEFAULT 80
#define CARRIER_DEFAULT 1
#define DLI_PATH_DEFAULT
#define DLI_GAIN_ATT_DEFAULT 0
#define ULO_GAIN_ATT_DEFAULT -200

#define TEMP_OFFSET_DEFAULT 0
#define CARRIER_ONOF_DEFAULT 1
#define PATH_DEFAULT true
#define DLI_ATTEN_DEFAULT 0
#define ULO_ATTEN_DEFAULT -200

#define ATTEN_OFFSET_DEFAULT -30
#define DLI_ATTEN_HIGHTHREADHOLD_DEFAULT 70
#define DLI_ATTEN_LOWTHREADHOLD_DEFAULT -430
#define DLI_FRBT_DAY_DEFAULT 7
#define DLI_FRBT_ATTEN_DEFALUT 0 ;
#define DLI_AGC_ONOFF_DEFAULT true
#define DLI_AGC_THREADHOLD_DEFAULT -100
#define DLI_SHUTDOWN_ONOFF_DEFAULT true
#define DLI_SHUTDOWN_THREADHOLD_DEFAULT -10
#define ULO_LEVEL_HIGH_THREADHOLD_DEFAULT -180
#define SELFTEST_DEFALULT_DEFAULT false
#define ULO_ALC_ONOFF_DEFAULT true
#define ULO_ALC_THREADHOLD_DEFAULT -400
#define ULO_SHUTDOWN_ONOFF_DEFAULT true
#define ULO_SHUTDOWN_THREADHOLD_DEFAULT -160

#define TableDataSetting_ATT_DL_LEVEL_STEP -1 
#define TableDataSetting_ATT_UL_LEVEL_STEP -1 
#define MBIC_AID  0xE0

#define Temp_High 				0xE014
#define DLI_P4_Level_Low		0xE043
#define DLI_P3_Level_Low 		0xE042
#define DLI_P2_Level_Low		0xE041
#define DLI_P1_Level_Low		0xE040
#define DLI_P4_Level_High		0xE047
#define DLI_P3_Level_High		0xE046
#define DLI_P2_Level_High		0xE045
#define DLI_P1_Level_High		0xE044
#define DLI_P4_AGC_Alarm		0xE05A
#define DLI_P3_AGC_Alarm		0xE059
#define DLI_P2_AGC_Alarm		0xE058
#define DLI_P1_AGC_Alarm		0xE057
#define DLI_P4_Shutdown_Alarm	0xE05E
#define DLI_P3_Shutdown_Alarm	0xE05D
#define DLI_P2_Shutdown_Alarm	0xE05C
#define DLI_P1_Shutdown_Alarm	0xE05B
#define ULO_P4_Level_High		0xE073
#define ULO_P3_Level_High		0xE072
#define ULO_P2_Level_High		0xE071
#define ULO_P1_Level_High		0xE070
#define ULO_P4_ALC_Alarm		0xE08A
#define ULO_P3_ALC_Alarm		0xE089
#define ULO_P2_ALC_Alarm		0xE088
#define ULO_P1_ALC_Alarm		0xE087
#define ULO_P4_Shutdown			0xE08E
#define ULO_P3_Shutdown		    0xE08D
#define ULO_P2_Shutdown		    0xE08C
#define ULO_P1_Shutdown		    0xE08B


int8_t DL_DET_Table_ref[AGC_Table_DL_Ref_Index_MAX][TABLE_LENGTH_MAX];
int8_t UL_DET_Table_ref[ALC_Table_UL_Ref_Index_MAX][TABLE_LENGTH_MAX];
bool Alarm_LED_OnSet;
uint8_t DataWrite[sizeof(BLUESTATUS_st)];
uint8_t Txdata[1024];
int8_t AutoControl_Save[MBIC_Table_INDEX][sizeof(ALC_dBm_t)];
uint16_t ADC1Ret[4];
bool UL_ALC_GainAttenSet[ALC_Alarm_UL_Index_MAX];
int16_t ALC_Level_Save[ALC_Alarm_UL_Index_MAX];
bool Initialize;
bool AGC_AlarmSet[AGC_Alarm_DL_Index_MAX];
uint8_t FRBT_Day_Inc;
uint16_t ADC3Ret[5];
volatile uint8_t LED_TestCnt = 0;
uint8_t TxData[2048];


ATT_TABLE_st Att_DL1;
ATT_TABLE_st Att_DL2;
ATT_TABLE_st Att_DL3;
ATT_TABLE_st Att_DL4;
ATT_TABLE_st Att_UL1;
ATT_TABLE_st Att_UL2;
ATT_TABLE_st Att_UL3;
ATT_TABLE_st Att_UL4;

DET_TABLEDL_st Det_DL1;
DET_TABLEDL_st Det_DL2;
DET_TABLEDL_st Det_DL3;
DET_TABLEDL_st Det_DL4;

DET_TABLEUL_st Det_UL1;
DET_TABLEUL_st Det_UL2;
DET_TABLEUL_st Det_UL3;
DET_TABLEUL_st Det_UL4;

TEMP_TABLE_st Temp_DL1;
TEMP_TABLE_st Temp_DL2;
TEMP_TABLE_st Temp_DL3;
TEMP_TABLE_st Temp_DL4;

TEMP_TABLE_st Temp_UL1;
TEMP_TABLE_st Temp_UL2;
TEMP_TABLE_st Temp_UL3;
TEMP_TABLE_st Temp_UL4;

BLUESTATUS_st bluecell_Currdatastatus;
BLUESTATUS_st bluecell_Prevdatastatus;
int16_t DL_AGC_StartAtten[AGC_Alarm_DL_Index_MAX] = {0,};
int16_t DL_PrevIwillgiveAtten[AGC_Alarm_DL_Index_MAX] = {0,};
bool DL_PathUserHandl[4] = {0,};
bool UL_PathUserHandl[4] = {0,};
typedef enum{
    DLI_FRBT_Time_Year = 0,
    DLI_FRBT_Time_Month,
    DLI_FRBT_Time_Day,
    DLI_FRBT_Time_Hour,
    DLI_FRBT_Time_Minute,
    DLI_FRBT_Time_Second,    
    DLI_FRBT_Time_Index_Max,        
};
volatile uint8_t StartTimeFRBT_Day[6] = {0,}; /*Start day Register*/
uint8_t FRBT_Day[6] = {0,}; /*Curr day Register*/
uint8_t PrevFRBT_Day[6] = {0,}; /*Prev day Register*/

typedef enum{
    FRBT_IDEL = 0,
    FRBT_TRACKING,
    FRBT_RUNNING,
}FRBT_Status_I;
typedef enum{
    Path1_OnOff = 0,
    Path2_OnOff,
    Path3_OnOff,
    Path4_OnOff,    
};
typedef enum{
    Atten_H = 0,
    Atten_L,        
};
   
typedef enum{
    SelfTest1 = 0,
    SelfTest2,
    SelfTest3,
    SelfTest4,    
};

typedef enum{
     MBIC_3_7G  =     0x80  ,              
     MBIC_3_8G     ,
     MBIC_3_9G     ,
     MBIC_4_0G     ,
     MBIC_4_1G     ,
     MBIC_4_6G     ,
     MBIC_4_7G     ,
     MBIC_4_8G     ,
     MBIC_4_9G     ,
     MBIC_5_0G     ,
     MBIC_DCM      ,
     MBIC_SBM      ,
     MBIC_KDDI     ,
}MBIC_CardType_t;
 typedef enum{
    BLUECELL_3_7G  =     0  ,              
    BLUECELL_3_8G     ,
    BLUECELL_3_9G     ,
    BLUECELL_4_0G     ,
    BLUECELL_4_1G     ,
    BLUECELL_4_6G     ,
    BLUECELL_SBM      ,
    BLUECELL_DCM      ,
    BLUECELL_KDDI     ,
    BLUECELL_4_7G     ,
    BLUECELL_4_8G     ,
    BLUECELL_4_9G     ,
    BLUECELL_5_0G     ,
 }Bluecell_CardType_t;
typedef enum{
    DLI_AGC_H = 0,
    DLI_AGC_L,
};
    

void Booting_LedInit(void){
    HAL_GPIO_WritePin(BOOT_LED_GPIO_Port,BOOT_LED_Pin,GPIO_PIN_RESET);
    HAL_GPIO_WritePin(LED_ACT_GPIO_Port,LED_ACT_Pin,GPIO_PIN_SET);
    HAL_GPIO_WritePin(LED_FAIL_GPIO_Port,LED_FAIL_Pin,GPIO_PIN_SET);

}


void Boot_LED_Toggle(void){
  if(bluecell_Currdatastatus.LED_TEST == false){
      if(LedTimerCnt > 500){
        HAL_GPIO_TogglePin(BOOT_LED_GPIO_Port,BOOT_LED_Pin);
        HAL_GPIO_TogglePin(LED_ACT_GPIO_Port,LED_ACT_Pin);
    //    if(AlarmTimerOnCnt > 3000){
        if(Alarm_LED_OnSet == true){
            HAL_GPIO_WritePin(LED_FAIL_GPIO_Port,LED_FAIL_Pin,GPIO_PIN_SET);
        }else{
            HAL_GPIO_WritePin(LED_FAIL_GPIO_Port,LED_FAIL_Pin,GPIO_PIN_RESET);
        }
    //    printf("Alarm_LED_OnSet : %d\r\n",Alarm_LED_OnSet);
        LedTimerCnt = 0;
      }
  }else{
        if(LedTimerCnt > 500){
//            printf("LED TESTING....\r\n");
            if(LED_TestCnt % 2){
                HAL_GPIO_WritePin(BOOT_LED_GPIO_Port,BOOT_LED_Pin,GPIO_PIN_SET);
                HAL_GPIO_WritePin(LED_FAIL_GPIO_Port,LED_FAIL_Pin,GPIO_PIN_RESET);
                HAL_GPIO_WritePin(LED_ACT_GPIO_Port,LED_ACT_Pin,GPIO_PIN_RESET);
            }else{
                HAL_GPIO_WritePin(BOOT_LED_GPIO_Port,BOOT_LED_Pin,GPIO_PIN_RESET);
                HAL_GPIO_WritePin(LED_FAIL_GPIO_Port,LED_FAIL_Pin,GPIO_PIN_SET);
                HAL_GPIO_WritePin(LED_ACT_GPIO_Port,LED_ACT_Pin,GPIO_PIN_SET);

            }
            LED_TestCnt++;
            LedTimerCnt = 0;
          /*Set LED TEST variable False after 12 flashes*/
          if(LED_TestCnt >= Led_ToggleCntSet){
            bluecell_Currdatastatus.LED_TEST = false;
            Led_ToggleCntSet = 20;
            LED_TestCnt = 0;
          }
        }
  }
  
}





uint8_t MBIC_DL_PE43711_Calc(uint8_t* Table,int16_t MBIC_Val,int16_t MBIC_UserVal){

    double ret = 0;
    double ret2 = 0;
    double ret3 = 0;
    uint8_t Result = 0;
    //ret = PE43711_Double(MBIC_Val); // Hidden Atten Calc
//    printf("MBIC_UserVal : %x \r\n",MBIC_UserVal); // 2
    ret = MBIC_Val;
    ret /= 10;
    ret *= -1;
    
    ret2 += MBIC_UserVal;
    ret2 /= 10;
    ret2 *= -1;

    
    ret += ret2;
    
    ret += HIDDENATTEN/10;//PE43711_Double(0,HIDDENATTEN);//Plus Default Atten 5
//    printf("ret1 : %f \r\n",ret); // 2
    ret = TableAtteGuarantee(Table,ret);//Table Guarantee
//    printf("ret2 : %f \r\n",ret);
    Result = PE43711_DataToHexConvert(ret);
    return Result;
}
uint8_t MBIC_UL_PE43711_Calc(uint8_t* Table,int16_t MBIC_Val,int16_t MBIC_UserVal,int16_t MBIC_ALCVal){

    double ret = 0;
    double ret2 = 0;
    double ret3 = 0;
    
    uint8_t Result = 0;
    if(MBIC_Val + MBIC_ALCVal < -200)
        MBIC_Val = MBIC_ALCVal = -100;
    //ret = PE43711_Double(MBIC_Val); // Hidden Atten Calc
//    printf("MBIC_UserVal : %x \r\n",MBIC_UserVal); // 2
    ret = MBIC_Val;
    ret /= 10;
    ret *= -1;
    ret2 += MBIC_UserVal;
    ret2 /= 10;
    ret2 *= -1;
    ret3 += MBIC_ALCVal;
    ret3 /= 10;
    ret3 *= -1;    
    ret =ret + ret2 + ret3;
//    printf("ret1 : %f \r\n",ret); // 2
    ret = TableAtteGuarantee(Table,ret);//Table Guarantee
//    printf("ret2 : %f \r\n",ret);
    Result = PE43711_DataToHexConvert(ret);
//    printf("Result %x \r\n",Result);
    return Result;
}

/*2 byte Data Double Convert Function*/


double PE43711_Double(uint8_t high_bit,uint8_t low_bit){
    //uint16_t tmp_h = 0,tmp_l = 0;
    double ret = 0;
    int16_t tmp = 0;
#if 0 // PYJ.2020.05.22_BEGIN -- 
    tmp_h = high_bit;
    tmp_l = low_bit;
    ret = ((tmp_h << 8) & 0xFF00);
    ret += (tmp_l & 0x00FF);
    /*Minus Convert*/
    if((((tmp_h << 8) & 0xFF00) & 0xF000) == 0xF000){
//        printf("minus Calc Start\r\n");
        ret = 0xFFFF - ret;
//        printf("0xFFFF - %x\r\n",ret);
        ret += 0x01;
        ret = ret - (2*ret);
//        printf("ret :  %x\r\n",ret);        
    }
//    printf("%s 1: ret : %x\r\n",__func__,ret);
    ret /= 10;
#else
    tmp = (int16_t)((high_bit << 8) | low_bit);
    ret = tmp * 0.1;
#if 0 // PYJ.2020.05.22_BEGIN -- 
    if(ret > 6000){
        printf("high_bit : %x LOW BIT : %x \r\n",high_bit,low_bit);
    }
#endif // PYJ.2020.05.22_END -- 
#endif // PYJ.2020.05.22_END -- 
//    printf("%s 2: ret : %f\r\n",__func__,ret);
    return ret;

}
double TableAtteGuarantee(uint8_t* Table,double AttenValue){
    int8_t GuaranteeData[256];
    double ret = 0;
    //double ref = 0;
    uint8_t cnt = 0;
    for(double ref = 0; ref < AttenValue; ref += 0.5){
        cnt++;       
    }
    
    Bluecell_StructCpy(&GuaranteeData[0],&Table[0],sizeof(ATT_TABLE_st));
//    printf("cnt : %d \r\n",cnt);
//    printf("H  : %x   L : %x \r\n",GuaranteeData[cnt * 2],GuaranteeData[cnt * 2 + 1]);
    ret =  GuaranteeData[cnt] * 0.5;
//= PE43711_Double(GuaranteeData[cnt * 2],GuaranteeData[cnt * 2 + 1]);
//    printf("ret3 : %f \r\n",ret); //1
    ret += AttenValue;
//    printf("ret4 : %f \r\n",ret);
    return ret;

}

#if 1 // PYJ.2020.05.25_BEGIN -- 


void Table_DataSetting(int8_t* pdata,int8_t RefData,double step,uint8_t size){
//    step /= 10;
    for(int i =0; i < size; i++){
        pdata[i] = RefData;
//        printf("pdata[%d] %d \r\n",i,pdata[i]);
        RefData += step; 
    }
}
void Table_Init(){
//    printf("Table Initialize\r\n");
    Table_DataSetting(&DL_DET_Table_ref[AGC_Table_DL1_Ref_Index][TABLE_MAX_VALUE],Det_DL1.Table_Ref,TableDataSetting_ATT_DL_LEVEL_STEP,Det_DL1.Table_Length);
    Table_DataSetting(&DL_DET_Table_ref[AGC_Table_DL2_Ref_Index][TABLE_MAX_VALUE],Det_DL2.Table_Ref,TableDataSetting_ATT_DL_LEVEL_STEP,Det_DL2.Table_Length);
    Table_DataSetting(&DL_DET_Table_ref[AGC_Table_DL3_Ref_Index][TABLE_MAX_VALUE],Det_DL3.Table_Ref,TableDataSetting_ATT_DL_LEVEL_STEP,Det_DL3.Table_Length);
    Table_DataSetting(&DL_DET_Table_ref[AGC_Table_DL4_Ref_Index][TABLE_MAX_VALUE],Det_DL4.Table_Ref,TableDataSetting_ATT_DL_LEVEL_STEP,Det_DL4.Table_Length);
    Table_DataSetting(&UL_DET_Table_ref[ALC_Table_UL1_Ref_Index][TABLE_MAX_VALUE],Det_UL1.Table_Ref,TableDataSetting_ATT_UL_LEVEL_STEP,Det_UL1.Table_Length);
    Table_DataSetting(&UL_DET_Table_ref[ALC_Table_UL2_Ref_Index][TABLE_MAX_VALUE],Det_UL2.Table_Ref,TableDataSetting_ATT_UL_LEVEL_STEP,Det_UL2.Table_Length);
    Table_DataSetting(&UL_DET_Table_ref[ALC_Table_UL3_Ref_Index][TABLE_MAX_VALUE],Det_UL3.Table_Ref,TableDataSetting_ATT_UL_LEVEL_STEP,Det_UL3.Table_Length);
    Table_DataSetting(&UL_DET_Table_ref[ALC_Table_UL4_Ref_Index][TABLE_MAX_VALUE],Det_UL4.Table_Ref,TableDataSetting_ATT_UL_LEVEL_STEP,Det_UL4.Table_Length);


//    EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_ATT_UL4_TABLE_ADDRESDS,&Det_DL1.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st) );
//    EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_DET_DL1_TABLE_ADDRESDS,&Det_DL2.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st) );
//    EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_DET_DL2_TABLE_ADDRESDS,&Det_DL3.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st) );
//    EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_DET_DL3_TABLE_ADDRESDS,&Det_DL4.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st) );
//
//
//    EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_DET_DL4_TABLE_ADDRESDS,&Det_UL1.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );
//    EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_DET_UL1_TABLE_ADDRESDS,&Det_UL2.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );
//    EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_DET_UL2_TABLE_ADDRESDS,&Det_UL3.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );
//    EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_DET_UL3_TABLE_ADDRESDS,&Det_UL4.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );



}
void Bluecell_AttenInitialize(){
    uint8_t val = 0;
    int16_t MBIC_ALC_Val = 0,MBIC_Val = 0,MBIC_UserVal = 0;

//    Bluecell_StructCpy(&AutoControl_Save[MBIC_Table_DL1_INDEX],&DL_DET_Table_ref[AGC_Table_DL1_Ref_Index][TABLE_MAX_VALUE],sizeof(AGC_dBm_t));
//    Bluecell_StructCpy(&AutoControl_Save[MBIC_Table_DL2_INDEX],&DL_DET_Table_ref[AGC_Table_DL2_Ref_Index][TABLE_MAX_VALUE],sizeof(AGC_dBm_t));
//    Bluecell_StructCpy(&AutoControl_Save[MBIC_Table_DL3_INDEX],&DL_DET_Table_ref[AGC_Table_DL3_Ref_Index][TABLE_MAX_VALUE],sizeof(AGC_dBm_t));
//    Bluecell_StructCpy(&AutoControl_Save[MBIC_Table_DL4_INDEX],&DL_DET_Table_ref[AGC_Table_DL4_Ref_Index][TABLE_MAX_VALUE],sizeof(AGC_dBm_t));
//    Bluecell_StructCpy(&AutoControl_Save[MBIC_Table_UL1_INDEX],&UL_DET_Table_ref[ALC_Table_UL1_Ref_Index][TABLE_MAX_VALUE],sizeof(ALC_dBm_t));
//    Bluecell_StructCpy(&AutoControl_Save[MBIC_Table_UL2_INDEX],&UL_DET_Table_ref[ALC_Table_UL2_Ref_Index][TABLE_MAX_VALUE],sizeof(ALC_dBm_t));
//    Bluecell_StructCpy(&AutoControl_Save[MBIC_Table_UL3_INDEX],&UL_DET_Table_ref[ALC_Table_UL3_Ref_Index][TABLE_MAX_VALUE],sizeof(ALC_dBm_t));
//    Bluecell_StructCpy(&AutoControl_Save[MBIC_Table_UL4_INDEX],&UL_DET_Table_ref[ALC_Table_UL4_Ref_Index][TABLE_MAX_VALUE],sizeof(ALC_dBm_t));

//    for(int a = 0; a < MBIC_Table_INDEX; a++){
//        printf("========================START %d=====================================\r\n",a);
//        if(a <= MBIC_Table_DL4_INDEX)
//        for(int i = 0; i < sizeof(AGC_dBm_t); i++)
//            printf("ref Tabe: %d \r\n",AutoControl_Save[MBIC_Table_DL1_INDEX + a][i]      );         
//        else
//            for(int i = 0; i < sizeof(ALC_dBm_t); i++)
//                printf("ref Tabe: %d \r\n",AutoControl_Save[MBIC_Table_DL1_INDEX + a][i]      ); 
//    }
////    
//    

    bluecell_Prevdatastatus.ATT_DL1_H = bluecell_Currdatastatus.ATT_DL1_H;
    bluecell_Prevdatastatus.ATT_DL1_L = bluecell_Currdatastatus.ATT_DL1_L;
    bluecell_Prevdatastatus.bluecell_User_DL1_H = bluecell_Currdatastatus.bluecell_User_DL1_H;
    bluecell_Prevdatastatus.bluecell_User_DL1_L = bluecell_Currdatastatus.bluecell_User_DL1_L;

    MBIC_Val = bluecell_Currdatastatus.ATT_DL1_H << 8 | bluecell_Currdatastatus.ATT_DL1_L;
    MBIC_UserVal = bluecell_Currdatastatus.bluecell_User_DL1_H << 8 | bluecell_Currdatastatus.bluecell_User_DL1_L;
//    printf("MBIC_UserVal : %d \r\n",MBIC_UserVal);
    val = MBIC_DL_PE43711_Calc(&Att_DL1.Table_0_0_dBm, // Table Offset
                        MBIC_Val,
                       MBIC_UserVal);// User Atten Low Bit

    PE43711_atten_ctrl(ALL_ATT.ATT_DL1,val);

    bluecell_Prevdatastatus.ATT_DL2_H = bluecell_Currdatastatus.ATT_DL2_H;
    bluecell_Prevdatastatus.ATT_DL2_L = bluecell_Currdatastatus.ATT_DL2_L;
    bluecell_Prevdatastatus.bluecell_User_DL2_H = bluecell_Currdatastatus.bluecell_User_DL2_H;
    bluecell_Prevdatastatus.bluecell_User_DL2_L = bluecell_Currdatastatus.bluecell_User_DL2_L;
    MBIC_Val = bluecell_Currdatastatus.ATT_DL2_H << 8 | bluecell_Currdatastatus.ATT_DL2_L;
    MBIC_UserVal = bluecell_Currdatastatus.bluecell_User_DL2_H << 8 | bluecell_Currdatastatus.bluecell_User_DL2_L;
    val = MBIC_DL_PE43711_Calc(&Att_DL2.Table_0_0_dBm, // Table Offset
                        MBIC_Val,
                       MBIC_UserVal);// User Atten Low Bit

    PE43711_atten_ctrl(ALL_ATT.ATT_DL2,val);

    bluecell_Prevdatastatus.ATT_DL3_H = bluecell_Currdatastatus.ATT_DL3_H;
    bluecell_Prevdatastatus.ATT_DL3_L = bluecell_Currdatastatus.ATT_DL3_L;
    bluecell_Prevdatastatus.bluecell_User_DL3_H = bluecell_Currdatastatus.bluecell_User_DL3_H;
    bluecell_Prevdatastatus.bluecell_User_DL3_L = bluecell_Currdatastatus.bluecell_User_DL3_L;
    MBIC_Val = bluecell_Currdatastatus.ATT_DL3_H << 8 | bluecell_Currdatastatus.ATT_DL3_L;
    MBIC_UserVal = bluecell_Currdatastatus.bluecell_User_DL3_H << 8 | bluecell_Currdatastatus.bluecell_User_DL3_L;
//    printf("DL 3 MAIN ATTEN :%x \r\n",MBIC_Val);
//    printf("DL 3 OFSSET ATTEN :%x \r\n",MBIC_UserVal);    
    val = MBIC_DL_PE43711_Calc(&Att_DL3.Table_0_0_dBm, // Table Offset
                        MBIC_Val,
                       MBIC_UserVal);// User Atten Low Bit

    PE43711_atten_ctrl(ALL_ATT.ATT_DL3,val);

    bluecell_Prevdatastatus.ATT_DL4_H = bluecell_Currdatastatus.ATT_DL4_H;
    bluecell_Prevdatastatus.ATT_DL4_L = bluecell_Currdatastatus.ATT_DL4_L;
    bluecell_Prevdatastatus.bluecell_User_DL4_H = bluecell_Currdatastatus.bluecell_User_DL4_H;
    bluecell_Prevdatastatus.bluecell_User_DL4_L = bluecell_Currdatastatus.bluecell_User_DL4_L;
    MBIC_Val = bluecell_Currdatastatus.ATT_DL4_H << 8 | bluecell_Currdatastatus.ATT_DL4_L;
    MBIC_UserVal = bluecell_Currdatastatus.bluecell_User_DL4_H << 8 | bluecell_Currdatastatus.bluecell_User_DL4_L;
    val = MBIC_DL_PE43711_Calc(&Att_DL4.Table_0_0_dBm, // Table Offset
                        MBIC_Val,
                       MBIC_UserVal);// User Atten Low Bit

    PE43711_atten_ctrl(ALL_ATT.ATT_DL4,val);



    bluecell_Prevdatastatus.ATT_UL1_H = bluecell_Currdatastatus.ATT_UL1_H;
    bluecell_Prevdatastatus.ATT_UL1_L = bluecell_Currdatastatus.ATT_UL1_L;
    bluecell_Prevdatastatus.bluecell_User_UL1_H = bluecell_Currdatastatus.bluecell_User_UL1_H;
    bluecell_Prevdatastatus.bluecell_User_UL1_L = bluecell_Currdatastatus.bluecell_User_UL1_L;
    bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten1_H = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_H;
    bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten1_L = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_L;    
    MBIC_Val = bluecell_Currdatastatus.ATT_UL1_H << 8 | bluecell_Currdatastatus.ATT_UL1_L;
    MBIC_ALC_Val = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_L;
    MBIC_UserVal = bluecell_Currdatastatus.bluecell_User_UL1_H << 8 | bluecell_Currdatastatus.bluecell_User_UL1_L;
    val = MBIC_UL_PE43711_Calc(&Att_UL1.Table_0_0_dBm, // Table Offset
                        MBIC_Val,
                       MBIC_UserVal,
                       MBIC_ALC_Val);// User Atten Low Bit

//        printf("%d val = %x \r\n",__LINE__,val);
    PE43711_atten_ctrl(ALL_ATT.ATT_UL1,val);

                bluecell_Prevdatastatus.ATT_UL2_H = bluecell_Currdatastatus.ATT_UL2_H;
    bluecell_Prevdatastatus.ATT_UL2_L = bluecell_Currdatastatus.ATT_UL2_L;
    bluecell_Prevdatastatus.bluecell_User_UL2_H = bluecell_Currdatastatus.bluecell_User_UL2_H;
    bluecell_Prevdatastatus.bluecell_User_UL2_L = bluecell_Currdatastatus.bluecell_User_UL2_L;
    bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten2_H = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_H;
    bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten2_L = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_L;    
    MBIC_Val = bluecell_Currdatastatus.ATT_UL2_H << 8 | bluecell_Currdatastatus.ATT_UL2_L;
    bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_H = 0;
    bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_L = 0;
    MBIC_ALC_Val = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_L;
    MBIC_UserVal = bluecell_Currdatastatus.bluecell_User_UL2_H << 8 | bluecell_Currdatastatus.bluecell_User_UL2_L;
//    printf("MBIC_ALC_Val : %x \r\n",MBIC_ALC_Val);
    val = MBIC_UL_PE43711_Calc(&Att_UL1.Table_0_0_dBm, // Table Offset
                        MBIC_Val,
                       MBIC_UserVal,
                       MBIC_ALC_Val);// User Atten Low Bit

//        printf("%d val = %x \r\n",__LINE__,val);
    PE43711_atten_ctrl(ALL_ATT.ATT_UL2,val);


                bluecell_Prevdatastatus.ATT_UL3_H = bluecell_Currdatastatus.ATT_UL3_H;
    bluecell_Prevdatastatus.ATT_UL3_L = bluecell_Currdatastatus.ATT_UL3_L;
    bluecell_Prevdatastatus.bluecell_User_UL3_H = bluecell_Currdatastatus.bluecell_User_UL3_H;
    bluecell_Prevdatastatus.bluecell_User_UL3_L = bluecell_Currdatastatus.bluecell_User_UL3_L;
    bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten3_H = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_H;
    bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten3_L = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_L;    
    MBIC_Val = bluecell_Currdatastatus.ATT_UL3_H << 8 | bluecell_Currdatastatus.ATT_UL3_L;
    MBIC_ALC_Val = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_L;
    MBIC_UserVal = bluecell_Currdatastatus.bluecell_User_UL3_H << 8 | bluecell_Currdatastatus.bluecell_User_UL3_L;
    val = MBIC_UL_PE43711_Calc(&Att_UL3.Table_0_0_dBm, // Table Offset
                        MBIC_Val,
                       MBIC_UserVal,
                       MBIC_ALC_Val);// User Atten Low Bit

//        printf("%d val = %x \r\n",__LINE__,val);
    PE43711_atten_ctrl(ALL_ATT.ATT_UL3,val);


    bluecell_Prevdatastatus.ATT_UL4_H = bluecell_Currdatastatus.ATT_UL4_H;
    bluecell_Prevdatastatus.ATT_UL4_L = bluecell_Currdatastatus.ATT_UL4_L;
    bluecell_Prevdatastatus.bluecell_User_UL4_H = bluecell_Currdatastatus.bluecell_User_UL4_H;
    bluecell_Prevdatastatus.bluecell_User_UL4_L = bluecell_Currdatastatus.bluecell_User_UL4_L;
    bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten4_H = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_H;
    bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten4_L = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_L;    
    MBIC_Val = bluecell_Currdatastatus.ATT_UL4_H << 8 | bluecell_Currdatastatus.ATT_UL4_L;
    MBIC_ALC_Val = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_L;
    MBIC_UserVal = bluecell_Currdatastatus.bluecell_User_UL4_H << 8 | bluecell_Currdatastatus.bluecell_User_UL4_L;
    val = MBIC_UL_PE43711_Calc(&Att_UL4.Table_0_0_dBm, // Table Offset
                        MBIC_Val,
                       MBIC_UserVal,
                       MBIC_ALC_Val);// User Atten Low Bit

//        printf("%d val = %x \r\n",__LINE__,val);
    PE43711_atten_ctrl(ALL_ATT.ATT_UL4,val);

}
typedef enum{
    ATTEN_H = 0,
    ATTEN_L,        
};
void Atten_DL_Ctrl_Function(PE43711_st* ATT,ATT_TABLE_st* Table,uint8_t* CurrAtten,uint8_t* PrevAtten,uint8_t* CurrHiddenAtten,uint8_t* PrevHiddenAtten){
     uint16_t MBIC_Val = 0;
     uint16_t MBIC_ALC_Val = 0;
     uint16_t MBIC_UserVal = 0;
     uint8_t val = 0;
    if(CurrAtten[ATTEN_H] != CurrAtten[ATTEN_H]
      ||CurrAtten[ATTEN_H] != CurrAtten[ATTEN_L]
      ||CurrHiddenAtten[ATTEN_H] != CurrHiddenAtten[ATTEN_H]
      ||CurrHiddenAtten[ATTEN_H] != CurrHiddenAtten[ATTEN_L]){
            PrevAtten[ATTEN_H] = CurrAtten[ATTEN_H];
            PrevAtten[ATTEN_L] = CurrAtten[ATTEN_L];
            PrevHiddenAtten[ATTEN_H] = CurrHiddenAtten[ATTEN_H];
            PrevHiddenAtten[ATTEN_L] = CurrHiddenAtten[ATTEN_L];
            MBIC_Val = CurrAtten[ATTEN_H] << 8 | CurrAtten[ATTEN_L];
            MBIC_UserVal = CurrHiddenAtten[ATTEN_H] << 8 | CurrHiddenAtten[ATTEN_L];
            val = MBIC_DL_PE43711_Calc(&Table->Table_0_0_dBm, // Table Offset
                                MBIC_Val,
                               MBIC_UserVal);// User Atten Low Bit
//            printf("%s : %d \r\n",__func__,__LINE__);   
//            printf("%d val = %x \r\n",__LINE__,val);
            PE43711_atten_ctrl2(ATT,val);
    }

}
typedef enum{
    ATTEN_DL1= 0 ,
    ATTEN_DL2,
    ATTEN_DL3,
    ATTEN_DL4,
    ATTEN_UL1,    
    ATTEN_UL2,    
    ATTEN_UL3,    
    ATTEN_UL4,    
    
};
void Atten_UL_Ctrl_Function(uint8_t index,ATT_TABLE_st* Table,uint8_t* CurrAtten,uint8_t* PrevAtten,uint8_t* CurrHiddenAtten,uint8_t* PrevHiddenAtten,uint8_t* CurrALCAtten,uint8_t* PrevALCAtten){
     int16_t MBIC_Val = 0;
     int16_t MBIC_UserVal = 0;
     int16_t MBIC_ALCVal = 0;     
     uint8_t val = 0;
    if(CurrAtten[ATTEN_H] != CurrAtten[ATTEN_H]
      ||CurrAtten[ATTEN_L] != CurrAtten[ATTEN_L]
      ||CurrHiddenAtten[ATTEN_H] != CurrHiddenAtten[ATTEN_H]
      ||CurrHiddenAtten[ATTEN_L] != CurrHiddenAtten[ATTEN_L]
      ||PrevALCAtten[ATTEN_H] != CurrALCAtten[ATTEN_H]
      ||PrevALCAtten[ATTEN_L] != CurrALCAtten[ATTEN_L]){

      
            PrevAtten[ATTEN_H] = CurrAtten[ATTEN_H];
            PrevAtten[ATTEN_L] = CurrAtten[ATTEN_L];
            PrevHiddenAtten[ATTEN_H] = CurrHiddenAtten[ATTEN_H];
            PrevHiddenAtten[ATTEN_L] = CurrHiddenAtten[ATTEN_L];
            CurrALCAtten[ATTEN_H] = CurrALCAtten[ATTEN_H];
            CurrALCAtten[ATTEN_L] = CurrALCAtten[ATTEN_L];
            MBIC_Val = CurrAtten[ATTEN_H] << 8 | CurrAtten[ATTEN_L];
            MBIC_UserVal = CurrHiddenAtten[ATTEN_H] << 8 | CurrHiddenAtten[ATTEN_L];
            MBIC_ALCVal= CurrALCAtten[ATTEN_H] << 8 | CurrALCAtten[ATTEN_L];
            val = MBIC_UL_PE43711_Calc(&Table->Table_0_0_dBm, // Table Offset
                                MBIC_Val,
                               MBIC_UserVal,
                               MBIC_ALCVal);// User Atten Low Bit
                               
//            printf("%s : %d \r\n",__func__,__LINE__);   
//            printf("%d val = %x \r\n",__LINE__,val);
            switch(index){
                case ATTEN_UL1:    PE43711_atten_ctrl(ALL_ATT.ATT_UL1,val);break;
                case ATTEN_UL2:    PE43711_atten_ctrl(ALL_ATT.ATT_UL2,val);break;
                case ATTEN_UL3:    PE43711_atten_ctrl(ALL_ATT.ATT_UL3,val);break;
                case ATTEN_UL4:    PE43711_UL4_atten_ctrl(val);break;
            }

    }

}
typedef enum{
    DL_ATTEN_H,
    DL_ATTEN_L,        
};
void DL_AttenOperate(uint8_t* Atten,uint8_t* PrevAtten,uint8_t* UserAtten,uint8_t* PrevUserAtten,PE43711_st ATT){
     uint8_t val = 0;
     uint16_t MBIC_Val = 0;
     uint16_t MBIC_ALC_Val = 0;
     uint16_t MBIC_UserVal = 0;    
        if((Atten[DL_ATTEN_H] != PrevAtten[DL_ATTEN_H])
         ||(Atten[DL_ATTEN_L] != PrevAtten[DL_ATTEN_L])
         ||(UserAtten[DL_ATTEN_H] != PrevUserAtten[DL_ATTEN_H])
         ||(UserAtten[DL_ATTEN_L] != PrevUserAtten[DL_ATTEN_L])){
    //         printf("%s : %d \r\n",__func__,__LINE__);   
                Atten[DL_ATTEN_H] = PrevAtten[DL_ATTEN_H];
                Atten[DL_ATTEN_L] = PrevAtten[DL_ATTEN_L];
                UserAtten[DL_ATTEN_H] = PrevUserAtten[DL_ATTEN_H];
                UserAtten[DL_ATTEN_L] = PrevUserAtten[DL_ATTEN_L];
                MBIC_Val =Atten[DL_ATTEN_H] << 8 |Atten[DL_ATTEN_L];
                MBIC_UserVal = UserAtten[DL_ATTEN_H] << 8 | UserAtten[DL_ATTEN_L];
                val = MBIC_DL_PE43711_Calc(&Att_DL1.Table_0_0_dBm, // Table Offset
                                    MBIC_Val,
                                   MBIC_UserVal);// User Atten Low Bit
//                printf("%s : %d \r\n",__func__,__LINE__);   
//                printf("%d val = %x \r\n",__LINE__,val);
                PE43711_atten_ctrl(ATT,val);
        }


}
typedef enum{
    UserAtten_H = 0,
    UserAtten_L,        
};

void CompareAttenData(BLUESTATUS_st Curr,BLUESTATUS_st Prev){
     uint8_t val = 0;
     uint16_t MBIC_Val = 0;
     uint16_t MBIC_ALC_Val = 0;
     uint16_t MBIC_UserVal = 0;
#if 1 // PYJ.2020.07.01_BEGIN -- 
    if((Curr.ATT_DL1_H != Prev.ATT_DL1_H)
     ||(Curr.ATT_DL1_L != Prev.ATT_DL1_L)
     ||(Curr.bluecell_User_DL1_H != Prev.bluecell_User_DL1_H)
     ||(Curr.bluecell_User_DL1_L != Prev.bluecell_User_DL1_L)){
//         printf("%s : %d \r\n",__func__,__LINE__);   
            bluecell_Prevdatastatus.ATT_DL1_H = bluecell_Currdatastatus.ATT_DL1_H;
            bluecell_Prevdatastatus.ATT_DL1_L = bluecell_Currdatastatus.ATT_DL1_L;
            bluecell_Prevdatastatus.bluecell_User_DL1_H = bluecell_Currdatastatus.bluecell_User_DL1_H;
            bluecell_Prevdatastatus.bluecell_User_DL1_L = bluecell_Currdatastatus.bluecell_User_DL1_L;
            MBIC_Val =Curr.ATT_DL1_H << 8 | Curr.ATT_DL1_L;
            MBIC_UserVal = Curr.bluecell_User_DL1_H << 8 | Curr.bluecell_User_DL1_L;
            val = MBIC_DL_PE43711_Calc(&Att_DL1.Table_0_0_dBm, // Table Offset
                                MBIC_Val,
                               MBIC_UserVal);// User Atten Low Bit
//            printf("%s : %d \r\n",__func__,__LINE__);   
//            printf("%d val = %x \r\n",__LINE__,val);
            PE43711_atten_ctrl(ALL_ATT.ATT_DL1,val);
    }
    if((Curr.ATT_DL2_H != Prev.ATT_DL2_H)
     ||(Curr.ATT_DL2_L != Prev.ATT_DL2_L)
     ||(Curr.bluecell_User_DL2_H != Prev.bluecell_User_DL2_H)
     ||(Curr.bluecell_User_DL2_L != Prev.bluecell_User_DL2_L)){
            bluecell_Prevdatastatus.ATT_DL2_H = bluecell_Currdatastatus.ATT_DL2_H;
            bluecell_Prevdatastatus.ATT_DL2_L = bluecell_Currdatastatus.ATT_DL2_L;
            bluecell_Prevdatastatus.bluecell_User_DL2_H = bluecell_Currdatastatus.bluecell_User_DL2_H;
            bluecell_Prevdatastatus.bluecell_User_DL2_L = bluecell_Currdatastatus.bluecell_User_DL2_L;
            MBIC_Val = Curr.ATT_DL2_H << 8 | Curr.ATT_DL2_L;
            MBIC_UserVal = Curr.bluecell_User_DL2_H << 8 | Curr.bluecell_User_DL2_L;
            val = MBIC_DL_PE43711_Calc(&Att_DL2.Table_0_0_dBm,// Table Offset
                                MBIC_Val,// Hidden Atten Low bit
                               MBIC_UserVal);// User Atten Low Bit
//            printf("%d val = %x \r\n",__LINE__,val);
            PE43711_atten_ctrl(ALL_ATT.ATT_DL2,val);
    }
     
    if((Curr.ATT_DL3_H != Prev.ATT_DL3_H)
     ||(Curr.ATT_DL3_L != Prev.ATT_DL3_L)
     ||(Curr.bluecell_User_DL3_H != Prev.bluecell_User_DL3_H)
     ||(Curr.bluecell_User_DL3_L != Prev.bluecell_User_DL3_L)){

        bluecell_Prevdatastatus.ATT_DL3_H = bluecell_Currdatastatus.ATT_DL3_H;
        bluecell_Prevdatastatus.ATT_DL3_L = bluecell_Currdatastatus.ATT_DL3_L;
        bluecell_Prevdatastatus.bluecell_User_DL3_H = bluecell_Currdatastatus.bluecell_User_DL3_H;
        bluecell_Prevdatastatus.bluecell_User_DL3_L = bluecell_Currdatastatus.bluecell_User_DL3_L;
            MBIC_Val = Curr.ATT_DL3_H << 8 | Curr.ATT_DL3_L;
            MBIC_UserVal = Curr.bluecell_User_DL3_H << 8 | Curr.bluecell_User_DL3_L;
            
            val = MBIC_DL_PE43711_Calc(&Att_DL3.Table_0_0_dBm,// Table Offset
                            MBIC_Val,// Hidden Atten Low bit
                           MBIC_UserVal);// User Atten Low Bit
//        printf("%d val = %x \r\n",__LINE__,val);
        PE43711_atten_ctrl(ALL_ATT.ATT_DL3,val);
    }
//    printf("\r\nCurr.ATT_DL3_H : %x \r\nPrev.ATT_DL3_H : %x \r\n",Curr.ATT_DL3_H,Prev.ATT_DL3_H);
//     printf("\r\nCurr.ATT_DL3_L : %x \r\nPrev.ATT_DL3_L : %x \r\n",Curr.ATT_DL3_L,Prev.ATT_DL3_L);
     
    if((Curr.ATT_DL4_H != Prev.ATT_DL4_H)
     ||(Curr.ATT_DL4_L != Prev.ATT_DL4_L)
     ||(Curr.bluecell_User_DL4_H != Prev.bluecell_User_DL4_H)
     ||(Curr.bluecell_User_DL4_L != Prev.bluecell_User_DL4_L)){
     
            bluecell_Prevdatastatus.ATT_DL4_H = bluecell_Currdatastatus.ATT_DL4_H;
            bluecell_Prevdatastatus.ATT_DL4_L = bluecell_Currdatastatus.ATT_DL4_L;
            bluecell_Prevdatastatus.bluecell_User_DL4_H = bluecell_Currdatastatus.bluecell_User_DL4_H;
            bluecell_Prevdatastatus.bluecell_User_DL4_L = bluecell_Currdatastatus.bluecell_User_DL4_L;
            MBIC_Val = (Curr.ATT_DL4_H << 8 | Curr.ATT_DL4_L);
//            printf("\r\nCurr.ATT_DL4_H : %x \rCurr.ATT_DL4_L : %x \r\n",Curr.ATT_DL4_H,Curr.ATT_DL4_L);
            MBIC_UserVal = Curr.bluecell_User_DL4_H << 8 | Curr.bluecell_User_DL4_L;
//            printf("\r\nCurr.bluecell_User_DL4_H : %x \rCurr.bluecell_User_DL4_L : %x \r\n",Curr.bluecell_User_DL4_H,Curr.bluecell_User_DL4_L);
//            printf("MBIC_UserVal : %x \r\n",MBIC_UserVal); // 2
            val = MBIC_DL_PE43711_Calc(&Att_DL4.Table_0_0_dBm,// Table Offset
                                MBIC_Val,// Hidden Atten Low bit
                               MBIC_UserVal);// User Atten Low Bit
//            printf("%d val = %x \r\n",__LINE__,val);
            PE43711_atten_ctrl(ALL_ATT.ATT_DL4,val);
    }
#else
    DL_AttenOperate(&bluecell_Currdatastatus.ATT_DL1_H,&bluecell_Prevdatastatus.ATT_DL1_L,
                    &bluecell_Currdatastatus.bluecell_User_DL1_H,&bluecell_Prevdatastatus.bluecell_User_DL1_L,ALL_ATT.ATT_DL1);
    DL_AttenOperate(&bluecell_Currdatastatus.ATT_DL2_H,&bluecell_Prevdatastatus.ATT_DL2_L,
                    &bluecell_Currdatastatus.bluecell_User_DL2_H,&bluecell_Prevdatastatus.bluecell_User_DL2_L,ALL_ATT.ATT_DL2);
    DL_AttenOperate(&bluecell_Currdatastatus.ATT_DL3_H,&bluecell_Prevdatastatus.ATT_DL3_L,
                    &bluecell_Currdatastatus.bluecell_User_DL3_H,&bluecell_Prevdatastatus.bluecell_User_DL3_L,ALL_ATT.ATT_DL3);    
    DL_AttenOperate(&bluecell_Currdatastatus.ATT_DL4_H,&bluecell_Prevdatastatus.ATT_DL4_L,
                    &bluecell_Currdatastatus.bluecell_User_DL4_H,&bluecell_Prevdatastatus.bluecell_User_DL4_L,ALL_ATT.ATT_DL4);

#endif // PYJ.2020.07.01_END -- 

    if(bluecell_Prevdatastatus.bluecell_User_UL1_H != 0xFF)
        bluecell_Prevdatastatus.bluecell_User_UL1_H =0xFF;
    if(bluecell_Prevdatastatus.bluecell_User_UL2_H != 0xFF)
        bluecell_Prevdatastatus.bluecell_User_UL2_H =0xFF;
    if(bluecell_Prevdatastatus.bluecell_User_UL3_H != 0xFF)
        bluecell_Prevdatastatus.bluecell_User_UL3_H =0xFF;
    if(bluecell_Prevdatastatus.bluecell_User_UL4_H != 0xFF)
        bluecell_Prevdatastatus.bluecell_User_UL4_H =0xFF;
    
#if 1 // PYJ.2020.06.27_BEGIN -- 
    if((Curr.ATT_UL1_H != Prev.ATT_UL1_H)
     ||(Curr.ATT_UL1_L != Prev.ATT_UL1_L)
     ||(Curr.bluecell_User_UL1_H != Prev.bluecell_User_UL1_H)
     ||(Curr.bluecell_User_UL1_L != Prev.bluecell_User_UL1_L)
     ||(Curr.MBIC_ULO_ALC_Atten1_H != Prev.MBIC_ULO_ALC_Atten1_H)
     ||(Curr.MBIC_ULO_ALC_Atten1_L != Prev.MBIC_ULO_ALC_Atten1_L)){
     
            bluecell_Prevdatastatus.ATT_UL1_H = bluecell_Currdatastatus.ATT_UL1_H;
            bluecell_Prevdatastatus.ATT_UL1_L = bluecell_Currdatastatus.ATT_UL1_L;
            bluecell_Prevdatastatus.bluecell_User_UL1_H = bluecell_Currdatastatus.bluecell_User_UL1_H;
            bluecell_Prevdatastatus.bluecell_User_UL1_L = bluecell_Currdatastatus.bluecell_User_UL1_L;
            bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten1_H = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_H;
    bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten1_L = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_L;    
    
            MBIC_Val = Curr.ATT_UL1_H << 8 | Curr.ATT_UL1_L;
            MBIC_ALC_Val = Curr.MBIC_ULO_ALC_Atten1_H << 8 | Curr.MBIC_ULO_ALC_Atten1_L;
            MBIC_UserVal = Curr.bluecell_User_UL1_H << 8 | Curr.bluecell_User_UL1_L;
            val = MBIC_UL_PE43711_Calc(&Att_UL1.Table_0_0_dBm,// Table Offset
                                MBIC_Val,// Hidden Atten Low bit
                               MBIC_UserVal,
                               MBIC_ALC_Val);// User Atten Low Bit
            //("%d val = %x \r\n",__LINE__,val);
//            printf("MBIC_Val : %x \r\n",MBIC_Val);
//            printf("MBIC_ALC_Val : %x \r\n",MBIC_ALC_Val);
//            printf("MBIC_UserVal : %x \r\n",MBIC_UserVal);            
            PE43711_atten_ctrl(ALL_ATT.ATT_UL1,val);
    }
//    Atten_UL_Ctrl_Function(ATTEN_UL1,
//                            &Att_UL1.Table_0_0_dBm,
//                            &bluecell_Currdatastatus.ATT_UL1_H,
//                            &bluecell_Prevdatastatus.ATT_UL1_L,
//                            &bluecell_Currdatastatus.bluecell_User_UL1_H,
//                            &bluecell_Prevdatastatus.bluecell_User_UL1_L,
//                            &bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_H,
//                            &bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten1_L);
#endif // PYJ.2020.06.27_END -- 

    if((Curr.ATT_UL2_H != Prev.ATT_UL2_H)
     ||(Curr.ATT_UL2_L != Prev.ATT_UL2_L)
     ||(Curr.bluecell_User_UL2_H != Prev.bluecell_User_UL2_H)
     ||(Curr.bluecell_User_UL2_L != Prev.bluecell_User_UL2_L)
     ||(Curr.MBIC_ULO_ALC_Atten2_H != Prev.MBIC_ULO_ALC_Atten2_H)
     ||(Curr.MBIC_ULO_ALC_Atten2_L != Prev.MBIC_ULO_ALC_Atten2_L)){
            bluecell_Prevdatastatus.ATT_UL2_H = bluecell_Currdatastatus.ATT_UL2_H;
            bluecell_Prevdatastatus.ATT_UL2_L = bluecell_Currdatastatus.ATT_UL2_L;
            bluecell_Prevdatastatus.bluecell_User_UL2_H = bluecell_Currdatastatus.bluecell_User_UL2_H;
            bluecell_Prevdatastatus.bluecell_User_UL2_L = bluecell_Currdatastatus.bluecell_User_UL2_L;
            bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten2_H = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_H;
            bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten2_L = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_L;    
            

            MBIC_Val = Curr.ATT_UL2_H << 8 | Curr.ATT_UL2_L;
            MBIC_ALC_Val = Curr.MBIC_ULO_ALC_Atten2_H << 8 | Curr.MBIC_ULO_ALC_Atten2_L;
            MBIC_UserVal = Curr.bluecell_User_UL2_H << 8 | Curr.bluecell_User_UL2_L;
//            printf("UL 2MBIC_Val : %02X \r\n",MBIC_Val);
//            printf("UL 2MBIC_UserVal : %02X \r\n",MBIC_UserVal);
//            printf("UL 2MBIC_ALC_Val : %02X \r\n",MBIC_ALC_Val);
            val = MBIC_UL_PE43711_Calc(&Att_UL2.Table_0_0_dBm,// Table Offset
                                MBIC_Val,// Hidden Atten Low bit
                               MBIC_UserVal,
                               MBIC_ALC_Val);// User Atten Low Bit
//            printf("UL 2 LINE: %d val = %x \r\n",__LINE__,val);
            PE43711_atten_ctrl(ALL_ATT.ATT_UL2,val);
    }
     
    if((Curr.ATT_UL3_H != Prev.ATT_UL3_H)
     ||(Curr.ATT_UL3_L != Prev.ATT_UL3_L)
     ||(Curr.bluecell_User_UL3_H != Prev.bluecell_User_UL3_H)
     ||(Curr.bluecell_User_UL3_L != Prev.bluecell_User_UL3_L)
     ||(Curr.MBIC_ULO_ALC_Atten3_H != Prev.MBIC_ULO_ALC_Atten3_H)
     ||(Curr.MBIC_ULO_ALC_Atten3_L != Prev.MBIC_ULO_ALC_Atten3_L))
     {
            bluecell_Prevdatastatus.ATT_UL3_H = bluecell_Currdatastatus.ATT_UL3_H;
            bluecell_Prevdatastatus.ATT_UL3_L = bluecell_Currdatastatus.ATT_UL3_L;
            bluecell_Prevdatastatus.bluecell_User_UL3_H = bluecell_Currdatastatus.bluecell_User_UL3_H;
            bluecell_Prevdatastatus.bluecell_User_UL3_L = bluecell_Currdatastatus.bluecell_User_UL3_L;
            bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten3_H = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_H;
            bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten3_L = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_L;    
            MBIC_Val = Curr.ATT_UL3_H << 8 | Curr.ATT_UL3_L;
            MBIC_ALC_Val = Curr.MBIC_ULO_ALC_Atten3_H << 8 | Curr.MBIC_ULO_ALC_Atten3_L;
            MBIC_UserVal = Curr.bluecell_User_UL3_H << 8 | Curr.bluecell_User_UL3_L;
            val = MBIC_UL_PE43711_Calc(&Att_UL3.Table_0_0_dBm,// Table Offset
                                MBIC_Val,// Hidden Atten Low bit
                               MBIC_UserVal,
                               MBIC_ALC_Val);// User Atten Low Bit
//    printf("bluecell_Currdatastatus.ATT_UL3_H : %0x \r\n",bluecell_Currdatastatus.ATT_UL3_H);
//    printf("bluecell_Currdatastatus.ATT_UL3_L : %0x \r\n",bluecell_Currdatastatus.ATT_UL3_L);
//    printf("bluecell_Currdatastatus.bluecell_User_UL3_H : %0x \r\n",bluecell_Currdatastatus.bluecell_User_UL3_H);
//    printf("bluecell_Currdatastatus.bluecell_User_UL3_L : %0x \r\n",bluecell_Currdatastatus.bluecell_User_UL3_L);        
//        printf("%d val = %x \r\n",__LINE__,val);

            PE43711_atten_ctrl(ALL_ATT.ATT_UL3,val);
    }
    if((Curr.ATT_UL4_H != Prev.ATT_UL4_H)
     ||(Curr.ATT_UL4_L != Prev.ATT_UL4_L)
     ||(Curr.bluecell_User_UL4_H != Prev.bluecell_User_UL4_H)
     ||(Curr.bluecell_User_UL4_L != Prev.bluecell_User_UL4_L)
     ||(Curr.MBIC_ULO_ALC_Atten4_H != Prev.MBIC_ULO_ALC_Atten4_H)
     ||(Curr.MBIC_ULO_ALC_Atten4_L != Prev.MBIC_ULO_ALC_Atten4_L))
     {
//            printf("bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten4_H : %02x \r\n",bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten4_H);
//            printf("bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten4_L : %02x \r\n",bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten4_L);
//            printf("bluecell_Prevdatastatus.ATT_UL4_H : %02x \r\n",bluecell_Prevdatastatus.ATT_UL4_H);
//            printf("bluecell_Prevdatastatus.ATT_UL4_L : %02x \r\n",bluecell_Prevdatastatus.ATT_UL4_L);
//            printf("bluecell_Prevdatastatus.bluecell_User_UL4_H : %02x \r\n",bluecell_Prevdatastatus.bluecell_User_UL4_H);
//            printf("bluecell_Prevdatastatus.bluecell_User_UL4_L : %02x \r\n",bluecell_Prevdatastatus.bluecell_User_UL4_L);        
//            printf("============================================================\r\n");
//            printf("bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_H : %02x \r\n",bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_H);
//            printf("bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_L : %02x \r\n",bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_L);
//            printf("bluecell_Currdatastatus.ATT_UL4_H : %02x \r\n",bluecell_Currdatastatus.ATT_UL4_H);
//            printf("bluecell_Currdatastatus.ATT_UL4_L : %02x \r\n",bluecell_Currdatastatus.ATT_UL4_L);
//            printf("bluecell_Currdatastatus.bluecell_User_UL4_H : %02x \r\n",bluecell_Currdatastatus.bluecell_User_UL4_H);
//            printf("bluecell_Currdatastatus.bluecell_User_UL4_L : %02x \r\n",bluecell_Currdatastatus.bluecell_User_UL4_L);        
            bluecell_Prevdatastatus.ATT_UL4_H = bluecell_Currdatastatus.ATT_UL4_H;
            bluecell_Prevdatastatus.ATT_UL4_L = bluecell_Currdatastatus.ATT_UL4_L;
            bluecell_Prevdatastatus.bluecell_User_UL4_H = bluecell_Currdatastatus.bluecell_User_UL4_H;
            bluecell_Prevdatastatus.bluecell_User_UL4_L = bluecell_Currdatastatus.bluecell_User_UL4_L;
            bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten4_H = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_H;
            bluecell_Prevdatastatus.MBIC_ULO_ALC_Atten4_L = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_L;
            MBIC_Val = Curr.ATT_UL4_H << 8 | Curr.ATT_UL4_L;
            MBIC_ALC_Val = Curr.MBIC_ULO_ALC_Atten4_H << 8 | Curr.MBIC_ULO_ALC_Atten4_L;
            MBIC_UserVal = Curr.bluecell_User_UL4_H << 8 | Curr.bluecell_User_UL4_L;
//            printf("UL 4MBIC_Val : %02X \r\n",MBIC_Val);
//            printf("UL 4MBIC_UserVal : %02X \r\n",MBIC_UserVal);
//            printf("UL 4MBIC_ALC_Val : %02X \r\n",MBIC_ALC_Val);            
            val = MBIC_UL_PE43711_Calc(&Att_UL4.Table_0_0_dBm,// Table Offset
                                MBIC_Val,// Hidden Atten Low bit
                               MBIC_UserVal,
                               MBIC_ALC_Val);// User Atten Low Bit
//            printf("%d val = %x \r\n",__LINE__,val);
            PE43711_UL4_atten_ctrl(val);
    }
//    memcpy(&bluecell_Prevdatastatus.ATT_DL1_H,&bluecell_Currdatastatus.ATT_DL1_H,32);
     
}

#endif // PYJ.2020.05.25_END -- 



void Bluecell_StructCpy(uint8_t* dst,uint8_t* src,uint16_t size){
  for(int i = 0; i < size; i++){
    dst[i]  = src[i];
  }
}


int16_t ConvertTo2byte(uint8_t highbit, uint8_t lowbit){
    int16_t ret = 0;
    ret += ((highbit << 8) & 0xFF00);
    ret += (lowbit & 0x00FF);

    return ret;
}





void Bluecell_DataCopy(uint8_t* dst,uint8_t* src,uint16_t size){
//    printf("Setting Start Value\r\n");
       for(int i = 0; i < size; i++){
         dst[i] = src[i];
//         printf("%02x ",src[i]);
       }
//        printf("Setting Start Value END \r\n");

}
void MBIC_TableDataCopy(uint8_t* dst,uint8_t* src,uint16_t size){
    dst[MBIC_TableIndex_Unit_Type] = UNIT_TYPE_MBIC;
    dst[MBIC_TableIndex_Reseved] = 0;
    dst[MBIC_TableIndex_Number] = dst[MBIC_TableIndex_Number];
//    printf("\r\dst[MBIC_TableIndex_Number] : %d \r\n",dst[MBIC_TableIndex_Number]);   
    dst[MBIC_TableIndex_Ref] = UNIT_TYPE_MBIC;    // Check
    

//    Att_DL1.Table_Length  = ATTENTABLEDLUL_LENGTH;
//    Att_DL2.Table_Length  = ATTENTABLEDLUL_LENGTH;
//    Att_DL3.Table_Length  = ATTENTABLEDLUL_LENGTH;
//    Att_DL4.Table_Length  = ATTENTABLEDLUL_LENGTH;
//    Att_UL1.Table_Length  = ATTENTABLEDLUL_LENGTH;
//    Att_UL2.Table_Length  = ATTENTABLEDLUL_LENGTH;
//    Att_UL3.Table_Length  = ATTENTABLEDLUL_LENGTH;
//    Att_UL4.Table_Length  = ATTENTABLEDLUL_LENGTH;
//    Det_DL1.Table_Length  = ATTENTABLEDET_DL_LENGTH;
//    Det_DL2.Table_Length  = ATTENTABLEDET_DL_LENGTH;
//    Det_DL3.Table_Length  = ATTENTABLEDET_DL_LENGTH;
//    Det_DL4.Table_Length  = ATTENTABLEDET_DL_LENGTH;
//    Det_UL1.Table_Length  = ATTENTABLEDET_UL_LENGTH;
//    Det_UL2.Table_Length  = ATTENTABLEDET_UL_LENGTH;
//    Det_UL3.Table_Length  = ATTENTABLEDET_UL_LENGTH;
//    Det_UL4.Table_Length  = ATTENTABLEDET_UL_LENGTH;
//    Temp_DL1.Table_Length = ATTENTABLE_TEMP_LENGTH;
//    Temp_DL2.Table_Length = ATTENTABLE_TEMP_LENGTH;
//    Temp_DL3.Table_Length = ATTENTABLE_TEMP_LENGTH;
//    Temp_DL4.Table_Length = ATTENTABLE_TEMP_LENGTH;
//    Temp_UL1.Table_Length = ATTENTABLE_TEMP_LENGTH;
//    Temp_UL2.Table_Length = ATTENTABLE_TEMP_LENGTH;
//    Temp_UL3.Table_Length = ATTENTABLE_TEMP_LENGTH;
//    Temp_UL4.Table_Length = ATTENTABLE_TEMP_LENGTH;  
    
    if(dst[MBIC_TableIndex_Number] >= DLI_P1_ATT_Accuracy_Table_Number
     &&dst[MBIC_TableIndex_Number] <= ULO_P4_ATT_Accuracy_Table_Number ){
        dst[MBIC_TableIndex_Length] = size;   //
     }
     else{
         dst[MBIC_TableIndex_Length] = size / 2;   //
     }


    for(int i = 0; i < size; i++){
      dst[i + MBIC_TableIndex_Max] = src[i];
//      printf("SRC : %x \r\n",src[i]);
    }
 

}
void MBIC_TableHeaderCopy(uint8_t* src,uint16_t size){
    src[MBIC_TableIndex_Unit_Type] = UNIT_TYPE_MBIC;
    src[MBIC_TableIndex_Reseved] = 0;
    src[MBIC_TableIndex_Number] = src[MBIC_PAYLOADSTART + 2];
    
    if(src[MBIC_TableIndex_Number] >= DLI_P1_ATT_Accuracy_Table_Number
     &&src[MBIC_TableIndex_Number] <= ULO_P4_ATT_Accuracy_Table_Number ){
        src[MBIC_TableIndex_Length] = size;   //
     }
     else{
         src[MBIC_TableIndex_Length] = size / 2;   //
     }
}


void Bluecell_TableLoad(uint8_t* data,uint8_t type){
    uint8_t tabletype = type;
//    OneByteToTwoByte data;
//    printf("%s : %x \r\n",__func__,tabletype);
//INDEX :5 COpy Start
    switch(tabletype){
        case DLI_P1_ATT_Accuracy_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,EEPROM_ATT_BASE              ,&Att_DL1.Table_0_0_dBm,sizeof(ATT_TABLE_st) );
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Att_DL1.Table_0_0_dBm,sizeof(ATT_TABLE_st));
//            printf("Table_Length : %d , Table_Ref : %d ",Att_DL1.Table_Length,Att_DL1.Table_Ref);
//            Bluecell_structprintf(&Att_DL1.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            data[BLUECELL_LENGTH_H] = 0;
            data[BLUECELL_LENGTH_L] = (sizeof(ATT_TABLE_st)) + 7 - 3;;
          break;
        case DLI_P2_ATT_Accuracy_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_DL1_TABLE_ADDRESDS),&Att_DL2.Table_0_0_dBm,sizeof(ATT_TABLE_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Att_DL2.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            data[BLUECELL_LENGTH_L] = (sizeof(ATT_TABLE_st)) + 7 - 3;
            break;
        case DLI_P3_ATT_Accuracy_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_DL2_TABLE_ADDRESDS),&Att_DL3.Table_0_0_dBm,sizeof(ATT_TABLE_st) );               
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Att_DL3.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            data[BLUECELL_LENGTH_L] = (sizeof(ATT_TABLE_st)) + 7 - 3;
            break;
        case DLI_P4_ATT_Accuracy_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_DL3_TABLE_ADDRESDS),&Att_DL4.Table_0_0_dBm,sizeof(ATT_TABLE_st) );               
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Att_DL4.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            data[BLUECELL_LENGTH_L] = (sizeof(ATT_TABLE_st)) + 7 - 3;
            break;
        case ULO_P1_ATT_Accuracy_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_DL4_TABLE_ADDRESDS),&Att_UL1.Table_0_0_dBm,sizeof(ATT_TABLE_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Att_UL1.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            data[BLUECELL_LENGTH_L] = (sizeof(ATT_TABLE_st)) + 7 - 3;
        break;
        case ULO_P2_ATT_Accuracy_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_UL1_TABLE_ADDRESDS),&Att_UL2.Table_0_0_dBm,sizeof(ATT_TABLE_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Att_UL2.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            data[BLUECELL_LENGTH_L] = (sizeof(ATT_TABLE_st)) + 7 - 3;
            break;
        case ULO_P3_ATT_Accuracy_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_UL2_TABLE_ADDRESDS),&Att_UL3.Table_0_0_dBm,sizeof(ATT_TABLE_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Att_UL3.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            data[BLUECELL_LENGTH_L] = (sizeof(ATT_TABLE_st)) + 7 - 3;
            break;
        case ULO_P4_ATT_Accuracy_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_UL3_TABLE_ADDRESDS),&Att_UL4.Table_0_0_dBm,sizeof(ATT_TABLE_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Att_UL4.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            data[BLUECELL_LENGTH_L] = (sizeof(ATT_TABLE_st)) + 7 - 3;
            break;
        case DLI_P1_Level_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_UL4_TABLE_ADDRESDS),&Det_DL1.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Det_DL1.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));
//            printf("Table_Length : %d , Table_Ref : %d ",Det_DL1.Table_Length,Det_DL1.Table_Ref);
            data[BLUECELL_LENGTH_L] = (sizeof(DET_TABLEDL_st)) + 7 - 3;
            break;
        case DLI_P2_Level_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_DL1_TABLE_ADDRESDS),&Det_DL2.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Det_DL2.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));
//            for(int i = 0 ; i < sizeof(DET_TABLEDL_st);i++)
//                printf("[%d Dbm] : %f \r\n",UL_DET_Table_ref[i],((data[BLUECELL_DATA + 1 + (i * 2)] << 8)| data[BLUECELL_DATA + 1 + (i * 2)+ 1]) * 0.001 );
        
            data[BLUECELL_LENGTH_L] = (sizeof(DET_TABLEDL_st)) + 7 - 3;
            break;
        case DLI_P3_Level_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_DL2_TABLE_ADDRESDS),&Det_DL3.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Det_DL3.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));
            data[BLUECELL_LENGTH_L] = (sizeof(DET_TABLEDL_st)) + 7 - 3;
            break;
        case DLI_P4_Level_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_DL3_TABLE_ADDRESDS),&Det_DL4.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Det_DL4.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));
            data[BLUECELL_LENGTH_L] = (sizeof(DET_TABLEDL_st)) + 7 - 3;
            break;
        case ULO_P1_Level_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_DL4_TABLE_ADDRESDS),&Det_UL1.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Det_UL1.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));
//            for(int i = 0 ; i < sizeof(DET_TABLEUL_st);i++)
//                printf("[%d Dbm] : %f \r\n",UL_DET_Table_ref[i],((data[BLUECELL_DATA + 1 + (i * 2)] << 8)| data[BLUECELL_DATA + 1 + (i * 2)+ 1]) * 0.001 );
            data[BLUECELL_LENGTH_L] = (sizeof(DET_TABLEUL_st)) + 7 - 3;
            break;
        case ULO_P2_Level_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_UL1_TABLE_ADDRESDS),&Det_UL2.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Det_UL2.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));
//            for(int i = 0 ; i < sizeof(DET_TABLEUL_st);i++)
//                printf("[%d Dbm] : %f \r\n",UL_DET_Table_ref[i],((data[BLUECELL_DATA + 1 + (i * 2)] << 8)| data[BLUECELL_DATA + 1 + (i * 2)+ 1]) * 0.001 );
        
            data[BLUECELL_LENGTH_L] = (sizeof(DET_TABLEUL_st)) + 7 - 3;
        
            break;
        case ULO_P3_Level_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_UL2_TABLE_ADDRESDS),&Det_UL3.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Det_UL3.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));
//            for(int i = 0 ; i < sizeof(DET_TABLEUL_st);i++)
//                printf("[%d Dbm] : %f \r\n",UL_DET_Table_ref[i],((data[BLUECELL_DATA + 1 + (i * 2)] << 8)| data[BLUECELL_DATA + 1 + (i * 2)+ 1]) * 0.001 );
        
            data[BLUECELL_LENGTH_L] = (sizeof(DET_TABLEUL_st)) + 7 - 3;
            break;
        case ULO_P4_Level_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_UL3_TABLE_ADDRESDS),&Det_UL4.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Det_UL4.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));
//            for(int i = 0 ; i < sizeof(DET_TABLEUL_st);i++)
//                printf("[%d Dbm] : %f \r\n",UL_DET_Table_ref[i],((data[BLUECELL_DATA + 1 + (i * 2)] << 8)| data[BLUECELL_DATA + 1 + (i * 2)+ 1]) * 0.001 );
        
            data[BLUECELL_LENGTH_L] = (sizeof(DET_TABLEUL_st)) + 7 - 3;

            break;
        case DLI_P1_ATT_Temp_guarantee_Table_Number:
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_UL4_TABLE_ADDRESDS),&Temp_DL1.Table_1_Temp,sizeof(TEMP_TABLE_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Temp_DL1.Table_1_Temp,sizeof(TEMP_TABLE_st));
            data[BLUECELL_LENGTH_L] = (sizeof(TEMP_TABLE_st)) + 7 - 3;
//            printf("Table_Length : %d , Table_Ref : %d ",Temp_DL1.Table_Length,Temp_DL1.Table_Ref);            
            break;
        case DLI_P2_ATT_Temp_guarantee_Table_Number:
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL1_TABLE_ADDRESDS),&Temp_DL2.Table_1_Temp,sizeof(TEMP_TABLE_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Temp_DL2.Table_1_Temp,sizeof(TEMP_TABLE_st));
            data[BLUECELL_LENGTH_L] = (sizeof(TEMP_TABLE_st)) + 7 - 3;

            break;
        case DLI_P3_ATT_Temp_guarantee_Table_Number:
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL2_TABLE_ADDRESDS),&Temp_DL3.Table_1_Temp,sizeof(TEMP_TABLE_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Temp_DL3.Table_1_Temp,sizeof(TEMP_TABLE_st));
            data[BLUECELL_LENGTH_L] = (sizeof(TEMP_TABLE_st)) + 7 - 3;

            break;
        case DLI_P4_ATT_Temp_guarantee_Table_Number:
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL3_TABLE_ADDRESDS),&Temp_DL4.Table_1_Temp,sizeof(TEMP_TABLE_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Temp_DL4.Table_1_Temp,sizeof(TEMP_TABLE_st));
        data[BLUECELL_LENGTH_L] = (sizeof(TEMP_TABLE_st)) + 7 - 3;

        break;
        case ULO_P1_ATT_Temp_guarantee_Table_Number:
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL4_TABLE_ADDRESDS),&Temp_UL1.Table_1_Temp,sizeof(TEMP_TABLE_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Temp_UL1.Table_1_Temp,sizeof(TEMP_TABLE_st));
            data[BLUECELL_LENGTH_L] = (sizeof(TEMP_TABLE_st)) + 7 - 3;
//            printf("Table_Length : %d , Table_Ref : %d ",Temp_UL1.Table_Length,Temp_UL1.Table_Ref);
        
            break;
        case ULO_P2_ATT_Temp_guarantee_Table_Number:
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_UL1_TABLE_ADDRESDS),&Temp_UL2.Table_1_Temp,sizeof(TEMP_TABLE_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Temp_UL2.Table_1_Temp,sizeof(TEMP_TABLE_st));
            data[BLUECELL_LENGTH_L] = (sizeof(TEMP_TABLE_st)) + 7 - 3;
        
            break;
        case ULO_P3_ATT_Temp_guarantee_Table_Number:
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_UL2_TABLE_ADDRESDS),&Temp_UL3.Table_1_Temp,sizeof(TEMP_TABLE_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Temp_UL3.Table_1_Temp,sizeof(TEMP_TABLE_st));
            data[BLUECELL_LENGTH_L] = (sizeof(TEMP_TABLE_st)) + 7 - 3;
        
            break;
        case ULO_P4_ATT_Temp_guarantee_Table_Number:
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_UL3_TABLE_ADDRESDS),&Temp_UL4.Table_1_Temp,sizeof(TEMP_TABLE_st) );   
            Bluecell_DataCopy(&data[BLUECELL_DATA + 1],&Temp_UL4.Table_1_Temp,sizeof(TEMP_TABLE_st));
            data[BLUECELL_LENGTH_L] = (sizeof(TEMP_TABLE_st)) + 7 - 3;
            break;
    }
        
    
}

void Bluecell_TableSave(uint8_t* data,uint8_t type){
    uint8_t tabletype = type;
    //printf("%s : %x \r\n",__func__,tabletype);
    switch(tabletype){
        case DLI_P1_ATT_Accuracy_Table_Number: 
            Bluecell_DataCopy(&Att_DL1.Table_0_0_dBm,&data[BLUECELL_DATA + 1],sizeof(ATT_TABLE_st));
            Att_DL1.Table_Ref = ATTENTABLEDL_REF;
            Att_DL1.Table_Length = ATTENTABLEDLUL_LENGTH;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_BASE)              ,&Att_DL1.Table_0_0_dBm,sizeof(ATT_TABLE_st) );
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_BASE)              ,&Att_DL1.Table_0_0_dBm,sizeof(ATT_TABLE_st) );
//            printf("Function : %s Line %d \r\n",__func__,__LINE__);
            break;
        case DLI_P2_ATT_Accuracy_Table_Number: //printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Att_DL2.Table_0_0_dBm,&data[BLUECELL_DATA + 1],sizeof(ATT_TABLE_st));
            Att_DL2.Table_Ref = ATTENTABLEDL_REF;
            Att_DL2.Table_Length = ATTENTABLEDLUL_LENGTH;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_DL1_TABLE_ADDRESDS),&Att_DL2.Table_0_0_dBm,sizeof(ATT_TABLE_st) );
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_DL1_TABLE_ADDRESDS),&Att_DL2.Table_0_0_dBm,sizeof(ATT_TABLE_st) );

//            printf("ADDRESS : %d \r\n",EEPROM_ATT_DL1_TABLE_ADDRESDS );
            break;
        case DLI_P3_ATT_Accuracy_Table_Number: //printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Att_DL3.Table_0_0_dBm,&data[BLUECELL_DATA + 1],sizeof(ATT_TABLE_st));
            Att_DL3.Table_Ref = ATTENTABLEDL_REF;
            Att_DL3.Table_Length = ATTENTABLEDLUL_LENGTH;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_DL2_TABLE_ADDRESDS),&Att_DL3.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_DL2_TABLE_ADDRESDS),&Att_DL3.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            break;
        case DLI_P4_ATT_Accuracy_Table_Number: //printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Att_DL4.Table_0_0_dBm,&data[BLUECELL_DATA + 1],sizeof(ATT_TABLE_st));
            Att_DL4.Table_Ref = ATTENTABLEDL_REF;
            Att_DL4.Table_Length = ATTENTABLEDLUL_LENGTH;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_DL3_TABLE_ADDRESDS),&Att_DL4.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_DL3_TABLE_ADDRESDS),&Att_DL4.Table_0_0_dBm,sizeof(ATT_TABLE_st));        
            break;
        case ULO_P1_ATT_Accuracy_Table_Number: //printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Att_UL1.Table_0_0_dBm,&data[BLUECELL_DATA + 1],sizeof(ATT_TABLE_st));
            Att_UL1.Table_Length = ATTENTABLEDLUL_LENGTH;
            Att_UL1.Table_Ref = ATTENTABLEUL_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_DL4_TABLE_ADDRESDS),&Att_UL1.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_DL4_TABLE_ADDRESDS),&Att_UL1.Table_0_0_dBm,sizeof(ATT_TABLE_st));        
            break;
        case ULO_P2_ATT_Accuracy_Table_Number: //printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Att_UL2.Table_0_0_dBm,&data[BLUECELL_DATA + 1],sizeof(ATT_TABLE_st));
            Att_UL2.Table_Length = ATTENTABLEDLUL_LENGTH;
            Att_UL2.Table_Ref = ATTENTABLEUL_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_UL1_TABLE_ADDRESDS),&Att_UL2.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_UL1_TABLE_ADDRESDS),&Att_UL2.Table_0_0_dBm,sizeof(ATT_TABLE_st));        
            break;
        case ULO_P3_ATT_Accuracy_Table_Number: //printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Att_UL3.Table_0_0_dBm,&data[BLUECELL_DATA + 1],sizeof(ATT_TABLE_st));
            Att_UL3.Table_Length = ATTENTABLEDLUL_LENGTH;
            Att_UL3.Table_Ref = ATTENTABLEUL_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_UL2_TABLE_ADDRESDS),&Att_UL3.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_UL2_TABLE_ADDRESDS),&Att_UL3.Table_0_0_dBm,sizeof(ATT_TABLE_st));        
            break;
        case ULO_P4_ATT_Accuracy_Table_Number: //printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Att_UL4.Table_0_0_dBm,&data[BLUECELL_DATA + 1],sizeof(ATT_TABLE_st));
            Att_UL4.Table_Length = ATTENTABLEDLUL_LENGTH;
            Att_UL4.Table_Ref = ATTENTABLEUL_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_UL3_TABLE_ADDRESDS),&Att_UL4.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_UL3_TABLE_ADDRESDS),&Att_UL4.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            break;
        case DLI_P1_Level_Table_Number: //printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Det_DL1.Table_Det5_dBm_H,&data[BLUECELL_DATA + 1],sizeof(DET_TABLEDL_st));
            Det_DL1.Table_Length = ATTENTABLEDET_DL_LENGTH;
            Det_DL1.Table_Ref = ATTENTABLEDET_DL_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_UL4_TABLE_ADDRESDS),&Det_DL1.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_UL4_TABLE_ADDRESDS),&Det_DL1.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));        
            break;
        case DLI_P2_Level_Table_Number: //printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Det_DL2.Table_Det5_dBm_H,&data[BLUECELL_DATA + 1],sizeof(DET_TABLEDL_st));
            Det_DL2.Table_Length = ATTENTABLEDET_DL_LENGTH;
            Det_DL2.Table_Ref = ATTENTABLEDET_DL_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_DET_DL1_TABLE_ADDRESDS),&Det_DL2.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_DL1_TABLE_ADDRESDS),&Det_DL2.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));        
            break;
        case DLI_P3_Level_Table_Number: //printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Det_DL3.Table_Det5_dBm_H,&data[BLUECELL_DATA + 1],sizeof(DET_TABLEDL_st));
            Det_DL3.Table_Length = ATTENTABLEDET_DL_LENGTH;
            Det_DL3.Table_Ref = ATTENTABLEDET_DL_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_DET_DL2_TABLE_ADDRESDS),&Det_DL3.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_DL2_TABLE_ADDRESDS),&Det_DL3.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));        
            break;
        case DLI_P4_Level_Table_Number://printf("Function : %s Line %d \r\n",__func__,__LINE__); 
            Bluecell_DataCopy(&Det_DL4.Table_Det5_dBm_H,&data[BLUECELL_DATA + 1],sizeof(DET_TABLEDL_st));
            Det_DL4.Table_Length = ATTENTABLEDET_DL_LENGTH;
            Det_DL4.Table_Ref = ATTENTABLEDET_DL_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_DET_DL3_TABLE_ADDRESDS),&Det_DL4.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_DL3_TABLE_ADDRESDS),&Det_DL4.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));        
            break;
        case ULO_P1_Level_Table_Number: //printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Det_UL1.Table_Det_15_dBm_H,&data[BLUECELL_DATA + 1],sizeof(DET_TABLEUL_st));
            Det_UL1.Table_Length = ATTENTABLEDET_UL_LENGTH;
            Det_UL1.Table_Ref = ATTENTABLEDET_UL_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_DET_DL4_TABLE_ADDRESDS),&Det_UL1.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));            
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_DL4_TABLE_ADDRESDS),&Det_UL1.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));            
            break;
        case ULO_P2_Level_Table_Number: //printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Det_UL2.Table_Det_15_dBm_H,&data[BLUECELL_DATA + 1],sizeof(DET_TABLEUL_st));
            Det_UL2.Table_Length = ATTENTABLEDET_UL_LENGTH;
            Det_UL2.Table_Ref = ATTENTABLEDET_UL_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_DET_UL1_TABLE_ADDRESDS),&Det_UL2.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));            
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_UL1_TABLE_ADDRESDS),&Det_UL2.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));                    
        break;
        case ULO_P3_Level_Table_Number: //printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Det_UL3.Table_Det_15_dBm_H,&data[BLUECELL_DATA + 1],sizeof(DET_TABLEUL_st));
            Det_UL3.Table_Length = ATTENTABLEDET_UL_LENGTH;
            Det_UL3.Table_Ref = ATTENTABLEDET_UL_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_DET_UL2_TABLE_ADDRESDS),&Det_UL3.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));            
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_UL2_TABLE_ADDRESDS),&Det_UL3.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));                    
            break;
        case ULO_P4_Level_Table_Number: //printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Det_UL4.Table_Det_15_dBm_H,&data[BLUECELL_DATA + 1],sizeof(DET_TABLEUL_st));
            Det_UL4.Table_Length = ATTENTABLEDET_UL_LENGTH;
            Det_UL4.Table_Ref = ATTENTABLEDET_UL_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_DET_UL3_TABLE_ADDRESDS),&Det_UL4.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));            
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_UL3_TABLE_ADDRESDS),&Det_UL4.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));                    
            break;
        case DLI_P1_ATT_Temp_guarantee_Table_Number://printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Temp_DL1.Table_1_Temp,&data[BLUECELL_DATA + 1],sizeof(TEMP_TABLE_st));
            Temp_DL1.Table_Length= ATTENTABLE_TEMP_LENGTH;
            Temp_DL1.Table_Ref= ATTENTABLE_TEMP_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_DET_UL4_TABLE_ADDRESDS),&Temp_DL1.Table_1_Temp,sizeof(TEMP_TABLE_st));                    
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_UL4_TABLE_ADDRESDS),&Temp_DL1.Table_1_Temp,sizeof(TEMP_TABLE_st));                            
            break;
        case DLI_P2_ATT_Temp_guarantee_Table_Number://printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Temp_DL2.Table_1_Temp,&data[BLUECELL_DATA + 1],sizeof(TEMP_TABLE_st));
            Temp_DL2.Table_Length= ATTENTABLE_TEMP_LENGTH;
            Temp_DL2.Table_Ref= ATTENTABLE_TEMP_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL1_TABLE_ADDRESDS),&Temp_DL2.Table_1_Temp,sizeof(TEMP_TABLE_st));                    
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL1_TABLE_ADDRESDS),&Temp_DL2.Table_1_Temp,sizeof(TEMP_TABLE_st));                            
            break;
        case DLI_P3_ATT_Temp_guarantee_Table_Number://printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Temp_DL3.Table_1_Temp,&data[BLUECELL_DATA + 1],sizeof(TEMP_TABLE_st));
            Temp_DL3.Table_Length= ATTENTABLE_TEMP_LENGTH;
            Temp_DL3.Table_Ref= ATTENTABLE_TEMP_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL2_TABLE_ADDRESDS),&Temp_DL3.Table_1_Temp,sizeof(TEMP_TABLE_st));                    
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL2_TABLE_ADDRESDS),&Temp_DL3.Table_1_Temp,sizeof(TEMP_TABLE_st));                            
            break;
        case DLI_P4_ATT_Temp_guarantee_Table_Number://printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Temp_DL4.Table_1_Temp,&data[BLUECELL_DATA + 1],sizeof(TEMP_TABLE_st));
            Temp_DL4.Table_Length= ATTENTABLE_TEMP_LENGTH;
            Temp_DL4.Table_Ref= ATTENTABLE_TEMP_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL3_TABLE_ADDRESDS),&Temp_DL4.Table_1_Temp,sizeof(TEMP_TABLE_st));                    
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL3_TABLE_ADDRESDS),&Temp_DL4.Table_1_Temp,sizeof(TEMP_TABLE_st));                            
            break;
        case ULO_P1_ATT_Temp_guarantee_Table_Number://printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Temp_UL1.Table_1_Temp,&data[BLUECELL_DATA + 1],sizeof(TEMP_TABLE_st));
            Temp_UL1.Table_Length= ATTENTABLE_TEMP_LENGTH;
            Temp_UL1.Table_Ref= ATTENTABLE_TEMP_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL4_TABLE_ADDRESDS),&Temp_UL1.Table_1_Temp,sizeof(TEMP_TABLE_st));                            
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL4_TABLE_ADDRESDS),&Temp_UL1.Table_1_Temp,sizeof(TEMP_TABLE_st));                                    
            break;
        case ULO_P2_ATT_Temp_guarantee_Table_Number:
            Bluecell_DataCopy(&Temp_UL2.Table_1_Temp,&data[BLUECELL_DATA + 1],sizeof(TEMP_TABLE_st));
            Temp_UL2.Table_Length= ATTENTABLE_TEMP_LENGTH;
            Temp_UL2.Table_Ref= ATTENTABLE_TEMP_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_TEMP_UL1_TABLE_ADDRESDS),&Temp_UL2.Table_1_Temp,sizeof(TEMP_TABLE_st));                            
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_UL1_TABLE_ADDRESDS),&Temp_UL2.Table_1_Temp,sizeof(TEMP_TABLE_st));                                    
            break;
        case ULO_P3_ATT_Temp_guarantee_Table_Number://printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Temp_UL3.Table_1_Temp,&data[BLUECELL_DATA + 1],sizeof(TEMP_TABLE_st));
            Temp_UL3.Table_Length= ATTENTABLE_TEMP_LENGTH;
            Temp_UL3.Table_Ref= ATTENTABLE_TEMP_REF;
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_TEMP_UL2_TABLE_ADDRESDS),&Temp_UL3.Table_1_Temp,sizeof(TEMP_TABLE_st));                            
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_UL2_TABLE_ADDRESDS),&Temp_UL3.Table_1_Temp,sizeof(TEMP_TABLE_st));                                    
            break;
        case ULO_P4_ATT_Temp_guarantee_Table_Number://printf("Function : %s Line %d \r\n",__func__,__LINE__);
            Bluecell_DataCopy(&Temp_UL4.Table_1_Temp,&data[BLUECELL_DATA + 1],sizeof(TEMP_TABLE_st));
            Temp_UL4.Table_Length= ATTENTABLE_TEMP_LENGTH;
            Temp_UL4.Table_Ref= ATTENTABLE_TEMP_REF;
            EEPROM_M24C08_write((uint8_t)EEPROM_M24C08_ID ,(EEPROM_TEMP_UL3_TABLE_ADDRESDS),&Temp_UL4.Table_1_Temp,sizeof(TEMP_TABLE_st));                                
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_UL3_TABLE_ADDRESDS),&Temp_UL4.Table_1_Temp,sizeof(TEMP_TABLE_st));                                        
            break;
    }
    
}

//uint8_t tableTest[sizeof(DET_TABLEDL_st)] ={0,};
void MBIC_TableLoad(uint8_t* data,uint8_t type){
    uint8_t tabletype = type;
//    OneByteToTwoByte data;
//    printf("%s : %x \r\n",__func__,tabletype);
//INDEX :5 COpy Start
    data[MBIC_CMD_0] = 0xC0;
    if( data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] > 70)
         data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = 70;
//    printf("\r\ntabletype : %d \r\n",tabletype);
    switch(tabletype){
        case DLI_P1_ATT_Accuracy_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,EEPROM_ATT_BASE              ,&Att_DL1.Table_0_0_dBm,sizeof(ATT_TABLE_st) );
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Att_DL1.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Att_DL1.Table_Ref; 
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Att_DL1.Table_Length;
          break;
        case DLI_P2_ATT_Accuracy_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_DL1_TABLE_ADDRESDS),&Att_DL2.Table_0_0_dBm,sizeof(ATT_TABLE_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Att_DL2.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Att_DL2.Table_Ref; 
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Att_DL2.Table_Length;
            break;
        case DLI_P3_ATT_Accuracy_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_DL2_TABLE_ADDRESDS),&Att_DL3.Table_0_0_dBm,sizeof(ATT_TABLE_st) );               
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Att_DL3.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Att_DL3.Table_Ref;
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Att_DL3.Table_Length;        
            break;
        case DLI_P4_ATT_Accuracy_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_DL3_TABLE_ADDRESDS),&Att_DL4.Table_0_0_dBm,sizeof(ATT_TABLE_st) );               
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Att_DL4.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Att_DL4.Table_Ref;
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Att_DL4.Table_Length;        
            break;
        case ULO_P1_ATT_Accuracy_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_DL4_TABLE_ADDRESDS),&Att_UL1.Table_0_0_dBm,sizeof(ATT_TABLE_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Att_UL1.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Att_UL1.Table_Ref;
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Att_UL1.Table_Length;

        break;
        case ULO_P2_ATT_Accuracy_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_UL1_TABLE_ADDRESDS),&Att_UL2.Table_0_0_dBm,sizeof(ATT_TABLE_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Att_UL2.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Att_UL2.Table_Ref;
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Att_UL2.Table_Length;

            break;
        case ULO_P3_ATT_Accuracy_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_UL2_TABLE_ADDRESDS),&Att_UL3.Table_0_0_dBm,sizeof(ATT_TABLE_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Att_UL3.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Att_UL3.Table_Ref;
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Att_UL3.Table_Length;

            break;
        case ULO_P4_ATT_Accuracy_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_UL3_TABLE_ADDRESDS),&Att_UL4.Table_0_0_dBm,sizeof(ATT_TABLE_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Att_UL4.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Att_UL4.Table_Ref;
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Att_UL4.Table_Length;

            break;
        case DLI_P1_Level_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_UL4_TABLE_ADDRESDS),&Det_DL1.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Det_DL1.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Det_DL1.Table_Ref;        
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Det_DL1.Table_Length;
        break;
        case DLI_P2_Level_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_DL1_TABLE_ADDRESDS),&Det_DL2.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Det_DL2.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Det_DL2.Table_Ref;
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Det_DL2.Table_Length;        
            break;
        case DLI_P3_Level_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_DL2_TABLE_ADDRESDS),&Det_DL3.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Det_DL3.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Det_DL3.Table_Ref;
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Det_DL3.Table_Length;        

            break;
        case DLI_P4_Level_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_DL3_TABLE_ADDRESDS),&Det_DL4.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Det_DL4.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Det_DL4.Table_Ref;
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Det_DL4.Table_Length;        

            break;
        case ULO_P1_Level_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_DL4_TABLE_ADDRESDS),&Det_UL1.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Det_UL1.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Det_UL1.Table_Ref;
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Det_UL1.Table_Length;

            break;
        case ULO_P2_Level_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_UL1_TABLE_ADDRESDS),&Det_UL2.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Det_UL2.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Det_UL2.Table_Ref;
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Det_UL2.Table_Length;
//            printf("Det_UL2.Table_Length : %d \r\n",Det_UL2.Table_Length);

        
            break;
        case ULO_P3_Level_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_UL2_TABLE_ADDRESDS),&Det_UL3.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Det_UL3.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Det_UL3.Table_Ref;
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Det_UL3.Table_Length;

            break;
        case ULO_P4_Level_Table_Number: 
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_UL3_TABLE_ADDRESDS),&Det_UL4.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Det_UL4.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Det_UL4.Table_Ref;
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Det_UL4.Table_Length;


            break;
        case DLI_P1_ATT_Temp_guarantee_Table_Number:
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_DET_UL4_TABLE_ADDRESDS),&Temp_DL1.Table_1_Temp,sizeof(TEMP_TABLE_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Temp_DL1.Table_1_Temp,sizeof(TEMP_TABLE_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Temp_DL1.Table_Ref;        
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Temp_DL1.Table_Length;
            break;
        case DLI_P2_ATT_Temp_guarantee_Table_Number:
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Temp_DL2.Table_1_Temp,sizeof(TEMP_TABLE_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Temp_DL2.Table_Ref;        
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Temp_DL2.Table_Length;        
            break;
        case DLI_P3_ATT_Temp_guarantee_Table_Number:
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Temp_DL3.Table_1_Temp,sizeof(TEMP_TABLE_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Temp_DL3.Table_Ref;        
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Temp_DL3.Table_Length;        
            break;
        case DLI_P4_ATT_Temp_guarantee_Table_Number:
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL3_TABLE_ADDRESDS),&Temp_DL4.Table_1_Temp,sizeof(TEMP_TABLE_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Temp_DL4.Table_1_Temp,sizeof(TEMP_TABLE_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Temp_DL4.Table_Ref;        
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Temp_DL4.Table_Length;        
            break;
        case ULO_P1_ATT_Temp_guarantee_Table_Number:
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL4_TABLE_ADDRESDS),&Temp_UL1.Table_1_Temp,sizeof(TEMP_TABLE_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Temp_UL1.Table_1_Temp,sizeof(TEMP_TABLE_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Temp_UL1.Table_Ref;        
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Temp_UL1.Table_Length;        
            break;
        case ULO_P2_ATT_Temp_guarantee_Table_Number:
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_UL1_TABLE_ADDRESDS),&Temp_UL2.Table_1_Temp,sizeof(TEMP_TABLE_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Temp_UL2.Table_1_Temp,sizeof(TEMP_TABLE_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Temp_UL2.Table_Ref;        
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Temp_UL2.Table_Length;                
            break;
        case ULO_P3_ATT_Temp_guarantee_Table_Number:
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_UL2_TABLE_ADDRESDS),&Temp_UL3.Table_1_Temp,sizeof(TEMP_TABLE_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Temp_UL3.Table_1_Temp,sizeof(TEMP_TABLE_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Temp_UL3.Table_Ref;        
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Temp_UL3.Table_Length;                
            break;
        case ULO_P4_ATT_Temp_guarantee_Table_Number:
            EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_TEMP_UL3_TABLE_ADDRESDS),&Temp_UL4.Table_1_Temp,sizeof(TEMP_TABLE_st) );   
            MBIC_TableDataCopy(&data[MBIC_PAYLOADSTART],&Temp_UL4.Table_1_Temp,sizeof(TEMP_TABLE_st));
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref] = Temp_UL4.Table_Ref;        
            data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = Temp_UL4.Table_Length;                
            break;
    }
    
//     printf("\rLoad MBIC_TableIndex_Number : %x \r\n",data[MBIC_PAYLOADSTART + MBIC_TableIndex_Number]);
    
}


void MBIC_TableSave(uint8_t* data,uint8_t type){
    uint8_t tabletype = type;
    
    //printf("%s : %x \r\n",__func__,tabletype);
    if( data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] > 70)
         data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] = 70;
//    printf("data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length]  : %d \r\n",sizeof(ATT_TABLE_st)  );
    data[MBIC_CMD_0] = 0xC1;
    switch(tabletype){
        case DLI_P1_ATT_Accuracy_Table_Number: 
            Bluecell_DataCopy(&Att_DL1.Table_0_0_dBm,&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st) );
            Att_DL1.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];    // Check
            Att_DL1.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];            
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_BASE)              ,&Att_DL1.Table_0_0_dBm,sizeof(ATT_TABLE_st) );
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   
            break;
        case DLI_P2_ATT_Accuracy_Table_Number: 
            Bluecell_DataCopy(&Att_DL2.Table_0_0_dBm,&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st) );
            Att_DL2.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];   // Check
            Att_DL2.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];            
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_DL1_TABLE_ADDRESDS),&Att_DL2.Table_0_0_dBm,sizeof(ATT_TABLE_st) );
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   
//            printf("ADDRESS : %d \r\n",EEPROM_ATT_DL1_TABLE_ADDRESDS );
            break;
        case DLI_P3_ATT_Accuracy_Table_Number: 
            Bluecell_DataCopy(&Att_DL3.Table_0_0_dBm,&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st) );
            Att_DL3.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];    // Check
            Att_DL3.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];            
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_DL2_TABLE_ADDRESDS),&Att_DL3.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   
            break;
        case DLI_P4_ATT_Accuracy_Table_Number: 
            Bluecell_DataCopy(&Att_DL4.Table_0_0_dBm,&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st) );
            Att_DL4.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];    // Check
            Att_DL4.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_DL3_TABLE_ADDRESDS),&Att_DL4.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

            break;
        case ULO_P1_ATT_Accuracy_Table_Number: 
            Bluecell_DataCopy(&Att_UL1.Table_0_0_dBm,&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));
            Att_UL1.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];    // Check
            Att_UL1.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_DL4_TABLE_ADDRESDS),&Att_UL1.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   
            break;
        case ULO_P2_ATT_Accuracy_Table_Number: 
            Bluecell_DataCopy(&Att_UL2.Table_0_0_dBm,&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st) );
            Att_UL2.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];
            Att_UL2.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_UL1_TABLE_ADDRESDS),&Att_UL2.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   
            break;
        case ULO_P3_ATT_Accuracy_Table_Number: 
            Bluecell_DataCopy(&Att_UL3.Table_0_0_dBm,&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st) );
            Att_UL3.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];    // Check
             Att_UL3.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_UL2_TABLE_ADDRESDS),&Att_UL3.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

            break;
        case ULO_P4_ATT_Accuracy_Table_Number: 
            Bluecell_DataCopy(&Att_UL4.Table_0_0_dBm,&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st) );
            Att_UL4.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];    // Check
            Att_UL4.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_UL3_TABLE_ADDRESDS),&Att_UL4.Table_0_0_dBm,sizeof(ATT_TABLE_st));
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

            break;
        case DLI_P1_Level_Table_Number: 

            Bluecell_DataCopy(&Det_DL1.Table_Det5_dBm_H,&data[MBIC_PAYLOADSTART + 5],sizeof(DET_TABLEDL_st));
            Det_DL1.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];    // Check
            Det_DL1.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_UL4_TABLE_ADDRESDS),&Det_DL1.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));
  //          EEPROM_M24C08_Read(EEPROM_M24C08_ID ,(EEPROM_ATT_UL4_TABLE_ADDRESDS),tableTest,sizeof(DET_TABLEDL_st));
//            for(int i = 0 ; i < sizeof(DET_TABLEDL_st); i++)
//                printf("tableTest : %x\r\n",tableTest[i]);
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

            break;
        case DLI_P2_Level_Table_Number: 
            Bluecell_DataCopy(&Det_DL2.Table_Det5_dBm_H,&data[MBIC_PAYLOADSTART + 5],sizeof(DET_TABLEDL_st));
            Det_DL2.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];   // Check
            Det_DL2.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_DET_DL1_TABLE_ADDRESDS),&Det_DL2.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

            break;
        case DLI_P3_Level_Table_Number: 
            Bluecell_DataCopy(&Det_DL3.Table_Det5_dBm_H,&data[MBIC_PAYLOADSTART + 5],sizeof(DET_TABLEDL_st));
            Det_DL3.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];
            Det_DL3.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_DET_DL2_TABLE_ADDRESDS),&Det_DL3.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

            break;
        case DLI_P4_Level_Table_Number: 
            Bluecell_DataCopy(&Det_DL4.Table_Det5_dBm_H,&data[MBIC_PAYLOADSTART + 5],sizeof(DET_TABLEDL_st));
            Det_DL4.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];
            Det_DL4.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_DET_DL3_TABLE_ADDRESDS),&Det_DL4.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st));
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

            break;
        case ULO_P1_Level_Table_Number: 
            Bluecell_DataCopy(&Det_UL1.Table_Det_15_dBm_H,&data[MBIC_PAYLOADSTART + 5],sizeof(DET_TABLEUL_st));
            Det_UL1.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];
            Det_UL1.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_DET_DL4_TABLE_ADDRESDS),&Det_UL1.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));            
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

            break;
        case ULO_P2_Level_Table_Number: 
            Bluecell_DataCopy(&Det_UL2.Table_Det_15_dBm_H,&data[MBIC_PAYLOADSTART + 5],sizeof(DET_TABLEUL_st));
            Det_UL2.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];
            Det_UL2.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_DET_UL1_TABLE_ADDRESDS),&Det_UL2.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));            
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

        break;
        case ULO_P3_Level_Table_Number: 
            Bluecell_DataCopy(&Det_UL3.Table_Det_15_dBm_H,&data[MBIC_PAYLOADSTART + 5],sizeof(DET_TABLEUL_st));
            Det_UL3.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];
            Det_UL3.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_DET_UL2_TABLE_ADDRESDS),&Det_UL3.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));            
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

            break;
        case ULO_P4_Level_Table_Number: 
            Bluecell_DataCopy(&Det_UL4.Table_Det_15_dBm_H,&data[MBIC_PAYLOADSTART + 5],sizeof(DET_TABLEUL_st));
            Det_UL4.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];
            Det_UL4.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_DET_UL3_TABLE_ADDRESDS),&Det_UL4.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));            
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

            break;
        case DLI_P1_ATT_Temp_guarantee_Table_Number:
            Bluecell_DataCopy(&Temp_DL1.Table_1_Temp,&data[MBIC_PAYLOADSTART + 5],sizeof(TEMP_TABLE_st) );
            Temp_DL1.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];
            Temp_DL1.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_DET_UL4_TABLE_ADDRESDS),&Temp_DL1.Table_1_Temp,sizeof(TEMP_TABLE_st));                    
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   
            printf("Temp_DL1 Length : %d \r\n",data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length]);

            break;
        case DLI_P2_ATT_Temp_guarantee_Table_Number:
            Bluecell_DataCopy(&Temp_DL2.Table_1_Temp,&data[MBIC_PAYLOADSTART + 5],sizeof(TEMP_TABLE_st) );
            Temp_DL2.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];
            Temp_DL2.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL1_TABLE_ADDRESDS),&Temp_DL2.Table_1_Temp,sizeof(TEMP_TABLE_st));                    
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

            break;
        case DLI_P3_ATT_Temp_guarantee_Table_Number:
            Bluecell_DataCopy(&Temp_DL3.Table_1_Temp,&data[MBIC_PAYLOADSTART + 5],sizeof(TEMP_TABLE_st) );
            Temp_DL3.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];
            Temp_DL3.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL2_TABLE_ADDRESDS),&Temp_DL3.Table_1_Temp,sizeof(TEMP_TABLE_st));                    
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

            break;
        case DLI_P4_ATT_Temp_guarantee_Table_Number:
            Bluecell_DataCopy(&Temp_DL4.Table_1_Temp,&data[MBIC_PAYLOADSTART + 5],sizeof(TEMP_TABLE_st) );
            Temp_DL4.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];
            Temp_DL4.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL3_TABLE_ADDRESDS),&Temp_DL4.Table_1_Temp,sizeof(TEMP_TABLE_st));                    
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

            break;
        case ULO_P1_ATT_Temp_guarantee_Table_Number:
            Bluecell_DataCopy(&Temp_UL1.Table_1_Temp,&data[MBIC_PAYLOADSTART + 5],sizeof(TEMP_TABLE_st) );
            Temp_UL1.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];
            Temp_UL1.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_TEMP_DL4_TABLE_ADDRESDS),&Temp_UL1.Table_1_Temp,sizeof(TEMP_TABLE_st));                            
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

            break;
        case ULO_P2_ATT_Temp_guarantee_Table_Number:
            Bluecell_DataCopy(&Temp_UL2.Table_1_Temp,&data[MBIC_PAYLOADSTART + 5],sizeof(TEMP_TABLE_st) );
            Temp_UL2.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];
            Temp_UL2.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_TEMP_UL1_TABLE_ADDRESDS),&Temp_UL2.Table_1_Temp,sizeof(TEMP_TABLE_st));                            
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

            break;
        case ULO_P3_ATT_Temp_guarantee_Table_Number:
            Bluecell_DataCopy(&Temp_UL3.Table_1_Temp,&data[MBIC_PAYLOADSTART + 5],sizeof(TEMP_TABLE_st) );
            Temp_UL3.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];
            Temp_UL3.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
//            printf("Temp_UL3.Table_Length : %d \r\n",Temp_UL3.Table_Length);
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_TEMP_UL2_TABLE_ADDRESDS),&Temp_UL3.Table_1_Temp,sizeof(TEMP_TABLE_st));                            
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

            break;
        case ULO_P4_ATT_Temp_guarantee_Table_Number:
            Bluecell_DataCopy(&Temp_UL4.Table_1_Temp,&data[MBIC_PAYLOADSTART + 5],sizeof(TEMP_TABLE_st));
            Temp_UL4.Table_Ref = data[MBIC_PAYLOADSTART + MBIC_TableIndex_Ref];
            Temp_UL4.Table_Length= data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length];
            EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_TEMP_UL3_TABLE_ADDRESDS),&Temp_UL4.Table_1_Temp,sizeof(TEMP_TABLE_st));                                
            MBIC_TableHeaderCopy(&data[MBIC_PAYLOADSTART + 5],sizeof(ATT_TABLE_st));   

            break;
    }
//    printf("\rSetting MBIC_TableIndex_Number : %x \r\n",data[MBIC_PAYLOADSTART + MBIC_TableIndex_Number]);
}

void Table_LengSet(){
    Att_DL1.Table_Ref = ATTENTABLEDL_REF;
    Att_DL2.Table_Ref = ATTENTABLEDL_REF;
    Att_DL3.Table_Ref = ATTENTABLEDL_REF;
    Att_DL4.Table_Ref = ATTENTABLEDL_REF;
    Att_UL1.Table_Ref = ATTENTABLEUL_REF;
    Att_UL2.Table_Ref = ATTENTABLEUL_REF;
    Att_UL3.Table_Ref = ATTENTABLEUL_REF;
    Att_UL4.Table_Ref = ATTENTABLEUL_REF;
    Det_DL1.Table_Ref = ATTENTABLEDET_DL_REF;
    Det_DL2.Table_Ref = ATTENTABLEDET_DL_REF;
    Det_DL3.Table_Ref = ATTENTABLEDET_DL_REF;
    Det_DL4.Table_Ref = ATTENTABLEDET_DL_REF;
    Det_UL1.Table_Ref = ATTENTABLEDET_UL_REF;
    Det_UL2.Table_Ref = ATTENTABLEDET_UL_REF;
    Det_UL3.Table_Ref = ATTENTABLEDET_UL_REF;
    Det_UL4.Table_Ref = ATTENTABLEDET_UL_REF;
    Temp_DL1.Table_Ref= ATTENTABLE_TEMP_REF;
    Temp_DL2.Table_Ref= ATTENTABLE_TEMP_REF;
    Temp_DL3.Table_Ref= ATTENTABLE_TEMP_REF;
    Temp_DL4.Table_Ref= ATTENTABLE_TEMP_REF;
    Temp_UL1.Table_Ref= ATTENTABLE_TEMP_REF;
    Temp_UL2.Table_Ref= ATTENTABLE_TEMP_REF;
    Temp_UL3.Table_Ref= ATTENTABLE_TEMP_REF;
    Temp_UL4.Table_Ref= ATTENTABLE_TEMP_REF;  


    Att_DL1.Table_Length = ATTENTABLEDLUL_LENGTH;
    Att_DL2.Table_Length = ATTENTABLEDLUL_LENGTH;
    Att_DL3.Table_Length = ATTENTABLEDLUL_LENGTH;
    Att_DL4.Table_Length = ATTENTABLEDLUL_LENGTH;
    Att_UL1.Table_Length = ATTENTABLEDLUL_LENGTH;
    Att_UL2.Table_Length = ATTENTABLEDLUL_LENGTH;
    Att_UL3.Table_Length = ATTENTABLEDLUL_LENGTH;
    Att_UL4.Table_Length = ATTENTABLEDLUL_LENGTH;
    Det_DL1.Table_Length = ATTENTABLEDET_DL_LENGTH;
    Det_DL2.Table_Length = ATTENTABLEDET_DL_LENGTH;
    Det_DL3.Table_Length = ATTENTABLEDET_DL_LENGTH;
    Det_DL4.Table_Length = ATTENTABLEDET_DL_LENGTH;
    Det_UL1.Table_Length = ATTENTABLEDET_UL_LENGTH;
    Det_UL2.Table_Length = ATTENTABLEDET_UL_LENGTH;
    Det_UL3.Table_Length = ATTENTABLEDET_UL_LENGTH;
    Det_UL4.Table_Length = ATTENTABLEDET_UL_LENGTH;
    Temp_DL1.Table_Length= ATTENTABLE_TEMP_LENGTH;
    Temp_DL2.Table_Length= ATTENTABLE_TEMP_LENGTH;
    Temp_DL3.Table_Length= ATTENTABLE_TEMP_LENGTH;
    Temp_DL4.Table_Length= ATTENTABLE_TEMP_LENGTH;
    Temp_UL1.Table_Length= ATTENTABLE_TEMP_LENGTH;
    Temp_UL2.Table_Length= ATTENTABLE_TEMP_LENGTH;
    Temp_UL3.Table_Length= ATTENTABLE_TEMP_LENGTH;
    Temp_UL4.Table_Length= ATTENTABLE_TEMP_LENGTH;     
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_ATT_BASE              ,&Att_DL1.Table_0_0_dBm,sizeof(ATT_TABLE_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_ATT_DL1_TABLE_ADDRESDS,&Att_DL2.Table_0_0_dBm,sizeof(ATT_TABLE_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_ATT_DL2_TABLE_ADDRESDS,&Att_DL3.Table_0_0_dBm,sizeof(ATT_TABLE_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_ATT_DL3_TABLE_ADDRESDS,&Att_DL4.Table_0_0_dBm,sizeof(ATT_TABLE_st) );
    
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_ATT_DL4_TABLE_ADDRESDS,&Att_UL1.Table_0_0_dBm,sizeof(ATT_TABLE_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_ATT_UL1_TABLE_ADDRESDS,&Att_UL2.Table_0_0_dBm,sizeof(ATT_TABLE_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_ATT_UL2_TABLE_ADDRESDS,&Att_UL3.Table_0_0_dBm,sizeof(ATT_TABLE_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_ATT_UL3_TABLE_ADDRESDS,&Att_UL4.Table_0_0_dBm,sizeof(ATT_TABLE_st) );
    
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_ATT_UL4_TABLE_ADDRESDS,&Det_DL1.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_DET_DL1_TABLE_ADDRESDS,&Det_DL2.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_DET_DL2_TABLE_ADDRESDS,&Det_DL3.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_DET_DL3_TABLE_ADDRESDS,&Det_DL4.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st) );
    
    
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_DET_DL4_TABLE_ADDRESDS,&Det_UL1.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_DET_UL1_TABLE_ADDRESDS,&Det_UL2.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_DET_UL2_TABLE_ADDRESDS,&Det_UL3.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_DET_UL3_TABLE_ADDRESDS,&Det_UL4.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st) );
    
    
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_DET_UL4_TABLE_ADDRESDS,&Temp_DL1.Table_1_Temp,sizeof(TEMP_TABLE_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_TEMP_DL1_TABLE_ADDRESDS,&Temp_DL2.Table_1_Temp,sizeof(TEMP_TABLE_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_TEMP_DL2_TABLE_ADDRESDS,&Temp_DL3.Table_1_Temp,sizeof(TEMP_TABLE_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_TEMP_DL3_TABLE_ADDRESDS,&Temp_DL4.Table_1_Temp,sizeof(TEMP_TABLE_st) );
    
    
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_TEMP_DL4_TABLE_ADDRESDS,&Temp_UL1.Table_1_Temp,sizeof(TEMP_TABLE_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_TEMP_UL1_TABLE_ADDRESDS,&Temp_UL2.Table_1_Temp,sizeof(TEMP_TABLE_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_TEMP_UL2_TABLE_ADDRESDS,&Temp_UL3.Table_1_Temp,sizeof(TEMP_TABLE_st) );
       EEPROM_M24C08_write(EEPROM_M24C08_ID,EEPROM_TEMP_UL3_TABLE_ADDRESDS,&Temp_UL4.Table_1_Temp,sizeof(TEMP_TABLE_st) );


}


bool Bluecell_Operate(uint8_t* data){
  uint8_t datatype = data[BLUECELL_TYPE];


  //double ret = 0 ,tmp = 0.1;
  int16_t tempdata = 0;
  int16_t CurrAtten = 0;
  int16_t ALC_TEMP[4] ={0,};
  int16_t Tmpdata = 0 ,Tmpdata2 = 0;
  double tmpedata2 = 0;
  uint8_t i = 0;
  uint16_t Crcret = 0;
  uint16_t Length = 0;
  switch(datatype){
    case BLUECELL_SOFTWARERESET:
//        printf("Bluecell Reset \r\n");
//        Table_Init();
        Table_LengSet();
//        Table_LengSet();
        NVIC_SystemReset();
        break;
	case Bluecell_ATT_DL1 				 :
//		printf("Function : %s Line %d \r\n",__func__,__LINE__);
       
        
        bluecell_Currdatastatus.ATT_DL1_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.ATT_DL1_L = data[BLUECELL_DATA + i++];
//        printf("bluecell_Currdatastatus.ATT_DL1_H : %x\r\n",bluecell_Currdatastatus.ATT_DL1_H);
//        printf("bluecell_Currdatastatus.ATT_DL1_L : %x\r\n",bluecell_Currdatastatus.ATT_DL1_L);  
        CurrAtten = bluecell_Currdatastatus.ATT_DL1_H << 8 | bluecell_Currdatastatus.ATT_DL1_L;
//        printf("LINE : %d Curr ATTEN : %d \r\n",__LINE__,CurrAtten);
        DL_PrevIwillgiveAtten[AGC_Alarm_DL1_Index] = 0;
        /*
            Atten Ctrl Function
        */
		CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
        break;
    case Bluecell_ATT_DL2                :
        bluecell_Currdatastatus.ATT_DL2_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.ATT_DL2_L = data[BLUECELL_DATA + i++];
//        printf("bluecell_Currdatastatus.ATT_DL2_H : %x\r\n",bluecell_Currdatastatus.ATT_DL2_H);
//        printf("bluecell_Currdatastatus.ATT_DL2_L : %x\r\n",bluecell_Currdatastatus.ATT_DL2_L);        
        CurrAtten = bluecell_Currdatastatus.ATT_DL2_H << 8 | bluecell_Currdatastatus.ATT_DL2_L;
//        printf("LINE : %d Curr ATTEN : %d \r\n",__LINE__,CurrAtten);
        DL_PrevIwillgiveAtten[AGC_Alarm_DL2_Index] = 0;

        /*
            Atten Ctrl Function
        */
		CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
        break;
	case Bluecell_ATT_DL3 				 :        
        bluecell_Currdatastatus.ATT_DL3_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.ATT_DL3_L = data[BLUECELL_DATA + i++];
        CurrAtten = bluecell_Currdatastatus.ATT_DL3_H << 8 | bluecell_Currdatastatus.ATT_DL3_L;
//        printf("LINE : %d Curr ATTEN : %d \r\n",__LINE__,CurrAtten);
        DL_PrevIwillgiveAtten[AGC_Alarm_DL3_Index] = 0;

        /*
            Atten Ctrl Function
        */
		CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
        break;
	case Bluecell_ATT_DL4 				 :    
        bluecell_Currdatastatus.ATT_DL4_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.ATT_DL4_L = data[BLUECELL_DATA + i++];
        CurrAtten = bluecell_Currdatastatus.ATT_DL4_H << 8 | bluecell_Currdatastatus.ATT_DL4_L;
//        printf("LINE : %d Curr ATTEN : %d \r\n",__LINE__,CurrAtten);
        DL_PrevIwillgiveAtten[AGC_Alarm_DL4_Index] = 0;    
        /*
            Atten Ctrl Function
        */
		CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
        break;
    case Bluecell_ATT_UL1                :

        bluecell_Currdatastatus.ATT_UL1_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.ATT_UL1_L =data[BLUECELL_DATA + i++];
        if(bluecell_Currdatastatus.ULO_ALC_ON_OFF == true){
            Tmpdata = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_L;
            Tmpdata2 = bluecell_Currdatastatus.ATT_UL1_H << 8 | bluecell_Currdatastatus.ATT_UL1_L;
            if(Tmpdata + Tmpdata2 <= -200){
                Tmpdata2 = -200 + (Tmpdata * -1);
                bluecell_Currdatastatus.ATT_UL1_H = ((Tmpdata2 & 0xFF00) >> 8);
                bluecell_Currdatastatus.ATT_UL1_L = Tmpdata2 & 0x00FF;                    
            }
            UL_ALC_GainAttenSet[ALC_Alarm_UL1_Index] = true;
            ALC_Level_Save[ALC_Alarm_UL1_Index] = bluecell_Currdatastatus.ULO_Level1_H << 8 | bluecell_Currdatastatus.ULO_Level1_L;
        }
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

//        printf("LINE : %d Curr ATTEN : %d \r\n",__LINE__,CurrAtten);
    
        /*
            Atten Ctrl Function
        */
		CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
        ALCTimerCnt = 0;
        //        printf("bluecell_Currdatastatus.ATT_UL1_H : %x\r\n",bluecell_Currdatastatus.ATT_UL1_H);
        //        printf("bluecell_Currdatastatus.ATT_UL1_L : %x\r\n",bluecell_Currdatastatus.ATT_UL1_L);        
        break;
    case Bluecell_ATT_UL2                :        
        bluecell_Currdatastatus.ATT_UL2_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.ATT_UL2_L = data[BLUECELL_DATA + i++];
        if(bluecell_Currdatastatus.ULO_ALC_ON_OFF == true){
            Tmpdata = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_L;
            Tmpdata2 = bluecell_Currdatastatus.ATT_UL2_H << 8 | bluecell_Currdatastatus.ATT_UL2_L;
            if(Tmpdata + Tmpdata2 <= -200){
                Tmpdata2 = -200 + (Tmpdata * -1);
                bluecell_Currdatastatus.ATT_UL2_H = ((Tmpdata2 & 0xFF00) >> 8);
                bluecell_Currdatastatus.ATT_UL2_L = Tmpdata2 & 0x00FF;                    
            }
            UL_ALC_GainAttenSet[ALC_Alarm_UL2_Index] = true;
            ALC_Level_Save[ALC_Alarm_UL2_Index] = bluecell_Currdatastatus.ULO_Level2_H << 8 | bluecell_Currdatastatus.ULO_Level2_L;
        }
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);


        /*
            Atten Ctrl Function
        */
		CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
        ALCTimerCnt = 0;
        break;    
    case Bluecell_ATT_UL3                :    
        bluecell_Currdatastatus.ATT_UL3_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.ATT_UL3_L = data[BLUECELL_DATA + i++];
        if(bluecell_Currdatastatus.ULO_ALC_ON_OFF == true){
            Tmpdata = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_L;
            Tmpdata2 = bluecell_Currdatastatus.ATT_UL3_H << 8 | bluecell_Currdatastatus.ATT_UL3_L;
            if(Tmpdata + Tmpdata2 <= -200){
                Tmpdata2 = -200 + (Tmpdata * -2);
                bluecell_Currdatastatus.ATT_UL3_H = ((Tmpdata2 & 0xFF00) >> 8);
                bluecell_Currdatastatus.ATT_UL3_L = Tmpdata2 & 0x00FF;                    
            }
            UL_ALC_GainAttenSet[ALC_Alarm_UL3_Index] = true;
            ALC_Level_Save[ALC_Alarm_UL3_Index] = bluecell_Currdatastatus.ULO_Level3_H << 8 | bluecell_Currdatastatus.ULO_Level3_L;
        }
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

        /*
            Atten Ctrl Function
        */
		CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
        ALCTimerCnt = 0;
        break;    
    case Bluecell_ATT_UL4                :        
        bluecell_Currdatastatus.ATT_UL4_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.ATT_UL4_L = data[BLUECELL_DATA + i++];
        if(bluecell_Currdatastatus.ULO_ALC_ON_OFF == true){
            Tmpdata = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_L;
            Tmpdata2 = bluecell_Currdatastatus.ATT_UL4_H << 8 | bluecell_Currdatastatus.ATT_UL4_L;
            if(Tmpdata + Tmpdata2 <= -200){
                Tmpdata2 = -200 + (Tmpdata * -2);
                bluecell_Currdatastatus.ATT_UL4_H = ((Tmpdata2 & 0xFF00) >> 8);
                bluecell_Currdatastatus.ATT_UL4_L = Tmpdata2 & 0x00FF;                    
            }
            UL_ALC_GainAttenSet[ALC_Alarm_UL4_Index] = true;
            ALC_Level_Save[ALC_Alarm_UL4_Index] = bluecell_Currdatastatus.ULO_Level4_H << 8 | bluecell_Currdatastatus.ULO_Level4_L;
        }
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

        ALCTimerCnt = 0;


        /*
            Atten Ctrl Function
        */
		CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
//		printf("ret : %f ,tmp %f \r\n",ret,tmp );
		break;
	case ATT_DL1_PATH 		 :
#if 0 // PYJ.2020.07.03_BEGIN -- 

        bluecell_Currdatastatus.ATT_DL1_PATH = data[BLUECELL_DATA]; 
        bluecell_Currdatastatus.DLI_Shutdown_Retry_Count1 = 0;
        bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count1 = 0xFF;
        if(data[BLUECELL_DATA]==0){
            HAL_GPIO_WritePin(PATH_EN_DL1_GPIO_Port,PATH_EN_DL1_Pin,GPIO_PIN_RESET);//CLOCK        
            DL_PathUserHandl[0] = true;
        }
        else{
            bluecell_Prevdatastatus.ATT_DL1_H = 0xFF;
            bluecell_Prevdatastatus.ATT_DL1_L =0xFF;
            DL_PathUserHandl[0] = false;                    
            HAL_GPIO_WritePin(PATH_EN_DL1_GPIO_Port,PATH_EN_DL1_Pin,GPIO_PIN_SET);//CLOCK
        }                
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
#else
//       printf("DL PATH 1 : %d \r\n",data[BLUECELL_DATA]);
       if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
              return true;
       if(data[BLUECELL_DATA] != 0)
           bluecell_Currdatastatus.Path_TempSave_Bit |= 0x80;
       else
          bluecell_Currdatastatus.Path_TempSave_Bit &= ~0x80;
       printf("%d :  bluecell_Currdatastatus.Path_TempSave_Bit : %x \r\n",data[BLUECELL_DATA], bluecell_Currdatastatus.Path_TempSave_Bit);


       DL_Path_OnOff(Path1_OnOff,
            data[BLUECELL_DATA],
            &bluecell_Currdatastatus.ATT_DL1_PATH,
            &bluecell_Prevdatastatus.ATT_DL1_H,
            &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count1,
            &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count1)  ;  

#endif // PYJ.2020.07.03_END -- 
	

		break;
	case ATT_UL1_PATH        :
#if 0 // PYJ.2020.07.03_BEGIN -- 
        if(data[BLUECELL_DATA]==0){
            HAL_GPIO_WritePin(PATH_EN_UL1_GPIO_Port,PATH_EN_UL1_Pin,GPIO_PIN_RESET);//CLOCK
            bluecell_Currdatastatus.ULO_Shutdown_Retry_Count1 = 0;
        }
        else{
            HAL_GPIO_WritePin(PATH_EN_UL1_GPIO_Port,PATH_EN_UL1_Pin,GPIO_PIN_SET);//CLOCK
            bluecell_Prevdatastatus.ATT_UL1_H = 0xFF;
            bluecell_Prevdatastatus.ATT_UL1_L = 0xFF;
            CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

        }
#else
        if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
               return true;
        if(data[BLUECELL_DATA] != 0)
            bluecell_Currdatastatus.Path_TempSave_Bit |= 0x08;
        else
           bluecell_Currdatastatus.Path_TempSave_Bit &= ~0x08;
        printf("%d :  bluecell_Currdatastatus.Path_TempSave_Bit : %x \r\n",data[BLUECELL_DATA], bluecell_Currdatastatus.Path_TempSave_Bit);

        UL_Path_OnOff(Path1_OnOff,
             data[BLUECELL_DATA],
             &bluecell_Currdatastatus.ATT_UL1_PATH,
             &bluecell_Prevdatastatus.ATT_UL1_H,
             &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count1,
             &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count1)  ;  

#endif // PYJ.2020.07.03_END -- 
        bluecell_Currdatastatus.ATT_UL1_PATH = data[BLUECELL_DATA];
//        printf("Function : %s Line %d \r\n",__func__,__LINE__);
		break;
	case ATT_SelfTest1		 :
#if 0 // PYJ.2020.07.05_BEGIN -- 
        
        if(data[BLUECELL_DATA]==0){
            HAL_GPIO_WritePin(_PATH_SW1_GPIO_Port,_PATH_SW1_Pin,GPIO_PIN_RESET);//CLOCK
            HAL_GPIO_WritePin(PATH_SW1_GPIO_Port,PATH_SW1_Pin,GPIO_PIN_SET);//CLOCK
        }
        else{
            HAL_GPIO_WritePin(_PATH_SW1_GPIO_Port,_PATH_SW1_Pin,GPIO_PIN_SET);//CLOCK
            HAL_GPIO_WritePin(PATH_SW1_GPIO_Port,PATH_SW1_Pin,GPIO_PIN_RESET);//CLOCK
        }
        bluecell_Currdatastatus.Selftest1 = data[BLUECELL_DATA];
//		printf("Function : %s Line %d \r\n",__func__,__LINE__);
#else
#if 0 // PYJ.2020.07.05_BEGIN -- 
        if(data[BLUECELL_DATA] == 0){
            bluecell_Currdatastatus.ATT_DL1_H = Selftest_DL_PrevAttenSave[0]; 
            bluecell_Currdatastatus.ATT_DL1_L = Selftest_DL_PrevAttenSave[1];  
            bluecell_Currdatastatus.ATT_UL1_H = Selftest_UL_PrevAttenSave[0]; 
            bluecell_Currdatastatus.ATT_UL1_L = Selftest_UL_PrevAttenSave[1];
        }else{
            Selftest_DL_PrevAttenSave[0] = bluecell_Currdatastatus.ATT_DL1_H;
            Selftest_DL_PrevAttenSave[1] = bluecell_Currdatastatus.ATT_DL1_L;            
            Selftest_UL_PrevAttenSave[0] = bluecell_Currdatastatus.ATT_UL1_H;
            Selftest_UL_PrevAttenSave[1] = bluecell_Currdatastatus.ATT_UL1_L;            
            bluecell_Currdatastatus.ATT_DL1_H = 0;
            bluecell_Currdatastatus.ATT_DL1_L = 0;        
            bluecell_Currdatastatus.ATT_UL1_H = 0;
            bluecell_Currdatastatus.ATT_UL1_L = 0;              
        }
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
#endif // PYJ.2020.07.05_END -- 
        SelfTest_Ctrl(SelfTest1,data[BLUECELL_DATA],&bluecell_Currdatastatus.Selftest1,&bluecell_Currdatastatus.ATT_DL1_H,&bluecell_Currdatastatus.ATT_UL1_H);

#endif // PYJ.2020.07.05_END -- 
		break;
	case ATT_DL2_PATH		 :
#if 0 // PYJ.2020.07.03_BEGIN -- 
        bluecell_Currdatastatus.ATT_DL2_PATH = data[BLUECELL_DATA]; 
        bluecell_Currdatastatus.DLI_Shutdown_Retry_Count2 = 0;
        bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count2 = 0xFF;
        if(data[BLUECELL_DATA]==0){
            HAL_GPIO_WritePin(PATH_EN_DL2_GPIO_Port,PATH_EN_DL2_Pin,GPIO_PIN_RESET);//CLOCK        
            DL_PathUserHandl[1] = true;
        }
        else{
            bluecell_Prevdatastatus.ATT_DL2_H = 0xFF;
            bluecell_Prevdatastatus.ATT_DL2_L =0xFF;
            DL_PathUserHandl[1] = false;                    
            HAL_GPIO_WritePin(PATH_EN_DL2_GPIO_Port,PATH_EN_DL2_Pin,GPIO_PIN_SET);//CLOCK
        }                
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
#else
        if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
          return true;
        if(data[BLUECELL_DATA] != 0)
            bluecell_Currdatastatus.Path_TempSave_Bit |= 0x40;
        else
           bluecell_Currdatastatus.Path_TempSave_Bit &= ~0x40;
        printf("%d :  bluecell_Currdatastatus.Path_TempSave_Bit : %x \r\n",data[BLUECELL_DATA], bluecell_Currdatastatus.Path_TempSave_Bit);

        DL_Path_OnOff(Path2_OnOff,
             data[BLUECELL_DATA],
             &bluecell_Currdatastatus.ATT_DL2_PATH,
             &bluecell_Prevdatastatus.ATT_DL2_H,
             &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count2,
             &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count2)  ;  

#endif // PYJ.2020.07.03_END -- 

//		printf("Function : %s Line %d \r\n",__func__,__LINE__);
		break;

		break;
	case ATT_UL2_PATH 		 :
#if 0 // PYJ.2020.07.03_BEGIN -- 
        if(data[BLUECELL_DATA]==0){
            HAL_GPIO_WritePin(PATH_EN_UL2_GPIO_Port,PATH_EN_UL2_Pin,GPIO_PIN_RESET);//CLOCK
            bluecell_Currdatastatus.ULO_Shutdown_Retry_Count2 = 0;
        }
        else{
            HAL_GPIO_WritePin(PATH_EN_UL2_GPIO_Port,PATH_EN_UL2_Pin,GPIO_PIN_SET);//CLOCK
            bluecell_Prevdatastatus.ATT_UL2_H = 0xFF;
            bluecell_Prevdatastatus.ATT_UL2_L = 0xFF;
            CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
        }
        bluecell_Currdatastatus.ATT_UL2_PATH = data[BLUECELL_DATA];
//         printf("UL SHUTDOWN RECOVERY OPERATE PATH : %d \r\n",bluecell_Currdatastatus.ATT_UL2_PATH);
#else
        if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
          return true;
        if(data[BLUECELL_DATA] != 0)
            bluecell_Currdatastatus.Path_TempSave_Bit |= 0x04;
        else
           bluecell_Currdatastatus.Path_TempSave_Bit &= ~0x04;
        printf("%d :  bluecell_Currdatastatus.Path_TempSave_Bit : %x \r\n",data[BLUECELL_DATA], bluecell_Currdatastatus.Path_TempSave_Bit);

        UL_Path_OnOff(Path2_OnOff,
             data[BLUECELL_DATA],
             &bluecell_Currdatastatus.ATT_UL2_PATH,
             &bluecell_Prevdatastatus.ATT_UL2_H,
             &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count2,
             &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count2)  ;  

#endif // PYJ.2020.07.03_END -- 
		break;
	case ATT_SelfTest2		 :
#if 0 // PYJ.2020.07.05_BEGIN -- 
        if(data[BLUECELL_DATA]==0){
            HAL_GPIO_WritePin(_PATH_SW2_GPIO_Port,_PATH_SW2_Pin,GPIO_PIN_RESET);//CLOCK
            HAL_GPIO_WritePin(PATH_SW2_GPIO_Port,PATH_SW2_Pin,GPIO_PIN_SET);//CLOCK
        }else{
            HAL_GPIO_WritePin(PATH_SW2_GPIO_Port,PATH_SW2_Pin,GPIO_PIN_RESET);//CLOCK
            HAL_GPIO_WritePin(_PATH_SW2_GPIO_Port,_PATH_SW2_Pin,GPIO_PIN_SET);//CLOCK
        }
        bluecell_Currdatastatus.Selftest2 = data[BLUECELL_DATA];
#else
        SelfTest_Ctrl(SelfTest2,data[BLUECELL_DATA],&bluecell_Currdatastatus.Selftest2,&bluecell_Currdatastatus.ATT_DL2_H,&bluecell_Currdatastatus.ATT_UL2_H);

#endif // PYJ.2020.07.05_END -- 
//		printf("Function : %s Line %d \r\n",__func__,__LINE__);
		break;
	case ATT_DL3_PATH :
#if 0 // PYJ.2020.07.03_BEGIN -- 
        bluecell_Currdatastatus.ATT_DL3_PATH = data[BLUECELL_DATA]; 
        bluecell_Currdatastatus.DLI_Shutdown_Retry_Count3 = 0;
        bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count3 = 0xFF;
        if(data[BLUECELL_DATA]==0){
            HAL_GPIO_WritePin(PATH_EN_DL3_GPIO_Port,PATH_EN_DL3_Pin,GPIO_PIN_RESET);//CLOCK        
            DL_PathUserHandl[2] = true;
        }
        else{
            bluecell_Prevdatastatus.ATT_DL3_H = 0xFF;
            bluecell_Prevdatastatus.ATT_DL3_L =0xFF;
            DL_PathUserHandl[2] = false;                    
            HAL_GPIO_WritePin(PATH_EN_DL3_GPIO_Port,PATH_EN_DL3_Pin,GPIO_PIN_SET);//CLOCK
        }                
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
#else
        if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
          return true;
        if(data[BLUECELL_DATA] != 0)
            bluecell_Currdatastatus.Path_TempSave_Bit |= 0x20;
        else
           bluecell_Currdatastatus.Path_TempSave_Bit &= ~0x20;
        printf("%d :  bluecell_Currdatastatus.Path_TempSave_Bit : %x \r\n",data[BLUECELL_DATA], bluecell_Currdatastatus.Path_TempSave_Bit);

        DL_Path_OnOff(Path3_OnOff,
             data[BLUECELL_DATA],
             &bluecell_Currdatastatus.ATT_DL3_PATH,
             &bluecell_Prevdatastatus.ATT_DL3_H,
             &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count3,
             &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count3)  ;  

#endif // PYJ.2020.07.03_END -- 

		break;
	case ATT_UL3_PATH :
#if 0 // PYJ.2020.07.03_BEGIN -- 
        if(data[BLUECELL_DATA]==0){
            HAL_GPIO_WritePin(PATH_EN_UL3_GPIO_Port,PATH_EN_UL3_Pin,GPIO_PIN_RESET);//CLOCK
            bluecell_Currdatastatus.ULO_Shutdown_Retry_Count3 = 0;
        }
        else{
            HAL_GPIO_WritePin(PATH_EN_UL3_GPIO_Port,PATH_EN_UL3_Pin,GPIO_PIN_SET);//CLOCK
            bluecell_Prevdatastatus.ATT_UL3_H = 0xFF;
            bluecell_Prevdatastatus.ATT_UL3_L =0xFF;
            CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
        }
        bluecell_Currdatastatus.ATT_UL3_PATH = data[BLUECELL_DATA];
#else
        if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
          return true;
        if(data[BLUECELL_DATA] != 0)
            bluecell_Currdatastatus.Path_TempSave_Bit |= 0x02;
        else
           bluecell_Currdatastatus.Path_TempSave_Bit &= ~0x02;
        printf("%d :  bluecell_Currdatastatus.Path_TempSave_Bit : %x \r\n",data[BLUECELL_DATA], bluecell_Currdatastatus.Path_TempSave_Bit);

        UL_Path_OnOff(Path3_OnOff,
             data[BLUECELL_DATA],
             &bluecell_Currdatastatus.ATT_UL3_PATH,
             &bluecell_Prevdatastatus.ATT_UL3_H,
             &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count3,
             &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count3)  ; 

#endif // PYJ.2020.07.03_END -- 
		break;
	case ATT_SelfTest3 :
#if 0 // PYJ.2020.07.05_BEGIN -- 
        if(data[BLUECELL_DATA]==0){
            HAL_GPIO_WritePin(_PATH_SW3_GPIO_Port,_PATH_SW3_Pin,GPIO_PIN_RESET);//CLOCK
            HAL_GPIO_WritePin(PATH_SW3_GPIO_Port,PATH_SW3_Pin,GPIO_PIN_SET);//CLOCK
        }
        else{
            HAL_GPIO_WritePin(PATH_SW3_GPIO_Port,PATH_SW3_Pin,GPIO_PIN_RESET);//CLOCK
            HAL_GPIO_WritePin(_PATH_SW3_GPIO_Port,_PATH_SW3_Pin,GPIO_PIN_SET);//CLOCK
        }
        bluecell_Currdatastatus.Selftest3 = data[BLUECELL_DATA];
#else
        SelfTest_Ctrl(SelfTest3,data[BLUECELL_DATA],&bluecell_Currdatastatus.Selftest3,&bluecell_Currdatastatus.ATT_DL3_H,&bluecell_Currdatastatus.ATT_UL3_H);

#endif // PYJ.2020.07.05_END -- 
//		printf("Function : %s Line %d \r\n",__func__,__LINE__);
		break;
	case ATT_DL4_PATH :
        if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
          return true;
        if(data[BLUECELL_DATA] != 0){
            bluecell_Currdatastatus.Path_TempSave_Bit |= 0x10;
        }
        else{
           bluecell_Currdatastatus.Path_TempSave_Bit &= ~0x10;
        }

        printf("data[BLUECELL_DATA] : %d \r\n",data[BLUECELL_DATA]);
        
        printf("3.bluecell_Currdatastatus.Path_TempSave_Bit : %x \r\n",bluecell_Currdatastatus.Path_TempSave_Bit);

        DL_Path_OnOff(Path4_OnOff,
             data[BLUECELL_DATA],
             &bluecell_Currdatastatus.ATT_DL4_PATH,
             &bluecell_Prevdatastatus.ATT_DL4_H,
             &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count4,
             &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count4)  ;  

		break;
	case ATT_UL4_PATH:
#if 0 // PYJ.2020.07.03_BEGIN -- 
        bluecell_Currdatastatus.ATT_UL4_PATH = data[BLUECELL_DATA]; 
        printf("PATH : %d \r\n",bluecell_Currdatastatus.ATT_UL4_PATH);
        bluecell_Currdatastatus.ULO_Shutdown_Retry_Count4 = 0;
        bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count4 = 0xFF;
        if(data[BLUECELL_DATA]==0){
            HAL_GPIO_WritePin(PATH_EN_UL4_GPIO_Port,PATH_EN_UL4_Pin,GPIO_PIN_RESET);//CLOCK        
            UL_PathUserHandl[3] = true;
        }
        else{
            bluecell_Prevdatastatus.ATT_UL4_H = 0xFF;
            bluecell_Prevdatastatus.ATT_UL4_L =0xFF;
            UL_PathUserHandl[3] = false;                    
            HAL_GPIO_WritePin(PATH_EN_UL4_GPIO_Port,PATH_EN_UL4_Pin,GPIO_PIN_SET);//CLOCK
        }                
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
#else
        if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
          return true;
        if(data[BLUECELL_DATA] != 0)
            bluecell_Currdatastatus.Path_TempSave_Bit |= 0x01;
        else
           bluecell_Currdatastatus.Path_TempSave_Bit &= ~0x01;
        printf("%d :  bluecell_Currdatastatus.Path_TempSave_Bit : %x \r\n",data[BLUECELL_DATA], bluecell_Currdatastatus.Path_TempSave_Bit);

        UL_Path_OnOff(Path4_OnOff,
             data[BLUECELL_DATA],
             &bluecell_Currdatastatus.ATT_UL4_PATH,
             &bluecell_Prevdatastatus.ATT_UL4_H,
             &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count4,
             &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count4)  ; 

#endif // PYJ.2020.07.03_END -- 

//		printf("Function : %s Line %d \r\n",__func__,__LINE__);
		break;
	case ATT_SelfTest4 :
#if 0 // PYJ.2020.07.05_BEGIN -- 
	  if(data[BLUECELL_DATA]==0){
	    HAL_GPIO_WritePin(_PATH_SW4_GPIO_Port,_PATH_SW4_Pin,GPIO_PIN_RESET);//CLOCK
	    HAL_GPIO_WritePin(PATH_SW4_GPIO_Port,PATH_SW4_Pin,GPIO_PIN_SET);//CLOCK
	  }else{
	    HAL_GPIO_WritePin(_PATH_SW4_GPIO_Port,_PATH_SW4_Pin,GPIO_PIN_SET);//CLOCK
	    HAL_GPIO_WritePin(PATH_SW4_GPIO_Port,PATH_SW4_Pin,GPIO_PIN_RESET);//CLOCK
	  }
      bluecell_Currdatastatus.Selftest4 = data[BLUECELL_DATA];
#else
        SelfTest_Ctrl(SelfTest4,data[BLUECELL_DATA],&bluecell_Currdatastatus.Selftest4,&bluecell_Currdatastatus.ATT_DL4_H,&bluecell_Currdatastatus.ATT_UL4_H);

#endif // PYJ.2020.07.05_END -- 
//		printf("Function : %s Line %d \r\n",__func__,__LINE__);
		break;
    case ATT_TableSet:
        Bluecell_TableSave(data, data[BLUECELL_DATA]);
        Bluecell_TableLoad(data, data[BLUECELL_DATA]);
        data[BLUECELL_TYPE] = ATT_TableGet;
        Crcret = CRC16_Generate(&data[BLUECELL_TYPE], data[BLUECELL_LENGTH_L]);
        data[data[BLUECELL_LENGTH_L] + 1] = ((Crcret & 0xFF00) >> 8);
        data[data[BLUECELL_LENGTH_L] + 2] = (Crcret & 0x00FF);
        data[data[BLUECELL_LENGTH_L] + 3] = 0xEB;
        
        Bluecell_StructCpy(&Txdata[0],&data[0],data[BLUECELL_LENGTH_L] + 4);
        Uart1_Data_Send(&Txdata[0], Txdata[BLUECELL_LENGTH_L] + 4);        
        break;
    case ATT_TableGet:
        Bluecell_TableLoad(data, data[BLUECELL_DATA]);
        data[BLUECELL_TYPE] = ATT_TableGet;
        Crcret = CRC16_Generate(&data[BLUECELL_TYPE], data[BLUECELL_LENGTH_L]);
        data[data[BLUECELL_LENGTH_L] + 1] = ((Crcret & 0xFF00) >> 8);
        data[data[BLUECELL_LENGTH_L] + 2] = (Crcret & 0x00FF);
        data[data[BLUECELL_LENGTH_L] + 3] = 0xEB;
        
        Bluecell_StructCpy(&Txdata[0],&data[0],data[BLUECELL_LENGTH_L] + 4);
        Uart1_Data_Send(&Txdata[0], Txdata[BLUECELL_LENGTH_L] + 4);
#if 0 // PYJ.2020.04.22_BEGIN -- 
        for(int i = 0 ; i < data[BLUECELL_LENGTH_L] + 3; i++ ){
//            printf("%x ",data[i]);
        Txdata[0] = data[0];        }
        printf("\r\n");
#endif // PYJ.2020.04.22_END -- 
//        printf("\r\nuint8_t data : %x  data[BLUECELL_LENGTH_L] + 6 : %d\r\n",data[0],data[BLUECELL_LENGTH_L] + 6);
        break;
    case Bluecell_StatusReq:
        if(Initialize == false){
//            printf("Atten Init \r\n");

            Bluecell_DataInit();
            HAL_Delay(10);
            Bluecell_AttenInitialize();

            Initialize = true;
        }
        DataStatusSet();
#if 0 // PYJ.2020.05.28_BEGIN -- 
        Bluecell_StructCpy(&Txdata[0],&bluecell_Currdatastatus.bluecell_header,94);
        Txdata[BLUECELL_LENGTH_L] = 94 - 3;//sizeof(BLUESTATUS_st) - 3;
        Txdata[94 - 2] = STH30_CreateCrc(&Txdata[BLUECELL_TYPE], Txdata[BLUECELL_LENGTH_L]);
#else        
//        printf("bluecell_Currdatastatus.ATT_UL4_H : %0x \r\n",bluecell_Currdatastatus.ATT_UL4_H);
//        printf("bluecell_Currdatastatus.ATT_UL4_L : %0x \r\n",bluecell_Currdatastatus.ATT_UL4_L);

        Bluecell_StructCpy(&Txdata[0],&bluecell_Currdatastatus.bluecell_header,sizeof(BLUESTATUS_st));
        Txdata[BLUECELL_LENGTH_L] = sizeof(BLUESTATUS_st) - 3;//sizeof(BLUESTATUS_st) - 3;
//        Txdata[sizeof(BLUESTATUS_st) - 2] = STH30_CreateCrc(&Txdata[BLUECELL_TYPE], Txdata[BLUECELL_LENGTH_L]);
        Length = sizeof(BLUESTATUS_st) - 4;
        Txdata[BLUECELL_LENGTH_H] = ((Length & 0xFF00) >> 8);
        Txdata[BLUECELL_LENGTH_L] = ((Length & 0x00FF));
        Crcret = ((CRC16_Generate(&Txdata[BLUECELL_TYPE], Length) ));
        Txdata[sizeof(BLUESTATUS_st) - 3] = ((Crcret & 0xFF00) >> 8 );
        Txdata[sizeof(BLUESTATUS_st) - 2] = ((Crcret & 0x00FF));
        
//        printf("PCB Version : %d.%d \r\n",bluecell_Currdatastatus.PCB_Version[0],bluecell_Currdatastatus.PCB_Version[1]);
//        printf("Serial Number : ");
//        for(int a = 0; a < 20; a++){
//            printf("%c",bluecell_Currdatastatus.Serial_Number[a]);
//        }
//        printf("\r\n");
//        printf("Manufacture_Date : ");
//        for(int a = 0; a < 3; a++){
//            printf("%c",bluecell_Currdatastatus.Manufacture_Date[a]);
//        }
//        printf("\r\n");
        
        
#endif // PYJ.2020.05.28_END -- 
#if 0 // PYJ.2020.04.22_BEGIN -- 
        for(int i = 0 ; i < sizeof(BLUESTATUS_st); i++ ){
            printf("%x ",Txdata[i]);
        }
        printf("\r\n");
#endif // PYJ.2020.04.22_END --   
#if 1 // PYJ.2020.07.01_BEGIN -- 
//        printf("===================START=======================\r\n");
//        printf("ALC ON %d                   | AGC ON %d\r\n",bluecell_Currdatastatus.ULO_ALC_ON_OFF,bluecell_Currdatastatus.DLI_AGC_ON_OFF);
//        printf("Shutdown DL ON OFF %d       | Shutdown UL ON OFF %d \r\n",bluecell_Currdatastatus.DLI_Shutdown_ON_OFF,bluecell_Currdatastatus.ULO_Shutdown_ON_OFF);
//        printf("PATH1 %d|Shutdown DL1 CNT %d  | PATH1 %d|Shutdown UL1 CNT %d\r\n",bluecell_Currdatastatus.ATT_DL1_PATH,bluecell_Currdatastatus.DLI_Shutdown_Retry_Count1,bluecell_Currdatastatus.ATT_DL1_PATH,bluecell_Currdatastatus.ULO_Shutdown_Retry_Count1);
//        printf("PATH2 %d|Shutdown DL2 CNT %d  | PATH2 %d|Shutdown UL2 CNT %d\r\n",bluecell_Currdatastatus.ATT_DL2_PATH,bluecell_Currdatastatus.DLI_Shutdown_Retry_Count2,bluecell_Currdatastatus.ATT_UL2_PATH,bluecell_Currdatastatus.ULO_Shutdown_Retry_Count2);
//        printf("PATH3 %d|Shutdown DL3 CNT %d  | PATH3 %d|Shutdown UL3 CNT %d\r\n",bluecell_Currdatastatus.ATT_DL3_PATH,bluecell_Currdatastatus.DLI_Shutdown_Retry_Count3,bluecell_Currdatastatus.ATT_UL3_PATH,bluecell_Currdatastatus.ULO_Shutdown_Retry_Count3);
//        printf("PATH4 %d|Shutdown DL4 CNT %d  | PATH4 %d|Shutdown UL4 CNT %d\r\n",bluecell_Currdatastatus.ATT_DL4_PATH,bluecell_Currdatastatus.DLI_Shutdown_Retry_Count4,bluecell_Currdatastatus.ATT_UL4_PATH,bluecell_Currdatastatus.ULO_Shutdown_Retry_Count4);
//        tempdata = (( bluecell_Currdatastatus.DLI_Level_Low_Threshold_H << 8) & 0xFF00) ;
//        tempdata +=  bluecell_Currdatastatus.DLI_Level_Low_Threshold_L ;
//        tempdata /= 10;    
////        printf("DL Thread Hold : %d \r\n",tempdata);
//        tempdata = (( bluecell_Currdatastatus.ATT_DL1_H << 8) & 0xFF00) ;
//        tempdata +=  bluecell_Currdatastatus.ATT_DL1_L ;
//        tempdata /= 10;    
//        printf("ATT_DL1 : %d \r\n",tempdata);
//        tempdata = (( bluecell_Currdatastatus.ATT_DL4_H << 8) & 0xFF00) ;
//        tempdata +=  bluecell_Currdatastatus.ATT_DL4_L ;
//        tempdata /= 10;    
//        printf("ATT_DL4 : %d \r\n",tempdata);

#if 0 // PYJ.2020.07.03_BEGIN -- 
        tempdata = (( bluecell_Currdatastatus.DLI_FRBT_Atten1_H << 8) & 0xFF00) ;
        tempdata +=  bluecell_Currdatastatus.DLI_FRBT_Atten1_L ;
         tempdata /= 10;    
        printf("FRBT 1 : %d \r\n",tempdata);

        tempdata = (( bluecell_Currdatastatus.DLI_FRBT_Atten2_H << 8) & 0xFF00) ;
        tempdata +=  bluecell_Currdatastatus.DLI_FRBT_Atten2_L ;
         tempdata /= 10;    
        printf("FRBT 2 : %d \r\n",tempdata);

        tempdata = (( bluecell_Currdatastatus.DLI_FRBT_Atten3_H << 8) & 0xFF00) ;
        tempdata +=  bluecell_Currdatastatus.DLI_FRBT_Atten3_L ;
         tempdata /= 10;    
        printf("FRBT 3 : %d \r\n",tempdata);
#endif // PYJ.2020.07.03_END -- 

//        tempdata = (( bluecell_Currdatastatus.DLI_FRBT_Atten4_H << 8) & 0xFF00) ;
//        tempdata +=  bluecell_Currdatastatus.DLI_FRBT_Atten4_L ;
//         tempdata /= 10;    
//        printf("FRBT 4 : %d \r\n",tempdata);
//        printf("DLI_FRBT_D_Day : %d \r\n",FRBT_Day_Inc);
//        printf("DLI_FRBT_Status : %d \r\n",bluecell_Currdatastatus.DLI_FRBT_Status);        
//        tempdata = (( bluecell_Currdatastatus.DLI_Level1_H << 8) & 0xFF00) ;
//        tempdata +=  bluecell_Currdatastatus.DLI_Level1_L ;
////        tempdata *= 0.1;    
//        printf("DLI_Level1 : %d \r\n",tempdata);        
//        tempdata = (( bluecell_Currdatastatus.DLI_Level4_H << 8) & 0xFF00) ;
//        tempdata +=  bluecell_Currdatastatus.DLI_Level4_L ;
////        tempdata *= 0.1;    
//        printf("DLI_Level4 : %d \r\n",tempdata);   
//
////        printf("DL HIGH ALARM : %d \r\n", bluecell_Currdatastatus.DLI_Level_High_Alarm1);
////        printf("DL LOW ALARM : %d \r\n", bluecell_Currdatastatus.DLI_Level_Low_Alarm1);
//        tempdata = (( bluecell_Currdatastatus.DLI_Shutdown_Threshold_H << 8) & 0xFF00) ;
//        tempdata +=  bluecell_Currdatastatus.DLI_Shutdown_Threshold_L ;
//        tempdata /= 10;
////        printf("DL Shutdown Threas : %d \r\n",tempdata);
//        tempdata = (( bluecell_Currdatastatus.ULO_Shutdown_Threshold_H << 8) & 0xFF00) ;
//        tempdata +=  bluecell_Currdatastatus.ULO_Shutdown_Threshold_L ;
//        tempdata /= 10;
//        printf("UL ULO_Shutdown_Threshold : %d \r\n",tempdata);        
//
//        tempdata = (( bluecell_Currdatastatus.ATT_UL1_H << 8) & 0xFF00) ;
//        tempdata +=  bluecell_Currdatastatus.ATT_UL1_L;
//        tempdata /= 10;
//        printf("UL1 ATT_UL1 : %d \r\n",tempdata);
//
//        tempdata = (( bluecell_Currdatastatus.ATT_UL2_H << 8) & 0xFF00) ;
//        tempdata +=  bluecell_Currdatastatus.ATT_UL2_L ;
//        tempdata /= 10;
//        printf("UL2 ATT_UL2 : %d \r\n",tempdata);
//
//        tempdata = (( bluecell_Currdatastatus.ATT_UL3_H << 8) & 0xFF00) ;
//        tempdata +=  bluecell_Currdatastatus.ATT_UL3_L ;
//        tempdata /= 10;
//        printf("UL3 ATT_UL3 : %d \r\n",tempdata);
//
//        tempdata = (( bluecell_Currdatastatus.ATT_UL4_H << 8) & 0xFF00) ;
//        tempdata +=  bluecell_Currdatastatus.ATT_UL4_L ;
//        tempdata /= 10;
//        printf("UL4 ATT_U4 : %d \r\n",tempdata);   
//
//
//        
//        printf("Temp Alarm %d \r\n",bluecell_Currdatastatus.ALARM_TEMP_HIGH);
//        printf("ALC  Alarm 1: %d 2:  %d 3: %d 4: %d\r\n",
//            bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm & ALARM_ALC_P1,
//            bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm & ALARM_ALC_P2,
//            bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm & ALARM_ALC_P3,
//            bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm & ALARM_ALC_P4);
//            ALC_TEMP[0] = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_L;
//            ALC_TEMP[1] = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_L;
//            ALC_TEMP[2] = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_L;
//            ALC_TEMP[3] = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_L;
//            printf("ALC%d ATTEN : %d \r\n",1,ALC_TEMP[0]);
//            printf("ALC%d ATTEN : %d \r\n",2,ALC_TEMP[1]);
//            printf("ALC%d ATTEN : %d \r\n",3,ALC_TEMP[2]);
//            printf("ALC%d ATTEN : %d \r\n",4,ALC_TEMP[3]);
////            printf("AGC  Alarm 1: %d \r\n",bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm & ALARM_AGC_P1);
////            printf("AGC  Alarm 2: %d \r\n",bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm & ALARM_AGC_P2);
////            printf("AGC  Alarm 3: %d \r\n",bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm & ALARM_AGC_P3);
////            printf("AGC  Alarm 4: %d \r\n",bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm & ALARM_AGC_P4);            
//
//        printf("Shutdown DL Alarm 1: %d \r\nShutdown DL Alarm 2:  %d \r\nShutdown DL Alarm 3: %d \r\nShutdown DL Alarm 4: %d\r\n",
//            bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN & ALARM_DLI_SHUTDOWN_P1,
//            bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN & ALARM_DLI_SHUTDOWN_P2,
//            bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN & ALARM_DLI_SHUTDOWN_P3,
//            bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN & ALARM_DLI_SHUTDOWN_P4
//            );
//        printf("Shutdown UL Alarm 1: %d \r\nShutdown UL Alarm 2:  %d \r\nShutdown UL Alarm 3: %d \r\nShutdown UL Alarm 4: %d\r\n",
//            bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN & ALARM_ULO_SHUTDOWN_P1,
//            bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN & ALARM_ULO_SHUTDOWN_P2,
//            bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN & ALARM_ULO_SHUTDOWN_P3,
//            bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN & ALARM_ULO_SHUTDOWN_P4
//        );
//        printf("DLI HIGH Threas High Hold 1: %d \r\nDLI HIGH Threas High Hold2:  %d \r\nDLI HIGH Threas High Hold3: %d \r\nDLI HIGH Threas High Hold4: %d\r\n",
//            bluecell_Currdatastatus.ALARM_DLI_Level & ALARM_DLI_P1_LEVEL_HIGH,
//            bluecell_Currdatastatus.ALARM_DLI_Level & ALARM_DLI_P2_LEVEL_HIGH,
//            bluecell_Currdatastatus.ALARM_DLI_Level & ALARM_DLI_P3_LEVEL_HIGH,
//            bluecell_Currdatastatus.ALARM_DLI_Level & ALARM_DLI_P4_LEVEL_HIGH
//        );        
//
//        printf("DLI LOW Threas High Hold 1: %d \r\nDLI LOW Threas High Hold 2:  %d \r\nDLI LOW Threas High Hold 3: %d \r\nDLI LOW Threas High Hold 4: %d\r\n",
//            bluecell_Currdatastatus.ALARM_DLI_Level & ALARM_DLI_P1_LEVEL_LOW,
//            bluecell_Currdatastatus.ALARM_DLI_Level & ALARM_DLI_P2_LEVEL_LOW,
//            bluecell_Currdatastatus.ALARM_DLI_Level & ALARM_DLI_P3_LEVEL_LOW,
//            bluecell_Currdatastatus.ALARM_DLI_Level & ALARM_DLI_P4_LEVEL_LOW
//        );              
//        printf("ULO HIGH Threas High Hold 1: %d \r\nULO HIGH Threas High Hold 2:  %d \r\nULO HIGH Threas High Hold 3: %d \r\nULO HIGH Threas High Hold 4: %d\r\n",
//            bluecell_Currdatastatus.ALARM_ULO_Level & ALARM_ULO_P1_LEVEL_HIGH,
//            bluecell_Currdatastatus.ALARM_ULO_Level & ALARM_ULO_P2_LEVEL_HIGH,
//            bluecell_Currdatastatus.ALARM_ULO_Level & ALARM_ULO_P3_LEVEL_HIGH,
//            bluecell_Currdatastatus.ALARM_ULO_Level & ALARM_ULO_P4_LEVEL_HIGH
//        );        
//        printf("===================END=======================\r\n");
#endif // PYJ.2020.07.01_END -- 

//        printf("Level DL Alarm %d \r\n");
//        printf("Level DL Alarm %d \r\n");


        Uart1_Data_Send(&Txdata[0], sizeof(BLUESTATUS_st));
        break;
    case Bluecell_StatusSave:
//        printf("Copy Complete");
//        Bluecell_StructCpy(&DataWrite[0],&bluecell_Currdatastatus.bluecell_header,sizeof(BLUESTATUS_st));
//        EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_ATT_BASE),&DataWrite[0],sizeof(BLUESTATUS_st));
//        Bluecell_StructCpy(&Txdata[0],&DataWrite[0],sizeof(BLUESTATUS_st));
//        Txdata[sizeof(BLUESTATUS_st) - 2] = STH30_CreateCrc(&Txdata[BLUECELL_TYPE], sizeof(BLUESTATUS_st) - 3);
//        Uart1_Data_Send(&Txdata[0], sizeof(BLUESTATUS_st));        
        EEPROM_M24C08_Zerowrite(EEPROM_M24C08_ID ,(EEPROM_ATT_BASE));
//        printf("ZERO WRITE COMPLETE");

         NVIC_SystemReset();

        break;

    case Bluecell_DL1_USER: 
        bluecell_Currdatastatus.bluecell_User_DL1_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.bluecell_User_DL1_L = data[BLUECELL_DATA + i++];
        CurrAtten = bluecell_Currdatastatus.bluecell_User_DL1_H << 8 | bluecell_Currdatastatus.bluecell_User_DL1_L;
//        printf("LINE : %d Curr ATTEN : %d \r\n",__LINE__,CurrAtten);
        
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
        break;
    case Bluecell_DL2_USER:
        bluecell_Currdatastatus.bluecell_User_DL2_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.bluecell_User_DL2_L = data[BLUECELL_DATA + i++];
        CurrAtten = bluecell_Currdatastatus.bluecell_User_DL2_H << 8 | bluecell_Currdatastatus.bluecell_User_DL2_L;
//        printf("LINE : %d Curr ATTEN : %d \r\n",__LINE__,CurrAtten);    
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
        break;
    case Bluecell_DL3_USER:
        bluecell_Currdatastatus.bluecell_User_DL3_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.bluecell_User_DL3_L = data[BLUECELL_DATA + i++];
        CurrAtten = bluecell_Currdatastatus.bluecell_User_DL3_H << 8 | bluecell_Currdatastatus.bluecell_User_DL3_L;
//        printf("LINE : %d Curr ATTEN : %d \r\n",__LINE__,CurrAtten);    
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
        break;
    case Bluecell_DL4_USER:     
        bluecell_Currdatastatus.bluecell_User_DL4_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.bluecell_User_DL4_L = data[BLUECELL_DATA + i++];
        CurrAtten = bluecell_Currdatastatus.bluecell_User_DL4_H << 8 | bluecell_Currdatastatus.bluecell_User_DL4_L;
//        printf("LINE : %d Curr ATTEN : %d \r\n",__LINE__,CurrAtten);    
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
        break;

    case Bluecell_UL1_USER: 
        bluecell_Currdatastatus.bluecell_User_UL1_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.bluecell_User_UL1_L = data[BLUECELL_DATA + i++];
        CurrAtten = bluecell_Currdatastatus.bluecell_User_UL1_H << 8 | bluecell_Currdatastatus.bluecell_User_UL1_L;
        if(CurrAtten >= 0 )
            CurrAtten = bluecell_Currdatastatus.bluecell_User_UL1_H =  bluecell_Currdatastatus.bluecell_User_UL1_L = 0;
        else if(CurrAtten <= -50 )
            CurrAtten = - 50;


        bluecell_Currdatastatus.bluecell_User_UL1_H = (CurrAtten & 0xFF00) >> 8;
        bluecell_Currdatastatus.bluecell_User_UL1_L = CurrAtten & 0x00FF;
        
//        printf("LINE : %d Curr ATTEN : %d \r\n",__LINE__,CurrAtten);        
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
        break;
    case Bluecell_UL2_USER:
        bluecell_Currdatastatus.bluecell_User_UL2_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.bluecell_User_UL2_L = data[BLUECELL_DATA + i++];
        CurrAtten = bluecell_Currdatastatus.bluecell_User_UL2_H << 8 | bluecell_Currdatastatus.bluecell_User_UL2_L;
//        printf("LINE : %d Curr ATTEN : %d \r\n",__LINE__,CurrAtten);        
        if(CurrAtten >= 0 )
            CurrAtten = bluecell_Currdatastatus.bluecell_User_UL2_H =  bluecell_Currdatastatus.bluecell_User_UL2_L = 0;
        else if(CurrAtten <= -50 )
            CurrAtten = - 50;    
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

        break;
    case Bluecell_UL3_USER:
        bluecell_Currdatastatus.bluecell_User_UL3_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.bluecell_User_UL3_L = data[BLUECELL_DATA + i++];
        CurrAtten = bluecell_Currdatastatus.bluecell_User_UL3_H << 8 | bluecell_Currdatastatus.bluecell_User_UL3_L;
//        printf("LINE : %d Curr ATTEN : %d \r\n",__LINE__,CurrAtten);        
        if(CurrAtten >= 0 )
            CurrAtten = bluecell_Currdatastatus.bluecell_User_UL3_H =  bluecell_Currdatastatus.bluecell_User_UL3_L = 0;
        else if(CurrAtten <= -50 )
            CurrAtten = - 50;    
    
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

        break;
    case Bluecell_UL4_USER:
        bluecell_Currdatastatus.bluecell_User_UL4_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.bluecell_User_UL4_L = data[BLUECELL_DATA + i++];
        CurrAtten = bluecell_Currdatastatus.bluecell_User_UL4_H << 8 | bluecell_Currdatastatus.bluecell_User_UL4_L;
        if(CurrAtten >= 0 )
            CurrAtten = bluecell_Currdatastatus.bluecell_User_UL4_H =  bluecell_Currdatastatus.bluecell_User_UL4_L = 0;
        else if(CurrAtten <= -50 )
            CurrAtten = - 50;    
        
//        printf("LINE : %d Curr ATTEN : %d \r\n",__LINE__,CurrAtten);        
    
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
        break;

        /*******/
#if 0 // PYJ.2020.05.13_BEGIN -- 
    수정 및 추가
#endif // PYJ.2020.05.13_END -- 
        /*******/
    case Bluecell_TEMP_USER                               :
        bluecell_Currdatastatus.bluecell_User_TEMP_OFFSET = data[BLUECELL_DATA + i++];
//        bluecell_Currdatastatus.bluecell_User_TEMP_OFFSET_L = data[BLUECELL_DATA + i++];
        break;
    case Bluecell_DLI_AGC_ON_OFF:                             
        bluecell_Currdatastatus.DLI_AGC_ON_OFF = data[BLUECELL_DATA + i];
//        printf("AGC ON OFF SET : %d \r\n",bluecell_Currdatastatus.DLI_AGC_ON_OFF);
        if(bluecell_Currdatastatus.DLI_AGC_ON_OFF == 0)
            bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm = 0;
        break;
    case Bluecell_ULO_ALC_ON_OFF:                             
        bluecell_Currdatastatus.ULO_ALC_ON_OFF = data[BLUECELL_DATA + i];
//        printf("ALC ON OFF SET : %d \r\n",bluecell_Currdatastatus.ULO_ALC_ON_OFF);
        if(bluecell_Currdatastatus.ULO_ALC_ON_OFF == 0)
            bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm = 0;    
        break;
    case Bluecell_DLI_AGC_Threshold:                          
        bluecell_Currdatastatus.DLI_AGC_Threshold_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.DLI_AGC_Threshold_L = data[BLUECELL_DATA + i++];
//        tempdata = (( bluecell_Currdatastatus.DLI_AGC_Threshold_H << 8) & 0xFF00) ;
//        tempdata +=  bluecell_Currdatastatus.DLI_AGC_Threshold_L ;
//        tempdata /= 10;
//        printf("tempdata : %d\r\n",tempdata);
//        bluecell_Currdatastatus.DLI_AGC_Threshold_H = ((tempdata & 0xFF00) >> 8);
//        bluecell_Currdatastatus.DLI_AGC_Threshold_L = (tempdata & 0x00FF); 

        break;
    case Bluecell_DLI_AGC_Threshold_Default:                  
        bluecell_Currdatastatus.DLI_AGC_Threshold_default = data[BLUECELL_DATA + i++];
        if(bluecell_Currdatastatus.DLI_AGC_Threshold_default == true){
            bluecell_Currdatastatus.DLI_AGC_Threshold_H = MBIC_DLI_AGC_Threshold_Default_H;
            bluecell_Currdatastatus.DLI_AGC_Threshold_L = MBIC_DLI_AGC_Threshold_Default_L;
            bluecell_Currdatastatus.DLI_AGC_Threshold_default = false;
//            printf("%s : %d \r\n",__func__,__LINE__);
        }
        break;
    case Bluecell_DLI_Shutdown_ON_OFF:                        
        bluecell_Currdatastatus.DLI_Shutdown_ON_OFF = data[BLUECELL_DATA + i++];
//        printf("%s : %d  DLI_Shutdown_ON_OFF : %d \r\n",__func__,__LINE__,bluecell_Currdatastatus.DLI_Shutdown_ON_OFF);
        
        break;
    case Bluecell_DLI_Shutdown_Threshold:                     
        bluecell_Currdatastatus.DLI_Shutdown_Threshold_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.DLI_Shutdown_Threshold_L = data[BLUECELL_DATA + i++];
        tempdata = (( bluecell_Currdatastatus.DLI_Shutdown_Threshold_H << 8) & 0xFF00) ;
        tempdata +=  bluecell_Currdatastatus.DLI_Shutdown_Threshold_L ;
        tempdata /= 10;
//        printf("bluecell_Currdatastatus.DLI_Shutdown_Threshold_H : %x \r\n",bluecell_Currdatastatus.DLI_Shutdown_Threshold_H);
//        printf("bluecell_Currdatastatus.DLI_Shutdown_Threshold_L : %x \r\n",bluecell_Currdatastatus.DLI_Shutdown_Threshold_L);        
//        printf("tempdata : %d\r\n",tempdata);
//        bluecell_Currdatastatus.DLI_Shutdown_Threshold_H = ((tempdata & 0xFF00) >> 8);
//        bluecell_Currdatastatus.DLI_Shutdown_Threshold_L = (tempdata & 0x00FF);
//        printf("tempdata %d \r\n",tempdata);

        break;
    case Bluecell_DLI_Shutdown_Threshold_Default:             
        bluecell_Currdatastatus.DLI_Shutdown_Threshold_Default = data[BLUECELL_DATA + i++];
        if(bluecell_Currdatastatus.DLI_Shutdown_Threshold_Default == true){
            bluecell_Currdatastatus.DLI_Shutdown_Threshold_H = MBIC_DLI_Shutdown_Threshold_Default_H;
            bluecell_Currdatastatus.DLI_Shutdown_Threshold_L = MBIC_DLI_Shutdown_Threshold_Default_L;
        }
//        printf("%s : %d \r\n",__func__,__LINE__);
//      printf("bluecell_Currdatastatus.DLI_Shutdown_Threshold_Default : %d \r\n",bluecell_Currdatastatus.DLI_Shutdown_Threshold_Default);
        break;
    case Bluecell_DLI_Shutdown_Count:                         
        /*NOP*/
        break;
    case Bluecell_DLI_Level_High_Threshold                :   
        bluecell_Currdatastatus.DLI_Level_High_Threshold_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.DLI_Level_High_Threshold_L = data[BLUECELL_DATA + i++];
        tempdata = (( bluecell_Currdatastatus.DLI_Level_High_Threshold_H << 8) & 0xFF00) ;
        tempdata +=  bluecell_Currdatastatus.DLI_Level_High_Threshold_L ;
        tempdata /= 10;
//        printf("DLI_Level_High_Threshold : %d\r\n",tempdata);
//        bluecell_Currdatastatus.DLI_Level_High_Threshold_H = ((tempdata & 0xFF00) >> 8);
//        bluecell_Currdatastatus.DLI_Level_High_Threshold_L = (tempdata & 0x00FF);
        break;
    case Bluecell_DLI_Level_Low_Threshold                 :   
        bluecell_Currdatastatus.DLI_Level_Low_Threshold_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.DLI_Level_Low_Threshold_L = data[BLUECELL_DATA + i++];
        tempdata = (( bluecell_Currdatastatus.DLI_Level_Low_Threshold_H << 8) & 0xFF00) ;
        tempdata +=  bluecell_Currdatastatus.DLI_Level_Low_Threshold_L ;
        tempdata /= 10;
//         printf("DLI_Level_Low_Threshold : %d\r\n",tempdata);
//        bluecell_Currdatastatus.DLI_Level_Low_Threshold_H = ((tempdata & 0xFF00) >> 8);
//        bluecell_Currdatastatus.DLI_Level_Low_Threshold_L = (tempdata & 0x00FF);    

        break;
    case Bluecell_DLI_Level_High_Low_Threshold_default    :   
        bluecell_Currdatastatus.DLI_Level_High_Low_Threshold_default = data[BLUECELL_DATA + i++];
        if(bluecell_Currdatastatus.DLI_Level_High_Low_Threshold_default == true){
            bluecell_Currdatastatus.DLI_Level_High_Threshold_H = MBIC_DLI_Level_High_Threshold_default_H;
            bluecell_Currdatastatus.DLI_Level_High_Threshold_L = MBIC_DLI_Level_High_Threshold_default_L;
            bluecell_Currdatastatus.DLI_Level_Low_Threshold_H = MBIC_DLI_Level_Low_Threshold_default_H;
            bluecell_Currdatastatus.DLI_Level_Low_Threshold_L = MBIC_DLI_Level_Low_Threshold_default_L;
        }
        break;
    case Bluecell_LED_TEST  :                                 
        bluecell_Currdatastatus.LED_TEST = true;
//        printf("%s : %d Value : %d \r\n",__func__,__LINE__,bluecell_Currdatastatus.LED_TEST);
        break;
    case Bluecell_Temperature_Offset                      :   
        bluecell_Currdatastatus.bluecell_User_TEMP_OFFSET = data[BLUECELL_DATA + i++];
//        printf("%s : %d \r\n",__func__,__LINE__);

        break;
    case Bluecell_Temp_High_Threshold                     :   
        bluecell_Currdatastatus.Temp_High_Threshold = data[BLUECELL_DATA + i++];
//        printf("%s : %d Temps_High_Threshold :  %d\r\n",__func__,__LINE__,bluecell_Currdatastatus.Temp_High_Threshold);
//        printf("Temp_High_Threshold : %d :   Det %d \r\n",bluecell_Currdatastatus.Temp_High_Threshold,bluecell_Currdatastatus.DET_TEMP);
//        printf("Temp_High_Alarm : %d \r\n",bluecell_Currdatastatus.Temp_High_Alarm);
//        printf("Txdata : %d \r\n",Txdata[201]);
        break;
    case Bluecell_Temp_High_Threshold_Default             :   
        bluecell_Currdatastatus.Temp_High_Threshold_Default = data[BLUECELL_DATA + i++];
        if(bluecell_Currdatastatus.Temp_High_Threshold_Default == true){
            bluecell_Currdatastatus.Temp_High_Threshold_Default = MBIC_Temp_High_Threshold_Default;
        }
//        printf("%s : %d \r\n",__func__,__LINE__);
        break;
    case Bluecell_ULO_Level_High_Threshold                :   
        bluecell_Currdatastatus.ULO_Level_High_Threshold_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.ULO_Level_High_Threshold_L = data[BLUECELL_DATA + i++];
        tempdata = (( bluecell_Currdatastatus.ULO_Level_High_Threshold_H << 8) & 0xFF00) ;
        tempdata +=  bluecell_Currdatastatus.ULO_Level_High_Threshold_L ;
        tempdata /= 10;
//         printf("ULO_Level_High_Threshold : %d\r\n",tempdata);
//        bluecell_Currdatastatus.ULO_Level_High_Threshold_H = ((tempdata & 0xFF00) >> 8);
//        bluecell_Currdatastatus.ULO_Level_High_Threshold_L = (tempdata & 0x00FF);   

       

        break;
    case Bluecell_ULO_Level_High_Threshold_default        :   
        bluecell_Currdatastatus.ULO_Level_High_Threshold_default = data[BLUECELL_DATA + i++];
        if(bluecell_Currdatastatus.ULO_Level_High_Threshold_default == true){
            bluecell_Currdatastatus.ULO_Level_High_Threshold_H = MBIC_ULO_Level_High_Threshold_Default_H;
            bluecell_Currdatastatus.ULO_Level_High_Threshold_L = MBIC_ULO_Level_High_Threshold_Default_L;
        }
        break;
    case Bluecell_ULO_ALC_Threshold                       :   
        bluecell_Currdatastatus.ULO_ALC_Threshold_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.ULO_ALC_Threshold_L = data[BLUECELL_DATA + i++];
        tempdata = (( bluecell_Currdatastatus.ULO_ALC_Threshold_H << 8) & 0xFF00) ;
        tempdata +=  bluecell_Currdatastatus.ULO_ALC_Threshold_L ;
        tempdata /= 10;
//        printf("ULO_ALC_Threshold : %d\r\n",tempdata);
//        bluecell_Currdatastatus.ULO_ALC_Threshold_H = ((tempdata & 0xFF00) >> 8);
//        bluecell_Currdatastatus.ULO_ALC_Threshold_L = (tempdata & 0x00FF);

        break;
    case Bluecell_ULO_ALC_Threshold_Default               :   
        bluecell_Currdatastatus.ULO_ALC_Threshold_Default = data[BLUECELL_DATA + i++];
        if(bluecell_Currdatastatus.ULO_Level_High_Threshold_default == true){
            bluecell_Currdatastatus.ULO_ALC_Threshold_H = MBIC_ULO_ALC_Threshold_Default_H;
            bluecell_Currdatastatus.ULO_ALC_Threshold_L = MBIC_ULO_ALC_Threshold_Default_L;
        }
//        printf("%s : %d \r\n",__func__,__LINE__);

        break;
    case Bluecell_ULO_Shutdown_ON_OFF                     :   
//        printf("%s Bluecell_ULO_Shutdown_ON_OFF : %d \r\n",__func__,bluecell_Currdatastatus.ULO_Shutdown_ON_OFF );
        bluecell_Currdatastatus.ULO_Shutdown_ON_OFF = data[BLUECELL_DATA + i++];

        break;
    case Bluecell_ULO_Shutdown_Threshold                  :   
        bluecell_Currdatastatus.ULO_Shutdown_Threshold_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.ULO_Shutdown_Threshold_L = data[BLUECELL_DATA + i++];
        tempdata = (( bluecell_Currdatastatus.ULO_Shutdown_Threshold_H << 8) & 0xFF00) ;
        tempdata +=  bluecell_Currdatastatus.ULO_Shutdown_Threshold_L ;
        tempdata /= 10;
//        printf("tempdata : %d\r\n",tempdata);
//        bluecell_Currdatastatus.ULO_Shutdown_Threshold_H = ((tempdata & 0xFF00) >> 8);
//        bluecell_Currdatastatus.ULO_Shutdown_Threshold_L = (tempdata & 0x00FF);     

        break;
    case Bluecell_ULO_Shutdown_Threshold_Default          :   
        bluecell_Currdatastatus.ULO_Shutdown_Threshold_Default = data[BLUECELL_DATA + i++];
        if(bluecell_Currdatastatus.ULO_Level_High_Threshold_default == true){
            bluecell_Currdatastatus.ULO_Shutdown_Threshold_H = MBIC_ULO_Shutdown_Threshold_Default_H;
            bluecell_Currdatastatus.ULO_Shutdown_Threshold_L = MBIC_ULO_Shutdown_Threshold_Default_L;
        }
//         printf("%s : %d \r\n",__func__,__LINE__);
        break;
    case Bluecell_ULO_Shutdown_Retry_Count                :   
        break;
    case Bluecell_Alarm_Mask:
        bluecell_Currdatastatus.ALARM_MASK1 = (data[BLUECELL_DATA + i+ 1] * 0.1);
//        printf("%s : %d   ALARM_MASK1 : %d \r\n",__func__,__LINE__,bluecell_Currdatastatus.ALARM_MASK1);
//        printf("Txdata : %d \r\n",Txdata[107]);
        break;
    case BLuecell_ATT_ALC1:
        bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_L = data[BLUECELL_DATA + i++];
        CurrAtten = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_L;
//        printf("LINE : %d Curr ATTEN : %d \r\n",__LINE__,CurrAtten);     
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

        break;
    case BLuecell_ATT_ALC2:
        bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_L = data[BLUECELL_DATA + i++];
        CurrAtten = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_L;
//        printf("LINE : %d Curr ATTEN : %d \r\n",__LINE__,CurrAtten);        
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

        break;
    case BLuecell_ATT_ALC3:
        bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_L = data[BLUECELL_DATA + i++];
        CurrAtten = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_L;
//        printf("LINE : %d Curr ATTEN : %d \r\n",__LINE__,CurrAtten);        
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

        break;
    case BLuecell_ATT_ALC4:
        bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_H = data[BLUECELL_DATA + i++];
        bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_L = data[BLUECELL_DATA + i++];
        CurrAtten = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_L;
//        printf("LINE : %d Curr ATTEN : %d \r\n",__LINE__,CurrAtten);        
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

        break;
    case Bluecell_BankSelect:
        bluecell_Currdatastatus.CPU_Bank_Select = data[BLUECELL_DATA + i++];
        if(bluecell_Currdatastatus.CPU_Bank_Select == HFR_AUTO_SEL){
//            printf("Curr Bank : %d \r\n",bluecell_Currdatastatus.CPU_Current_Bank);
            if(bluecell_Currdatastatus.CPU_Current_Bank == HFR_BANK1_SEL){
                bluecell_Currdatastatus.CPU_Bank_Select = HFR_BANK2_SEL;
            }else{
                bluecell_Currdatastatus.CPU_Bank_Select = HFR_BANK1_SEL;
            }
        }        
//        printf("bluecell_Currdatastatus.CPU_Bank_Select : %d \r\n",bluecell_Currdatastatus.CPU_Bank_Select);
        break;
    case Bluecell_TimeSetting:
        TimeSetting(&data[BLUECELL_CRCINDEX]);
#if 0 // PYJ.2020.07.03_BEGIN -- 
            for(int i = 0; i < DLI_FRBT_Time_Index_Max; i++){
                FRBT_Day[DLI_FRBT_Time_Year + i] = data[BLUECELL_CRCINDEX + i]; /* Curr day */
//                printf("data[BLUECELL_CRCINDEX + i] : %d \r\n",data[BLUECELL_CRCINDEX + i]);
            }
            printf("BLUECELL TIME APPLY : %d - %d - %d - %d - %d - %d \r\n",
            FRBT_Day[DLI_FRBT_Time_Year],
            FRBT_Day[DLI_FRBT_Time_Month],
            FRBT_Day[DLI_FRBT_Time_Day],
            FRBT_Day[DLI_FRBT_Time_Hour],
            FRBT_Day[DLI_FRBT_Time_Minute],
            FRBT_Day[DLI_FRBT_Time_Second]);
            
            if(FRBT_Day[DLI_FRBT_Time_Day] != PrevFRBT_Day[DLI_FRBT_Time_Day]){
//                printf("FRBT_Day[DLI_FRBT_Time_Day] : %d  PrevFRBT_Day[DLI_FRBT_D_Day] : %d \r\n",
//                  FRBT_Day[DLI_FRBT_Time_Day] ,
//                  PrevFRBT_Day[DLI_FRBT_Time_Day]);
#if 1 // PYJ.2020.07.02_BEGIN -- 
                FRBT_Day_Inc++;
                bluecell_Currdatastatus.DLI_FRBT_Status = FRBT_TRACKING;
#else
            bluecell_Currdatastatus.DLI_FRBT_D_Day = 7;
            bluecell_Currdatastatus.DLI_FRBT_Status = FRBT_TRACKING;
#endif // PYJ.2020.07.02_END -- 
                printf("D day Plus : %d \r\n",FRBT_Day_Inc);
            }
            
            for(int i = 0; i < DLI_FRBT_Time_Index_Max; i++){
                PrevFRBT_Day[DLI_FRBT_Time_Year + i] = FRBT_Day[DLI_FRBT_Time_Year + i]; /* Curr day */
            }   
//            printf("BLUECELL TIME APPLY : %d - %d - %d - %d - %d - %d \r\n",
//            PrevFRBT_Day[DLI_FRBT_Time_Year],
//            PrevFRBT_Day[DLI_FRBT_Time_Month],
//            PrevFRBT_Day[DLI_FRBT_Time_Day],
//            PrevFRBT_Day[DLI_FRBT_Time_Hour],
//            PrevFRBT_Day[DLI_FRBT_Time_Minute],
//            PrevFRBT_Day[DLI_FRBT_Time_Second]);            
//            printf("FRBT_Day[DLI_FRBT_Time_Day] : %d  PrevFRBT_Day[DLI_FRBT_D_Day] : %d \r\n",
//            FRBT_Day[DLI_FRBT_Time_Day] ,
//            PrevFRBT_Day[DLsI_FRBT_Time_Day]);
        }
        printf("Time Set Complete\r\n");
#endif // PYJ.2020.07.03_END -- 
        break;
     case Bluecell_Factory_Set:
         bluecell_Currdatastatus.Factory_Set_Initialization = data[BLUECELL_DATA + i++];
//         printf("Factory Set\r\n");
         if(bluecell_Currdatastatus.Factory_Set_Initialization == 1){
            Factory_Set();
         }
         break;
    case Bluecell_CarrierOnOff:
        bluecell_Currdatastatus.Carrier_ON_OFF = data[BLUECELL_DATA + i++]; 
        Carrier_ONOFF(bluecell_Currdatastatus.Carrier_ON_OFF);
        printf("Carrier %d \r\n",bluecell_Currdatastatus.Carrier_ON_OFF);
    break;
    case Bluecell_PCBVersionSet:
//        printf("Bluecell_PCBVersionSet\r\n");
        for(int i = 0; i < 2; i++){
//            printf("%d",data[BLUECELL_DATA + i]);
            bluecell_Currdatastatus.PCB_Version[i] = data[BLUECELL_DATA + i]; 
        }
        break;
    case Bluecell_SerialNumberSet:
//        printf("Bluecell_SerialNumberSet\r\n");
    for(int i = 0; i < 20; i++){
//        printf("%c",data[BLUECELL_DATA + i]);
        bluecell_Currdatastatus.Serial_Number[i] = data[BLUECELL_DATA + i]; 
    }
         
        break;
    case Bluecell_ManufactureDateSet:
        for(int i = 0; i < 3; i++){
//            printf("Manufacture_Date : %d \r\n",data[BLUECELL_DATA + i]);
            bluecell_Currdatastatus.Manufacture_Date[i] = data[BLUECELL_DATA + i]; 
        }
        break;
    case Bluecell_DL_Det_ALL_Offset:   
        bluecell_Currdatastatus.DL_Det_ALL_Offset = data[BLUECELL_DATA]; 
//        printf("DL_Det_ALL_Offset : %d \r\n",bluecell_Currdatastatus.DL_Det_ALL_Offset);
        break;
    case Bluecell_UL_Det_Path1_Offset: 
        bluecell_Currdatastatus.UL_Det_Path_Offset[0] = data[BLUECELL_DATA]; 
//        printf("Bluecell_UL_Det_Path1_Offset : %d \r\n",bluecell_Currdatastatus.UL_Det_Path_Offset[0]);
        break; 
    case Bluecell_UL_Det_Path2_Offset:   
        bluecell_Currdatastatus.UL_Det_Path_Offset[1] = data[BLUECELL_DATA]; 
//        printf("Bluecell_UL_Det_Path2_Offset : %d \r\n",bluecell_Currdatastatus.UL_Det_Path_Offset[1]);        
        break;
    case Bluecell_UL_Det_Path3_Offset:    
        bluecell_Currdatastatus.UL_Det_Path_Offset[2] = data[BLUECELL_DATA]; 
//        printf("Bluecell_UL_Det_Path3_Offset : %d \r\n",bluecell_Currdatastatus.UL_Det_Path_Offset[2]);        
        break;
    case Bluecell_UL_Det_Path4_Offset:
        bluecell_Currdatastatus.UL_Det_Path_Offset[3] = data[BLUECELL_DATA]; 
//        printf("Bluecell_UL_Det_Path4_Offset : %d \r\n",bluecell_Currdatastatus.UL_Det_Path_Offset[3]);        
        break;
    case Bluecell_Temp_Shutdown_Path_ON_OFF:
         bluecell_Currdatastatus.Path_TempShutdown_Set = data[BLUECELL_DATA];
         printf("data[BLUECELL_DATA] : %d \r\n",data[BLUECELL_DATA]);
         printf("Path_TempShutdown_Set : %d \r\n",bluecell_Currdatastatus.Path_TempShutdown_Set);    
         Temp_Shutdown_ONOFF(bluecell_Currdatastatus.Path_TempShutdown_Set);
        break;
  }
  
  if(datatype != Bluecell_StatusReq
  && datatype != Bluecell_LED_TEST
  && datatype != ATT_TableSet
  && datatype != ATT_TableGet
  && datatype != Bluecell_Temp_Shutdown_Path_ON_OFF)
  
  {
//      Bluecell_StructCpy(&DataWrite[0],&bluecell_Currdatastatus.bluecell_header,sizeof(BLUESTATUS_st));
      
      EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_WINDOW_STATUS_ADDRESDS),&bluecell_Currdatastatus.bluecell_header,sizeof(BLUESTATUS_st));

//      EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_WINDOW_STATUS_ADDRESDS),&DataWrite[0],sizeof(BLUESTATUS_st));
//      EEPROM_M24C08_Read(EEPROM_M24C08_ID,EEPROM_WINDOW_STATUS_ADDRESDS,&bluecell_Currdatastatus.bluecell_header,sizeof(BLUESTATUS_st) );
//      Bluecell_StructCpy(&Txdata[0],&DataWrite[0],sizeof(BLUESTATUS_st));
//      Txdata[sizeof(BLUESTATUS_st) - 2] = STH30_CreateCrc(&Txdata[BLUECELL_TYPE], sizeof(BLUESTATUS_st) - 3);
//      Uart1_Data_Send(&Txdata[0], sizeof(BLUESTATUS_st));        
  }
  return true;
}
void DataStatusSet(void){
        bluecell_Currdatastatus.bluecell_header = 0xbe;
        bluecell_Currdatastatus.bluecell_type = Bluecell_StatusReq;
        bluecell_Currdatastatus.bluecell_length = 94 - 3;
        bluecell_Currdatastatus.bluecell_crcindex = 94 - 2 + 1;
//        bluecell_Currdatastatus.ATT_DL1_PATH = HAL_GPIO_ReadPin(PATH_EN_DL1_GPIO_Port,PATH_EN_DL1_Pin);//CLOCK;        
//        bluecell_Currdatastatus.ATT_DL2_PATH = HAL_GPIO_ReadPin(PATH_EN_DL2_GPIO_Port,PATH_EN_DL2_Pin);//CLOCK;
//        bluecell_Currdatastatus.ATT_DL3_PATH = HAL_GPIO_ReadPin(PATH_EN_DL3_GPIO_Port,PATH_EN_DL3_Pin);//CLOCK;
//        bluecell_Currdatastatus.ATT_DL4_PATH = HAL_GPIO_ReadPin(PATH_EN_DL4_GPIO_Port,PATH_EN_DL4_Pin);//CLOCK;
//        bluecell_Currdatastatus.ATT_UL1_PATH = HAL_GPIO_ReadPin(PATH_EN_UL1_GPIO_Port,PATH_EN_UL1_Pin);//CLOCK;
//        bluecell_Currdatastatus.ATT_UL2_PATH = HAL_GPIO_ReadPin(PATH_EN_UL2_GPIO_Port,PATH_EN_UL2_Pin);//CLOCK;
//        bluecell_Currdatastatus.ATT_UL3_PATH = HAL_GPIO_ReadPin(PATH_EN_UL3_GPIO_Port,PATH_EN_UL3_Pin);//CLOCK;
//        bluecell_Currdatastatus.ATT_UL4_PATH = HAL_GPIO_ReadPin(PATH_EN_UL4_GPIO_Port,PATH_EN_UL4_Pin);//CLOCK;
        bluecell_Currdatastatus.bluecell_etx = 0xeb;
             
        
     
}

void HFR_TypeInit(){
    bluecell_Currdatastatus.Type =   HAL_GPIO_ReadPin(UNIT_ID0_GPIO_Port,UNIT_ID0_Pin);
    bluecell_Currdatastatus.Type +=  HAL_GPIO_ReadPin(UNIT_ID1_GPIO_Port,UNIT_ID1_Pin) << 1;
    bluecell_Currdatastatus.Type +=  HAL_GPIO_ReadPin(UNIT_ID2_GPIO_Port,UNIT_ID2_Pin) << 2;
    bluecell_Currdatastatus.Type +=  HAL_GPIO_ReadPin(UNIT_ID3_GPIO_Port,UNIT_ID3_Pin) << 3;
//    printf("0: %d \r\n",HAL_GPIO_ReadPin(UNIT_ID0_GPIO_Port,UNIT_ID0_Pin));
//    printf("1: %d \r\n",HAL_GPIO_ReadPin(UNIT_ID1_GPIO_Port,UNIT_ID1_Pin));
//    printf("2: %d \r\n",HAL_GPIO_ReadPin(UNIT_ID2_GPIO_Port,UNIT_ID2_Pin));
//    printf("3: %d \r\n",HAL_GPIO_ReadPin(UNIT_ID3_GPIO_Port,UNIT_ID3_Pin));   
    switch(bluecell_Currdatastatus.Type){
        case BLUECELL_3_7G: bluecell_Currdatastatus.Type = 0x80;bluecell_Currdatastatus.Carrier_ID = 0x01 ;break;//printf("Type BLUECELL_3_7G  Ready....\r\n"); break;
        case BLUECELL_3_8G: bluecell_Currdatastatus.Type = 0x81;bluecell_Currdatastatus.Carrier_ID = 0x02;break;// printf("Type BLUECELL_3_8G  Ready....\r\n");break;
        case BLUECELL_3_9G: bluecell_Currdatastatus.Type = 0x82;bluecell_Currdatastatus.Carrier_ID = 0x04;break;//printf("Type BLUECELL_3_9G  Ready....\r\n"); break;
        case BLUECELL_4_0G: bluecell_Currdatastatus.Type = 0x83;bluecell_Currdatastatus.Carrier_ID = 0x03;break;// printf("Type BLUECELL_4_0G  Ready....\r\n");break;
        case BLUECELL_4_1G: bluecell_Currdatastatus.Type = 0x84;bluecell_Currdatastatus.Carrier_ID = 0x02;break; //printf("Type BLUECELL_4_1G  Ready....\r\n");break;
        case BLUECELL_4_6G: bluecell_Currdatastatus.Type = 0x85;bluecell_Currdatastatus.Carrier_ID = 0x01;break;// printf("Type BLUECELL_4_6G  Ready....\r\n");break;
        case BLUECELL_4_7G: bluecell_Currdatastatus.Type = 0x86;bluecell_Currdatastatus.Carrier_ID = 0x00;break;// printf("Type BLUECELL_4_7G  Ready....\r\n");break;
        case BLUECELL_4_8G: bluecell_Currdatastatus.Type = 0x87;bluecell_Currdatastatus.Carrier_ID = 0x00;break;// printf("Type BLUECELL_4_8G  Ready....\r\n");break;
        case BLUECELL_4_9G: bluecell_Currdatastatus.Type = 0x88;bluecell_Currdatastatus.Carrier_ID = 0x00;break;// printf("Type BLUECELL_4_9G  Ready....\r\n");break;
        case BLUECELL_5_0G: bluecell_Currdatastatus.Type = 0x89;bluecell_Currdatastatus.Carrier_ID = 0x00;break;// printf("Type BLUECELL_5_0G  Ready....\r\n");break;
        case BLUECELL_DCM : bluecell_Currdatastatus.Type = 0x8A;bluecell_Currdatastatus.Carrier_ID = 0x01;break;//printf("Type BLUECELL_DCM  Ready....\r\n"); break;
        case BLUECELL_SBM : bluecell_Currdatastatus.Type = 0x8B;bluecell_Currdatastatus.Carrier_ID = 0x03;break;// printf("Type BLUECELL_SBM  Ready....\r\n");break;
        case BLUECELL_KDDI: bluecell_Currdatastatus.Type = 0x8C;bluecell_Currdatastatus.Carrier_ID = 0x02;break;//printf("Type BLUECELL_KDDI  Ready....\r\n"); break;
//        default : printf("Type %x  Ready....\r\n",bluecell_Currdatastatus.Type);break;
    }
//    printf("Type %x  Ready....\r\n",bluecell_Currdatastatus.Type);
//    printf("bluecell_Currdatastatus.Type : %02x \r\n",bluecell_Currdatastatus.Type);
}
 void Bluecell_DataInit(){
/*
    MBIC Request List 
    Turn off all paths at boot
 */
   
    MBIC_UL_ShutdownCount = &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count1;   
    MBIC_DL_ShutdownCount = &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count1;   

    PrevMBIC_UL_ShutdownCount = &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count1;
    PrevMBIC_DL_ShutdownCount = &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count1;   
    for(int i = 0; i < DET_Alarm_DL_Shutdown_Index_MAX; i++){
        PrevMBIC_UL_ShutdownCount[i] = 0xFF;
        PrevMBIC_DL_ShutdownCount[i] = 0xFF;        
    }
#if 1 // PYJ.2020.06.17_BEGIN -- 
    printf("bluecell_Currdatastatus.Path_TempSave_Bit : %x \r\n",bluecell_Currdatastatus.Path_TempSave_Bit);
    if(bluecell_Currdatastatus.Path_TempSave_Bit & 0x80)
        bluecell_Currdatastatus.ATT_DL1_PATH = true;
    else
        bluecell_Currdatastatus.ATT_DL1_PATH = false;

    if(bluecell_Currdatastatus.Path_TempSave_Bit & 0x40)
        bluecell_Currdatastatus.ATT_DL2_PATH = true;
    else
        bluecell_Currdatastatus.ATT_DL2_PATH = false;

    if(bluecell_Currdatastatus.Path_TempSave_Bit & 0x20)
        bluecell_Currdatastatus.ATT_DL3_PATH = true;
    else
        bluecell_Currdatastatus.ATT_DL3_PATH = false;

    if(bluecell_Currdatastatus.Path_TempSave_Bit & 0x10)
        bluecell_Currdatastatus.ATT_DL4_PATH = true;
    else
        bluecell_Currdatastatus.ATT_DL4_PATH = false;

    if(bluecell_Currdatastatus.Path_TempSave_Bit & 0x08)
        bluecell_Currdatastatus.ATT_UL1_PATH = true;
    else
        bluecell_Currdatastatus.ATT_UL1_PATH = false;

    if(bluecell_Currdatastatus.Path_TempSave_Bit & 0x04)
        bluecell_Currdatastatus.ATT_UL2_PATH = true;
    else
        bluecell_Currdatastatus.ATT_UL2_PATH = false;

    if(bluecell_Currdatastatus.Path_TempSave_Bit & 0x02)
        bluecell_Currdatastatus.ATT_UL3_PATH = true;
    else
        bluecell_Currdatastatus.ATT_UL3_PATH = false;

    if(bluecell_Currdatastatus.Path_TempSave_Bit & 0x01)
        bluecell_Currdatastatus.ATT_UL4_PATH = true;
    else
        bluecell_Currdatastatus.ATT_UL4_PATH = false;

    HAL_GPIO_WritePin(PATH_EN_DL1_GPIO_Port,PATH_EN_DL1_Pin,bluecell_Currdatastatus.ATT_DL1_PATH);   
    HAL_GPIO_WritePin(PATH_EN_DL2_GPIO_Port,PATH_EN_DL2_Pin,bluecell_Currdatastatus.ATT_DL2_PATH);   
    HAL_GPIO_WritePin(PATH_EN_DL3_GPIO_Port,PATH_EN_DL3_Pin,bluecell_Currdatastatus.ATT_DL3_PATH);   
    HAL_GPIO_WritePin(PATH_EN_DL4_GPIO_Port,PATH_EN_DL4_Pin,bluecell_Currdatastatus.ATT_DL4_PATH);   

    
    HAL_GPIO_WritePin(PATH_EN_UL1_GPIO_Port,PATH_EN_UL1_Pin,bluecell_Currdatastatus.ATT_UL1_PATH);   
    HAL_GPIO_WritePin(PATH_EN_UL2_GPIO_Port,PATH_EN_UL2_Pin,bluecell_Currdatastatus.ATT_UL2_PATH);   
//    printf("bluecell_Currdatastatus.ATT_UL2_PATH : %d \r\n",bluecell_Currdatastatus.ATT_UL2_PATH);
    HAL_GPIO_WritePin(PATH_EN_UL3_GPIO_Port,PATH_EN_UL3_Pin,bluecell_Currdatastatus.ATT_UL3_PATH);   
    HAL_GPIO_WritePin(PATH_EN_UL4_GPIO_Port,PATH_EN_UL4_Pin,bluecell_Currdatastatus.ATT_UL4_PATH);   
#endif // PYJ.2020.06.17_END -- 
    
    HAL_Delay(10);
//    printf("UL 1 H : %x \r\n",bluecell_Currdatastatus.ATT_UL4_H);
//    printf("UL 1 L : %x \r\n",bluecell_Currdatastatus.ATT_UL4_L);    
    CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
    if(bluecell_Currdatastatus.Selftest1==0){
//        printf("Selftest1 : 0 \r\n");
        HAL_GPIO_WritePin(_PATH_SW1_GPIO_Port,_PATH_SW1_Pin,GPIO_PIN_RESET);//CLOCK
        HAL_GPIO_WritePin(PATH_SW1_GPIO_Port,PATH_SW1_Pin,GPIO_PIN_SET);//CLOCK
    }else{
//        printf("Selftest1 : 1 \r\n");
        HAL_GPIO_WritePin(_PATH_SW1_GPIO_Port,_PATH_SW1_Pin,GPIO_PIN_SET);//CLOCK
        HAL_GPIO_WritePin(PATH_SW1_GPIO_Port,PATH_SW1_Pin,GPIO_PIN_RESET);//CLOCK
    }
    if(bluecell_Currdatastatus.Selftest2==0){
//                printf("Selftest1 : 0 \r\n");
        HAL_GPIO_WritePin(_PATH_SW2_GPIO_Port,_PATH_SW2_Pin,GPIO_PIN_RESET);//CLOCK
        HAL_GPIO_WritePin(PATH_SW2_GPIO_Port,PATH_SW2_Pin,GPIO_PIN_SET);//CLOCK
    }else{
//        printf("Selftest2 : 1 \r\n");
        HAL_GPIO_WritePin(_PATH_SW2_GPIO_Port,_PATH_SW2_Pin,GPIO_PIN_SET);//CLOCK
        HAL_GPIO_WritePin(PATH_SW2_GPIO_Port,PATH_SW2_Pin,GPIO_PIN_RESET);//CLOCK
    }
    if(bluecell_Currdatastatus.Selftest3==0){
//                printf("Selftest1 : 0 \r\n");
        HAL_GPIO_WritePin(_PATH_SW3_GPIO_Port,_PATH_SW3_Pin,GPIO_PIN_RESET);//CLOCK
        HAL_GPIO_WritePin(PATH_SW3_GPIO_Port,PATH_SW3_Pin,GPIO_PIN_SET);//CLOCK
    }else{
//                printf("Selftest3 : 1 \r\n");
        HAL_GPIO_WritePin(_PATH_SW3_GPIO_Port,_PATH_SW3_Pin,GPIO_PIN_SET);//CLOCK
        HAL_GPIO_WritePin(PATH_SW3_GPIO_Port,PATH_SW3_Pin,GPIO_PIN_RESET);//CLOCK
    }
    if(bluecell_Currdatastatus.Selftest4==0){
//                printf("Selftest4 : 0 \r\n");
        HAL_GPIO_WritePin(_PATH_SW4_GPIO_Port,_PATH_SW4_Pin,GPIO_PIN_RESET);//CLOCK
        HAL_GPIO_WritePin(PATH_SW4_GPIO_Port,PATH_SW4_Pin,GPIO_PIN_SET);//CLOCK
    }else{
//                printf("Selftest4 : 1 \r\n");
        HAL_GPIO_WritePin(_PATH_SW4_GPIO_Port,_PATH_SW4_Pin,GPIO_PIN_SET);//CLOCK
        HAL_GPIO_WritePin(PATH_SW4_GPIO_Port,PATH_SW4_Pin,GPIO_PIN_RESET);//CLOCK
    }


    DataStatusSet();
}


uint32_t MBIC_DataSend(uint8_t* data){
    uint32_t i = 0;
    uint32_t Length = 0;
    uint16_t Crcret = 0;
    int16_t tmpdata = 0;
     uint32_t HeaderLength = 79;
	

    
    /*ALARM BIT LIST*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = Alarm_Bit_List;
    Length += 10;
    data[MBIC_PAYLOADSTART + i++] = 10; // LENGTH
    

    data[MBIC_PAYLOADSTART + i++] = 0x80;
    data[MBIC_PAYLOADSTART + i++] = 0xFF;
    data[MBIC_PAYLOADSTART + i++] = 0xFF;
    data[MBIC_PAYLOADSTART + i++] = 0x0F;
    data[MBIC_PAYLOADSTART + i++] = 0xFF;
     if(bluecell_Currdatastatus.Carrier_ON_OFF == false 
     || bluecell_Currdatastatus.ALARM_TESTMODE == true){/*Carrier OFF -> Alarm OFF*/

        if(bluecell_Currdatastatus.ALARM_TESTMODE == false){
            data[MBIC_PAYLOADSTART + i++] = 0;
            data[MBIC_PAYLOADSTART + i++] = 0;
            data[MBIC_PAYLOADSTART + i++] = 0;
            data[MBIC_PAYLOADSTART + i++] = 0;
            data[MBIC_PAYLOADSTART + i++] = 0;
        }else{
            data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_Test_Dummy1;
            data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_Test_Dummy2;
            data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_Test_Dummy3;
            data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_Test_Dummy4;
            data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_Test_Dummy5;
        }
//        printf("Alarm Test Mode ON \r\n");
     }else{
        if(bluecell_Currdatastatus.ALARM_MASK1 != false)
            data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_TEMP_HIGH;
        else
            data[MBIC_PAYLOADSTART + i++] = 0;
        
#if 0 // PYJ.2020.08.18_BEGIN -- 
        if(bluecell_Currdatastatus.ALARM_MASK2 != false)
            data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_DLI_Level;
        else
            data[MBIC_PAYLOADSTART + i++] = 0;

        if(bluecell_Currdatastatus.ALARM_MASK3 != false)
            data[MBIC_PAYLOADSTART + i++] = (bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm & 0xF0 )
                                          | (bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN & 0x0F);
        else
            data[MBIC_PAYLOADSTART + i++] = 0;    
        if(bluecell_Currdatastatus.ALARM_MASK4 != false)                                      
            data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_ULO_Level;
        else
        data[MBIC_PAYLOADSTART + i++] = 0;

        if(bluecell_Currdatastatus.ALARM_MASK5 != false)
            data[MBIC_PAYLOADSTART + i++] = (bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm & 0xF0)
                                           |(bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN & 0x0F);
        else
            data[MBIC_PAYLOADSTART + i++] = 0;     
#else
//        printf("bluecell_Currdatastatus.ALARM_DLI_Level : %x \r\n",bluecell_Currdatastatus.ALARM_DLI_Level);
//        printf("bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm : %x \r\n",bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm);
//        printf("bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN : %x \r\n",bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN);
//        printf("bluecell_Currdatastatus.ALARM_ULO_Level : %x \r\n",bluecell_Currdatastatus.ALARM_ULO_Level);
//        printf("bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm : %x \r\n",bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm);
//        printf("bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN : %x \r\n",bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN);        
        data[MBIC_PAYLOADSTART + i++] = 0;

        if(bluecell_Currdatastatus.ALARM_MASK2 & 0x80){
             data[MBIC_PAYLOADSTART + i - 1] = (bluecell_Currdatastatus.ALARM_DLI_Level & 0x80);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &= ~0x80; 
        }
        if(bluecell_Currdatastatus.ALARM_MASK2 & 0x40){
             data[MBIC_PAYLOADSTART + i - 1] |= (bluecell_Currdatastatus.ALARM_DLI_Level & 0x40);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1 ] &=  ~0x40;
        }
        if(bluecell_Currdatastatus.ALARM_MASK2 & 0x20){
             data[MBIC_PAYLOADSTART + i - 1 ] |= (bluecell_Currdatastatus.ALARM_DLI_Level & 0x20);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &=  ~0x20;
        }
        
        if(bluecell_Currdatastatus.ALARM_MASK2 & 0x10){
             data[MBIC_PAYLOADSTART + i - 1] |= (bluecell_Currdatastatus.ALARM_DLI_Level & 0x10);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &=  ~0x10;
        }
        
        if(bluecell_Currdatastatus.ALARM_MASK2 & 0x08){
             data[MBIC_PAYLOADSTART + i - 1] |= (bluecell_Currdatastatus.ALARM_DLI_Level & 0x08);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &= ~0x08; 
        }

        if(bluecell_Currdatastatus.ALARM_MASK2 & 0x04){
             data[MBIC_PAYLOADSTART + i - 1] |= (bluecell_Currdatastatus.ALARM_DLI_Level & 0x04);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1 ] &=  ~0x04;
        }
        if(bluecell_Currdatastatus.ALARM_MASK2 & 0x02){
             data[MBIC_PAYLOADSTART + i - 1 ] |= (bluecell_Currdatastatus.ALARM_DLI_Level & 0x02);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &=  ~0x02;
        }
        
        if(bluecell_Currdatastatus.ALARM_MASK2 & 0x01){
             data[MBIC_PAYLOADSTART + i - 1] |= (bluecell_Currdatastatus.ALARM_DLI_Level & 0x01);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &=  ~0x01;
        }
        


        data[MBIC_PAYLOADSTART + i++] = 0;

        if(bluecell_Currdatastatus.ALARM_MASK3 & 0x80){
             data[MBIC_PAYLOADSTART + i - 1] = (bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm & 0x80);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &= ~0x80; 
        }

        if(bluecell_Currdatastatus.ALARM_MASK3 & 0x40){
             data[MBIC_PAYLOADSTART + i - 1] |= (bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm & 0x40);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1 ] &=  ~0x40;
        }
        if(bluecell_Currdatastatus.ALARM_MASK3 & 0x20){
             data[MBIC_PAYLOADSTART + i - 1 ] |= (bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm & 0x20);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &=  ~0x20;
        }
        
        if(bluecell_Currdatastatus.ALARM_MASK3 & 0x10){
             data[MBIC_PAYLOADSTART + i - 1] |= (bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm & 0x10);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &=  ~0x10;
        }
        
        if(bluecell_Currdatastatus.ALARM_MASK3 & 0x08){
             data[MBIC_PAYLOADSTART + i - 1] |= (bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN & 0x08);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &= ~0x08; 
        }

        if(bluecell_Currdatastatus.ALARM_MASK3 & 0x04){
             data[MBIC_PAYLOADSTART + i - 1] |= (bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN & 0x04);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1 ] &=  ~0x04;
        }
        if(bluecell_Currdatastatus.ALARM_MASK3 & 0x02){
             data[MBIC_PAYLOADSTART + i - 1 ] |= (bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN & 0x02);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &=  ~0x02;
        }
        
        if(bluecell_Currdatastatus.ALARM_MASK3 & 0x01){
             data[MBIC_PAYLOADSTART + i - 1] |= (bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN & 0x01);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &=  ~0x01;
        }
        
//    printf("(bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN ) : %x \r\n",(bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN ));
       
        data[MBIC_PAYLOADSTART + i++] = 0;

        if(bluecell_Currdatastatus.ALARM_MASK4 & 0x08){
             data[MBIC_PAYLOADSTART + i - 1] = (bluecell_Currdatastatus.ALARM_ULO_Level & 0x08);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &= ~0x08; 
        }

        if(bluecell_Currdatastatus.ALARM_MASK4 & 0x04){
             data[MBIC_PAYLOADSTART + i - 1] |= (bluecell_Currdatastatus.ALARM_ULO_Level & 0x04);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1 ] &=  ~0x04;
        }
        if(bluecell_Currdatastatus.ALARM_MASK4 & 0x02){
             data[MBIC_PAYLOADSTART + i - 1 ] |= (bluecell_Currdatastatus.ALARM_ULO_Level & 0x02);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &=  ~0x02;
        }

        if(bluecell_Currdatastatus.ALARM_MASK4 & 0x01){
             data[MBIC_PAYLOADSTART + i - 1] |= (bluecell_Currdatastatus.ALARM_ULO_Level & 0x01);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &=  ~0x01;
        }



//////////////////////////////////
        data[MBIC_PAYLOADSTART + i++] = 0;

        if(bluecell_Currdatastatus.ALARM_MASK5 & 0x80){
             data[MBIC_PAYLOADSTART + i - 1] = (bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm & 0x80);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &= ~0x80; 
        }

        if(bluecell_Currdatastatus.ALARM_MASK5 & 0x40){
             data[MBIC_PAYLOADSTART + i - 1] |= (bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm & 0x40);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1 ] &=  ~0x40;
        }
        if(bluecell_Currdatastatus.ALARM_MASK5 & 0x20){
             data[MBIC_PAYLOADSTART + i - 1 ] |= (bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm & 0x20);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &=  ~0x20;
        }
        if(bluecell_Currdatastatus.ALARM_MASK5 & 0x10){
             data[MBIC_PAYLOADSTART + i - 1] |= (bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm & 0x10);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &=  ~0x10;
        }
//        printf("(bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN ) : %x \r\n",(bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN ));
        if(bluecell_Currdatastatus.ALARM_MASK5 & 0x08){
             data[MBIC_PAYLOADSTART + i - 1] |= (bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN & 0x08);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &= ~0x08; 
        }

        if(bluecell_Currdatastatus.ALARM_MASK5 & 0x04){
             data[MBIC_PAYLOADSTART + i - 1] |= (bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN & 0x04);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1 ] &=  ~0x04;
        }
        if(bluecell_Currdatastatus.ALARM_MASK5 & 0x02){
             data[MBIC_PAYLOADSTART + i - 1 ] |= (bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN & 0x02);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &=  ~0x02;
        }
        
        if(bluecell_Currdatastatus.ALARM_MASK5 & 0x01){
             data[MBIC_PAYLOADSTART + i - 1] |= (bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN & 0x01);
        }
        else{
            data[MBIC_PAYLOADSTART + i - 1] &=  ~0x01;
        }
        

#endif // PYJ.2020.08.18_END -- 
    }
    /*ALARM BIT MASK*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = Alarm_Mask;
    Length += 5;
    data[MBIC_PAYLOADSTART + i++] = 5; // LENGTH
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_MASK1;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_MASK2;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_MASK3;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_MASK4;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_MASK5;
    /*Alarm_Test_Mode*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = Alarm_Test_Mode;
    Length += 1;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_TESTMODE;
    /*Alarm_Test_Mode*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = Alarm_Test_Dummy;
    Length += 5;
    data[MBIC_PAYLOADSTART + i++] = 5; // LENGTH
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_Test_Dummy1;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_Test_Dummy2;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_Test_Dummy3;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_Test_Dummy4;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ALARM_Test_Dummy5;        

    /*CPU_Version*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = CPU_Version;
    Length += 3;
    data[MBIC_PAYLOADSTART + i++] = 3; // LENGTH
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPUVERSION1;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPUVERSION2;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPUVERSION3;
//    printf("Version [3] : %x\r\n ",bluecell_Currdatastatus.CPUVERSION3);


    /*CPU_Current_Bank*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = CPU_Current_Bank;
    Length += 1;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH        
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Current_Bank;


    /*CPU_Bank1_Image_Version*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = CPU_Bank1_Image_Version;
    data[MBIC_PAYLOADSTART + i++] = 3; // LENGTH
    Length += 3;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank1_Image_Version1;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank1_Image_Version2;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank1_Image_Version3;

    /*CPU_Bank1_Image_BuildTime*/

    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = CPU_Bank1_Image_BuildTime;
    data[MBIC_PAYLOADSTART + i++] = 6; // LENGTH
    Length += 6;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime1;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime2;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime3;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime4;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime5;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank1_Image_BuildTime6;

    /*CPU_Bank1_Image_Name*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = CPU_Bank1_Image_Name;
    data[MBIC_PAYLOADSTART + i++] = 32; // LENGTH
    Length += 32;  
    uint8_t* tmpstr;
    tmpstr = &bluecell_Currdatastatus.CPU_Bank1_Image_Name;
    for(int a = 0; a < 32; a++){
        data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank1_Image_Name[a];
//        printf("%x ",tmpstr[a]);
    }
//    printf("\r\n");

    /*CPU_Bank2_Image_Version*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = CPU_Bank2_Image_Version;
    data[MBIC_PAYLOADSTART + i++] = 3; // LENGTH
    Length += 3;  
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank2_Image_Version1;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank2_Image_Version2;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank2_Image_Version3;

    /*CPU_Bank2_Image_BuildTime*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = CPU_Bank2_Image_BuildTime;
    data[MBIC_PAYLOADSTART + i++] = 6; // LENGTH
    Length += 6;          
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime1;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime2;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime3;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime4;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime5;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank2_Image_BuildTime6;



   /*CPU_Bank2_Image_Name*/
   data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
   data[MBIC_PAYLOADSTART + i++] = CPU_Bank2_Image_Name;
   data[MBIC_PAYLOADSTART + i++] = 32; // LENGTH
    Length += 32;  
   for(int a = 0; a < 32; a++){
        data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.CPU_Bank2_Image_Name[a];
   }



    /*Temperature*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = Temperature;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1;  
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DET_TEMP;

    /*Temperature_Offset*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = Temperature_Offset;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1  ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.bluecell_User_TEMP_OFFSET;



    /*Temperature_Offset*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = Temp_High_Threshold;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1;  
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.Temp_High_Threshold;


    /*Node*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = Node;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1;  
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.NODE;



    /*Type*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = Type;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.Type;
//    printf(" bluecell_Currdatastatus.Type : %x \r\n", bluecell_Currdatastatus.Type);
     /*PCB_Version*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = PCB_Version;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2;       
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.PCB_Version[0];
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.PCB_Version[1];


     /*Serial_Number*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = Serial_Number;
    data[MBIC_PAYLOADSTART + i++] = 20; // LENGTH
    Length += 20     ;      
    for(int a = 0; a < 20; a++){
        data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.Serial_Number[a];
    }

     /*Manufacture*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = Manufacture;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1     ;      
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.Manufacture = 0x01;




     /*Manufacture_Date*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = Manufacture_Date;
    data[MBIC_PAYLOADSTART + i++] = 3; // LENGTH
    Length += 3   ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.Manufacture_Date[0];
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.Manufacture_Date[1];
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.Manufacture_Date[2];

     /*Freq_ID*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = Freq_ID;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1     ;      
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.Freq_ID;


     /*Carrier_ID*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = Carrier_ID;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1       ;   
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.Carrier_ID;



     /*Carrier_ID*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = Carrier_ON_OFF;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1  ;          
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.Carrier_ON_OFF;


    
     /*DLI_P1_Level*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_P1_Level;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2     ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_P1_Level1_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_P1_Level1_L;
    
     /*DLI_P2_Level*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_P2_Level;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2   ;  
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_P2_Level2_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_P2_Level2_L;

     /*DLI_P3_Level*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_P3_Level;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2   ;  
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_P3_Level3_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_P3_Level3_L;

     /*DLI_P4_Level*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_P4_Level;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2   ;  
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_P4_Level4_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_P4_Level4_L;

     /*ULO_P1_Level*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_P1_Level;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2     ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_P1_Level1_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_P1_Level1_L;
    
     /*ULO_P2_Level*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_P2_Level;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2     ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_P2_Level2_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_P2_Level2_L;

     /*ULO_P3_Level*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_P3_Level;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2   ;  
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_P3_Level3_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_P3_Level3_L;

     /*ULO_P4_Level*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_P4_Level;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2     ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_P4_Level4_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_P4_Level4_L;  

    


    
     /*DLI_RF_Path1_ON_OFF*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_RF_Path1_ON_OFF;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1  ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ATT_DL1_PATH;
     /*DLI_RF_Path2_ON_OFF*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_RF_Path2_ON_OFF;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1          ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ATT_DL2_PATH;
     /*DLI_RF_Path3_ON_OFF*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_RF_Path3_ON_OFF;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1          ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ATT_DL3_PATH;
     /*DLI_RF_Path4_ON_OFF*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_RF_Path4_ON_OFF;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1          ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ATT_DL4_PATH;

    /*DLI_Gain_Atten1*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_Gain_Atten1;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2  ;
    tmpdata = bluecell_Currdatastatus.ATT_DL1_H << 8 | bluecell_Currdatastatus.ATT_DL1_L;
//    tmpdata *= 10;
//    printf("tmpdata : %x \r\n",tmpdata);
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 


    /*DLI_Gain_Atten2*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_Gain_Atten2;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2        ;  
    tmpdata = bluecell_Currdatastatus.ATT_DL2_H << 8 | bluecell_Currdatastatus.ATT_DL2_L;
//    tmpdata *= 10;
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 


    /*DLI_Gain_Atten3*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_Gain_Atten3;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2          ;
    tmpdata = bluecell_Currdatastatus.ATT_DL3_H << 8 | bluecell_Currdatastatus.ATT_DL3_L;
//    tmpdata *= 10;
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 


    /*DLI_Gain_Atten4*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_Gain_Atten4;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2        ;  
    tmpdata = bluecell_Currdatastatus.ATT_DL4_H << 8 | bluecell_Currdatastatus.ATT_DL4_L;
//    tmpdata *= 10;
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 



     /*DLI_Gain_Atten_Offset1*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_Gain_Atten_Offset1;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2;
    tmpdata = bluecell_Currdatastatus.bluecell_User_DL1_H << 8 | bluecell_Currdatastatus.bluecell_User_DL1_L;
//    tmpdata *= 10;    
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 

     /*DLI_Gain_Atten_Offset2*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_Gain_Atten_Offset2;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2        ;
    tmpdata = bluecell_Currdatastatus.bluecell_User_DL2_H << 8 | bluecell_Currdatastatus.bluecell_User_DL2_L;
//    tmpdata *= 10;   
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 

     /*DLI_Gain_Atten_Offset3*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_Gain_Atten_Offset3;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2        ;
    tmpdata = bluecell_Currdatastatus.bluecell_User_DL3_H << 8 | bluecell_Currdatastatus.bluecell_User_DL3_L;
//    tmpdata *= 10;   
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 

     /*DLI_Gain_Atten_Offset4*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_Gain_Atten_Offset4;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2        ;
    tmpdata = bluecell_Currdatastatus.bluecell_User_DL4_H << 8 | bluecell_Currdatastatus.bluecell_User_DL4_L;
//    tmpdata *= 10;   
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 



     /*DLI_Level_High_Threshold*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_Level_High_Threshold;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2    ;          
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_Level_High_Threshold_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_Level_High_Threshold_L;

     /*DLI_Level_Low_Threshold*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_Level_Low_Threshold;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2     ;         
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_Level_Low_Threshold_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_Level_Low_Threshold_L;



     /*DLI_Level*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_Level;
    data[MBIC_PAYLOADSTART + i++] = 8; // LENGTH
    Length += 8     ;
    tmpdata = bluecell_Currdatastatus.DLI_Level1_H << 8 | bluecell_Currdatastatus.DLI_Level1_L;
    tmpdata *= 10;
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 

    tmpdata = bluecell_Currdatastatus.DLI_Level2_H << 8 | bluecell_Currdatastatus.DLI_Level2_L;
    tmpdata *= 10;    
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 

    tmpdata = bluecell_Currdatastatus.DLI_Level3_H << 8 | bluecell_Currdatastatus.DLI_Level3_L;
    tmpdata *= 10;
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 

    tmpdata = bluecell_Currdatastatus.DLI_Level4_H << 8 | bluecell_Currdatastatus.DLI_Level4_L;
    tmpdata *= 10;
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 


    
     /*DLI_FRBT_Atten*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_FRBT_Atten;
    data[MBIC_PAYLOADSTART + i++] = 8; // LENGTH
    Length += 8   ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_FRBT_Atten1_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_FRBT_Atten1_L;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_FRBT_Atten2_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_FRBT_Atten2_L;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_FRBT_Atten3_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_FRBT_Atten3_L;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_FRBT_Atten4_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_FRBT_Atten4_L;



    
     /*DLI_FRBT_D_Day*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_FRBT_D_Day;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1   ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_FRBT_D_Day;
     /*DLI_FRBT_Status*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_FRBT_Status;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1         ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_FRBT_Status;

    

     /*DLI_AGC_ON_OFF*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_AGC_ON_OFF;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1    ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_AGC_ON_OFF;




     /*DLI_AGC_Threshold*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_AGC_Threshold;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2    ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_AGC_Threshold_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_AGC_Threshold_L;

     /*DLI_Shutdown_ON_OFF*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_Shutdown_ON_OFF;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1       ;     
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_Shutdown_ON_OFF;

     /*DLI_Shutdown_ON_OFF*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_Shutdown_Threshold;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2       ;   
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_Shutdown_Threshold_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_Shutdown_Threshold_L;




     /*DLI_Shutdown_Count*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = DLI_Shutdown_Count;
    data[MBIC_PAYLOADSTART + i++] = 4; // LENGTH
    Length += 4        ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_Shutdown_Retry_Count1;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_Shutdown_Retry_Count2;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_Shutdown_Retry_Count3;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.DLI_Shutdown_Retry_Count4;


     /*ULO_RF_Path1_ON_OFF*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_RF_Path1_ON_OFF;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1           ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ATT_UL1_PATH;
     /*ULO_RF_Path3_ON_OFF*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_RF_Path2_ON_OFF;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1        ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ATT_UL2_PATH;

     /*ULO_RF_Path3_ON_OFF*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_RF_Path3_ON_OFF;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1        ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ATT_UL3_PATH;
     /*ULO_RF_Path4_ON_OFF*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_RF_Path4_ON_OFF;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1     ;   
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ATT_UL4_PATH;


     /*ULO_Gain_Atten1*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_Gain_Atten1;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2      ;     
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ATT_UL1_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ATT_UL1_L;


     /*ULO_Gain_Atten2*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_Gain_Atten2;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2      ;     
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ATT_UL2_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ATT_UL2_L;

     /*ULO_Gain_Atten3*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_Gain_Atten3;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2    ;      
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ATT_UL3_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ATT_UL3_L;

     /*ULO_Gain_Atten4*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_Gain_Atten4;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2       ;    
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ATT_UL4_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ATT_UL4_L;
    
     /*ULO_Gain_Atten_Offset1*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_Gain_Atten_Offset1;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2      ;      

    tmpdata = bluecell_Currdatastatus.bluecell_User_UL1_H << 8 | bluecell_Currdatastatus.bluecell_User_UL1_L;
//    tmpdata *= 10;   
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 

     /*ULO_Gain_Atten_Offset2*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_Gain_Atten_Offset2;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2     ;         
    tmpdata = bluecell_Currdatastatus.bluecell_User_UL2_H << 8 | bluecell_Currdatastatus.bluecell_User_UL2_L;
//    tmpdata *= 10;   
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 


     /*ULO_Gain_Atten_Offset3*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_Gain_Atten_Offset3;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2        ;      
    tmpdata = bluecell_Currdatastatus.bluecell_User_UL3_H << 8 | bluecell_Currdatastatus.bluecell_User_UL3_L;
//    tmpdata *= 10;
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 


     /*ULO_Gain_Atten_Offset4*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_Gain_Atten_Offset4;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2    ;          
    tmpdata = bluecell_Currdatastatus.bluecell_User_UL4_H << 8 | bluecell_Currdatastatus.bluecell_User_UL4_L;
//    tmpdata *= 10;
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 





     /*ULO_Level_High_Threshold*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_Level_High_Threshold;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2   ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_Level_High_Threshold_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_Level_High_Threshold_L;





     /*ULO_Level*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_Level;
    data[MBIC_PAYLOADSTART + i++] = 8; // LENGTH
    Length += 8           ;
    tmpdata = bluecell_Currdatastatus.ULO_Level1_H << 8 | bluecell_Currdatastatus.ULO_Level1_L;
    tmpdata *= 10;
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 
    tmpdata = bluecell_Currdatastatus.ULO_Level2_H << 8 | bluecell_Currdatastatus.ULO_Level2_L;
    tmpdata *= 10;
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 

    tmpdata = bluecell_Currdatastatus.ULO_Level3_H << 8 | bluecell_Currdatastatus.ULO_Level3_L;
    tmpdata *= 10;
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 

    tmpdata = bluecell_Currdatastatus.ULO_Level4_H << 8 | bluecell_Currdatastatus.ULO_Level4_L;
    tmpdata *= 10;
    data[MBIC_PAYLOADSTART + i++] = ((tmpdata & 0xFF00) >> 8);
    data[MBIC_PAYLOADSTART + i++] = (tmpdata & 0x00FF); 


    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_SelfTest1;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1 ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.Selftest1;
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_SelfTest2;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1 ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.Selftest2;
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_SelfTest3;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1 ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.Selftest3;
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_SelfTest4;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1 ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.Selftest4;    


    
     /*ULO_ALC_ON_OFF*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_ALC_ON_OFF;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1 ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_ALC_ON_OFF;
     /*ULO_ALC_Threshold*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_ALC_Threshold;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2 ;        
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_ALC_Threshold_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_ALC_Threshold_L;



     /*ULO_ALC_Threshold*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_Shutdown_ON_OFF;
    data[MBIC_PAYLOADSTART + i++] = 1; // LENGTH
    Length += 1;           
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_Shutdown_ON_OFF;

     /*ULO_ALC_Threshold*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_Shutdown_Threshold;
    data[MBIC_PAYLOADSTART + i++] = 2; // LENGTH
    Length += 2;                
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_Shutdown_Threshold_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_Shutdown_Threshold_L;



     /*ULO_Shutdown_Threshold*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_Shutdown_Retry_Count;
    data[MBIC_PAYLOADSTART + i++] = 4; // LENGTH
    Length += 4;          
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_Shutdown_Retry_Count1;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_Shutdown_Retry_Count2;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_Shutdown_Retry_Count3;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.ULO_Shutdown_Retry_Count4;



#if 1 // PYJ.2020.06.20_BEGIN -- 
     /*ULO_ALC_Atten*/
    data[MBIC_PAYLOADSTART + i++] = MBIC_AID;
    data[MBIC_PAYLOADSTART + i++] = ULO_ALC_Atten;
    data[MBIC_PAYLOADSTART + i++] = 8; // LENGTH
    Length += 8   ;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_L;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_L;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_L;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_H;
    data[MBIC_PAYLOADSTART + i++] = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_L;
#endif // PYJ.2020.06.20_END -- 
    Length = (Length  + (3 * HeaderLength));

    data[MBIC_LENGTH_0] = ((Length & 0xFF00) >> 8);    
    data[MBIC_LENGTH_1] = (Length & 0x00FF);  
    
    Crcret =CRC16_Generate(&data[MBIC_PAYLOADSTART], Length);
    
    data[MBIC_HEADERCHECKSUM_0] = Chksum_Create(data);     
    
    data[MBIC_PAYLOADSTART + i++] = (Crcret & 0xFF00) >> 8;  
    data[MBIC_PAYLOADSTART + i++] = (Crcret & 0x00FF); 
    data[MBIC_PAYLOADSTART + i++] = 0x03; 

    
//    printf("CRC ret : %X \r\n",Crcret);
    Uart1_Data_Send(data, Length + 22 + 3);
    return Length;

}



void Factory_Set(){
    int16_t tempdata = 0;
//    printf("Factory Set Start \r\n");
    /*ALARM MASK*/
    bluecell_Currdatastatus.ALARM_MASK1 = 0x80;
    bluecell_Currdatastatus.ALARM_MASK2 = 0xFF ;
    bluecell_Currdatastatus.ALARM_MASK3 = 0xFF;
    bluecell_Currdatastatus.ALARM_MASK4 = 0x0F ;
    bluecell_Currdatastatus.ALARM_MASK5 = 0xFF; 
    /*Temp OFFSET*/
//    bluecell_Currdatastatus.bluecell_User_TEMP_OFFSET = TEMP_OFFSET_DEFAULT;
    /*Temp High Thread Hold*/
    bluecell_Currdatastatus.Temp_High_Threshold = Temp_THREADHOLD_DEFAULT;
    /*Carrier On off*/
    bluecell_Currdatastatus.Carrier_ON_OFF = Temp_THREADHOLD_DEFAULT;    
    /*DL PATH */
    bluecell_Currdatastatus.ATT_DL1_PATH = PATH_DEFAULT;    
    bluecell_Currdatastatus.ATT_DL2_PATH = PATH_DEFAULT;    
    bluecell_Currdatastatus.ATT_DL3_PATH = PATH_DEFAULT;    
    bluecell_Currdatastatus.ATT_DL4_PATH = PATH_DEFAULT;    
    /*DL GAIN Atten*/
    bluecell_Currdatastatus.ATT_DL1_H = DLI_ATTEN_DEFAULT;    
    bluecell_Currdatastatus.ATT_DL2_H = DLI_ATTEN_DEFAULT;    
    bluecell_Currdatastatus.ATT_DL3_H = DLI_ATTEN_DEFAULT;    
    bluecell_Currdatastatus.ATT_DL4_H = DLI_ATTEN_DEFAULT;    
    bluecell_Currdatastatus.ATT_DL1_L = DLI_ATTEN_DEFAULT;    
    bluecell_Currdatastatus.ATT_DL2_L = DLI_ATTEN_DEFAULT;    
    bluecell_Currdatastatus.ATT_DL3_L = DLI_ATTEN_DEFAULT;    
    bluecell_Currdatastatus.ATT_DL4_L = DLI_ATTEN_DEFAULT;    
    bluecell_Currdatastatus.Path_TempSave_Bit = 0xFF;
 
   
    /*DL GAIN OFFSET*/
    tempdata  = ATTEN_OFFSET_DEFAULT;
    bluecell_Currdatastatus.bluecell_User_DL1_H = ((tempdata & 0xFF00) >> 8);    
    bluecell_Currdatastatus.bluecell_User_DL1_L = ((tempdata & 0x00FF));        
    bluecell_Currdatastatus.bluecell_User_DL2_H = ((tempdata & 0xFF00) >> 8);    
    bluecell_Currdatastatus.bluecell_User_DL2_L = ((tempdata & 0x00FF));        
    bluecell_Currdatastatus.bluecell_User_DL3_H = ((tempdata & 0xFF00) >> 8);    
    bluecell_Currdatastatus.bluecell_User_DL3_L = ((tempdata & 0x00FF));        
    bluecell_Currdatastatus.bluecell_User_DL4_H = ((tempdata & 0xFF00) >> 8);    
    bluecell_Currdatastatus.bluecell_User_DL4_L = ((tempdata & 0x00FF));      

    tempdata  = DLI_ATTEN_HIGHTHREADHOLD_DEFAULT;
    bluecell_Currdatastatus.DLI_Level_High_Threshold_H = ((tempdata & 0xFF00) >> 8);
    bluecell_Currdatastatus.DLI_Level_High_Threshold_L = ((tempdata & 0x00FF));

    tempdata  = DLI_ATTEN_LOWTHREADHOLD_DEFAULT;
    bluecell_Currdatastatus.DLI_Level_Low_Threshold_H = ((tempdata & 0xFF00) >> 8);
    bluecell_Currdatastatus.DLI_Level_Low_Threshold_L = ((tempdata & 0x00FF));


    bluecell_Currdatastatus.DLI_FRBT_D_Day = DLI_FRBT_DAY_DEFAULT;
    
    bluecell_Currdatastatus.DLI_FRBT_Atten1_H = DLI_FRBT_ATTEN_DEFALUT;
    bluecell_Currdatastatus.DLI_FRBT_Atten1_H = DLI_FRBT_ATTEN_DEFALUT;
    bluecell_Currdatastatus.DLI_FRBT_Atten1_H = DLI_FRBT_ATTEN_DEFALUT;
    bluecell_Currdatastatus.DLI_FRBT_Atten1_H = DLI_FRBT_ATTEN_DEFALUT;
    bluecell_Currdatastatus.DLI_FRBT_Atten1_L= DLI_FRBT_ATTEN_DEFALUT;    
    bluecell_Currdatastatus.DLI_FRBT_Atten1_L= DLI_FRBT_ATTEN_DEFALUT;    
    bluecell_Currdatastatus.DLI_FRBT_Atten1_L= DLI_FRBT_ATTEN_DEFALUT;    
    bluecell_Currdatastatus.DLI_FRBT_Atten1_L= DLI_FRBT_ATTEN_DEFALUT;        

    bluecell_Currdatastatus.DLI_AGC_ON_OFF = DLI_AGC_ONOFF_DEFAULT;   


    tempdata  = DLI_AGC_THREADHOLD_DEFAULT;
    bluecell_Currdatastatus.DLI_AGC_Threshold_H = ((tempdata & 0xFF00) >> 8);        
    bluecell_Currdatastatus.DLI_AGC_Threshold_L = ((tempdata & 0x00FF));            

    bluecell_Currdatastatus.DLI_Shutdown_ON_OFF = DLI_SHUTDOWN_ONOFF_DEFAULT;
    
    tempdata  = DLI_SHUTDOWN_THREADHOLD_DEFAULT;
    bluecell_Currdatastatus.DLI_Shutdown_Threshold_H = ((tempdata & 0xFF00) >> 8);        
    bluecell_Currdatastatus.DLI_Shutdown_Threshold_L = ((tempdata & 0x00FF));            
//    bluecell_Currdatastatus.DLI_Shutdown_Retry_Count1 = 0;
//    bluecell_Currdatastatus.DLI_Shutdown_Retry_Count2 = 0;
//    bluecell_Currdatastatus.DLI_Shutdown_Retry_Count3 = 0;
//    bluecell_Currdatastatus.DLI_Shutdown_Retry_Count4 = 0;    
    DL_Path_OnOff(Path1_OnOff,
      bluecell_Currdatastatus.ATT_DL1_PATH,
      &bluecell_Currdatastatus.ATT_DL1_PATH,
      &bluecell_Prevdatastatus.ATT_DL1_H,
      &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count1,
      &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count1)  ;   
      DL_Path_OnOff(Path2_OnOff,
       bluecell_Currdatastatus.ATT_DL2_PATH,
       &bluecell_Currdatastatus.ATT_DL2_PATH,
       &bluecell_Prevdatastatus.ATT_DL2_H,
       &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count2,
       &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count2)  ;   
      DL_Path_OnOff(Path3_OnOff,
       bluecell_Currdatastatus.ATT_DL3_PATH,
       &bluecell_Currdatastatus.ATT_DL3_PATH,
       &bluecell_Prevdatastatus.ATT_DL3_H,
       &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count3,
       &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count3)  ;   
      DL_Path_OnOff(Path4_OnOff,
       bluecell_Currdatastatus.ATT_DL4_PATH,
       &bluecell_Currdatastatus.ATT_DL4_PATH,
       &bluecell_Prevdatastatus.ATT_DL4_H,
       &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count4,
       &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count4)  ;   
      
      




    bluecell_Currdatastatus.ATT_UL1_PATH = PATH_DEFAULT;    
    bluecell_Currdatastatus.ATT_UL2_PATH = PATH_DEFAULT;    
    bluecell_Currdatastatus.ATT_UL3_PATH = PATH_DEFAULT;    
    bluecell_Currdatastatus.ATT_UL4_PATH = PATH_DEFAULT;    

    tempdata  = ULO_ATTEN_DEFAULT;
    bluecell_Currdatastatus.ATT_UL1_H = ((tempdata & 0xFF00) >> 8);    
    bluecell_Currdatastatus.ATT_UL1_L = ((tempdata & 0x00FF));    
    bluecell_Currdatastatus.ATT_UL2_H = ((tempdata & 0xFF00) >> 8);    
    bluecell_Currdatastatus.ATT_UL2_L = ((tempdata & 0x00FF));    
    bluecell_Currdatastatus.ATT_UL3_H = ((tempdata & 0xFF00) >> 8);    
    bluecell_Currdatastatus.ATT_UL3_L = ((tempdata & 0x00FF));    
    bluecell_Currdatastatus.ATT_UL4_H = ((tempdata & 0xFF00) >> 8);    
    bluecell_Currdatastatus.ATT_UL4_L = ((tempdata & 0x00FF));    

    tempdata  = ATTEN_OFFSET_DEFAULT;
    bluecell_Currdatastatus.bluecell_User_UL1_H = ((tempdata & 0xFF00) >> 8);    
    bluecell_Currdatastatus.bluecell_User_UL1_L = ((tempdata & 0x00FF));        
    bluecell_Currdatastatus.bluecell_User_UL2_H = ((tempdata & 0xFF00) >> 8);    
    bluecell_Currdatastatus.bluecell_User_UL2_L = ((tempdata & 0x00FF));        
    bluecell_Currdatastatus.bluecell_User_UL3_H = ((tempdata & 0xFF00) >> 8);    
    bluecell_Currdatastatus.bluecell_User_UL3_L = ((tempdata & 0x00FF));        
    bluecell_Currdatastatus.bluecell_User_UL4_H = ((tempdata & 0xFF00) >> 8);    
    bluecell_Currdatastatus.bluecell_User_UL4_L = ((tempdata & 0x00FF));    

    tempdata  = ULO_LEVEL_HIGH_THREADHOLD_DEFAULT;
    bluecell_Currdatastatus.ULO_Level_High_Threshold_H = ((tempdata & 0xFF00) >> 8);
    bluecell_Currdatastatus.ULO_Level_High_Threshold_L = ((tempdata & 0x00FF));    

    bluecell_Currdatastatus.Selftest1 = SELFTEST_DEFALULT_DEFAULT;
    bluecell_Currdatastatus.Selftest2 = SELFTEST_DEFALULT_DEFAULT;
    bluecell_Currdatastatus.Selftest3 = SELFTEST_DEFALULT_DEFAULT;
    bluecell_Currdatastatus.Selftest4 = SELFTEST_DEFALULT_DEFAULT;


    bluecell_Currdatastatus.ULO_ALC_ON_OFF = ULO_ALC_ONOFF_DEFAULT;

    tempdata = ULO_ALC_THREADHOLD_DEFAULT;
    bluecell_Currdatastatus.ULO_ALC_Threshold_H = ((tempdata & 0xFF00) >> 8);    
    bluecell_Currdatastatus.ULO_ALC_Threshold_L = ((tempdata & 0x00FF));        


    bluecell_Currdatastatus.ULO_Shutdown_ON_OFF = ULO_SHUTDOWN_ONOFF_DEFAULT;

    tempdata  = ULO_SHUTDOWN_THREADHOLD_DEFAULT;
    bluecell_Currdatastatus.ULO_Shutdown_Threshold_H = ((tempdata & 0xFF00) >> 8);        
    bluecell_Currdatastatus.ULO_Shutdown_Threshold_L = ((tempdata & 0x00FF));            
    
    UL_Path_OnOff(Path1_OnOff,
         bluecell_Currdatastatus.ATT_UL1_PATH,
         &bluecell_Currdatastatus.ATT_UL1_PATH,
         &bluecell_Prevdatastatus.ATT_UL1_H,
         &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count1,
         &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count1)  ;   
         UL_Path_OnOff(Path2_OnOff,
          bluecell_Currdatastatus.ATT_UL2_PATH,
          &bluecell_Currdatastatus.ATT_UL2_PATH,
          &bluecell_Prevdatastatus.ATT_UL2_H,
          &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count2,
          &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count2)  ;   
         UL_Path_OnOff(Path3_OnOff,
          bluecell_Currdatastatus.ATT_UL3_PATH,
          &bluecell_Currdatastatus.ATT_UL3_PATH,
          &bluecell_Prevdatastatus.ATT_UL3_H,
          &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count3,
          &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count3)  ;   
         UL_Path_OnOff(Path4_OnOff,
          bluecell_Currdatastatus.ATT_UL4_PATH,
          &bluecell_Currdatastatus.ATT_UL4_PATH,
          &bluecell_Prevdatastatus.ATT_UL4_H,
          &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count4,
          &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count4)  ;   

    DL_PrevIwillgiveAtten[0] = 99; 
    DL_PrevIwillgiveAtten[1] = 99;         
    DL_PrevIwillgiveAtten[2] = 99;         
    DL_PrevIwillgiveAtten[3] = 99;             
    bluecell_Prevdatastatus.ATT_DL1_H = 0xFF;    
    bluecell_Prevdatastatus.ATT_DL2_H = 0xFF;    
    bluecell_Prevdatastatus.ATT_DL3_H = 0xFF;    
    bluecell_Prevdatastatus.ATT_DL4_H = 0xFF;    
    bluecell_Prevdatastatus.ATT_DL1_L = 0xFF;    
    bluecell_Prevdatastatus.ATT_DL2_L = 0xFF;    
    bluecell_Prevdatastatus.ATT_DL3_L = 0xFF;    
    bluecell_Prevdatastatus.ATT_DL4_L = 0xFF;   


    bluecell_Prevdatastatus.ATT_UL1_H = 0xFF;    
    bluecell_Prevdatastatus.ATT_UL2_H = 0xFF;    
    bluecell_Prevdatastatus.ATT_UL3_H = 0xFF;    
    bluecell_Prevdatastatus.ATT_UL4_H = 0xFF;    
    bluecell_Prevdatastatus.ATT_UL1_L = 0xFF;    
    bluecell_Prevdatastatus.ATT_UL2_L = 0xFF;    
    bluecell_Prevdatastatus.ATT_UL3_L = 0xFF;    
    bluecell_Prevdatastatus.ATT_UL4_L = 0xFF;    



    
    

}

void DL_Path_OnOff(uint8_t Index,uint8_t value,uint8_t* path,uint8_t* PrevAtten,uint8_t* retrycnt,uint8_t* PrevRetryCnt){
    GPIO_TypeDef *Port = 0;
    uint16_t Pin = 0;    
    switch(Index){
        case Path1_OnOff:
        Port = PATH_EN_DL1_GPIO_Port;
        Pin = PATH_EN_DL1_Pin;
        break;
        case Path2_OnOff:
        Port = PATH_EN_DL2_GPIO_Port;
        Pin = PATH_EN_DL2_Pin;
        break;
        case Path3_OnOff:
        Port = PATH_EN_DL3_GPIO_Port;
        Pin = PATH_EN_DL3_Pin;
        break;
        case Path4_OnOff:
        Port = PATH_EN_DL4_GPIO_Port;
        Pin = PATH_EN_DL4_Pin;
        break;
    }
    *path = value; 
    *retrycnt = 0;
    *PrevRetryCnt = 0xFF;
    if(value==0){
        HAL_GPIO_WritePin(Port,Pin,GPIO_PIN_RESET);//CLOCK        
        DL_PathUserHandl[0] = true;
    }
    else{
        PrevAtten[Atten_H] = 0xFF;
        PrevAtten[Atten_L] = 0xFF;
        DL_PathUserHandl[Index] = false;                    
        HAL_GPIO_WritePin(Port,Pin,GPIO_PIN_SET);//CLOCK
    }                
    CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

}
void UL_Path_OnOff(uint8_t Index,uint8_t value,uint8_t* path,uint8_t* PrevAtten,uint8_t* retrycnt,uint8_t* PrevRetryCnt){
    GPIO_TypeDef *Port = 0;
    uint16_t Pin = 0;    
  
    switch(Index){
        case Path1_OnOff:
        Port = PATH_EN_UL1_GPIO_Port;
        Pin = PATH_EN_UL1_Pin;
        break;
        case Path2_OnOff:
        Port = PATH_EN_UL2_GPIO_Port;
        Pin = PATH_EN_UL2_Pin;
        break;
        case Path3_OnOff:
        Port = PATH_EN_UL3_GPIO_Port;
        Pin = PATH_EN_UL3_Pin;
        break;
        case Path4_OnOff:
        Port = PATH_EN_UL4_GPIO_Port;
        Pin = PATH_EN_UL4_Pin;
        break;
    }
    *path = value; 
    *retrycnt = 0;
    *PrevRetryCnt = 0xFF;
    if(value == 0){
        HAL_GPIO_WritePin(Port,Pin,GPIO_PIN_RESET);//CLOCK        
    }
    else{
        PrevAtten[Atten_H] = 0xFF;
        PrevAtten[Atten_L] = 0xFF;
        HAL_GPIO_WritePin(Port,Pin,GPIO_PIN_SET);//CLOCK
    }
    CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

}
void TimeSetting(uint8_t* data){
    if(bluecell_Currdatastatus.DLI_FRBT_Status == 0)
        return;
    
//    printf("DLI_FRBT_Status : %d \r\n",bluecell_Currdatastatus.DLI_FRBT_Status);
//    printf("DLI_AGC_ON_OFF : %d \r\n",bluecell_Currdatastatus.DLI_AGC_ON_OFF);    
//    printf("DLI_FRBT_D_Day : %d \r\n",bluecell_Currdatastatus.DLI_FRBT_D_Day);    
//    printf("Curr Day %d \r\n ",FRBT_Day_Inc);
    if(bluecell_Currdatastatus.DLI_AGC_ON_OFF == true 
    && FRBT_Day_Inc < bluecell_Currdatastatus.DLI_FRBT_D_Day
    && bluecell_Currdatastatus.DLI_FRBT_Status != FRBT_RUNNING){
        for(int i = 0; i < DLI_FRBT_Time_Index_Max; i++){
            FRBT_Day[DLI_FRBT_Time_Year + i] = data[i]; /* Curr day */
        }
        
//        printf("BLUECELL TIME APPLY : %d - %d - %d - %d - %d - %d \r\n",        
//        FRBT_Day[DLI_FRBT_Time_Year],
//        FRBT_Day[DLI_FRBT_Time_Month],
//        FRBT_Day[DLI_FRBT_Time_Day],
//        FRBT_Day[DLI_FRBT_Time_Hour],
//        FRBT_Day[DLI_FRBT_Time_Minute],
//        FRBT_Day[DLI_FRBT_Time_Second]);
        if(FRBT_Day[DLI_FRBT_Time_Day] != PrevFRBT_Day[DLI_FRBT_Time_Day]){
//                printf("FRBT_Day[DLI_FRBT_Time_Day] : %d  PrevFRBT_Day[DLI_FRBT_D_Day] : %d \r\n",
//              FRBT_Day[DLI_FRBT_Time_Day] ,
//              PrevFRBT_Day[DLI_FRBT_Time_Day]);
            FRBT_Day_Inc++;
            bluecell_Currdatastatus.DLI_FRBT_Status = FRBT_TRACKING;
//            printf("D day Plus : %d \r\n",FRBT_Day_Inc);
        }
        
        for(int i = 0; i < DLI_FRBT_Time_Index_Max; i++){
            PrevFRBT_Day[DLI_FRBT_Time_Year + i] = FRBT_Day[DLI_FRBT_Time_Year + i]; /* Curr day */
        }   
//            printf("BLUECELL TIME APPLY : %d - %d - %d - %d - %d - %d \r\n",
//        PrevFRBT_Day[DLI_FRBT_Time_Year],
//        PrevFRBT_Day[DLI_FRBT_Time_Month],
//        PrevFRBT_Day[DLI_FRBT_Time_Day],
//        PrevFRBT_Day[DLI_FRBT_Time_Hour],
//        PrevFRBT_Day[DLI_FRBT_Time_Minute],
//        PrevFRBT_Day[DLI_FRBT_Time_Second]);            
//            printf("FRBT_Day[DLI_FRBT_Time_Day] : %d  PrevFRBT_Day[DLI_FRBT_D_Day] : %d \r\n",
//        FRBT_Day[DLI_FRBT_Time_Day] ,
//        PrevFRBT_Day[DLI_FRBT_Time_Day]);
    }
//    printf("Time Set Complete\r\n");
}
void Carrier_ONOFF(uint8_t val){
    if(val == 1){
        bluecell_Currdatastatus.ATT_DL1_PATH = PATH_DEFAULT;    
        bluecell_Currdatastatus.ATT_DL2_PATH = PATH_DEFAULT;    
        bluecell_Currdatastatus.ATT_DL3_PATH = PATH_DEFAULT;    
        bluecell_Currdatastatus.ATT_DL4_PATH = PATH_DEFAULT;    
        bluecell_Currdatastatus.ATT_UL1_PATH = PATH_DEFAULT;    
        bluecell_Currdatastatus.ATT_UL2_PATH = PATH_DEFAULT;    
        bluecell_Currdatastatus.ATT_UL3_PATH = PATH_DEFAULT;    
        bluecell_Currdatastatus.ATT_UL4_PATH = PATH_DEFAULT;   
        bluecell_Currdatastatus.Path_TempSave_Bit = 0xFF;
        DL_Path_OnOff(Path1_OnOff,
             true,
             &bluecell_Currdatastatus.ATT_DL1_PATH,
             &bluecell_Prevdatastatus.ATT_DL1_H,
             &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count1,
             &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count1)  ;  
        DL_Path_OnOff(Path2_OnOff,
             true,
             &bluecell_Currdatastatus.ATT_DL2_PATH,
             &bluecell_Prevdatastatus.ATT_DL2_H,
             &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count2,
             &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count2)  ;  
        DL_Path_OnOff(Path3_OnOff,
             true,
             &bluecell_Currdatastatus.ATT_DL3_PATH,
             &bluecell_Prevdatastatus.ATT_DL3_H,
             &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count3,
             &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count3)  ;          

        DL_Path_OnOff(Path4_OnOff,
             true,
             &bluecell_Currdatastatus.ATT_DL4_PATH,
             &bluecell_Prevdatastatus.ATT_DL4_H,
             &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count4,
             &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count4)  ;  

        UL_Path_OnOff(Path1_OnOff,
             true,
             &bluecell_Currdatastatus.ATT_UL1_PATH,
             &bluecell_Prevdatastatus.ATT_UL1_H,
             &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count1,
             &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count1)  ;  
        UL_Path_OnOff(Path2_OnOff,
             true,
             &bluecell_Currdatastatus.ATT_UL2_PATH,
             &bluecell_Prevdatastatus.ATT_UL2_H,
             &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count2,
             &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count2)  ;  
        UL_Path_OnOff(Path3_OnOff,
             true,
             &bluecell_Currdatastatus.ATT_UL3_PATH,
             &bluecell_Prevdatastatus.ATT_UL3_H,
             &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count3,
             &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count3)  ;          

        UL_Path_OnOff(Path4_OnOff,
             true,
             &bluecell_Currdatastatus.ATT_UL4_PATH,
             &bluecell_Prevdatastatus.ATT_UL4_H,
             &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count4,
             &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count4)  ;               

//        HAL_Delay(10);
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
    }else{
        bluecell_Currdatastatus.ATT_DL1_PATH = false;    
        bluecell_Currdatastatus.ATT_DL2_PATH = false;    
        bluecell_Currdatastatus.ATT_DL3_PATH = false;    
        bluecell_Currdatastatus.ATT_DL4_PATH = false;    
        bluecell_Currdatastatus.ATT_UL1_PATH = false;    
        bluecell_Currdatastatus.ATT_UL2_PATH = false;    
        bluecell_Currdatastatus.ATT_UL3_PATH = false;    
        bluecell_Currdatastatus.ATT_UL4_PATH = false; 
        bluecell_Currdatastatus.Path_TempSave_Bit = 0x00;        
        DL_Path_OnOff(Path1_OnOff,
             false,
             &bluecell_Currdatastatus.ATT_DL1_PATH,
             &bluecell_Prevdatastatus.ATT_DL1_H,
             &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count1,
             &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count1)  ;  
        DL_Path_OnOff(Path2_OnOff,
             false,
             &bluecell_Currdatastatus.ATT_DL2_PATH,
             &bluecell_Prevdatastatus.ATT_DL2_H,
             &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count2,
             &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count2)  ;  
        DL_Path_OnOff(Path3_OnOff,
             false,
             &bluecell_Currdatastatus.ATT_DL3_PATH,
             &bluecell_Prevdatastatus.ATT_DL3_H,
             &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count3,
             &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count3)  ;          

        DL_Path_OnOff(Path4_OnOff,
             false,
             &bluecell_Currdatastatus.ATT_DL4_PATH,
             &bluecell_Prevdatastatus.ATT_DL4_H,
             &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count4,
             &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count4)  ;  

        UL_Path_OnOff(Path1_OnOff,
             false,
             &bluecell_Currdatastatus.ATT_UL1_PATH,
             &bluecell_Prevdatastatus.ATT_UL1_H,
             &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count1,
             &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count1)  ;  
        UL_Path_OnOff(Path2_OnOff,
             false,
             &bluecell_Currdatastatus.ATT_UL2_PATH,
             &bluecell_Prevdatastatus.ATT_UL2_H,
             &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count2,
             &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count2)  ;  
        UL_Path_OnOff(Path3_OnOff,
             false,
             &bluecell_Currdatastatus.ATT_UL3_PATH,
             &bluecell_Prevdatastatus.ATT_UL3_H,
             &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count3,
             &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count3)  ;          

        UL_Path_OnOff(Path4_OnOff,
             false,
             &bluecell_Currdatastatus.ATT_UL4_PATH,
             &bluecell_Prevdatastatus.ATT_UL4_H,
             &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count4,
             &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count4)  ;  


//        bluecell_Currdatastatus.DLI_Shutdown_ON_OFF = false;
//        bluecell_Currdatastatus.ULO_Shutdown_ON_OFF = false;
//        bluecell_Currdatastatus.DLI_AGC_ON_OFF = false;
//        bluecell_Currdatastatus.ULO_ALC_ON_OFF = false;
        
        bluecell_Currdatastatus.ALARM_TEMP_HIGH = 0;
        bluecell_Currdatastatus.ALARM_DLI_Level = 0;
        bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN = 0;
        bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm = 0;
        bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm = 0;
        bluecell_Currdatastatus.ALARM_ULO_Level = 0;        
        bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN = 0;    
        bluecell_Currdatastatus.DLI_Shutdown_Alarm1 = false;
        bluecell_Currdatastatus.DLI_Shutdown_Alarm2 = false;
        bluecell_Currdatastatus.DLI_Shutdown_Alarm3 = false;
        bluecell_Currdatastatus.DLI_Shutdown_Alarm4 = false;        

        bluecell_Currdatastatus.DLI_Shutdown_Retry_Count1 = false;
        bluecell_Currdatastatus.DLI_Shutdown_Retry_Count2 = false;
        bluecell_Currdatastatus.DLI_Shutdown_Retry_Count3 = false;
        bluecell_Currdatastatus.DLI_Shutdown_Retry_Count4 = false;

        bluecell_Currdatastatus.ULO_Shutdown_Alarm1 = false;
        bluecell_Currdatastatus.ULO_Shutdown_Alarm2 = false;
        bluecell_Currdatastatus.ULO_Shutdown_Alarm3 = false;
        bluecell_Currdatastatus.ULO_Shutdown_Alarm4 = false;        

        bluecell_Currdatastatus.ULO_Shutdown_Alarm1 = false;
        bluecell_Currdatastatus.ULO_Shutdown_Alarm2 = false;
        bluecell_Currdatastatus.ULO_Shutdown_Alarm3 = false;
        bluecell_Currdatastatus.ULO_Shutdown_Alarm4 = false;        
    }
}
void Temp_Shutdown_ONOFF(uint8_t val){
    printf("val :%d \r\n",val);
    printf("Path_TempShutdown_Set : %d \r\n",bluecell_Currdatastatus.Path_TempShutdown_Set);    
    printf(" bluecell_Currdatastatus.Path_TempSave_Bit : %x \r\n", bluecell_Currdatastatus.Path_TempSave_Bit);
    if(val == 0){// ON //Path ON
#if 0 // PYJ.2020.08.14_BEGIN -- 
         bluecell_Currdatastatus.ATT_DL1_PATH= TempShutdown_DL_SaveData[0];    
         bluecell_Currdatastatus.ATT_DL2_PATH= TempShutdown_DL_SaveData[1];    
         bluecell_Currdatastatus.ATT_DL3_PATH= TempShutdown_DL_SaveData[2];    
         bluecell_Currdatastatus.ATT_DL4_PATH= TempShutdown_DL_SaveData[3];    
         bluecell_Currdatastatus.ATT_UL1_PATH= TempShutdown_UL_SaveData[0];    
         bluecell_Currdatastatus.ATT_UL2_PATH= TempShutdown_UL_SaveData[1];    
         bluecell_Currdatastatus.ATT_UL3_PATH= TempShutdown_UL_SaveData[2];    
         bluecell_Currdatastatus.ATT_UL4_PATH= TempShutdown_UL_SaveData[3];   
#endif // PYJ.2020.08.14_END -- 
        if(bluecell_Currdatastatus.Path_TempSave_Bit & 0x80)
            bluecell_Currdatastatus.ATT_DL1_PATH = true;
        else
            bluecell_Currdatastatus.ATT_DL1_PATH = false;
        
        if(bluecell_Currdatastatus.Path_TempSave_Bit & 0x40)
            bluecell_Currdatastatus.ATT_DL2_PATH = true;
        else
            bluecell_Currdatastatus.ATT_DL2_PATH = false;
        
        if(bluecell_Currdatastatus.Path_TempSave_Bit & 0x20)
            bluecell_Currdatastatus.ATT_DL3_PATH = true;
        else
            bluecell_Currdatastatus.ATT_DL3_PATH = false;
        
        if(bluecell_Currdatastatus.Path_TempSave_Bit & 0x10)
            bluecell_Currdatastatus.ATT_DL4_PATH = true;
        else
            bluecell_Currdatastatus.ATT_DL4_PATH = false;
        
        if(bluecell_Currdatastatus.Path_TempSave_Bit & 0x08)
            bluecell_Currdatastatus.ATT_UL1_PATH = true;
        else
            bluecell_Currdatastatus.ATT_UL1_PATH = false;
        
        if(bluecell_Currdatastatus.Path_TempSave_Bit & 0x04)
            bluecell_Currdatastatus.ATT_UL2_PATH = true;
        else
            bluecell_Currdatastatus.ATT_UL2_PATH = false;
        
        if(bluecell_Currdatastatus.Path_TempSave_Bit & 0x02)
            bluecell_Currdatastatus.ATT_UL3_PATH = true;
        else
            bluecell_Currdatastatus.ATT_UL3_PATH = false;
        
        if(bluecell_Currdatastatus.Path_TempSave_Bit & 0x01)
            bluecell_Currdatastatus.ATT_UL4_PATH = true;
        else
            bluecell_Currdatastatus.ATT_UL4_PATH = false;
          printf("Path ON \r\n");

    }
    else{// OFF

#if 0 // PYJ.2020.08.14_BEGIN -- 
        TempShutdown_DL_SaveData[0] = bluecell_Currdatastatus.ATT_DL1_PATH;
        TempShutdown_DL_SaveData[1] = bluecell_Currdatastatus.ATT_DL2_PATH;
        TempShutdown_DL_SaveData[2] = bluecell_Currdatastatus.ATT_DL3_PATH;
        TempShutdown_DL_SaveData[3] = bluecell_Currdatastatus.ATT_DL4_PATH;
        TempShutdown_UL_SaveData[0] = bluecell_Currdatastatus.ATT_UL1_PATH;
        TempShutdown_UL_SaveData[1] = bluecell_Currdatastatus.ATT_UL2_PATH;
        TempShutdown_UL_SaveData[2] = bluecell_Currdatastatus.ATT_UL3_PATH;
        TempShutdown_UL_SaveData[3] = bluecell_Currdatastatus.ATT_UL4_PATH;
#endif // PYJ.2020.08.14_END -- 

        
        bluecell_Currdatastatus.ATT_DL1_PATH = false;    
        bluecell_Currdatastatus.ATT_DL2_PATH = false;    
        bluecell_Currdatastatus.ATT_DL3_PATH = false;    
        bluecell_Currdatastatus.ATT_DL4_PATH = false;    
        bluecell_Currdatastatus.ATT_UL1_PATH = false;    
        bluecell_Currdatastatus.ATT_UL2_PATH = false;    
        bluecell_Currdatastatus.ATT_UL3_PATH = false;    
        bluecell_Currdatastatus.ATT_UL4_PATH = false;   
        printf("Path OOF \r\n");
        bluecell_Currdatastatus.ALARM_TEMP_HIGH = 0;
        bluecell_Currdatastatus.ALARM_DLI_Level = 0;
        bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN = 0;
        bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm = 0;
        bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm = 0;
        bluecell_Currdatastatus.ALARM_ULO_Level = 0;        
        bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN = 0;    
        bluecell_Currdatastatus.DLI_Shutdown_Alarm1 = false;
        bluecell_Currdatastatus.DLI_Shutdown_Alarm2 = false;
        bluecell_Currdatastatus.DLI_Shutdown_Alarm3 = false;
        bluecell_Currdatastatus.DLI_Shutdown_Alarm4 = false;        

        bluecell_Currdatastatus.DLI_Shutdown_Retry_Count1 = false;
        bluecell_Currdatastatus.DLI_Shutdown_Retry_Count2 = false;
        bluecell_Currdatastatus.DLI_Shutdown_Retry_Count3 = false;
        bluecell_Currdatastatus.DLI_Shutdown_Retry_Count4 = false;

        bluecell_Currdatastatus.ULO_Shutdown_Alarm1 = false;
        bluecell_Currdatastatus.ULO_Shutdown_Alarm2 = false;
        bluecell_Currdatastatus.ULO_Shutdown_Alarm3 = false;
        bluecell_Currdatastatus.ULO_Shutdown_Alarm4 = false;        

        bluecell_Currdatastatus.ULO_Shutdown_Alarm1 = false;
        bluecell_Currdatastatus.ULO_Shutdown_Alarm2 = false;
        bluecell_Currdatastatus.ULO_Shutdown_Alarm3 = false;
        bluecell_Currdatastatus.ULO_Shutdown_Alarm4 = false;  
        
      
    }
    DL_Path_OnOff(Path1_OnOff,
            bluecell_Currdatastatus.ATT_DL1_PATH,
            &bluecell_Currdatastatus.ATT_DL1_PATH,
            &bluecell_Prevdatastatus.ATT_DL1_H,
            &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count1,
            &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count1)  ;  
    DL_Path_OnOff(Path2_OnOff,
            bluecell_Currdatastatus.ATT_DL2_PATH,
            &bluecell_Currdatastatus.ATT_DL2_PATH,
            &bluecell_Prevdatastatus.ATT_DL2_H,
            &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count2,
            &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count2)  ;  
    DL_Path_OnOff(Path3_OnOff,
            bluecell_Currdatastatus.ATT_DL3_PATH,
            &bluecell_Currdatastatus.ATT_DL3_PATH,
            &bluecell_Prevdatastatus.ATT_DL3_H,
            &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count3,
            &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count3)  ;          

    DL_Path_OnOff(Path4_OnOff,
            bluecell_Currdatastatus.ATT_DL4_PATH,
            &bluecell_Currdatastatus.ATT_DL4_PATH,
            &bluecell_Prevdatastatus.ATT_DL4_H,
            &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count4,
            &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count4)  ;  

    UL_Path_OnOff(Path1_OnOff,
            bluecell_Currdatastatus.ATT_UL1_PATH,
            &bluecell_Currdatastatus.ATT_UL1_PATH,
            &bluecell_Prevdatastatus.ATT_UL1_H,
            &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count1,
            &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count1)  ;  
    UL_Path_OnOff(Path2_OnOff,
            bluecell_Currdatastatus.ATT_UL2_PATH,
            &bluecell_Currdatastatus.ATT_UL2_PATH,
            &bluecell_Prevdatastatus.ATT_UL2_H,
            &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count2,
            &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count2)  ;  
    UL_Path_OnOff(Path3_OnOff,
            bluecell_Currdatastatus.ATT_UL3_PATH,
            &bluecell_Currdatastatus.ATT_UL3_PATH,
            &bluecell_Prevdatastatus.ATT_UL3_H,
            &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count3,
            &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count3)  ;          

    UL_Path_OnOff(Path4_OnOff,
            bluecell_Currdatastatus.ATT_UL4_PATH,
            &bluecell_Currdatastatus.ATT_UL4_PATH,
            &bluecell_Prevdatastatus.ATT_UL4_H,
            &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count4,
            &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count4)  ;               

//        HAL_Delay(10);
    CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);    
}

#define OVERPOWER_STR "Overpower"
#define OVER_INPUT_STR "Over-Input"
#define ALARM_REPORT_LENGTH 42
//uint8_t AlarmReport_History[Alarm_type_IndexMax] = {0,};
volatile uint8_t Alarm_ReportData[40 + 2 + 22 + 3] = {0,}; // 40 Alarm Data + 2 UNIT ID, 21 Header , 3 Tail
uint8_t* Alarm_Report_Send(uint16_t Alarm_type,uint8_t val){
//    if(AlarmReport_History[Alarm_type] != true){
//        return;
//    }
    uint8_t index = 0;
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = 0x00;       //UNIT ID0
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = 0xF1;       //UNIT ID1
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = (uint8_t)((Alarm_type & 0xFF00) >> 8);       //A ID 0 
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = (uint8_t)(Alarm_type & 0x00FF); //A ID 1
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = val;        //Status 1
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = 0;          //Alarm Time
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = 0;          //Alarm Time
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = 0;          //Alarm Time      
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = 0;          //Alarm Time      
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = 0;          //Alarm Time      
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = 0;          //Alarm Time      
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = 0;          //Clear Time      
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = 0;          //Clear Time      
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = 0;          //Clear Time      
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = 0;          //Clear Time      
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = 0;          //Clear Time      
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = 0;          //Clear Time      
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = 0;          //Band ID : MBIC : 0x00 Default
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = bluecell_Currdatastatus.Carrier_ID;
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = bluecell_Currdatastatus.Freq_ID;    
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = 0;//Alarm SeqNum0 RF Board Default 0
    Alarm_ReportData[MBIC_PAYLOADSTART + index++] = 0;//Alarm SeqNum1 RF Board Default 0   

    // 0~ 19 
    for(int i = MBIC_PAYLOADSTART + 22; i < MBIC_PAYLOADSTART + ALARM_REPORT_LENGTH; i++)
        Alarm_ReportData[i] = 0;
    

    int16_t LimitData_UL_High = 0;
    
    int16_t LimitData_DL_High = 0;    
    int16_t LimitData_DL_Low = 0;    


    int16_t LimitData_DL_Shutdown = 0;    
    int16_t LimitData_UL_Shutdown = 0;    
    
    double ret = 0;
    int16_t Res_DL_dBm[DET_Alarm_DL_Index_MAX] = {0,};
    int16_t Res_UL_dBm[DET_Alarm_UL_Index_MAX] = {0,};    
    

    LimitData_UL_High = ConvertTo2byte(bluecell_Currdatastatus.ULO_Level_High_Threshold_H,bluecell_Currdatastatus.ULO_Level_High_Threshold_L) * 0.1;
    LimitData_DL_High = ConvertTo2byte(bluecell_Currdatastatus.DLI_Level_High_Threshold_H,bluecell_Currdatastatus.DLI_Level_High_Threshold_L)* 0.1;
    LimitData_DL_Low  = ConvertTo2byte(bluecell_Currdatastatus.DLI_Level_Low_Threshold_H,bluecell_Currdatastatus.DLI_Level_Low_Threshold_L)* 0.1;

    LimitData_DL_Shutdown = ConvertTo2byte(bluecell_Currdatastatus.DLI_Shutdown_Threshold_H,bluecell_Currdatastatus.DLI_Shutdown_Threshold_L)* 0.1;
    LimitData_UL_Shutdown = ConvertTo2byte(bluecell_Currdatastatus.ULO_Shutdown_Threshold_H,bluecell_Currdatastatus.ULO_Shutdown_Threshold_L)* 0.1;
    

    ret  = bluecell_Currdatastatus.DLI_P1_Level1_H << 8;
    ret += bluecell_Currdatastatus.DLI_P1_Level1_L;   
    ret *= 0.001;    
    Res_DL_dBm[DET_Alarm_DL1_Index] 
        = bluecell_Currdatastatus.DLI_Level1_H << 8 | bluecell_Currdatastatus.DLI_Level1_L;//(int8_t)Bluecell_TestPro(AGC_AutoControl_ADC_Compare(ret,&Det_DL1.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st)));
    ret  = bluecell_Currdatastatus.DLI_P2_Level2_H << 8;
    ret += bluecell_Currdatastatus.DLI_P2_Level2_L;   
    ret *= 0.001;  

    Res_DL_dBm[DET_Alarm_DL2_Index] 
        = bluecell_Currdatastatus.DLI_Level2_H << 8 | bluecell_Currdatastatus.DLI_Level2_L;//(int8_t)Bluecell_TestPro(AGC_AutoControl_ADC_Compare(ret,&Det_DL2.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st)));
    ret  = bluecell_Currdatastatus.DLI_P3_Level3_H << 8;
    ret += bluecell_Currdatastatus.DLI_P3_Level3_L;   
    ret *= 0.001;  

    Res_DL_dBm[DET_Alarm_DL3_Index] 
        = bluecell_Currdatastatus.DLI_Level3_H << 8 | bluecell_Currdatastatus.DLI_Level3_L;//(int8_t)Bluecell_TestPro(AGC_AutoControl_ADC_Compare(ret,&Det_DL3.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st)));


    ret  = bluecell_Currdatastatus.DLI_P4_Level4_H << 8;
    ret += bluecell_Currdatastatus.DLI_P4_Level4_L;   
    ret *= 0.001;  

    Res_DL_dBm[DET_Alarm_DL4_Index] 
        = bluecell_Currdatastatus.DLI_Level4_H << 8 | bluecell_Currdatastatus.DLI_Level4_L;//(int8_t)Bluecell_TestPro(AGC_AutoControl_ADC_Compare(ret,&Det_DL4.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st)));



    ret  = bluecell_Currdatastatus.ULO_P1_Level1_H << 8;
    ret += bluecell_Currdatastatus.ULO_P1_Level1_L;   
    ret *= 0.001;

    Res_UL_dBm[DET_Alarm_UL1_Index] 
        = bluecell_Currdatastatus.ULO_Level1_H << 8 | bluecell_Currdatastatus.ULO_Level1_L; //(int8_t)Bluecell_TestPro(AutoControl_ADC_Compare(ret,&Det_UL1.Table_Det_15_dBm_H,Det_UL1.Table_Length * 2));


    ret  = bluecell_Currdatastatus.ULO_P2_Level2_H << 8;
    ret += bluecell_Currdatastatus.ULO_P2_Level2_L;   
    ret *= 0.001;

    Res_UL_dBm[DET_Alarm_UL2_Index] 
        = bluecell_Currdatastatus.ULO_Level2_H << 8 | bluecell_Currdatastatus.ULO_Level2_L;//(int8_t)Bluecell_TestPro(AutoControl_ADC_Compare(ret,&Det_UL2.Table_Det_15_dBm_H,Det_UL2.Table_Length * 2));

    ret  = bluecell_Currdatastatus.ULO_P3_Level3_H << 8;
    ret += bluecell_Currdatastatus.ULO_P3_Level3_L;   
    ret *= 0.001;

    Res_UL_dBm[DET_Alarm_UL3_Index] 
        = bluecell_Currdatastatus.ULO_Level3_H << 8 | bluecell_Currdatastatus.ULO_Level3_L;//(int8_t)Bluecell_TestPro(AutoControl_ADC_Compare(ret,&Det_UL3.Table_Det_15_dBm_H,Det_UL3.Table_Length * 2));


    ret  = bluecell_Currdatastatus.ULO_P4_Level4_H << 8;
    ret += bluecell_Currdatastatus.ULO_P4_Level4_L;   
    ret *= 0.001;

    Res_UL_dBm[DET_Alarm_UL4_Index] 
        = bluecell_Currdatastatus.ULO_Level4_H << 8 | bluecell_Currdatastatus.ULO_Level4_L;//(int8_t)Bluecell_TestPro(AutoControl_ADC_Compare(ret,&Det_UL4.Table_Det_15_dBm_H,Det_UL4.Table_Length * 2));


 
    switch(Alarm_type){
        case Temp_High:             sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],"Temp:%d, Th:%d",bluecell_Currdatastatus.DET_TEMP,bluecell_Currdatastatus.Temp_High_Threshold);    break;
        case DLI_P4_Level_Low:      sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],"DLI:%d, Th:%d",Res_DL_dBm[DET_Alarm_DL1_Index],LimitData_DL_Low);    break;
        case DLI_P3_Level_Low:      sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],"DLI:%d, Th:%d",Res_DL_dBm[DET_Alarm_DL2_Index],LimitData_DL_Low);    break;
        case DLI_P2_Level_Low:      sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],"DLI:%d, Th:%d",Res_DL_dBm[DET_Alarm_DL3_Index],LimitData_DL_Low);    break;
        case DLI_P1_Level_Low:      sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],"DLI:%d, Th:%d",Res_DL_dBm[DET_Alarm_DL4_Index],LimitData_DL_Low);    break;
        case DLI_P4_Level_High:     sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],"DLI:%d, Th:%d",Res_DL_dBm[DET_Alarm_DL1_Index],LimitData_DL_High);    break;
        case DLI_P3_Level_High:     sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],"DLI:%d, Th:%d",Res_DL_dBm[DET_Alarm_DL2_Index],LimitData_DL_High);    break;
        case DLI_P2_Level_High:     sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],"DLI:%d, Th:%d",Res_DL_dBm[DET_Alarm_DL3_Index],LimitData_DL_High);    break;
        case DLI_P1_Level_High:     sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],"DLI:%d, Th:%d",Res_DL_dBm[DET_Alarm_DL4_Index],LimitData_DL_High);    break;
        case DLI_P4_AGC_Alarm:
        case DLI_P3_AGC_Alarm:
        case DLI_P2_AGC_Alarm:
        case DLI_P1_AGC_Alarm:      break;
        case DLI_P4_Shutdown_Alarm: sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],OVERPOWER_STR);    break;
        case DLI_P3_Shutdown_Alarm: sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],OVERPOWER_STR);    break;
        case DLI_P2_Shutdown_Alarm: sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],OVERPOWER_STR);    break;
        case DLI_P1_Shutdown_Alarm: sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],OVERPOWER_STR);    break;
        case ULO_P4_Level_High:     sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],"ULO:%d, Th:%d",Res_UL_dBm[DET_Alarm_UL1_Index],LimitData_UL_High);    break;
        case ULO_P3_Level_High:     sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],"ULO:%d, Th:%d",Res_UL_dBm[DET_Alarm_UL2_Index],LimitData_UL_High);    break;
        case ULO_P2_Level_High:     sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],"ULO:%d, Th:%d",Res_UL_dBm[DET_Alarm_UL3_Index],LimitData_UL_High);    break;
        case ULO_P1_Level_High:     sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],"ULO:%d, Th:%d",Res_UL_dBm[DET_Alarm_UL4_Index],LimitData_UL_High);    break;
        case ULO_P4_ALC_Alarm:
        case ULO_P3_ALC_Alarm:
        case ULO_P2_ALC_Alarm:
        case ULO_P1_ALC_Alarm:      break;
        case ULO_P4_Shutdown:       sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],OVER_INPUT_STR);    break;
        case ULO_P3_Shutdown:       sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],OVER_INPUT_STR);    break;
        case ULO_P2_Shutdown:       sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],OVER_INPUT_STR);    break;
        case ULO_P1_Shutdown:       sprintf(&Alarm_ReportData[MBIC_PAYLOADSTART + 22],OVER_INPUT_STR);    break;
        default: printf("Wrong Type \r\n");break;
    }
    
//    Alarm_ReportData[MBIC_PAYLOADSTART + 1] = Alarm_type;    
//    Alarm_ReportData[MBIC_PAYLOADSTART + 2] = val;        
    
    printf("%s \r\n",&Alarm_ReportData[MBIC_PAYLOADSTART + 22]);
//    printf("Type : %x  size length : %d \r\n",Alarm_type,sizeof(Alarm_ReportData));
//    MBIC_HeaderMergeFunction(Alarm_ReportData,ALARM_REPORT_LENGTH);
    Alarm_ReportData[MBIC_PREAMBLE_0] = MBIC_PREAMBLE0;
    Alarm_ReportData[MBIC_PREAMBLE_1] = MBIC_PREAMBLE1;
    Alarm_ReportData[MBIC_PREAMBLE_2] = MBIC_PREAMBLE2;
    Alarm_ReportData[MBIC_PREAMBLE_3] = MBIC_PREAMBLE3;   

    Alarm_ReportData[MBIC_SUBUID_0] = MBIC_SUBUID0;
    Alarm_ReportData[MBIC_SUBUID_1] = MBIC_SUBUID1;

    Alarm_ReportData[MBIC_RCODE_0] = 0;

    Alarm_ReportData[MBIC_TRID_0] = 0;
    Alarm_ReportData[MBIC_TRID_1] = 0;

    Alarm_ReportData[MBIC_SEQSUM_0] = 0;

    Alarm_ReportData[MBIC_TTL_0] = 0;

    Alarm_ReportData[MBIC_TIME_0] = 0;
    Alarm_ReportData[MBIC_TIME_1] = 0;
    Alarm_ReportData[MBIC_TIME_2] = 0;
    Alarm_ReportData[MBIC_TIME_3] = 0;
    Alarm_ReportData[MBIC_TIME_4] = 0;
    Alarm_ReportData[MBIC_TIME_5] = 0;
    Alarm_ReportData[MBIC_ERRRESPONSE_0] = MBIC_ERRRESPONSE;
    Alarm_ReportData[MBIC_CMD_0] = 0xF1;





    Alarm_ReportData[MBIC_LENGTH_0] = (ALARM_REPORT_LENGTH & 0xFF00) >> 8;
    Alarm_ReportData[MBIC_LENGTH_1] = ALARM_REPORT_LENGTH & 0x00FF;

    Alarm_ReportData[MBIC_HEADERCHECKSUM_0] = Chksum_Create(Alarm_ReportData);    

    
    uint16_t crcret =CRC16_Generate(&Alarm_ReportData[MBIC_PAYLOADSTART], ALARM_REPORT_LENGTH);
    
//                        printf("\r\n crc ret : %x \r\n",crcret);
    Alarm_ReportData[MBIC_PAYLOADSTART + 42] =(( crcret  & 0xFF00)>> 8);  
//        printf(" Alarm_ReportData[MBIC_PAYLOADSTART + 41] : %x \r\n", Alarm_ReportData[MBIC_PAYLOADSTART + 41]);
    Alarm_ReportData[MBIC_PAYLOADSTART + 43] = (( crcret  & 0x00FF));  
//        printf(" Alarm_ReportData[MBIC_PAYLOADSTART + 42] : %x \r\n", Alarm_ReportData[MBIC_PAYLOADSTART + 42]);    
    Alarm_ReportData[MBIC_PAYLOADSTART + 44] = 0x03; 
//        printf(" Alarm_ReportData[MBIC_PAYLOADSTART + 43] : %x \r\n", Alarm_ReportData[MBIC_PAYLOADSTART + 43]);    
    Uart1_Data_Send(&Alarm_ReportData[0],sizeof(Alarm_ReportData));
            printf(" Alarm_ReportData[MBIC_PAYLOADSTART + 42] : %x \r\n", Alarm_ReportData[MBIC_PAYLOADSTART + 42]);
}

bool MBIC_Operate(uint8_t* data){
//    Bluecell_StructCpy(&Txdata[0],&bluecell_Currdatastatus.bluecell_header,sizeof(BLUESTATUS_st));
	uint8_t datatype = data[MBIC_PAYLOADSTART + 1];
   // uint8_t Length = (data[MBIC_PROT_SUB_DATA_INDEX + 2]);
    uint8_t cmd = data[MBIC_PROT_CMD_INDEX];
    int16_t Tmpdata = 0;
    int16_t Tmpdata2 = 0;    
	int16_t tempdata = 0;
    //uint16_t Temp_ADC = 0;
    //uint16_t i = 0;
    //double temp = 0;
    //int16_t Level = 0;
    //int16_t tmpdata = 0;
    /*Day Save*/
#if 0 // PYJ.2020.07.03_BEGIN -- 
    if(bluecell_Currdatastatus.DLI_AGC_ON_OFF == true && bluecell_Currdatastatus.DLI_FRBT_D_Day < 7
        && bluecell_Currdatastatus.DLI_FRBT_Status != FRBT_RUNNING){
        for(int i = 0; i < DLI_FRBT_Time_Index_Max; i++){
            FRBT_Day[DLI_FRBT_Time_Year + i] = data[MBIC_TIME_0 + i]; /* Curr day */
        }

        if(FRBT_Day[DLI_FRBT_Time_Day] != PrevFRBT_Day[DLI_FRBT_D_Day])
            bluecell_Currdatastatus.DLI_FRBT_D_Day++;
        
        for(int i = 0; i < DLI_FRBT_Time_Index_Max; i++){
            PrevFRBT_Day[DLI_FRBT_Time_Year + i] = FRBT_Day[DLI_FRBT_Time_Year + i]; /* Curr day */
        }        
    }
#else
    TimeSetting(&data[MBIC_TIME_0]);

#endif // PYJ.2020.07.03_END -- 
    for(int k = 0; k < 2048; k++)
        TxData[k] = data[k];
    
    data = TxData;
    uint16_t Length = data[MBIC_LENGTH_0] << 8 | data[MBIC_LENGTH_1];
    //uint8_t* Tempdata;
    uint16_t occurlen = Length;
    /*AID*/
  /* for(int i = 0; i < Length; i++){
        SubData[i] = (data[MBIC_PROT_SUB_DATA_INDEX + 3 + i]);
    }*/
    //    SubData     임시 데이터 변수 선언 Subdata로 데이터 전송


	data[MBIC_PREAMBLE_0] = MBIC_PREAMBLE0;
	data[MBIC_PREAMBLE_1] = MBIC_PREAMBLE1;
	data[MBIC_PREAMBLE_2] = MBIC_PREAMBLE2;
	data[MBIC_PREAMBLE_3] = MBIC_PREAMBLE3;

	data[MBIC_SUBUID_0] = MBIC_SUBUID0;
	data[MBIC_SUBUID_1] = MBIC_SUBUID1;

	data[MBIC_RCODE_0] = data[MBIC_RCODE_0];

	data[MBIC_TRID_0] = data[MBIC_TRID_0];
	data[MBIC_TRID_1] = data[MBIC_TRID_1];

	data[MBIC_SEQSUM_0] = data[MBIC_SEQSUM_0];

	data[MBIC_TTL_0] = data[MBIC_TTL_0];

    data[MBIC_TIME_0] = data[MBIC_TIME_0];
	data[MBIC_TIME_1] = data[MBIC_TIME_1];
	data[MBIC_TIME_2] = data[MBIC_TIME_2];
	data[MBIC_TIME_3] = data[MBIC_TIME_3];
	data[MBIC_TIME_4] = data[MBIC_TIME_4];
	data[MBIC_TIME_5] = data[MBIC_TIME_5];

    data[MBIC_ERRRESPONSE_0] = MBIC_ERRRESPONSE;

    if(cmd == MBIC_GET){
        if(Initialize == false){
            Bluecell_DataInit();
            Bluecell_AttenInitialize();
            Initialize = true;

        }
        HFR_TypeInit();        
        data[MBIC_CMD_0] = 0x80;//MBIC_ERRRESPONSE;
        Length = MBIC_DataSend(data);
    }
    else if(cmd == MBIC_SET){
       protocolReplay:
        datatype = data[MBIC_PAYLOADSTART + 1];
        switch(datatype){
            case  Alarm_Mask                              :
                bluecell_Currdatastatus.ALARM_MASK1 = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.ALARM_MASK2 = data[MBIC_PAYLOADSTART + 4]; 
                bluecell_Currdatastatus.ALARM_MASK3 = data[MBIC_PAYLOADSTART + 5]; 
                bluecell_Currdatastatus.ALARM_MASK4 = data[MBIC_PAYLOADSTART + 6]; 
                bluecell_Currdatastatus.ALARM_MASK5 = data[MBIC_PAYLOADSTART + 7]; 
                break;
            case  Alarm_Test_Mode                         :
//                printf("bluecell_Currdatastatus.ALsARM_TESTMODE : %d \r\n",bluecell_Currdatastatus.ALARM_TESTMODE);
                bluecell_Currdatastatus.ALARM_TESTMODE = data[MBIC_PAYLOADSTART + 3]; 
                break;
            case  Alarm_Test_Dummy                        :
                bluecell_Currdatastatus.ALARM_Test_Dummy1 = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.ALARM_Test_Dummy2 = data[MBIC_PAYLOADSTART + 4];
                bluecell_Currdatastatus.ALARM_Test_Dummy3 = data[MBIC_PAYLOADSTART + 5];
                bluecell_Currdatastatus.ALARM_Test_Dummy4 = data[MBIC_PAYLOADSTART + 6];
                bluecell_Currdatastatus.ALARM_Test_Dummy5 = data[MBIC_PAYLOADSTART + 7];
//                printf("Dummy 1 : %d \r\n",bluecell_Currdatastatus.ALARM_Test_Dummy1);
//                printf("Dummy 2 : %d \r\n",bluecell_Currdatastatus.ALARM_Test_Dummy2);
//                printf("Dummy 3 : %d \r\n",bluecell_Currdatastatus.ALARM_Test_Dummy3);
//                printf("Dummy 4 : %d \r\n",bluecell_Currdatastatus.ALARM_Test_Dummy4);
//                printf("Dummy 5 : %d \r\n",bluecell_Currdatastatus.ALARM_Test_Dummy5);                
                break;
            case  CPU_Bank_Select_Reboot_by               :
                bluecell_Currdatastatus.CPU_Bank_Select = data[MBIC_PAYLOADSTART + 3]; 
                if(bluecell_Currdatastatus.CPU_Bank_Select == HFR_AUTO_SEL){
//                    printf("Curr Bank : %d \r\n",bluecell_Currdatastatus.CPU_Current_Bank);
                    if(bluecell_Currdatastatus.CPU_Current_Bank == HFR_BANK1_SEL){
                        bluecell_Currdatastatus.CPU_Bank_Select = HFR_BANK2_SEL;
                    }else{
                        bluecell_Currdatastatus.CPU_Bank_Select = HFR_BANK1_SEL;
                    }
                }
                Bluecell_StructCpy(&DataWrite[0],&bluecell_Currdatastatus.bluecell_header,sizeof(BLUESTATUS_st));
                EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_WINDOW_STATUS_ADDRESDS),&DataWrite[0],sizeof(BLUESTATUS_st));
                EEPROM_M24C08_Read(EEPROM_M24C08_ID,EEPROM_WINDOW_STATUS_ADDRESDS,&bluecell_Currdatastatus.bluecell_header,sizeof(BLUESTATUS_st) );
//                printf("bluecell_Currdatastatus.CPU_Bank_Select : %d \r\n",bluecell_Currdatastatus.CPU_Bank_Select);
//                printf("I will Booting Bank : %d \r\n",bluecell_Currdatastatus.CPU_Current_Bank);
                NVIC_SystemReset();
                break;
            case  SW_Reset                                :
//                Table_LengSet();
//                printf("SoftWare Reset Start \r\n");
                bluecell_Currdatastatus.S_W_Reset = data[MBIC_PAYLOADSTART + 3]; 
                NVIC_SystemReset();
                break;
            case  Factory_Set_Initialization              :
                bluecell_Currdatastatus.Factory_Set_Initialization = data[MBIC_PAYLOADSTART + 3]; 
                Factory_Set();
                    
                break;
            case  Temperature_Offset                      :
                bluecell_Currdatastatus.bluecell_User_TEMP_OFFSET = data[MBIC_PAYLOADSTART + 3]; 
//                printf("%s : %d \r\n",__func__,__LINE__);
                break;
            case  Temp_High_Threshold                     :
                bluecell_Currdatastatus.Temp_High_Threshold = data[MBIC_PAYLOADSTART + 3]; 
                break;
            case  Temp_High_Threshold_Default             :
				bluecell_Currdatastatus.Temp_High_Threshold = Temp_THREADHOLD_DEFAULT;
//                bluecell_Currdatastatus.Temp_High_Threshold_Default = data[MBIC_PAYLOADSTART + 3]; 
                break;
            case  LED_TEST                                :
                bluecell_Currdatastatus.LED_TEST = data[MBIC_PAYLOADSTART + 3]; 
                break;
            case PCB_Version:
                for(int i = 0 ; i < 2; i++)
                    bluecell_Currdatastatus.PCB_Version[i] = data[MBIC_PAYLOADSTART + 3 + i]; 
                break;            
            case Serial_Number:
                for(int i = 0 ; i < 20; i++)
                    bluecell_Currdatastatus.Serial_Number[i] = data[MBIC_PAYLOADSTART + 3 + i]; 
                break;
                
            case Manufacture_Date:
                for(int i = 0 ; i < 3; i++)
                    bluecell_Currdatastatus.Manufacture_Date[i] = data[MBIC_PAYLOADSTART + 3 + i]; 
                break;
            case Temp_Shutdown_Path_ON_OFF:
                bluecell_Currdatastatus.Path_TempShutdown_Set = data[MBIC_PAYLOADSTART + 3];
                Temp_Shutdown_ONOFF(bluecell_Currdatastatus.Path_TempShutdown_Set);
                break;
            case  Carrier_ON_OFF                          :
                bluecell_Currdatastatus.Carrier_ON_OFF = data[MBIC_PAYLOADSTART + 3]; 
                Carrier_ONOFF(bluecell_Currdatastatus.Carrier_ON_OFF);
                break;
            case  DLI_RF_Path1_ON_OFF             :
                if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
                    return true;
                if(data[MBIC_PAYLOADSTART + 3] != 0)
                    bluecell_Currdatastatus.Path_TempSave_Bit |= 0x80;
                else
                   bluecell_Currdatastatus.Path_TempSave_Bit &= ~0x80;
                DL_Path_OnOff(Path1_OnOff,
                    data[MBIC_PAYLOADSTART + 3],
                    &bluecell_Currdatastatus.ATT_DL1_PATH,
                    &bluecell_Prevdatastatus.ATT_DL1_H,
                    &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count1,
                    &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count1)  ;      
                break;
            case  DLI_RF_Path2_ON_OFF                     :
                if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
                    return true;
                if(data[MBIC_PAYLOADSTART + 3] != 0)
                    bluecell_Currdatastatus.Path_TempSave_Bit |= 0x40; 
                else
                   bluecell_Currdatastatus.Path_TempSave_Bit &= ~0x40;       
                
                DL_Path_OnOff(Path2_OnOff,
                    data[MBIC_PAYLOADSTART + 3],
                    &bluecell_Currdatastatus.ATT_DL2_PATH,
                    &bluecell_Prevdatastatus.ATT_DL2_H,
                    &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count2,
                    &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count2)  ;                  
                break;
            case  DLI_RF_Path3_ON_OFF                     :
                if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
                    return true;
                if(data[MBIC_PAYLOADSTART + 3] != 0)
                    bluecell_Currdatastatus.Path_TempSave_Bit |= 0x20;
                    else
                   bluecell_Currdatastatus.Path_TempSave_Bit &= ~0x20;
                DL_Path_OnOff(Path3_OnOff,
                    data[MBIC_PAYLOADSTART + 3],
                    &bluecell_Currdatastatus.ATT_DL3_PATH,
                    &bluecell_Prevdatastatus.ATT_DL3_H,
                    &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count3,
                    &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count3)  ;                  

                break;
            case  DLI_RF_Path4_ON_OFF                     :
                if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
                    return true;
                if(data[MBIC_PAYLOADSTART + 3] != 0)
                    bluecell_Currdatastatus.Path_TempSave_Bit |= 0x10;
                else
                   bluecell_Currdatastatus.Path_TempSave_Bit &= ~0x10;
                DL_Path_OnOff(Path4_OnOff,
                    data[MBIC_PAYLOADSTART + 3],
                    &bluecell_Currdatastatus.ATT_DL4_PATH,
                    &bluecell_Prevdatastatus.ATT_DL4_H,
                    &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count4,
                    &bluecell_Prevdatastatus.DLI_Shutdown_Retry_Count4)  ;                  

                break;
            case  DLI_Gain_Atten1                         :
                bluecell_Currdatastatus.ATT_DL1_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.ATT_DL1_L = data[MBIC_PAYLOADSTART + 4]; 

                DL_PrevIwillgiveAtten[AGC_Alarm_DL1_Index] = 0;
//                printf("bluecell_Currdatastatus.ATT_DL1_H : %x\r\n",bluecell_Currdatastatus.ATT_DL1_H);
//                printf("bluecell_Currdatastatus.ATT_DL1_L : %x\r\n",bluecell_Currdatastatus.ATT_DL1_L);              
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
                break;
            case  DLI_Gain_Atten2                         :
                bluecell_Currdatastatus.ATT_DL2_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.ATT_DL2_L = data[MBIC_PAYLOADSTART + 4]; 
                DL_PrevIwillgiveAtten[AGC_Alarm_DL2_Index] = 0;
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
//                printf("bluecell_Currdatastatus.ATT_DL2_H : %x\r\n",bluecell_Currdatastatus.ATT_DL2_H);
//                printf("bluecell_Currdatastatus.ATT_DL2_L : %x\r\n",bluecell_Currdatastatus.ATT_DL2_L); 

                break;
            case  DLI_Gain_Atten3                         :
                bluecell_Currdatastatus.ATT_DL3_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.ATT_DL3_L = data[MBIC_PAYLOADSTART + 4]; 
                DL_PrevIwillgiveAtten[AGC_Alarm_DL3_Index] = 0;
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

                break;
            case  DLI_Gain_Atten4                         :
                bluecell_Currdatastatus.ATT_DL4_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.ATT_DL4_L = data[MBIC_PAYLOADSTART + 4]; 
                DL_PrevIwillgiveAtten[AGC_Alarm_DL4_Index] = 0;
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

                break;
            case  DLI_Gain_Atten_Offset1                  :
                bluecell_Currdatastatus.bluecell_User_DL1_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.bluecell_User_DL1_L = data[MBIC_PAYLOADSTART + 4]; 
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

                break;
            case  DLI_Gain_Atten_Offset2                  :
                bluecell_Currdatastatus.bluecell_User_DL2_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.bluecell_User_DL2_L = data[MBIC_PAYLOADSTART + 4];
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

                break;
            case  DLI_Gain_Atten_Offset3                  :
                bluecell_Currdatastatus.bluecell_User_DL3_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.bluecell_User_DL3_L = data[MBIC_PAYLOADSTART + 4]; 
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

                break;
            case  DLI_Gain_Atten_Offset4                  :
                bluecell_Currdatastatus.bluecell_User_DL4_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.bluecell_User_DL4_L = data[MBIC_PAYLOADSTART + 4]; 
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

                break;
            case  DLI_Level_High_Threshold                :
                bluecell_Currdatastatus.DLI_Level_High_Threshold_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.DLI_Level_High_Threshold_L = data[MBIC_PAYLOADSTART + 4]; 

                break;
            case  DLI_Level_Low_Threshold                 :
                bluecell_Currdatastatus.DLI_Level_Low_Threshold_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.DLI_Level_Low_Threshold_L = data[MBIC_PAYLOADSTART + 4]; 

                break;
            case  DLI_Level_High_Low_Threshold_default    :
			    tempdata  = DLI_ATTEN_HIGHTHREADHOLD_DEFAULT;
			    bluecell_Currdatastatus.DLI_Level_High_Threshold_H = ((tempdata & 0xFF00) >> 8);
			    bluecell_Currdatastatus.DLI_Level_High_Threshold_L = ((tempdata & 0x00FF));

			    tempdata  = DLI_ATTEN_LOWTHREADHOLD_DEFAULT;
			    bluecell_Currdatastatus.DLI_Level_Low_Threshold_H = ((tempdata & 0xFF00) >> 8);
			    bluecell_Currdatastatus.DLI_Level_Low_Threshold_L = ((tempdata & 0x00FF));				
              //  bluecell_Currdatastatus.DLI_Level_High_Low_Threshold_default = data[MBIC_PAYLOADSTART + 3]; 

                break;
            case DLI_FRBT_D_Day: 
                bluecell_Currdatastatus.DLI_FRBT_D_Day = data[MBIC_PAYLOADSTART + 3];
                if(bluecell_Currdatastatus.DLI_FRBT_D_Day == 0){
                    FRBT_Day_Inc = 0;
                    bluecell_Currdatastatus.DLI_FRBT_Status = FRBT_IDEL; 
                    
                }else{
                    bluecell_Currdatastatus.DLI_FRBT_Status = FRBT_TRACKING; 
                }
                break;

            case  DLI_AGC_ON_OFF                   :
                /*AGC multi apply*/
                bluecell_Currdatastatus.DLI_AGC_ON_OFF = data[MBIC_PAYLOADSTART + 3];
                if( bluecell_Currdatastatus.DLI_AGC_ON_OFF == false){
                    AGC_AlarmSet[AGC_Alarm_DL1_Index] = false;
                    AGC_AlarmSet[AGC_Alarm_DL2_Index] = false;
                    AGC_AlarmSet[AGC_Alarm_DL3_Index] = false;
                    AGC_AlarmSet[AGC_Alarm_DL4_Index] = false;
                    for(int i = 0; i < DLI_FRBT_Time_Index_Max; i++){
                       PrevFRBT_Day[DLI_FRBT_Time_Year + i] = FRBT_Day[DLI_FRBT_Time_Year + i] = 0;
                    }

                    FRBT_Day_Inc = 0;
                    bluecell_Currdatastatus.DLI_FRBT_Status = FRBT_IDEL;                    
                    bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm = 0;
                }else{
                    for(int i = 0; i < DLI_FRBT_Time_Index_Max; i++){
                        StartTimeFRBT_Day[DLI_FRBT_Time_Year + i] = data[MBIC_TIME_0 + i]; /* Curr day */
                    }
                    FRBT_Day_Inc = 1;
//                    printf("FRBT Tracking START \r\n");
//                    printf("FRBT Start Time Save : %d Y %d M %d D %d H %d M %d S\r\n",
//                    StartTimeFRBT_Day[DLI_FRBT_Time_Year],
//                    StartTimeFRBT_Day[DLI_FRBT_Time_Month],
//                    StartTimeFRBT_Day[DLI_FRBT_Time_Day],
//                    StartTimeFRBT_Day[DLI_FRBT_Time_Hour],
//                    StartTimeFRBT_Day[DLI_FRBT_Time_Minute],
//                    StartTimeFRBT_Day[DLI_FRBT_Time_Second]);
                }
                DL_AGC_StartAtten[AGC_Alarm_DL1_Index] 
                    = bluecell_Currdatastatus.ATT_DL1_H << 8 | bluecell_Currdatastatus.ATT_DL1_L;
                DL_AGC_StartAtten[AGC_Alarm_DL2_Index] 
                    = bluecell_Currdatastatus.ATT_DL2_H << 8 | bluecell_Currdatastatus.ATT_DL2_L;
                DL_AGC_StartAtten[AGC_Alarm_DL3_Index] 
                    = bluecell_Currdatastatus.ATT_DL3_H << 8 | bluecell_Currdatastatus.ATT_DL3_L;
                DL_AGC_StartAtten[AGC_Alarm_DL4_Index] 
                    = bluecell_Currdatastatus.ATT_DL4_H << 8 | bluecell_Currdatastatus.ATT_DL4_L;

                for(int i = 0; i < AGC_Alarm_DL_Index_MAX; i++){
                    DL_PrevIwillgiveAtten[i]= 0;                
                }
                break;
            case  DLI_AGC_Threshold                       :
                bluecell_Currdatastatus.DLI_AGC_Threshold_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.DLI_AGC_Threshold_L = data[MBIC_PAYLOADSTART + 4]; 

                break;
            case  DLI_AGC_Threshold_Default               :
			    tempdata  = DLI_AGC_THREADHOLD_DEFAULT;
			    bluecell_Currdatastatus.DLI_AGC_Threshold_H = ((tempdata & 0xFF00) >> 8);        
			    bluecell_Currdatastatus.DLI_AGC_Threshold_L = ((tempdata & 0x00FF));   				
//                bluecell_Currdatastatus.DLI_AGC_Threshold_default = data[MBIC_PAYLOADSTART + 3]; 
                break;
            case  DLI_Shutdown_ON_OFF                     :
                bluecell_Currdatastatus.DLI_Shutdown_ON_OFF = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.DLI_Shutdown_Retry_Count1 = 0;
                bluecell_Currdatastatus.DLI_Shutdown_Retry_Count2 = 0;
                bluecell_Currdatastatus.DLI_Shutdown_Retry_Count3 = 0;
                bluecell_Currdatastatus.DLI_Shutdown_Retry_Count4 = 0;                
                for(int i = 0; i < DET_Alarm_DL_Index_MAX; i++){
                    DET_DL_Shutdown_Off_AlarmTimerCnt[i] = 0;
                    DET_DL_Shutdown_On_AlarmTimerCnt[i] = 0;
                    DET_DL_Normal_Shutdown_On_AlarmTimerCnt[i] = 0;
                }
                break;
            case  DLI_Shutdown_Threshold                  :
                bluecell_Currdatastatus.DLI_Shutdown_Threshold_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.DLI_Shutdown_Threshold_L = data[MBIC_PAYLOADSTART + 4]; 

                break;
            case  DLI_Shutdown_Threshold_Default          :
			    tempdata  = DLI_SHUTDOWN_THREADHOLD_DEFAULT;
			    bluecell_Currdatastatus.DLI_Shutdown_Threshold_H = ((tempdata & 0xFF00) >> 8);        
			    bluecell_Currdatastatus.DLI_Shutdown_Threshold_L = ((tempdata & 0x00FF));  				

                break;
            case  ULO_RF_Path1_ON_OFF            :
                if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
                    return true;
                if(data[MBIC_PAYLOADSTART + 3] != 0)
                    bluecell_Currdatastatus.Path_TempSave_Bit |= 0x08;
                else
                   bluecell_Currdatastatus.Path_TempSave_Bit &= ~0x08;
                UL_Path_OnOff(Path1_OnOff,
                    data[MBIC_PAYLOADSTART + 3],
                    &bluecell_Currdatastatus.ATT_UL1_PATH,
                    &bluecell_Prevdatastatus.ATT_UL1_H,
                    &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count1,
                    &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count1)  ;                   

                break;
            case  ULO_RF_Path2_ON_OFF                    :
                if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
                  return true;
                if(data[MBIC_PAYLOADSTART + 3] != 0)
                    bluecell_Currdatastatus.Path_TempSave_Bit |= 0x04;
                else
                    bluecell_Currdatastatus.Path_TempSave_Bit &= ~0x04;
                UL_Path_OnOff(Path2_OnOff,
                    data[MBIC_PAYLOADSTART + 3],
                    &bluecell_Currdatastatus.ATT_UL2_PATH,
                    &bluecell_Prevdatastatus.ATT_UL2_H,
                    &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count2,
                    &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count2)  ;  
                break;
            case  ULO_RF_Path3_ON_OFF                    :
                if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
                  return true;
                if(data[MBIC_PAYLOADSTART + 3] != 0)
                    bluecell_Currdatastatus.Path_TempSave_Bit |= 0x02;
                else
                    bluecell_Currdatastatus.Path_TempSave_Bit &= ~0x02;
                UL_Path_OnOff(Path3_OnOff,
                    data[MBIC_PAYLOADSTART + 3],
                    &bluecell_Currdatastatus.ATT_UL3_PATH,
                    &bluecell_Prevdatastatus.ATT_UL3_H,
                    &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count3,
                    &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count3)  ;  
                break;
            case  ULO_RF_Path4_ON_OFF                    :
                if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
                  return true;
                if(data[MBIC_PAYLOADSTART + 3] != 0)
                    bluecell_Currdatastatus.Path_TempSave_Bit |= 0x01;
                else
                    bluecell_Currdatastatus.Path_TempSave_Bit &= ~0x01;
                UL_Path_OnOff(Path4_OnOff,
                    data[MBIC_PAYLOADSTART + 3],
                    &bluecell_Currdatastatus.ATT_UL4_PATH,
                    &bluecell_Prevdatastatus.ATT_UL4_H,
                    &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count4,
                    &bluecell_Prevdatastatus.ULO_Shutdown_Retry_Count4)  ;  

                break;
            case  ULO_Gain_Atten1                         :
                bluecell_Currdatastatus.ATT_UL1_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.ATT_UL1_L = data[MBIC_PAYLOADSTART + 4]; 
                if(bluecell_Currdatastatus.ULO_ALC_ON_OFF == true){
                    Tmpdata = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_L;
                    Tmpdata2 = bluecell_Currdatastatus.ATT_UL1_H << 8 | bluecell_Currdatastatus.ATT_UL1_L;
                    if(Tmpdata + Tmpdata2 <= -200){
                        Tmpdata2 = -200 + (Tmpdata * -1);
                        bluecell_Currdatastatus.ATT_UL1_H = ((Tmpdata2 & 0xFF00) >> 8);
                        bluecell_Currdatastatus.ATT_UL1_L = Tmpdata2 & 0x00FF;                    
                    }
                    UL_ALC_GainAttenSet[ALC_Alarm_UL1_Index] = true;
                    ALC_Level_Save[ALC_Alarm_UL1_Index] = bluecell_Currdatastatus.ULO_Level1_H << 8 | bluecell_Currdatastatus.ULO_Level1_L;
                }
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

                break;
            case  ULO_Gain_Atten2                         :
                bluecell_Currdatastatus.ATT_UL2_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.ATT_UL2_L = data[MBIC_PAYLOADSTART + 4]; 
                if(bluecell_Currdatastatus.ULO_ALC_ON_OFF == true){
                    Tmpdata = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_L;
                    Tmpdata2 = bluecell_Currdatastatus.ATT_UL1_H << 8 | bluecell_Currdatastatus.ATT_UL1_L;
                    if(Tmpdata + Tmpdata2 <= -200){
                        Tmpdata2 = -200 + (Tmpdata * -1);
                        bluecell_Currdatastatus.ATT_UL1_H = ((Tmpdata2 & 0xFF00) >> 8);
                        bluecell_Currdatastatus.ATT_UL1_L = Tmpdata2 & 0x00FF;                    
                    }                    
                    UL_ALC_GainAttenSet[ALC_Alarm_UL2_Index] = true;
                    ALC_Level_Save[ALC_Alarm_UL2_Index] = bluecell_Currdatastatus.ULO_Level2_H << 8 | bluecell_Currdatastatus.ULO_Level2_L;
                }
            
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

                break;
            case  ULO_Gain_Atten3                         :
                bluecell_Currdatastatus.ATT_UL3_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.ATT_UL3_L = data[MBIC_PAYLOADSTART + 4]; 
                if(bluecell_Currdatastatus.ULO_ALC_ON_OFF == true){
                    Tmpdata = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_L;
                    Tmpdata2 = bluecell_Currdatastatus.ATT_UL1_H << 8 | bluecell_Currdatastatus.ATT_UL1_L;
                    if(Tmpdata + Tmpdata2 <= -200){
                        Tmpdata2 = -200 + (Tmpdata * -1);
                        bluecell_Currdatastatus.ATT_UL1_H = ((Tmpdata2 & 0xFF00) >> 8);
                        bluecell_Currdatastatus.ATT_UL1_L = Tmpdata2 & 0x00FF;                    
                    }                    
                    UL_ALC_GainAttenSet[ALC_Alarm_UL3_Index] = true;
                    ALC_Level_Save[ALC_Alarm_UL3_Index] = bluecell_Currdatastatus.ULO_Level3_H << 8 | bluecell_Currdatastatus.ULO_Level3_L;
                }
            
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

                break;
            case  ULO_Gain_Atten4                         :
                bluecell_Currdatastatus.ATT_UL4_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.ATT_UL4_L = data[MBIC_PAYLOADSTART + 4]; 
                if(bluecell_Currdatastatus.ULO_ALC_ON_OFF == true){
                    Tmpdata = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_L;
                    Tmpdata2 = bluecell_Currdatastatus.ATT_UL1_H << 8 | bluecell_Currdatastatus.ATT_UL1_L;
                    if(Tmpdata + Tmpdata2 <= -200){
                        Tmpdata2 = -200 + (Tmpdata * -1);
                        bluecell_Currdatastatus.ATT_UL1_H = ((Tmpdata2 & 0xFF00) >> 8);
                        bluecell_Currdatastatus.ATT_UL1_L = Tmpdata2 & 0x00FF;                    
                    }                    
                    UL_ALC_GainAttenSet[ALC_Alarm_UL4_Index] = true;
                    ALC_Level_Save[ALC_Alarm_UL4_Index] = bluecell_Currdatastatus.ULO_Level4_H << 8 | bluecell_Currdatastatus.ULO_Level4_L  ;                      
                }
                printf("data ctrl\r\n");
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

                break;
            case  ULO_Gain_Atten_Offset1                  :
                bluecell_Currdatastatus.bluecell_User_UL1_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.bluecell_User_UL1_L = data[MBIC_PAYLOADSTART + 4]; 
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

                break;
            case  ULO_Gain_Atten_Offset2                  :
                bluecell_Currdatastatus.bluecell_User_UL2_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.bluecell_User_UL2_L = data[MBIC_PAYLOADSTART + 4]; 
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

                break;
            case  ULO_Gain_Atten_Offset3                  :
                bluecell_Currdatastatus.bluecell_User_UL3_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.bluecell_User_UL3_L = data[MBIC_PAYLOADSTART + 4]; 
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

                break;
            case  ULO_Gain_Atten_Offset4                  :
                bluecell_Currdatastatus.bluecell_User_UL4_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.bluecell_User_UL4_L = data[MBIC_PAYLOADSTART + 4]; 
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);

                break;
            case  ULO_Level_High_Threshold                :
                bluecell_Currdatastatus.ULO_Level_High_Threshold_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.ULO_Level_High_Threshold_L = data[MBIC_PAYLOADSTART + 4]; 
                break;
            case  ULO_Level_High_Threshold_default        :
			    tempdata  = ULO_LEVEL_HIGH_THREADHOLD_DEFAULT;
			    bluecell_Currdatastatus.ULO_Level_High_Threshold_H = ((tempdata & 0xFF00) >> 8);
			    bluecell_Currdatastatus.ULO_Level_High_Threshold_L = ((tempdata & 0x00FF));    				
//                bluecell_Currdatastatus.ULO_Level_High_Threshold_default = data[MBIC_PAYLOADSTART + 3]; 
                break;
            case ULO_SelfTest1:
#if 0 // PYJ.2020.07.05_BEGIN -- 
                if(data[MBIC_PAYLOADSTART + 3]==0){
                    HAL_GPIO_WritePin(_PATH_SW1_GPIO_Port,_PATH_SW1_Pin,GPIO_PIN_RESET);//CLOCK
                    HAL_GPIO_WritePin(PATH_SW1_GPIO_Port,PATH_SW1_Pin,GPIO_PIN_SET);//CLOCK
                }
                else{
                    HAL_GPIO_WritePin(_PATH_SW1_GPIO_Port,_PATH_SW1_Pin,GPIO_PIN_SET);//CLOCK
                    HAL_GPIO_WritePin(PATH_SW1_GPIO_Port,PATH_SW1_Pin,GPIO_PIN_RESET);//CLOCK
                }
                bluecell_Currdatastatus.Selftest1 = data[MBIC_PAYLOADSTART + 3];                
#else
                SelfTest_Ctrl(SelfTest1,data[MBIC_PAYLOADSTART + 3],&bluecell_Currdatastatus.Selftest1,&bluecell_Currdatastatus.ATT_DL1_H,&bluecell_Currdatastatus.ATT_UL1_H);

#endif // PYJ.2020.07.05_END -- 
                break;
            case ULO_SelfTest2:
                SelfTest_Ctrl(SelfTest2,data[MBIC_PAYLOADSTART + 3],&bluecell_Currdatastatus.Selftest2,&bluecell_Currdatastatus.ATT_DL2_H,&bluecell_Currdatastatus.ATT_UL2_H);

                break;
            case ULO_SelfTest3:
                SelfTest_Ctrl(SelfTest3,data[MBIC_PAYLOADSTART + 3],&bluecell_Currdatastatus.Selftest3,&bluecell_Currdatastatus.ATT_DL3_H,&bluecell_Currdatastatus.ATT_UL3_H);

                break;
            case ULO_SelfTest4:
                SelfTest_Ctrl(SelfTest4,data[MBIC_PAYLOADSTART + 3],&bluecell_Currdatastatus.Selftest4,&bluecell_Currdatastatus.ATT_DL4_H,&bluecell_Currdatastatus.ATT_UL4_H);
                printf("UL SelfTest \r\n");
                break;
            case  ULO_ALC_ON_OFF                   :
                bluecell_Currdatastatus.ULO_ALC_ON_OFF = data[MBIC_PAYLOADSTART + 3]; 
                if(bluecell_Currdatastatus.ULO_ALC_ON_OFF == 0)
                    bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm = 0;

                break;
            case  ULO_ALC_Threshold                       :
                bluecell_Currdatastatus.ULO_ALC_Threshold_H = data[MBIC_PAYLOADSTART + 3];
                bluecell_Currdatastatus.ULO_ALC_Threshold_L = data[MBIC_PAYLOADSTART + 4];

                break;
            case  ULO_ALC_Threshold_Default               :
			    tempdata = ULO_ALC_THREADHOLD_DEFAULT;
			    bluecell_Currdatastatus.ULO_ALC_Threshold_H = ((tempdata & 0xFF00) >> 8);    
			    bluecell_Currdatastatus.ULO_ALC_Threshold_L = ((tempdata & 0x00FF));  	
//                printf("ALC DEFAULT VALUE SETTING COMPLETE \r\n");
                break;
            case  ULO_Shutdown_ON_OFF                     :
                bluecell_Currdatastatus.ULO_Shutdown_ON_OFF = data[MBIC_PAYLOADSTART + 3]; 

                break;
            case  ULO_Shutdown_Threshold                  :
                bluecell_Currdatastatus.ULO_Shutdown_Threshold_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.ULO_Shutdown_Threshold_L = data[MBIC_PAYLOADSTART + 4]; 

                break;
            case  ULO_Shutdown_Threshold_Default          :
			    tempdata  = ULO_SHUTDOWN_THREADHOLD_DEFAULT;
			    bluecell_Currdatastatus.ULO_Shutdown_Threshold_H = ((tempdata & 0xFF00) >> 8);        
			    bluecell_Currdatastatus.ULO_Shutdown_Threshold_L = ((tempdata & 0x00FF));    
                break;
            case ULO_ALC_Atten:
                bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_H = data[MBIC_PAYLOADSTART + 3]; 
                bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_L = data[MBIC_PAYLOADSTART + 4]; 
                bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_H = data[MBIC_PAYLOADSTART + 5]; 
                bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_L = data[MBIC_PAYLOADSTART + 6]; 
                bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_H = data[MBIC_PAYLOADSTART + 7]; 
                bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_L = data[MBIC_PAYLOADSTART + 8];                 
                bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_H = data[MBIC_PAYLOADSTART + 9]; 
                bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_L = data[MBIC_PAYLOADSTART + 10];  
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
                break;
        }
        if(data[MBIC_PAYLOADSTART + data[MBIC_PAYLOADSTART + 2] + 3 ] == 0xE0 && occurlen > 0){
            occurlen -= data[MBIC_PAYLOADSTART + 2] + 3;
            for(int k = 0; k < occurlen; k++){
                data[MBIC_PAYLOADSTART + k] = data[MBIC_PAYLOADSTART + data[MBIC_PAYLOADSTART + 2] + 3 + k];
            }
            goto protocolReplay;
        }
         data[MBIC_CMD_0] = 0x81;//MBIC_ERRRESPONSE;
        Length = MBIC_DataSend(data);
        Bluecell_StructCpy(&DataWrite[0],&bluecell_Currdatastatus.bluecell_header,sizeof(BLUESTATUS_st));
        EEPROM_M24C08_write(EEPROM_M24C08_ID ,(EEPROM_WINDOW_STATUS_ADDRESDS),&DataWrite[0],sizeof(BLUESTATUS_st));
    }
    else if(cmd == MBIC_Table_Get){
        /*Table Get */
//            data[MBIC_PAYLOADSTART + 1] //Reserve Data
        //protocolTableLoadReplay:
       

        switch(data[MBIC_PAYLOADSTART + 2]){
        	case DLI_P1_Level_Table_Number                 :
        	case DLI_P2_Level_Table_Number                 :
        	case DLI_P3_Level_Table_Number                 :
        	case DLI_P4_Level_Table_Number                 :
        	case ULO_P1_Level_Table_Number                 :
        	case ULO_P2_Level_Table_Number                 :
        	case ULO_P3_Level_Table_Number                 :
        	case ULO_P4_Level_Table_Number                 :
        	case DLI_P1_ATT_Temp_guarantee_Table_Number    :
        	case DLI_P2_ATT_Temp_guarantee_Table_Number    :
        	case DLI_P3_ATT_Temp_guarantee_Table_Number    :
        	case DLI_P4_ATT_Temp_guarantee_Table_Number    :
        	case ULO_P1_ATT_Temp_guarantee_Table_Number    :
        	case ULO_P2_ATT_Temp_guarantee_Table_Number    :
        	case ULO_P3_ATT_Temp_guarantee_Table_Number    :
        	case ULO_P4_ATT_Temp_guarantee_Table_Number    :
        	case DLI_P1_ATT_Accuracy_Table_Number          :
        	case DLI_P2_ATT_Accuracy_Table_Number          :
        	case DLI_P3_ATT_Accuracy_Table_Number          :
        	case DLI_P4_ATT_Accuracy_Table_Number          :
        	case ULO_P1_ATT_Accuracy_Table_Number          :
        	case ULO_P2_ATT_Accuracy_Table_Number          :
        	case ULO_P3_ATT_Accuracy_Table_Number          :
        	case ULO_P4_ATT_Accuracy_Table_Number          :
                MBIC_TableLoad(data,data[MBIC_PAYLOADSTART + 2]);
                if(data[MBIC_PAYLOADSTART + MBIC_TableIndex_Number] >= DLI_P1_ATT_Accuracy_Table_Number
                 &&data[MBIC_TableIndex_Number] <= ULO_P4_ATT_Accuracy_Table_Number ){                
                    MBIC_HeaderMergeFunction(data,data[MBIC_PAYLOADSTART + 4] + 5);
                    data[MBIC_HEADERCHECKSUM_0] = Chksum_Create(data);        
                    uint16_t crcret = ((CRC16_Generate(&data[MBIC_PAYLOADSTART], (data[MBIC_PAYLOADSTART + 4] ) + 5) ) );
//                        printf("\r\n crc ret : %x \r\n",crcret);
                    data[MBIC_PAYLOADSTART + (data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] ) + 5] =(( crcret  & 0xFF00)>> 8);  
                    data[MBIC_PAYLOADSTART + (data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] ) + 6] = (( crcret  & 0x00FF));  
                    data[MBIC_PAYLOADSTART + (data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] ) + 7] = 0x03; 

                    Uart1_Data_Send(data, (data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length]) + 5 + 22 + 3);

                }else{
                    MBIC_HeaderMergeFunction(data,(data[MBIC_PAYLOADSTART + 4] * 2) + 5);
                    data[MBIC_HEADERCHECKSUM_0] = Chksum_Create(data);        
                    uint16_t crcret = ((CRC16_Generate(&data[MBIC_PAYLOADSTART], (data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] * 2) + 5) ) );
//                        printf("\r\n crc ret : %x \r\n",crcret);
                    data[MBIC_PAYLOADSTART + (data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] * 2) + 5] =(( crcret  & 0xFF00)>> 8);  
                    data[MBIC_PAYLOADSTART + (data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] * 2) + 6] = (( crcret  & 0x00FF));  
                    data[MBIC_PAYLOADSTART + (data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] * 2) + 7] = 0x03;
//                    printf("==data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] : %d \r\n",data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length]);
                    Uart1_Data_Send(data, ((data[MBIC_PAYLOADSTART + MBIC_TableIndex_Length] + 1) * 2)    + 5 + 22 + 3);
                }
                
            break;
       }
    }
    else if(cmd == MBIC_Table_Set){
           // protocolTableSaveReplay:
//            data[MBIC_PAYLOADSTART + 1] //Reserve Data
            switch(data[MBIC_PAYLOADSTART + 2]){
                case DLI_P1_Level_Table_Number                 :
                case DLI_P2_Level_Table_Number                 :
                case DLI_P3_Level_Table_Number                 :
                case DLI_P4_Level_Table_Number                 :
                case ULO_P1_Level_Table_Number                 :
                case ULO_P2_Level_Table_Number                 :
                case ULO_P3_Level_Table_Number                 :
                case ULO_P4_Level_Table_Number                 :
                case DLI_P1_ATT_Temp_guarantee_Table_Number    :
                case DLI_P2_ATT_Temp_guarantee_Table_Number    :
                case DLI_P3_ATT_Temp_guarantee_Table_Number    :
                case DLI_P4_ATT_Temp_guarantee_Table_Number    :
                case ULO_P1_ATT_Temp_guarantee_Table_Number    :
                case ULO_P2_ATT_Temp_guarantee_Table_Number    :
                case ULO_P3_ATT_Temp_guarantee_Table_Number    :
                case ULO_P4_ATT_Temp_guarantee_Table_Number    :
                case DLI_P1_ATT_Accuracy_Table_Number          :
                case DLI_P2_ATT_Accuracy_Table_Number          :
                case DLI_P3_ATT_Accuracy_Table_Number          :
                case DLI_P4_ATT_Accuracy_Table_Number          :
                case ULO_P1_ATT_Accuracy_Table_Number          :
                case ULO_P2_ATT_Accuracy_Table_Number          :
                case ULO_P3_ATT_Accuracy_Table_Number          :
                case ULO_P4_ATT_Accuracy_Table_Number          :
              //Header 문장 + sizeof(ATT_TABLE_st) + EXT 문장 Length 추가
                MBIC_TableSave(data,data[MBIC_PAYLOADSTART + 2]);
                if(data[MBIC_PAYLOADSTART + MBIC_TableIndex_Number] >= DLI_P1_ATT_Accuracy_Table_Number
                 &&data[MBIC_TableIndex_Number] <= ULO_P4_ATT_Accuracy_Table_Number ){                
                    MBIC_HeaderMergeFunction(data,1);
                    data[MBIC_HEADERCHECKSUM_0] = Chksum_Create(data);
//                    Uart1_Data_Send(data, (data[MBIC_PAYLOADSTART + 4]) + 5 + 22 + 3);
                    uint16_t crcret = (CRC16_Generate(&data[MBIC_PAYLOADSTART], 1 ) );
//                        printf("\r\n crc ret : %x \r\n",crcret);
                    data[MBIC_PAYLOADSTART + 1] =(( crcret  & 0xFF00)>> 8);  
                    data[MBIC_PAYLOADSTART + 2] = (( crcret  & 0x00FF));  
                    data[MBIC_PAYLOADSTART + 3] = 0x03; 

                    Uart1_Data_Send(data,   22 + 3 + 1);

                }
                else{
                    MBIC_HeaderMergeFunction(data,1);
                    data[MBIC_HEADERCHECKSUM_0] = Chksum_Create(data);
                    uint16_t crcret = (CRC16_Generate(&data[MBIC_PAYLOADSTART], 1) ) ;
//                    printf("\r\n crc ret : %x \r\n",crcret);
                    data[MBIC_PAYLOADSTART + 1] =(( crcret  & 0xFF00)>> 8);  
                    data[MBIC_PAYLOADSTART + 2] = (( crcret  & 0x00FF));  
                    data[MBIC_PAYLOADSTART + 3] = 0x03; 

                    Uart1_Data_Send(data,   22 + 3 + 1);
                }                
            }

    }
    else{
        MBIC_Bootloader_FirmwareUpdate(data);
        
        /*NOP*/
//        printf("DATA Updating\r\n");
    }
//    Uart1_Data_Send(&data[0], data[BLUECELL_LENGTH] + 3);
	return true;
}

uint16_t Ascendingcompare(const void *a, const void *b)    // 오름차순 비교 함수 구현
{
    uint16_t num1 = *(int *)a;    // void 포인터를 int 포인터로 변환한 뒤 역참조하여 값을 가져옴
    uint16_t num2 = *(int *)b;    // void 포인터를 int 포인터로 변환한 뒤 역참조하여 값을 가져옴

    if (num1 < num2)    // a가 b보다 작을 때는
        return -1;      // -1 반환
    
    if (num1 > num2)    // a가 b보다 클 때는
        return 1;       // 1 반환
    
    return 0;    // a와 b가 같을 때는 0 반환
}
uint16_t Descendingcompare(const void *a, const void *b)    // 내림차순 비교 함수 구현
{
    uint16_t num1 = *(uint16_t *)a;    // void 포인터를 uint16_t 포인터로 변환한 뒤 역참조하여 값을 가져옴
    uint16_t num2 = *(uint16_t *)b;    // void 포인터를 uint16_t 포인터로 변환한 뒤 역참조하여 값을 가져옴

    if (num1 > num2)    // a가 b보다 클 때는
        return -1;      // -1 반환
    
    if (num1 < num2)    // a가 b보다 작을 때는
        return 1;       // 1 반환
    
    return 0;           // a와 b가 같을 때는 0 반환
}
void DascendigFunc(uint16_t* src,uint32_t size ){
  int temp;

  
  for(int i = 0 ; i < size - 1 ; i ++) {
      for(int j = i+1 ; j < size ; j ++) {
	  if(src[i] < src[j]) {
              temp = src[j];
              src[j] = src[i];
              src[i] = temp;
        }
      }
  }
}

uint32_t SumFunc(uint16_t* data,uint16_t size){
    uint32_t ret = 0;
    for (uint16_t i = 0; i < size; i++)    // 배열의 요소 개수만큼 반복
    {
        ret += data[i];    // sum과 배열의 요소를 더해서 다시 sum에 저장
    }
    return ret;
}




bool ADC_Alarm_DL_High_Set[DET_Alarm_DL_Index_MAX] = {false,} ;
bool ADC_Alarm_DL_Low_Set[DET_Alarm_DL_Index_MAX] = {false,} ;

bool ADC_Alarm_UL_Set[DET_Alarm_UL_Index_MAX] = {false,} ;
bool ADC_Alarm_DL_Shutdown_Set[DET_Alarm_DL_Shutdown_Index_MAX] = {false,} ;
bool ADC_Alarm_UL_Shutdown_Set[DET_Alarm_UL_Shutdown_Index_MAX] = {false,} ;

bool ADC_Alarm_DL_Normal_Shutdown_Set[DET_Alarm_DL_Shutdown_Index_MAX] = {false,} ;
bool ADC_Alarm_UL_Normal_Shutdown_Set[DET_Alarm_UL_Shutdown_Index_MAX] = {false,} ;

void DET_LevelAlarmCheck(){
    //int16_t DL[DET_Alarm_DL_Index_MAX] = {0,};
    //int16_t UL[DET_Alarm_UL_Index_MAX] = {0,};
    int16_t LimitData_UL_High = 0;
    
    int16_t LimitData_DL_High = 0;    
    int16_t LimitData_DL_Low = 0;    


    int16_t LimitData_DL_Shutdown = 0;    
    int16_t LimitData_UL_Shutdown = 0;    
    
    double ret = 0;
    int16_t Res_DL_dBm[DET_Alarm_DL_Index_MAX] = {0,};
    int16_t Res_UL_dBm[DET_Alarm_UL_Index_MAX] = {0,};    
    

    LimitData_UL_High = ConvertTo2byte(bluecell_Currdatastatus.ULO_Level_High_Threshold_H,bluecell_Currdatastatus.ULO_Level_High_Threshold_L) * 0.1;
    LimitData_DL_High = ConvertTo2byte(bluecell_Currdatastatus.DLI_Level_High_Threshold_H,bluecell_Currdatastatus.DLI_Level_High_Threshold_L)* 0.1;
    LimitData_DL_Low = ConvertTo2byte(bluecell_Currdatastatus.DLI_Level_Low_Threshold_H,bluecell_Currdatastatus.DLI_Level_Low_Threshold_L)* 0.1;

    LimitData_DL_Shutdown = ConvertTo2byte(bluecell_Currdatastatus.DLI_Shutdown_Threshold_H,bluecell_Currdatastatus.DLI_Shutdown_Threshold_L)* 0.1;
    LimitData_UL_Shutdown = ConvertTo2byte(bluecell_Currdatastatus.ULO_Shutdown_Threshold_H,bluecell_Currdatastatus.ULO_Shutdown_Threshold_L)* 0.1;
    

    ret  = bluecell_Currdatastatus.DLI_P1_Level1_H << 8;
    ret += bluecell_Currdatastatus.DLI_P1_Level1_L;   
    ret *= 0.001;    
    Res_DL_dBm[DET_Alarm_DL1_Index] 
        = bluecell_Currdatastatus.DLI_Level1_H << 8 | bluecell_Currdatastatus.DLI_Level1_L;//(int8_t)Bluecell_TestPro(AGC_AutoControl_ADC_Compare(ret,&Det_DL1.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st)));
    ret  = bluecell_Currdatastatus.DLI_P2_Level2_H << 8;
    ret += bluecell_Currdatastatus.DLI_P2_Level2_L;   
    ret *= 0.001;  

    Res_DL_dBm[DET_Alarm_DL2_Index] 
        = bluecell_Currdatastatus.DLI_Level2_H << 8 | bluecell_Currdatastatus.DLI_Level2_L;//(int8_t)Bluecell_TestPro(AGC_AutoControl_ADC_Compare(ret,&Det_DL2.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st)));
    ret  = bluecell_Currdatastatus.DLI_P3_Level3_H << 8;
    ret += bluecell_Currdatastatus.DLI_P3_Level3_L;   
    ret *= 0.001;  

    Res_DL_dBm[DET_Alarm_DL3_Index] 
        = bluecell_Currdatastatus.DLI_Level3_H << 8 | bluecell_Currdatastatus.DLI_Level3_L;//(int8_t)Bluecell_TestPro(AGC_AutoControl_ADC_Compare(ret,&Det_DL3.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st)));


    ret  = bluecell_Currdatastatus.DLI_P4_Level4_H << 8;
    ret += bluecell_Currdatastatus.DLI_P4_Level4_L;   
    ret *= 0.001;  

    Res_DL_dBm[DET_Alarm_DL4_Index] 
        = bluecell_Currdatastatus.DLI_Level4_H << 8 | bluecell_Currdatastatus.DLI_Level4_L;//(int8_t)Bluecell_TestPro(AGC_AutoControl_ADC_Compare(ret,&Det_DL4.Table_Det5_dBm_H,sizeof(DET_TABLEDL_st)));



    ret  = bluecell_Currdatastatus.ULO_P1_Level1_H << 8;
    ret += bluecell_Currdatastatus.ULO_P1_Level1_L;   
    ret *= 0.001;

    Res_UL_dBm[DET_Alarm_UL1_Index] 
        = bluecell_Currdatastatus.ULO_Level1_H << 8 | bluecell_Currdatastatus.ULO_Level1_L; //(int8_t)Bluecell_TestPro(AutoControl_ADC_Compare(ret,&Det_UL1.Table_Det_15_dBm_H,Det_UL1.Table_Length * 2));


    ret  = bluecell_Currdatastatus.ULO_P2_Level2_H << 8;
    ret += bluecell_Currdatastatus.ULO_P2_Level2_L;   
    ret *= 0.001;

    Res_UL_dBm[DET_Alarm_UL2_Index] 
        = bluecell_Currdatastatus.ULO_Level2_H << 8 | bluecell_Currdatastatus.ULO_Level2_L;//(int8_t)Bluecell_TestPro(AutoControl_ADC_Compare(ret,&Det_UL2.Table_Det_15_dBm_H,Det_UL2.Table_Length * 2));

    ret  = bluecell_Currdatastatus.ULO_P3_Level3_H << 8;
    ret += bluecell_Currdatastatus.ULO_P3_Level3_L;   
    ret *= 0.001;

    Res_UL_dBm[DET_Alarm_UL3_Index] 
        = bluecell_Currdatastatus.ULO_Level3_H << 8 | bluecell_Currdatastatus.ULO_Level3_L;//(int8_t)Bluecell_TestPro(AutoControl_ADC_Compare(ret,&Det_UL3.Table_Det_15_dBm_H,Det_UL3.Table_Length * 2));


    ret  = bluecell_Currdatastatus.ULO_P4_Level4_H << 8;
    ret += bluecell_Currdatastatus.ULO_P4_Level4_L;   
    ret *= 0.001;

    Res_UL_dBm[DET_Alarm_UL4_Index] 
        = bluecell_Currdatastatus.ULO_Level4_H << 8 | bluecell_Currdatastatus.ULO_Level4_L;//(int8_t)Bluecell_TestPro(AutoControl_ADC_Compare(ret,&Det_UL4.Table_Det_15_dBm_H,Det_UL4.Table_Length * 2));


    /*
        DL Level Alarm Check Part
    */
//    printf("======================================================\r\n");
    for(int i = 0 ; i < DET_Alarm_DL_Index_MAX; i++){
        if(LimitData_DL_High <= Res_DL_dBm[DET_Alarm_DL1_Index + i]){
            ADC_Alarm_DL_High_Set[DET_Alarm_DL1_Index + i] = true;
//            printf("ADC_Alarm_DL_High_Set %d ,Value : %d\r\n",DET_Alarm_UL1_Index + i,ADC_Alarm_DL_High_Set[DET_Alarm_UL1_Index + i]);            
        }
        else{
            if(LimitData_DL_High - 2 >= Res_DL_dBm[DET_Alarm_DL1_Index + i])
                ADC_Alarm_DL_High_Set[DET_Alarm_DL1_Index + i] = false;
//            printf("ADC_Alarm_DL_High_Set %d ,Value : %d\r\n",DET_Alarm_UL1_Index + i,ADC_Alarm_DL_High_Set[DET_Alarm_UL1_Index + i]);            
        }
#if 0 // PYJ.2020.06.22_BEGIN -- 
        printf("LimitData_DL_High: %d Res_DL_dBm [%d] : %d ,Value : %d\r\n",
        LimitData_DL_High,
        DET_Alarm_UL1_Index + i,
        Res_DL_dBm[DET_Alarm_DL1_Index + i],
        ADC_Alarm_DL_High_Set[DET_Alarm_DL1_Index + i]);            
#endif // PYJ.2020.06.22_END -- 

//        LimitData_DL_Low,
//        DET_Alarm_UL1_Index + i,
//        Res_DL_dBm[DET_Alarm_DL1_Index + i],
//        ADC_Alarm_DL_High_Set[LimitData_DL_High + i]);            
    }    
    
    /*
        DL Shutdown Alarm Check Part
    */
    uint8_t* DL_PathStatus = &bluecell_Currdatastatus.ATT_DL1_PATH ;
    uint8_t* DL_RetryCount = &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count1 ;
    int16_t DL_Atten[DET_Alarm_DL_Shutdown_Index_MAX] = {0,};
    
    DL_Atten[DET_Alarm_DL1_Index] = bluecell_Currdatastatus.ATT_DL1_H << 8 | bluecell_Currdatastatus.ATT_DL1_L;
    DL_Atten[DET_Alarm_DL2_Index] = bluecell_Currdatastatus.ATT_DL2_H << 8 | bluecell_Currdatastatus.ATT_DL2_L;
    DL_Atten[DET_Alarm_DL3_Index] = bluecell_Currdatastatus.ATT_DL3_H << 8 | bluecell_Currdatastatus.ATT_DL3_L;
    DL_Atten[DET_Alarm_DL4_Index] = bluecell_Currdatastatus.ATT_DL4_H << 8 | bluecell_Currdatastatus.ATT_DL4_L;


    for(int i = 0 ; i < DET_Alarm_DL_Shutdown_Index_MAX; i++){
        if(DL_PathStatus[DET_Alarm_DL1_Shutdown_Index + i] == true
            && (LimitData_DL_Shutdown - 2 >= Res_DL_dBm[DET_Alarm_DL1_Shutdown_Index + i])
            && (MBIC_DL_ShutdownCount[DET_Alarm_DL1_Shutdown_Index + i] > 0)){
            ADC_Alarm_DL_Normal_Shutdown_Set[DET_Alarm_DL1_Shutdown_Index + i] = true;
            if(DET_DL_Normal_Shutdown_On_AlarmTimerCnt[DET_Alarm_DL1_Shutdown_Index + i] > MBIC_OFF_MAINTAIN_SEC){
                if(DL_RetryCount[DET_Alarm_DL1_Shutdown_Index + i] > 0){// Nomal Operate
                    DL_RetryCount[DET_Alarm_DL1_Shutdown_Index + i] = 0;
//                    printf("DL%d_PATH : %d Retry Count Initialize Start %d \r\n",i+1,DL_PathStatus[DET_Alarm_DL1_Shutdown_Index + i],bluecell_Currdatastatus.DLO_Shutdown_Retry_Count2);
                }
            }
        }else{
            ADC_Alarm_DL_Normal_Shutdown_Set[DET_Alarm_DL1_Shutdown_Index + i] = false;
        }
    }
    for(int i = 0 ; i < DET_Alarm_DL_Shutdown_Index_MAX; i++){
        if(LimitData_DL_Shutdown <= Res_DL_dBm[DET_Alarm_DL1_Shutdown_Index + i]){
//            if(DL_Atten[DET_Alarm_DL1_Index + i] * 0.1 <= -15)
                ADC_Alarm_DL_Shutdown_Set[DET_Alarm_DL1_Shutdown_Index + i] = true;
        }
        else{
//             if(LimitData_DL_Shutdown - 2 >= Res_DL_dBm[DET_Alarm_DL1_Shutdown_Index + i])
              if(MBIC_DL_ShutdownCount[DET_Alarm_DL1_Shutdown_Index + i] > 0)
                ADC_Alarm_DL_Shutdown_Set[DET_Alarm_DL1_Shutdown_Index + i] = false;
        }
    }

//    printf("======================================================\r\n");
        uint8_t* AlarmStatus = &bluecell_Currdatastatus.DLI_Level_Low_Alarm1;
        uint8_t* PathStatus = &bluecell_Currdatastatus.ATT_DL1_PATH;
        for(int i = 0 ; i < DET_Alarm_DL_Index_MAX; i++){
            if(PathStatus[DET_Alarm_DL1_Index + i] == false){
                 ADC_Alarm_DL_Low_Set[DET_Alarm_DL1_Index + i] = false;
                 continue;
            }
            if(AlarmStatus[DET_Alarm_DL1_Index + i] == false){
                if(LimitData_DL_Low >= Res_DL_dBm[DET_Alarm_DL1_Index + i])
                {
                    ADC_Alarm_DL_Low_Set[DET_Alarm_DL1_Index + i] = true;
                }
                if(LimitData_DL_Low + 2 <= Res_DL_dBm[DET_Alarm_DL1_Index + i]){
                    ADC_Alarm_DL_Low_Set[DET_Alarm_DL1_Index + i] = false;
                }
            }else{
                if(LimitData_DL_Low + 1 >= Res_DL_dBm[DET_Alarm_DL1_Index + i])
                {
                    ADC_Alarm_DL_Low_Set[DET_Alarm_DL1_Index + i] = true;
                }
                if(LimitData_DL_Low + 2 <= Res_DL_dBm[DET_Alarm_DL1_Index + i]){
                    ADC_Alarm_DL_Low_Set[DET_Alarm_DL1_Index + i] = false;
                }
            }


        
#if 0 // PYJ.2020.06.22_BEGIN -- 
        printf("=========================================================\r\n");
        printf("LimitData_DL_Low: %d Res_DL_dBm [%d] : %d ,Value : %d Real Alamr : %d \r\n",
        LimitData_DL_Low,
        DET_Alarm_UL1_Index + i,
        Res_DL_dBm[DET_Alarm_DL1_Index + i],
        ADC_Alarm_DL_Low_Set[DET_Alarm_DL1_Index + i],
        AlarmStatus[DET_Alarm_DL1_Index + i]);            
#endif // PYJ.2020.06.22_END -- 
    }       
    
    /*
        UL Shutdown Alarm Check Part
    */
    
    uint8_t* UL_PathStatus = &bluecell_Currdatastatus.ATT_UL1_PATH ;
    uint8_t* UL_RetryCount = &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count1 ;
        
//    printf("============================================================================\r\n");
    for(int i = 0 ; i < DET_Alarm_UL_Shutdown_Index_MAX; i++){
        if(UL_PathStatus[DET_Alarm_UL1_Shutdown_Index + i] == true){
            ADC_Alarm_UL_Normal_Shutdown_Set[DET_Alarm_UL1_Shutdown_Index + i] = true;
            if(DET_UL_Normal_Shutdown_On_AlarmTimerCnt[DET_Alarm_UL1_Shutdown_Index + i] > MBIC_OFF_MAINTAIN_SEC){
                if(UL_RetryCount[DET_Alarm_UL1_Shutdown_Index + i] > 0){// Nomal Operate
                    UL_RetryCount[DET_Alarm_UL1_Shutdown_Index + i] = 0;
//                    printf("UL%d_PATH : %d Retry Count Initialize Start %d \r\n",i+1,UL_PathStatus[DET_Alarm_UL1_Shutdown_Index + i],bluecell_Currdatastatus.ULO_Shutdown_Retry_Count2);
                }
            }
        }else{
            ADC_Alarm_UL_Normal_Shutdown_Set[DET_Alarm_UL1_Shutdown_Index + i] = false;
        }
        
        if(LimitData_UL_Shutdown <= Res_UL_dBm[DET_Alarm_UL1_Shutdown_Index + i]){
            ADC_Alarm_UL_Shutdown_Set[DET_Alarm_UL1_Shutdown_Index + i] = true;
//            printf("Shutdown threas hold : %d | Curr Meas : %d Shutdown UL %d | Alarm ON Count : %d\r\n",LimitData_UL_Shutdown,Res_UL_dBm[DET_Alarm_UL1_Shutdown_Index + i],i + 1,UL_RetryCount[DET_Alarm_UL1_Shutdown_Index + i] );
        }
        else{
            if(LimitData_UL_Shutdown - 2 >= Res_UL_dBm[DET_Alarm_UL1_Shutdown_Index + i])
                ADC_Alarm_UL_Shutdown_Set[DET_Alarm_UL1_Shutdown_Index + i] = false;
//            printf("Shutdown threas hold : %d | Curr Meas : %d Shutdown UL %d | Alarm OFF Count : %d\r\n",LimitData_UL_Shutdown,Res_UL_dBm[DET_Alarm_UL1_Shutdown_Index + i],i + 1,UL_RetryCount[DET_Alarm_UL1_Shutdown_Index + i] );
        }
    }
    /*
        UL Level Alarm Check Part
    */
    uint8_t* UL_Alarm_Timer_Status = &bluecell_Currdatastatus.ULO_Level_High_Alarm1;
    uint8_t* UL_ADC = &bluecell_Currdatastatus.ULO_P1_Level1_H;
    
//    LimitData_UL_High = -27;
//    printf("==========================================================\r\n");
    for(int i = 0 ; i < DET_Alarm_UL_Index_MAX; i++){
        if(LimitData_UL_High <= Res_UL_dBm[DET_Alarm_UL1_Index + i]){
            ADC_Alarm_UL_Set[DET_Alarm_UL1_Index + i] = true;
//            printf("ON _Limit : %d   UL%d : %d  ADC_Alarm_UL_Set %d ,Value : %d\r\n",LimitData_UL_High,i+1,Res_UL_dBm[DET_Alarm_UL1_Index + i],DET_Alarm_UL1_Index + i,ADC_Alarm_UL_Set[DET_Alarm_UL1_Index + i]);
        }
        else{
            if(LimitData_UL_High - 2 >= Res_UL_dBm[DET_Alarm_UL1_Index + i])
                ADC_Alarm_UL_Set[DET_Alarm_UL1_Index + i] = false;
            DET_UL_On_AlarmTimerCnt[DET_Alarm_UL1_Index + i] = 0;
//            printf("OFF _Limit : %d   UL%d : %d  ADC_Alarm_UL_Set %d ,Value : %d\r\n",LimitData_UL_High,i+1,Res_UL_dBm[DET_Alarm_UL1_Index + i],DET_Alarm_UL1_Index + i,ADC_Alarm_UL_Set[DET_Alarm_UL1_Index + i]);            
        }
#if 1 // PYJ.2020.06.22_BEGIN -- 
#if 0 // PYJ.2020.06.22_BEGIN --
                printf("ADC : %f LimitData_UL_High: %d Res_UL_dBm [%d] : %d ,Value : %d\r\n",
                (UL_ADC[i * 2] << 8 | UL_ADC[i * 2 + 1]) * 0.001,
                LimitData_UL_High,
                DET_Alarm_UL1_Index + i,
                Res_UL_dBm[DET_Alarm_UL1_Index + i],
                ADC_Alarm_UL_Set[DET_Alarm_UL1_Index + i]);            
#endif // PYJ.2020.06.22_END -- 
#endif // PYJ.2020.06.22_END -- 
        
    }    

}

void Temp_AttenCheck(int8_t Temp){
    int8_t CurrentTemp = 0;

    

}
volatile uint16_t HFR_ADC1_Array[6] = {0,};
uint8_t HFR_ADC1_SamplingCnt = 0;
#if 0 // PYJ.2020.08.07_BEGIN -- 
void ADC_Check(void){
    //static uint8_t Cnt = 0;
   double ADC1DoubleRet[4];
   double ADC3DoubleRet[5];
   uint32_t ADC1_Average_value[ADC1_CNT];
   static uint32_t HFR_ADC1_Average_value[ADC1_CNT];
   uint32_t ADC3_Average_value[ADC3_CNT];

   // double ret = 0;
    uint16_t MIN_ADC[ADC3_CNT] = {0,};
    uint16_t cnt[ADC3_CNT] = {0,};
    double temp;
//    if(AdcTimerCnt > 10){
    // 정렬할 배열, 요소 개수, 요소 크기, 비교 함수를 넣어줌



    if(adc3cnt >= ADC_AVERAGECNT){
//        printf("%f\r\n",ADC3value[4]*3.3/4095);
#if 1 // PYJ.2020.05.25_BEGIN -- 
      for(int i = 0; i < ADC3_CNT; i++){
                DascendigFunc(&ADC3valuearray[i][0],ADC_AVERAGECNT);
                MIN_ADC[i] = ADC3valuearray[i][0] - 12;
                for(int a = 0; a < ADC_AVERAGECNT; a++){
//                     printf("ADC3valuearray[%d][%d] : %d \r\n",i,a,ADC3valuearray[i][a]);
                    if(ADC3valuearray[i][a] < MIN_ADC[i]){
                        cnt[i] = a;
    //                    printf("cnt[i] %d \r\n",cnt[i]);
                        break;
                    }else{
                        cnt[i] = ADC_AVERAGECNT;
                    }
                }
                ADC3_Average_value[i] = SumFunc(&ADC3valuearray[i][0],cnt[i]);
    //            printf("ADC3_Average_value[%d] : %d / %f \r\n",i,ADC3_Average_value[i],ADC3_Average_value[i]/cnt[i] * Volt_Calc_val);
            }

            for(int i = 0; i < ADC3_CNT; i++){
                ADC3DoubleRet[i] = (((ADC3_Average_value[i] / cnt[i]) * 3.3 /4096) * 1000);
                ADC3Ret[i] = ADC3DoubleRet[i];
                ADC3_Average_value[i] = 0;
            }
            
            bluecell_Currdatastatus.DLI_P1_Level1_H 
                = ((ADC3Ret[1] & 0xFF00) >> 8);
            bluecell_Currdatastatus.DLI_P1_Level1_L 
                = ((ADC3Ret[1] & 0x00FF));
            

            bluecell_Currdatastatus.DLI_P2_Level2_H 
                = ((ADC3Ret[2] & 0xFF00) >> 8);
            bluecell_Currdatastatus.DLI_P2_Level2_L 
                = ((ADC3Ret[2] & 0x00FF) );

                
            bluecell_Currdatastatus.DLI_P3_Level3_H 
                = ((ADC3Ret[3] & 0xFF00) >> 8);
            bluecell_Currdatastatus.DLI_P3_Level3_L 
                = ((ADC3Ret[3] & 0x00FF) );

                
            bluecell_Currdatastatus.DLI_P4_Level4_H 
                = ((ADC3Ret[4] & 0xFF00) >> 8);
            bluecell_Currdatastatus.DLI_P4_Level4_L 
                = ((ADC3Ret[4] & 0x00FF) );

                
            bluecell_Currdatastatus.ULO_P4_Level4_H 
                = ((ADC3Ret[0] & 0xFF00) >> 8);
            bluecell_Currdatastatus.ULO_P4_Level4_L 
                = ((ADC3Ret[0] & 0x00FF) );
#endif // PYJ.2020.05.25_END -- 
#if 0 // PYJ.2020.04.26_BEGIN -- 
            double ret = 0;
            ret = (ADC3Ret[0]) * 0.001;
            printf("ADC3Ret[0] : %d        UL4 : %f\r\n",ADC3Ret[0],ret);
            ret = (ADC3Ret[1]) * 0.001;
            printf("ADC3Ret[1] : %d        DL1 : %f\r\n",ADC3Ret[1],ret);
            ret = (ADC3Ret[2]) * 0.001;
            printf("ADC3Ret[2] : %d        DL2 : %f\r\n",ADC3Ret[2],ret);
            ret = (ADC3Ret[3]) * 0.001;
            printf("ADC3Ret[3] : %d        DL3 : %f\r\n",ADC3Ret[3],ret);

            ret = (ADC3Ret[4]) * 0.001;
            printf("ADC3Ret[4] : %d        DL4 : %f\r\n",ADC3Ret[4],ret);
#endif // PYJ.2020.04.26_END -- 
        adc3cnt = 0;

    }

#if 0 // PYJ.2020.08.06_BEGIN -- 
    if(adc1cnt >= ADC_AVERAGECNT){ 
        for(int i = 0; i < ADC1_CNT; i++){
            DascendigFunc(&ADC1valuearray[i][0],ADC_AVERAGECNT);
            MIN_ADC[i] = ADC1valuearray[i][0] - 12;
            for(int a = 0; a < ADC_AVERAGECNT; a++){
//                 printf("ADC1valuearray[%d][%d] : %d \r\n",i,a,ADC1valuearray[i][a]);
                if(ADC1valuearray[i][a] < MIN_ADC[i]){
                    cnt[i] = a;
//                    printf("cnt[i] %d \r\n",cnt[i]);
                    break;
                }else{
                    cnt[i] = ADC_AVERAGECNT;
                }
            }
            ADC1_Average_value[i] = SumFunc(&ADC1valuearray[i][0],cnt[i]);
//            printf("ADC1_Average_value[%d] : %d / %f \r\n",i,ADC1_Average_value[i],ADC1_Average_value[i]/cnt[i] * Volt_Calc_val);
        }

        for(int i = 0; i < 4; i++){
            ADC1DoubleRet[i] = (((ADC1_Average_value[i] / cnt[i]) * 3.3 /4095) * 1000);
            ADC1Ret[i] = ADC1DoubleRet[i];
//            ADC1Ret[i] = ADC1_Average_value[i] / cnt[i];
            ADC1_Average_value[i] = 0;
        }
       
        bluecell_Currdatastatus.ULO_P1_Level1_H 
            = ((ADC1Ret[0] & 0xFF00) >> 8);
        bluecell_Currdatastatus.ULO_P1_Level1_L 
            = ((ADC1Ret[0] & 0x00FF) );

            
        bluecell_Currdatastatus.ULO_P2_Level2_H 
            = ((ADC1Ret[1] & 0xFF00) >> 8);
        bluecell_Currdatastatus.ULO_P2_Level2_L 
            = ((ADC1Ret[1] & 0x00FF) );

            
        bluecell_Currdatastatus.ULO_P3_Level3_H 
            = ((ADC1Ret[2] & 0xFF00) >> 8);
        bluecell_Currdatastatus.ULO_P3_Level3_L 
            = ((ADC1Ret[2] & 0x00FF) );

//            printf("ADC1_Average_value[%d] : %d / %f \r\n",i,ADC1_Average_value[i],ADC1_Average_value[i]/cnt[i] * Volt_Calc_val);            
#if 0 // PYJ.2020.05.14_BEGIN -- 
        bluecell_Currdatastatus.DET_TEMP_H  
            =((ADC1Ret[3] & 0xFF00) >> 8);
        bluecell_Currdatastatus.DET_TEMP_L  
            =((ADC1Ret[3] & 0x00FF) );
#else    
/* *
온도 소수점 제거
*/
    temp = (ADC1Ret[3] * 0.001);
//    printf("DetEnd");
//    printf("temp %f \r\n",temp  );
    bluecell_Currdatastatus.DET_TEMP =  ((temp - 0.5) * 100);
//    printf("DET_TEMP %d \r\n",bluecell_Currdatastatus.DET_TEMP  );
    bluecell_Currdatastatus.DET_TEMP  += bluecell_Currdatastatus.bluecell_User_TEMP_OFFSET;
//    printf("DET_TEMP + bluecell_Currdatastatus.bluecell_User_TEMP_OFFSET  :  %d \r\n",bluecell_Currdatastatus.DET_TEMP  );
//     temp= ((( - 0.5 ) * 100)  + );

#endif // PYJ.2020.05.14_END -- 


//        ret = ((ADC1Ret[0]) * Volt_Calc_val);
      //  printf("UL1 : %f\r\n",ret);

//        ret = ((ADC1Ret[1]) * Volt_Calc_val);
//        printf("UL2 : %f\r\n",ret);

//        ret = ((ADC1Ret[2]) * Volt_Calc_val);
////        printf("UL3 : %f\r\n",ret);
//        bluecell_Currdatastatus.DET_TEMP_H  
//            =((ADC1Ret[3] & 0xFF00) >> 8);
//        bluecell_Currdatastatus.DET_TEMP_L  
//            =((ADC1Ret[3] & 0x00FF) );
//    printf("bluecell_Currdatastatus.DET_TEMP  %d \r\n",bluecell_Currdatastatus.DET_TEMP  );
//    printf(" ADC1Ret[3]    %x \r\n",  ADC1Ret[3]   );


//        ret = ((ADC1Ret[3]) * Volt_Calc_val);
//        printf("Temp : %f\r\n",ret);
        adc1cnt = 0;

    }
#else    
      if(adc1cnt >= ADC_AVERAGECNT){ 
            for(int i = 0; i < ADC1_CNT; i++){
                DascendigFunc(&ADC1valuearray[i][0],ADC_AVERAGECNT);
                MIN_ADC[i] = ADC1valuearray[i][0] - 12;
                for(int a = 0; a < ADC_AVERAGECNT; a++){
    //                 printf("ADC1valuearray[%d][%d] : %d \r\n",i,a,ADC1valuearray[i][a]);
                    if(ADC1valuearray[i][a] < MIN_ADC[i]){
                        cnt[i] = a;
    //                    printf("cnt[i] %d \r\n",cnt[i]);
                        break;
                    }else{
                        cnt[i] = ADC_AVERAGECNT;
                    }
                }
                ADC1_Average_value[i] = SumFunc(&ADC1valuearray[i][0],cnt[i]);
    //            printf("ADC1_Average_value[%d] : %d / %f \r\n",i,ADC1_Average_value[i],ADC1_Average_value[i]/cnt[i] * Volt_Calc_val);
            }
    
            for(int i = 0; i < 4; i++){
                ADC1DoubleRet[i] = (((ADC1_Average_value[i] / cnt[i]) * 3.3 /4095) * 1000);
                ADC1Ret[i] = ADC1DoubleRet[i];
    //            ADC1Ret[i] = ADC1_Average_value[i] / cnt[i];
                ADC1_Average_value[i] = 0;
            }
           
            bluecell_Currdatastatus.ULO_P1_Level1_H 
                = ((ADC1Ret[0] & 0xFF00) >> 8);
            bluecell_Currdatastatus.ULO_P1_Level1_L 
                = ((ADC1Ret[0] & 0x00FF) );
                
            bluecell_Currdatastatus.ULO_P2_Level2_H 
                = ((ADC1Ret[1] & 0xFF00) >> 8);
            bluecell_Currdatastatus.ULO_P2_Level2_L 
                = ((ADC1Ret[1] & 0x00FF) );
                
            bluecell_Currdatastatus.ULO_P3_Level3_H 
                = ((ADC1Ret[2] & 0xFF00) >> 8);
            bluecell_Currdatastatus.ULO_P3_Level3_L 
                = ((ADC1Ret[2] & 0x00FF) );
    
    //            printf("ADC1_Average_value[%d] : %d / %f \r\n",i,ADC1_Average_value[i],ADC1_Average_value[i]/cnt[i] * Volt_Calc_val);            
#if 0 // PYJ.2020.05.14_BEGIN -- 
            bluecell_Currdatastatus.DET_TEMP_H  
                =((ADC1Ret[3] & 0xFF00) >> 8);
            bluecell_Currdatastatus.DET_TEMP_L  
                =((ADC1Ret[3] & 0x00FF) );
#else    
    /* *
    온도 소수점 제거
    */
        temp = (ADC1Ret[3] * 0.001);
    //    printf("DetEnd");
    //    printf("temp %f \r\n",temp  );
        bluecell_Currdatastatus.DET_TEMP =  ((temp - 0.5) * 100);
    //    printf("DET_TEMP %d \r\n",bluecell_Currdatastatus.DET_TEMP  );
        bluecell_Currdatastatus.DET_TEMP  += bluecell_Currdatastatus.bluecell_User_TEMP_OFFSET;
    //    printf("DET_TEMP + bluecell_Currdatastatus.bluecell_User_TEMP_OFFSET  :  %d \r\n",bluecell_Currdatastatus.DET_TEMP  );
    //     temp= ((( - 0.5 ) * 100)  + );
    
#endif // PYJ.2020.05.14_END -- 
    
    
    //        ret = ((ADC1Ret[0]) * Volt_Calc_val);
          //  printf("UL1 : %f\r\n",ret);
    
    //        ret = ((ADC1Ret[1]) * Volt_Calc_val);
    //        printf("UL2 : %f\r\n",ret);
    
    //        ret = ((ADC1Ret[2]) * Volt_Calc_val);
    ////        printf("UL3 : %f\r\n",ret);
    //        bluecell_Currdatastatus.DET_TEMP_H  
    //            =((ADC1Ret[3] & 0xFF00) >> 8);
    //        bluecell_Currdatastatus.DET_TEMP_L  
    //            =((ADC1Ret[3] & 0x00FF) );
    //    printf("bluecell_Currdatastatus.DET_TEMP  %d \r\n",bluecell_Currdatastatus.DET_TEMP  );
    //    printf(" ADC1Ret[3]    %x \r\n",  ADC1Ret[3]   );
    
    
    //        ret = ((ADC1Ret[3]) * Volt_Calc_val);
    //        printf("Temp : %f\r\n",ret);
            adc1cnt = 0;
    
        }


#endif // PYJ.2020.08.06_END -- 
    /*
        After ADC calculation is completed, start Det Alarm check.
    */
    DET_LevelAlarmCheck();/*DL UL Alarm Check*/
}
#else
/*
    HFR Requset List 
    
    Total : 50 Sampling 

    
*/

uint16_t* ArrayMoveBack(uint16_t* array,uint8_t size){
  
  for(int i = 0; i < size; i++){
    array[i] = array[i + 1];
  }
  return array;
}

#define HFR_REQUSET_TOTAL_CNT 6
#if 0 // PYJ.2020.08.07_BEGIN -- 
void ADC_Sampling_Func(){
    uint8_t ret = ADC_100ms_Cnt % 2;
    
    static uint32_t Adc1_ret[ADC1_CNT] = {0,};
    static uint16_t Adc1_arrange[ADC1_CNT] = {0,};
    static uint16_t Adc1_HFR_Array[ADC1_CNT][6] = {0,};
    static uint16_t Adc1_HFR_Desc_Array[ADC1_CNT][6] = {0,};
    static uint32_t Adc1_HFR_Ret[ADC1_CNT]= {0,};
    
    
    static uint32_t Adc3_ret[ADC3_CNT] = {0,};    
    static uint16_t Adc3_arrange[ADC1_CNT][50]= {0,};
    static uint8_t Sampling_Cnt = 0; // 1cbt 100ms
    static uint8_t Total_SamplingCnt = 0; // 6 Cnt - 600ms
    if(ret == 0){
        for(int i = 0; i < ADC1_CNT;i++){//ADC1_CNT; i++){
            Adc1_ret[i] += SumFunc(&ADC1valuearray[i][0],adc1cnt);
            Adc1_ret[i] /= adc1cnt;
            Adc1_arrange[i] += Adc1_ret[i];
//              printf("%d :  %d / %d  Cnt : %d \r\n",i,ADC1value[i], Adc1_ret[i],Sampling_Cnt);
//            Adc1_arrange_Array[i][Sampling_Cnt] = Adc1_ret[i] / adc1cnt;
//            Adc1_arrange[i] += Adc1_ret[i] / adc1cnt;
//            printf("%d :: %d \r\n",Sampling_Cnt,Adc1_arrange[0][Sampling_Cnt]);
//            Adc1_ret[i] = 0;
        }
        adc1cnt = 0;
        Sampling_Cnt++;
    }
    

    if(Sampling_Cnt >= 50){
        for(int ii = 0; ii < ADC1_CNT; ii++){
            if(Total_SamplingCnt == HFR_REQUSET_TOTAL_CNT - 1){
                ArrayMoveBack(&Adc1_HFR_Array[ii][0],HFR_REQUSET_TOTAL_CNT);
                
                Adc1_HFR_Array[ii][HFR_REQUSET_TOTAL_CNT - 1] 
                    = Adc1_arrange[ii] / (Sampling_Cnt);
                
//                printf("1.   [%d] HFR Algo : %d \r\n",ii, Adc1_HFR_Array[ii][HFR_REQUSET_TOTAL_CNT - 1] );
                
            }else{
//                printf("intialize \r\n");
                Adc1_HFR_Array[ii][Total_SamplingCnt] 
                    = Adc1_arrange[ii] / (Sampling_Cnt);
            }

            for(int repl = 0; repl < 6; repl++){
               Adc1_HFR_Desc_Array[ii][repl] = Adc1_HFR_Array[ii][repl];
//               printf("[%d] Adc1_HFR_Desc_Array[%d] : %d \r\n",ii,repl,Adc1_HFR_Desc_Array[ii][repl]);
            }
            
            DascendigFunc(&Adc1_HFR_Desc_Array[ii][0],HFR_REQUSET_TOTAL_CNT);
            
            

            for(int a = 1; a < 5; a++){
                Adc1_HFR_Ret[ii] += Adc1_HFR_Desc_Array[ii][a];
//                printf("[%d] Adc1_HFR_Desc_Array[%d] : %d \r\n",ii,a,Adc1_HFR_Desc_Array[ii][a]);

            }
            Adc1_HFR_Ret[ii] /= 4;

//            printf("2.   [%d] HFR Algo : %d \r\n",ii,Adc1_HFR_Ret[ii]);



            Adc1_ret[ii] = 0;
            Adc1_arrange[ii] = 0;
            Adc1_HFR_Ret[ii] = 0;
        }
        Total_SamplingCnt++;
        ADC_100ms_Cnt = 0;   
        Sampling_Cnt = 0;
    }
    if(Total_SamplingCnt >= 5)
        Total_SamplingCnt = 5;
}
#else
uint32_t Adc1_ret[ADC1_CNT] = {0,};
uint16_t Adc1_arrange[ADC1_CNT] = {0,};
uint16_t Adc1_HFR_Array[ADC1_CNT][6] = {0,};
uint16_t Adc1_HFR_Desc_Array[ADC1_CNT][6] = {0,};
uint32_t Adc1_HFR_Ret[ADC1_CNT]= {0,};

uint32_t Adc3_ret[ADC3_CNT] = {0,};
uint16_t Adc3_arrange[ADC3_CNT] = {0,};
uint16_t Adc3_HFR_Array[ADC3_CNT][6] = {0,};
uint16_t Adc3_HFR_Desc_Array[ADC3_CNT][6] = {0,};
uint32_t Adc3_HFR_Ret[ADC3_CNT]= {0,};

uint8_t Sampling_Cnt = 0; // 1cbt 100ms
uint8_t Total_SamplingCnt = 0; // 6 Cnt - 600ms
#if 0 // PYJ.2020.08.11_BEGIN -- 
void ADC_Sampling_Func(){
    uint8_t ret = ADC_100ms_Cnt % 2;
    

    double ADC1DoubleRet[ADC1_CNT];
    double ADC3DoubleRet[ADC3_CNT];
    double temp;
    
    if(ret == 0){
        for(int i = 0; i < ADC1_CNT;i++){//ADC1_CNT; i++){
            Adc1_ret[i] += SumFunc(&ADC1valuearray[i][0],adc1cnt);
            Adc1_ret[i] /= adc1cnt;
            Adc1_arrange[i] += Adc1_ret[i];
        }
        for(int i = 0; i < ADC3_CNT;i++){//ADC3_CNT; i++){
            Adc3_ret[i] += SumFunc(&ADC3valuearray[i][0],adc3cnt);
            Adc3_ret[i] /= adc3cnt;
            Adc3_arrange[i] += Adc3_ret[i];
        }        
//        printf("%d :  %d / %d  Cnt : %d \r\n",i,ADC3value[i], Adc3_ret[i],Sampling_Cnt);        
        adc1cnt = 0;
        adc3cnt = 0;
        Sampling_Cnt++;
        printf("ADC_100ms_Cnt : %d \r\n",ADC_100ms_Cnt);
    }else{
        return;
    }
    

    if(Sampling_Cnt >= 50){
#if 1 // PYJ.2020.08.07_BEGIN -- 
        for(int ii = 0; ii < ADC1_CNT; ii++){
            if(Total_SamplingCnt == HFR_REQUSET_TOTAL_CNT - 1){
                ArrayMoveBack(&Adc1_HFR_Array[ii][0],HFR_REQUSET_TOTAL_CNT);
                
                Adc1_HFR_Array[ii][HFR_REQUSET_TOTAL_CNT - 1] 
                    = Adc1_arrange[ii] / (Sampling_Cnt);
                
                
            }else{
                Adc1_HFR_Array[ii][Total_SamplingCnt] 
                    = Adc1_arrange[ii] / (Sampling_Cnt);
            }

            for(int repl = 0; repl < 6; repl++){
               Adc1_HFR_Desc_Array[ii][repl] = Adc1_HFR_Array[ii][repl];
            }
            
            DascendigFunc(&Adc1_HFR_Desc_Array[ii][0],HFR_REQUSET_TOTAL_CNT);
            for(int a = 1; a < 5; a++){
                Adc1_HFR_Ret[ii] += Adc1_HFR_Desc_Array[ii][a];
            }
            Adc1_HFR_Ret[ii] /= 4;

            ADC1DoubleRet[ii] = ((Adc1_HFR_Ret[ii] * 3.3 /4096) * 1000);
            ADC1Ret[ii] = ADC1DoubleRet[ii];
            
            Adc1_ret[ii] = 0;
            Adc1_arrange[ii] = 0;
            Adc1_HFR_Ret[ii] = 0;
        }


        bluecell_Currdatastatus.ULO_P1_Level1_H 
            = ((ADC1Ret[0] & 0xFF00) >> 8);
        bluecell_Currdatastatus.ULO_P1_Level1_L 
                = ((ADC1Ret[0] & 0x00FF) );


        bluecell_Currdatastatus.ULO_P2_Level2_H 
            = ((ADC1Ret[1] & 0xFF00) >> 8);
        bluecell_Currdatastatus.ULO_P2_Level2_L 
            = ((ADC1Ret[1] & 0x00FF) );


        bluecell_Currdatastatus.ULO_P3_Level3_H 
            = ((ADC1Ret[2] & 0xFF00) >> 8);
        bluecell_Currdatastatus.ULO_P3_Level3_L 
            = ((ADC1Ret[2] & 0x00FF) );

        /* *
        온도 소수점 제거
        */
        temp = (ADC1Ret[3] * 0.001);
        bluecell_Currdatastatus.DET_TEMP =  ((temp - 0.5) * 100);
        bluecell_Currdatastatus.DET_TEMP  += bluecell_Currdatastatus.bluecell_User_TEMP_OFFSET;
#endif // PYJ.2020.08.07_END -- 



        for(int ii = 0; ii < ADC3_CNT; ii++){
            if(Total_SamplingCnt == HFR_REQUSET_TOTAL_CNT - 1){
                ArrayMoveBack(&Adc3_HFR_Array[ii][0],HFR_REQUSET_TOTAL_CNT);
                
                Adc3_HFR_Array[ii][HFR_REQUSET_TOTAL_CNT - 1] 
                    = Adc3_arrange[ii] / (Sampling_Cnt);
                
                
            }else{
                Adc3_HFR_Array[ii][Total_SamplingCnt] 
                    = Adc3_arrange[ii] / (Sampling_Cnt);
            }

            for(int repl = 0; repl < 6; repl++){
               Adc3_HFR_Desc_Array[ii][repl] = Adc3_HFR_Array[ii][repl];
            }
            
            DascendigFunc(&Adc3_HFR_Desc_Array[ii][0],HFR_REQUSET_TOTAL_CNT);
            for(int a = 1; a < 5; a++){
                Adc3_HFR_Ret[ii] += Adc3_HFR_Desc_Array[ii][a];
            }
            Adc3_HFR_Ret[ii] /= 4;

            ADC3DoubleRet[ii] = ((Adc3_HFR_Ret[ii] * 3.3 /4096) * 1000);
            ADC3Ret[ii] = ADC3DoubleRet[ii];


            Adc3_ret[ii] = 0;
            Adc3_arrange[ii] = 0;
            Adc3_HFR_Ret[ii] = 0;
        }
        
        Total_SamplingCnt++;
        ADC_100ms_Cnt = 0;   
        Sampling_Cnt = 0;


        bluecell_Currdatastatus.DLI_P1_Level1_H 
            = ((ADC3Ret[1] & 0xFF00) >> 8);
        bluecell_Currdatastatus.DLI_P1_Level1_L 
            = ((ADC3Ret[1] & 0x00FF));
        

        bluecell_Currdatastatus.DLI_P2_Level2_H 
            = ((ADC3Ret[2] & 0xFF00) >> 8);
        bluecell_Currdatastatus.DLI_P2_Level2_L 
            = ((ADC3Ret[2] & 0x00FF) );

            
        bluecell_Currdatastatus.DLI_P3_Level3_H 
            = ((ADC3Ret[3] & 0xFF00) >> 8);
        bluecell_Currdatastatus.DLI_P3_Level3_L 
            = ((ADC3Ret[3] & 0x00FF) );

            
        bluecell_Currdatastatus.DLI_P4_Level4_H 
            = ((ADC3Ret[4] & 0xFF00) >> 8);
        bluecell_Currdatastatus.DLI_P4_Level4_L 
            = ((ADC3Ret[4] & 0x00FF) );

            
        bluecell_Currdatastatus.ULO_P4_Level4_H 
            = ((ADC3Ret[0] & 0xFF00) >> 8);
        bluecell_Currdatastatus.ULO_P4_Level4_L 
            = ((ADC3Ret[0] & 0x00FF) );        
    }
    if(Total_SamplingCnt >= 5)
        Total_SamplingCnt = 5;
}
//#else 
void ADC_Sampling_Func(uint8_t mode,uint16_t Timer2ms_AdcValue,uint8_t index){
    static uint32_t TempAdc1[ADC1_CNT] = {0,};
    static uint32_t TempAdc3[ADC3_CNT] = {0,}; 
    static uint8_t ADC1_TotalCnt[ADC1_CNT] = {0,} ;
    static uint8_t ADC3_TotalCnt[ADC3_CNT] = {0,} ;  
    
    static uint8_t ADC1_TotalSamplingCnt[ADC1_CNT] = {0,} ;
    static uint8_t ADC3_TotalSamplingCnt[ADC3_CNT] = {0,} ;  
    double temp = 0;
    double ADC1DoubleRet[ADC1_CNT];
    double ADC3DoubleRet[ADC3_CNT];


    if(mode == 1){
        TempAdc1[index] += Timer2ms_AdcValue;
        ADC1_TotalCnt[index]++;

        if(ADC1_TotalCnt[index] >= 50){
            TempAdc1[index] /= ADC1_TotalCnt[index];
           /* ADC1DoubleRet[index]  = ((TempAdc1[index] * 3.3 /4096) * 1000);
            TempAdc1[index] = ADC1DoubleRet[index];*/
            /**/

            
           if(ADC1_TotalSamplingCnt[index] == HFR_REQUSET_TOTAL_CNT - 1){
               ArrayMoveBack(&Adc1_HFR_Array[index][0],HFR_REQUSET_TOTAL_CNT);
               Adc1_HFR_Array[index][HFR_REQUSET_TOTAL_CNT - 1] 
                   = TempAdc1[index];
           }
           else{
               Adc1_HFR_Array[index][ADC1_TotalSamplingCnt[index]] 
                   = TempAdc1[index];
           }

           for(int repl = 0; repl < 6; repl++){
              Adc1_HFR_Desc_Array[index][repl] = Adc1_HFR_Array[index][repl];
//               if(index == 3)
//                printf("Adc1_HFR_Array[index] : %d \r\n",Adc1_HFR_Array[index][repl]);
              
           }
           
           DascendigFunc(&Adc1_HFR_Desc_Array[index][0],HFR_REQUSET_TOTAL_CNT);
           for(int a = 1; a < 5; a++){
               Adc1_HFR_Ret[index] += Adc1_HFR_Desc_Array[index][a];
               
           }
           Adc1_HFR_Ret[index] /= 4;

           ADC1DoubleRet[index] = ((Adc1_HFR_Ret[index] * 3.3 /4096) * 1000);
           ADC1Ret[index] = ADC1DoubleRet[index];



            /**/
            if(index == 0){
                bluecell_Currdatastatus.ULO_P1_Level1_H 
                    = (((uint16_t)ADC1Ret[index] & 0xFF00) >> 8);
                bluecell_Currdatastatus.ULO_P1_Level1_L 
                        = (((uint16_t)ADC1Ret[index] & 0x00FF) );
            }
            else if(index == 1){
                bluecell_Currdatastatus.ULO_P2_Level2_H 
                    = (((uint16_t)ADC1Ret[index] & 0xFF00) >> 8);
                bluecell_Currdatastatus.ULO_P2_Level2_L 
                    = (((uint16_t)ADC1Ret[index] & 0x00FF) );
            }
            else if(index == 2){

                bluecell_Currdatastatus.ULO_P3_Level3_H 
                    = (((uint16_t)ADC1Ret[index] & 0xFF00) >> 8);
                bluecell_Currdatastatus.ULO_P3_Level3_L 
                    = (((uint16_t)ADC1Ret[index] & 0x00FF) );
            }
            /* *
            온도 소수점 제거
            */
            else if(index == 3){
//                printf("Temp %d \r\n",ADC1Ret[index]);
                temp = ((uint16_t)ADC1Ret[index] * 0.001);
                bluecell_Currdatastatus.DET_TEMP =  ((temp - 0.5) * 100);
                bluecell_Currdatastatus.DET_TEMP  += bluecell_Currdatastatus.bluecell_User_TEMP_OFFSET;        
            }
            Adc1_ret[index] = 0;
            Adc1_arrange[index] = 0;
            Adc1_HFR_Ret[index] = 0;            
            ADC1_TotalCnt[index] = 0;
            TempAdc1[index] = 0;
            ADC1_TotalSamplingCnt[index]++;
        }        
    }
    else if(mode == 3){
        TempAdc3[index] += Timer2ms_AdcValue;    
        ADC3_TotalCnt[index]++;

        if(ADC3_TotalCnt[index] >= 50){
            TempAdc3[index] /= ADC3_TotalCnt[index];
//            ADC3DoubleRet[index]  = ((TempAdc3[index] * 3.3 /4096) * 1000);
//            TempAdc3[index] = ADC3DoubleRet[index];



/**/

            
           if(ADC3_TotalSamplingCnt[index] == HFR_REQUSET_TOTAL_CNT - 1){
               ArrayMoveBack(&Adc3_HFR_Array[index][0],HFR_REQUSET_TOTAL_CNT);
               Adc3_HFR_Array[index][HFR_REQUSET_TOTAL_CNT - 1] 
                   = TempAdc3[index];
           }
           else{
               Adc3_HFR_Array[index][ADC3_TotalSamplingCnt[index]] 
                   = TempAdc3[index];
           }

           for(int repl = 0; repl < 6; repl++){
              Adc3_HFR_Desc_Array[index][repl] = Adc3_HFR_Array[index][repl];
//               if(index == 3)
//                printf("Adc3_HFR_Array[index] : %d \r\n",Adc3_HFR_Array[index][repl]);
              
           }
           
           DascendigFunc(&Adc3_HFR_Desc_Array[index][0],HFR_REQUSET_TOTAL_CNT);
           for(int a = 1; a < 5; a++){
               Adc3_HFR_Ret[index] += Adc3_HFR_Desc_Array[index][a];
               
           }
           Adc3_HFR_Ret[index] /= 4;

           ADC3DoubleRet[index] = ((Adc3_HFR_Ret[index] * 3.3 /4096) * 1000);
           ADC3Ret[index] = ADC3DoubleRet[index];



            /**/

            if(index == 1){
                bluecell_Currdatastatus.DLI_P1_Level1_H 
                    = (((uint16_t)TempAdc3[index] & 0xFF00) >> 8);
                bluecell_Currdatastatus.DLI_P1_Level1_L 
                    = (((uint16_t)TempAdc3[index] & 0x00FF));
            }
            else if(index == 2){
                bluecell_Currdatastatus.DLI_P2_Level2_H 
                    = (((uint16_t)TempAdc3[index] & 0xFF00) >> 8);
                bluecell_Currdatastatus.DLI_P2_Level2_L 
                    = (((uint16_t)TempAdc3[index] & 0x00FF) );
            }
            else if(index == 3){                
                bluecell_Currdatastatus.DLI_P3_Level3_H 
                    = (((uint16_t)TempAdc3[index] & 0xFF00) >> 8);
                bluecell_Currdatastatus.DLI_P3_Level3_L 
                    = (((uint16_t)TempAdc3[index] & 0x00FF) );
            }
            else if(index == 4){                
                bluecell_Currdatastatus.DLI_P4_Level4_H 
                    = (((uint16_t)TempAdc3[index] & 0xFF00) >> 8);
                bluecell_Currdatastatus.DLI_P4_Level4_L 
                    = (((uint16_t)TempAdc3[index] & 0x00FF) );
            }
            else if(index == 0){                
                bluecell_Currdatastatus.ULO_P4_Level4_H 
                    = (((uint16_t)TempAdc3[index] & 0xFF00) >> 8);
                bluecell_Currdatastatus.ULO_P4_Level4_L 
                    = (((uint16_t)TempAdc3[index] & 0x00FF) );           
            }
            Adc3_ret[index] = 0;
            Adc3_arrange[index] = 0;
            Adc3_HFR_Ret[index] = 0;            
            ADC3_TotalCnt[index] = 0;
            TempAdc3[index] = 0;
            ADC3_TotalSamplingCnt[index]++;

        }        

    }

    if(ADC1_TotalSamplingCnt[index] >= 5)
        ADC1_TotalSamplingCnt[index] = 5;   
    if(ADC3_TotalSamplingCnt[index] >= 5)
        ADC3_TotalSamplingCnt[index] = 5;   
    
    
}

#endif // PYJ.2020.08.11_END -- 


#endif // PYJ.2020.08.07_END -- 
#if 0 // PYJ.2020.08.12_BEGIN -- 
void ADC_Check(void){
#if 1 // PYJ.2020.08.07_BEGIN -- 
    //static uint8_t Cnt = 0;
   double ADC1DoubleRet[4];
   double ADC3DoubleRet[5];
   uint32_t ADC1_Average_value[ADC1_CNT];
   static uint32_t HFR_ADC1_Average_value[ADC1_CNT];
   uint32_t ADC3_Average_value[ADC3_CNT];

   // double ret = 0;
    uint16_t MIN_ADC[ADC3_CNT] = {0,};
    uint16_t cnt[ADC3_CNT] = {0,};
    double temp;
//    if(AdcTimerCnt > 10){
    // 정렬할 배열, 요소 개수, 요소 크기, 비교 함수를 넣어줌
//
//    if(ADC_100ms_Cnt >= 100){
//        printf("%d\r\n",ADC_100ms_Cnt);
//    }

    if(adc3cnt >= ADC_AVERAGECNT){
//    if(ADC_100ms_Cnt >= 100){
        ADC_100ms_Cnt = 0;
        printf("adc3cnt : %d \r\n",adc3cnt);
#if 1 // PYJ.2020.05.25_BEGIN -- 
      for(int i = 0; i < ADC3_CNT; i++){
                DascendigFunc(&ADC3valuearray[i][0],ADC_AVERAGECNT);
                MIN_ADC[i] = ADC3valuearray[i][0] - 12;
                for(int a = 0; a < ADC_AVERAGECNT; a++){
                    if(ADC3valuearray[i][a] < MIN_ADC[i]){
                        cnt[i] = a;
    //                    printf("cnt[i] %d \r\n",cnt[i]);
                        break;
                    }else{
                        cnt[i] = ADC_AVERAGECNT;
                    }
                }
                ADC3_Average_value[i] = SumFunc(&ADC3valuearray[i][0],cnt[i]);
            }

            for(int i = 0; i < ADC3_CNT; i++){
                ADC3DoubleRet[i] = (((ADC3_Average_value[i] / cnt[i]) * 3.3 /4096) * 1000);
                ADC3Ret[i] = ADC3DoubleRet[i];
                ADC3_Average_value[i] = 0;
            }
            
            bluecell_Currdatastatus.DLI_P1_Level1_H 
                = ((ADC3Ret[1] & 0xFF00) >> 8);
            bluecell_Currdatastatus.DLI_P1_Level1_L 
                = ((ADC3Ret[1] & 0x00FF));
            

            bluecell_Currdatastatus.DLI_P2_Level2_H 
                = ((ADC3Ret[2] & 0xFF00) >> 8);
            bluecell_Currdatastatus.DLI_P2_Level2_L 
                = ((ADC3Ret[2] & 0x00FF) );

                
            bluecell_Currdatastatus.DLI_P3_Level3_H 
                = ((ADC3Ret[3] & 0xFF00) >> 8);
            bluecell_Currdatastatus.DLI_P3_Level3_L 
                = ((ADC3Ret[3] & 0x00FF) );

                
            bluecell_Currdatastatus.DLI_P4_Level4_H 
                = ((ADC3Ret[4] & 0xFF00) >> 8);
            bluecell_Currdatastatus.DLI_P4_Level4_L 
                = ((ADC3Ret[4] & 0x00FF) );

                
            bluecell_Currdatastatus.ULO_P4_Level4_H 
                = ((ADC3Ret[0] & 0xFF00) >> 8);
            bluecell_Currdatastatus.ULO_P4_Level4_L 
                = ((ADC3Ret[0] & 0x00FF) );
#endif // PYJ.2020.05.25_END -- 
        adc3cnt = 0;

    }
    if(adc1cnt >= ADC_AVERAGECNT){ 
        for(int i = 0; i < ADC1_CNT; i++){
            DascendigFunc(&ADC1valuearray[i][0],ADC_AVERAGECNT);
            MIN_ADC[i] = ADC1valuearray[i][0] - 12;
            for(int a = 0; a < ADC_AVERAGECNT; a++){
                if(ADC1valuearray[i][a] < MIN_ADC[i]){
                    cnt[i] = a;
                    break;
                }else{
                    cnt[i] = ADC_AVERAGECNT;
                }
            }
            ADC1_Average_value[i] = SumFunc(&ADC1valuearray[i][0],cnt[i]);
        }

        for(int i = 0; i < 4; i++){
            ADC1DoubleRet[i] = (((ADC1_Average_value[i] / cnt[i]) * 3.3 /4095) * 1000);
            ADC1Ret[i] = ADC1DoubleRet[i];
            ADC1_Average_value[i] = 0;
        }
       
        bluecell_Currdatastatus.ULO_P1_Level1_H 
            = ((ADC1Ret[0] & 0xFF00) >> 8);
        bluecell_Currdatastatus.ULO_P1_Level1_L 
            = ((ADC1Ret[0] & 0x00FF) );

            
        bluecell_Currdatastatus.ULO_P2_Level2_H 
            = ((ADC1Ret[1] & 0xFF00) >> 8);
        bluecell_Currdatastatus.ULO_P2_Level2_L 
            = ((ADC1Ret[1] & 0x00FF) );

            
        bluecell_Currdatastatus.ULO_P3_Level3_H 
            = ((ADC1Ret[2] & 0xFF00) >> 8);
        bluecell_Currdatastatus.ULO_P3_Level3_L 
            = ((ADC1Ret[2] & 0x00FF) );

/* *
온도 소수점 제거
*/
    temp = (ADC1Ret[3] * 0.001);
    bluecell_Currdatastatus.DET_TEMP =  ((temp - 0.5) * 100);
    bluecell_Currdatastatus.DET_TEMP  += bluecell_Currdatastatus.bluecell_User_TEMP_OFFSET;



        adc1cnt = 0;

    }
#else    
    //static uint8_t Cnt = 0;
   double ADC1DoubleRet[4];
   double ADC3DoubleRet[5];
   uint32_t ADC1_Average_value[ADC1_CNT];
   static uint32_t HFR_ADC1_Average_value[ADC1_CNT];
   uint32_t ADC3_Average_value[ADC3_CNT];

   // double ret = 0;
    uint16_t MIN_ADC[ADC3_CNT] = {0,};
    uint16_t cnt[ADC3_CNT] = {0,};
    double temp;
//    if(AdcTimerCnt > 10){
    // 정렬할 배열, 요소 개수, 요소 크기, 비교 함수를 넣어줌
//
//    if(ADC_100ms_Cnt >= 100){
//        printf("%d\r\n",ADC_100ms_Cnt);
//    }

//    if(adc3cnt >= ADC_AVERAGECNT){
    if(ADC_100ms_Cnt >= 100){
        
        //        printf("adc3cnt : %d \r\n",adc3cnt);
        for(int i = 0; i < ADC3_CNT; i++){
            ADC3DoubleRet[i] = HFR_ADC3value[i] / adc3cnt;
            
            Adc3_HFR_Array[i][Total_SamplingCnt] = ADC3DoubleRet[i];
            if(Total_SamplingCnt == HFR_REQUSET_TOTAL_CNT - 1){
                ArrayMoveBack(&Adc3_HFR_Array[i][0],HFR_REQUSET_TOTAL_CNT);
            }
            for(int repl = 0; repl < 6; repl++){
               Adc3_HFR_Desc_Array[i][repl] = Adc3_HFR_Array[i][repl];
               
            }
            DascendigFunc(&Adc3_HFR_Desc_Array[i][0],HFR_REQUSET_TOTAL_CNT);
            for(int a = 1; a < 5; a++){
                Adc3_HFR_Ret[i] += Adc3_HFR_Desc_Array[i][a];
                
            }
            Adc3_HFR_Ret[i] /= 4;
            ADC3DoubleRet[i] = ((Adc3_HFR_Ret[i] * 3.3 /4096) * 1000);
            ADC3Ret[i] = ADC3DoubleRet[i];
            Adc3_HFR_Ret[i] = 0;      
            HFR_ADC3value[i] =0 ;
        }
        bluecell_Currdatastatus.DLI_P1_Level1_H 
            = ((ADC3Ret[1] & 0xFF00) >> 8);
        bluecell_Currdatastatus.DLI_P1_Level1_L 
            = ((ADC3Ret[1] & 0x00FF));
        
        
        bluecell_Currdatastatus.DLI_P2_Level2_H 
            = ((ADC3Ret[2] & 0xFF00) >> 8);
        bluecell_Currdatastatus.DLI_P2_Level2_L 
            = ((ADC3Ret[2] & 0x00FF) );
        
            
        bluecell_Currdatastatus.DLI_P3_Level3_H 
            = ((ADC3Ret[3] & 0xFF00) >> 8);
        bluecell_Currdatastatus.DLI_P3_Level3_L 
            = ((ADC3Ret[3] & 0x00FF) );
        
            
        bluecell_Currdatastatus.DLI_P4_Level4_H 
            = ((ADC3Ret[4] & 0xFF00) >> 8);
        bluecell_Currdatastatus.DLI_P4_Level4_L 
            = ((ADC3Ret[4] & 0x00FF) );
        
            
        bluecell_Currdatastatus.ULO_P4_Level4_H 
            = ((ADC3Ret[0] & 0xFF00) >> 8);
        bluecell_Currdatastatus.ULO_P4_Level4_L 
            = ((ADC3Ret[0] & 0x00FF) );

        
        for(int i = 0; i < ADC1_CNT; i++){
            ADC1DoubleRet[i] = HFR_ADC1value[i] / adc1cnt;
            Adc1_HFR_Array[i][Total_SamplingCnt] = ADC1DoubleRet[i];
            if(Total_SamplingCnt == HFR_REQUSET_TOTAL_CNT - 1){
                ArrayMoveBack(&Adc1_HFR_Array[i][0],HFR_REQUSET_TOTAL_CNT);
            }
            for(int repl = 0; repl < 6; repl++){
               Adc1_HFR_Desc_Array[i][repl] = Adc1_HFR_Array[i][repl];
               
            }
            DascendigFunc(&Adc1_HFR_Desc_Array[i][0],HFR_REQUSET_TOTAL_CNT);
            for(int a = 1; a < 5; a++){
                Adc1_HFR_Ret[i] += Adc1_HFR_Desc_Array[i][a];
                
            }
            Adc1_HFR_Ret[i] /= 4;
            ADC1DoubleRet[i] = ((Adc1_HFR_Ret[i] * 3.3 /4096) * 1000);
            ADC1Ret[i] = ADC1DoubleRet[i];
            Adc1_HFR_Ret[i] = 0;     
            HFR_ADC1value[i] = 0;
        }
        bluecell_Currdatastatus.ULO_P1_Level1_H 
            = ((ADC1Ret[0] & 0xFF00) >> 8);
        bluecell_Currdatastatus.ULO_P1_Level1_L 
            = ((ADC1Ret[0] & 0x00FF) );

            
        bluecell_Currdatastatus.ULO_P2_Level2_H 
            = ((ADC1Ret[1] & 0xFF00) >> 8);
        bluecell_Currdatastatus.ULO_P2_Level2_L 
            = ((ADC1Ret[1] & 0x00FF) );

            
        bluecell_Currdatastatus.ULO_P3_Level3_H 
            = ((ADC1Ret[2] & 0xFF00) >> 8);
        bluecell_Currdatastatus.ULO_P3_Level3_L 
            = ((ADC1Ret[2] & 0x00FF) );

/* *
온도 소수점 제거
*/
        temp = (ADC1Ret[3] * 0.001);
        bluecell_Currdatastatus.DET_TEMP =  ((temp - 0.5) * 100);
        bluecell_Currdatastatus.DET_TEMP  += bluecell_Currdatastatus.bluecell_User_TEMP_OFFSET;        


        Total_SamplingCnt++;
        
        if(Total_SamplingCnt >=5)
            Total_SamplingCnt = 5;
         
        adc3cnt = 0;
        adc1cnt = 0;
        ADC_100ms_Cnt = 0;

    }

#endif // PYJ.2020.08.07_END -- 
//    ADC_Sampling_Func();

    /*
        After ADC calculation is completed, start Det Alarm check.
    */

    DET_LevelAlarmCheck();/*DL UL Alarm Check*/
}
#else
#define Percent       2
#define Percent100 5
void ADC_Check(void){
#if 1 // PYJ.2020.08.07_BEGIN -- 
    //static uint8_t Cnt = 0;
   double ADC1DoubleRet[4];
   double ADC3DoubleRet[5];
   uint32_t ADC1_Average_value[ADC1_CNT];
   static uint32_t HFR_ADC1_Average_value[ADC1_CNT];
   uint32_t ADC3_Average_value[ADC3_CNT];
    uint16_t MIN_ADC[ADC3_CNT] = {0,};
    uint16_t cnt[ADC3_CNT] = {0,};
    double temp;
    
//    if(AdcTimerCnt > 10){
    // 정렬할 배열, 요소 개수, 요소 크기, 비교 함수를 넣어줌
//
    if(ADC_100ms_Cnt >= 100){
#if 1 // PYJ.2020.05.25_BEGIN -- 
    for(int i = 0; i < ADC3_CNT; i++){
        for(int index = 0; index < 100; index++){
            ADC3Desc_valuearray[i][index] = ADC3valuearray[i][index];
        }
        DascendigFunc(&ADC3Desc_valuearray[i][0],ADC_AVERAGECNT);
            
        ADC3_Average_value[i] = SumFunc(&ADC3Desc_valuearray[i][0],Percent100);

        ADC3_Average_value[i] /=Percent100;
       
        if(Total_SamplingCnt == HFR_REQUSET_TOTAL_CNT - 1){
            ArrayMoveBack(&Adc3_HFR_Array[i][0],HFR_REQUSET_TOTAL_CNT);
            Adc3_HFR_Array[i][Total_SamplingCnt] = ADC3_Average_value[i]; 
             for(int index = 0; index <6; index++){
                 Adc3_HFR_Desc_Array[i][index] = Adc3_HFR_Array[i][index] ;
//                 if(i == 4)
//                 printf("%d   Adc3_HFR_Desc_Array : %d \r\n",index,Adc3_HFR_Desc_Array[i][index]);
             }                  
            

             DascendigFunc(&Adc3_HFR_Desc_Array[i][0],6);
             ADC3_Average_value[i] = 0;

            for(int index = 0; index <Percent; index++){
                 ADC3_Average_value[i] += Adc3_HFR_Desc_Array[i][index];
            }
            ADC3_Average_value[i] /= Percent;
        }
        else{
            Adc3_HFR_Array[i][Total_SamplingCnt] = ADC3_Average_value[i];
        }

        ADC3DoubleRet[i] = (((ADC3_Average_value[i] ) * 3.3 /4096) * 1000);
        ADC3Ret[i] = ADC3DoubleRet[i];
        ADC3_Average_value[i] = 0;
    }
    bluecell_Currdatastatus.DLI_P1_Level1_H 
        = ((ADC3Ret[1] & 0xFF00) >> 8);
    bluecell_Currdatastatus.DLI_P1_Level1_L 
        = ((ADC3Ret[1] & 0x00FF));
    

    bluecell_Currdatastatus.DLI_P2_Level2_H 
        = ((ADC3Ret[2] & 0xFF00) >> 8);
    bluecell_Currdatastatus.DLI_P2_Level2_L 
        = ((ADC3Ret[2] & 0x00FF) );

        
    bluecell_Currdatastatus.DLI_P3_Level3_H 
        = ((ADC3Ret[3] & 0xFF00) >> 8);
    bluecell_Currdatastatus.DLI_P3_Level3_L 
        = ((ADC3Ret[3] & 0x00FF) );

        
    bluecell_Currdatastatus.DLI_P4_Level4_H 
        = ((ADC3Ret[4] & 0xFF00) >> 8);
    bluecell_Currdatastatus.DLI_P4_Level4_L 
        = ((ADC3Ret[4] & 0x00FF) );

        
    bluecell_Currdatastatus.ULO_P4_Level4_H 
        = ((ADC3Ret[0] & 0xFF00) >> 8);
    bluecell_Currdatastatus.ULO_P4_Level4_L 
        = ((ADC3Ret[0] & 0x00FF) );
#endif // PYJ.2020.05.25_END -- 
        adc3cnt = 0;

    for(int i = 0; i < ADC1_CNT; i++){
        for(int index = 0; index < 100; index++){
            ADC1Desc_valuearray[i][index] = ADC1valuearray[i][index];
        }
        DascendigFunc(&ADC1Desc_valuearray[i][0],ADC_AVERAGECNT);
            
        ADC1_Average_value[i] = SumFunc(&ADC1Desc_valuearray[i][0],Percent);

        ADC1_Average_value[i] /=Percent;
       
        if(Total_SamplingCnt == HFR_REQUSET_TOTAL_CNT - 1){
            ArrayMoveBack(&Adc1_HFR_Array[i][0],HFR_REQUSET_TOTAL_CNT);
            Adc1_HFR_Array[i][Total_SamplingCnt] = ADC1_Average_value[i]; 
             for(int index = 0; index <6; index++){
                 Adc1_HFR_Desc_Array[i][index] = Adc1_HFR_Array[i][index] ;
             }                  
            

             DascendigFunc(&Adc1_HFR_Desc_Array[i][0],6);
             ADC1_Average_value[i] = 0;
             
            for(int index = 0; index <3; index++)
                 ADC1_Average_value[i] += Adc1_HFR_Desc_Array[i][index];
            
            ADC1_Average_value[i] /= 3;                
            
        }
        else{
            Adc1_HFR_Array[i][Total_SamplingCnt] = ADC1_Average_value[i];
        }

        ADC1DoubleRet[i] = (((ADC1_Average_value[i] ) * 3.3 /4096) * 1000);
        ADC1Ret[i] = ADC1DoubleRet[i];
        ADC1_Average_value[i] = 0;
    }

        bluecell_Currdatastatus.ULO_P1_Level1_H 
            = ((ADC1Ret[0] & 0xFF00) >> 8);
        bluecell_Currdatastatus.ULO_P1_Level1_L 
            = ((ADC1Ret[0] & 0x00FF) );

            
        bluecell_Currdatastatus.ULO_P2_Level2_H 
            = ((ADC1Ret[1] & 0xFF00) >> 8);
        bluecell_Currdatastatus.ULO_P2_Level2_L 
            = ((ADC1Ret[1] & 0x00FF) );

            
        bluecell_Currdatastatus.ULO_P3_Level3_H 
            = ((ADC1Ret[2] & 0xFF00) >> 8);
        bluecell_Currdatastatus.ULO_P3_Level3_L 
            = ((ADC1Ret[2] & 0x00FF) );

/* *
온도 소수점 제거
*/
    temp = (ADC1Ret[3] * 0.001);
    bluecell_Currdatastatus.DET_TEMP =  ((temp - 0.5) * 100);
    bluecell_Currdatastatus.DET_TEMP  += bluecell_Currdatastatus.bluecell_User_TEMP_OFFSET;
//    printf("bluecell_Currdatastatus.DET_TEMP : %d \r\n",bluecell_Currdatastatus.DET_TEMP);
    
        ADC_100ms_Cnt = 0;

        adc1cnt = 0;
        
        Total_SamplingCnt++;
//         printf("1. Total_SamplingCnt %d\r\n",Total_SamplingCnt);
        if(Total_SamplingCnt >= 5)
            Total_SamplingCnt = 5;

    }
#endif//    ADC_Sampling_Func();

    /*
        After ADC calculation is completed, start Det Alarm check.
    */

    DET_LevelAlarmCheck();/*DL UL Alarm Check*/
}


#endif // PYJ.2020.08.12_END -- 

#endif // PYJ.2020.08.07_END -- 



#if 1 // PYJ.2020.05.12_BEGIN -- 

/*One Point  round*/
double Bluecell_round( double value )
{
    unsigned short data = value * 1000;
    unsigned short temp = 0;
    double ret = 0;
//    printf("1: %d\r\n",data);
    temp = data % 10;
    if(temp >= 5){
        data = data - temp + 10;
    }else{
        data = data - temp;
    }
//    printf("2: %d\r\n",data);
    temp = (data % 100) * 0.1;
//    printf("3: %d\r\n",temp);
    if(temp >= 5){
        data = data - (temp * 10)+ 100;
    }else{
        data = data - (temp * 10);
    }
//     printf("4: %d\r\n",data);
     ret = data;
       // printf("ret : %f\r\n",ret / 1000);

     return ret / 1000;
}
/*One Point  round*/
#if 0 // PYJ.2020.06.26_BEGIN -- 
double Bluecell_TestPro(double value )
{
    int16_t temp = (value * 10);
    double temp_float = 0;
    bool minus_set = 0;
//    printf("0. temp  : %d\r\n",temp);

    temp = temp % 10;
//    printf("1. temp  : %d\r\n",temp);
    if((int16_t)temp == 0)
        return value;
    if(temp < 0){
        temp *= -1;//Convert Minus To plus
//        printf("MInus set : 2. temp  : %d\r\n",temp);        
        minus_set = true; 
    }
    temp_float = temp * 0.1;
//    printf("3. temp_float: %f    temp  : %f\r\n",temp_float,temp);            
//    printf("4. value : %f temp : %d   temp_float : %f \r\n",value,temp,temp_float);        
    
    if(temp >= 5){

        if(minus_set == true){
            value -= 1;
            value += temp_float;
        }else{
            value += 1;
            value -= temp_float;
        }
            
//    printf("temp_float : %f \r\n",temp_float);
    }
    else{
#if 1 // PYJ.2020.05.25_BEGIN -- 
         if(minus_set == true){
             value += temp_float;
         }
         else{
            value -= temp_float;
         }
#else         
        value -= temp_float;

#endif // PYJ.2020.05.25_END -- 
//        printf("temp_float : %f \r\n",temp_float);
    }
    
    
//    printf("temp  : %f \r\n",value);
     return (value);
}
#else
double Bluecell_TestPro(double value ){
    bool minusset = false;
    uint8_t temp = 0;
    if(value < 0){
        value *= -1;
        minusset = true;
    }
    
    value *= 10;
    temp = value;
    
    if(temp % 10 > 5){
        temp = temp - (temp % 10);
        temp += 10;
    }else{
        temp = temp - (temp % 10);
    }

    value = (temp * 0.1);
//    printf("round Ret : %f \r\n",value);
    if(minusset ==true)
       value = value * -1;
    
    return value;

}
int8_t Bluecell_TestPro2(double value ){
    bool minusset = false;
    int8_t remine = 0;
    double originval = value;
    uint8_t temp = 0;
//    printf("value : %f \r\n",value);
    if(value < 0){
        value *= -1;
        originval *= -1;
        minusset = true;
    }
    value *= 10;
//    printf("value*10 : %f \r\n",value);
    temp = (int8_t)value;
//    printf("temp <-value*10 : %d \r\n",temp );
    remine = (temp % 10);  
//    printf("temp <-value*10 % remine : %f \r\n",remine);

   
        if(remine >= 5){
//            printf("temp : %d remind : %d \r\n",temp,remine);
            temp = temp - remine;
//            printf("tempret  : %d \r\n",temp);        
//            printf("1.temp : %d \r\n",temp);
//            if(value >= 10){
                temp += 10;//0.5 for
//            printf("2.temp : %d \r\n",temp);
//            }
        }else{
            if(originval > 1)
                temp = (int8_t)originval;
            else{
               temp = (int8_t)originval;
            }
            temp *= 10;
//            printf("originval : %f  temp : %d \r\n",originval,temp);
        }

        value = (temp * 0.1);
//        printf("1.round Ret : %f \r\n",value);
        if(minusset ==true)
           value = value * -1;
//        printf("2.round Ret : %f \r\n",value);    
    return value;

}

#endif // PYJ.2020.06.26_END -- 


#endif // PYJ.2020.05.12_END -- 

#if 0 // PYJ.2020.05.12_BEGIN -- 
double AutoControl_ADC_Compare(double CurrentAdc,uint8_t* CompareAdc,uint8_t size){
    double ret = 0xFF,CurrRet = 0,TableAdc,TableAdcret; 
    uint8_t LastIndex = 0;
    double Max_ADC = 0,Min_ADC = 0;
    double step = 0;
    double dot = 0,tempret = 0xFF;
    for(int i =0; i < size / 2; i++){
        TableAdc = CompareAdc[i * 2] << 8;
        TableAdc += CompareAdc[i * 2 + 1];
        TableAdc /= 1000;
//        printf("TableAdc[%d] : %f \r\n",i,TableAdc);
        CurrRet = TableAdc - CurrentAdc;
        
        if(CurrRet < 0){ // plus 공식
            CurrRet = (CurrRet * -2) + CurrRet;
        }
        if(ret > CurrRet){
            ret = CurrRet;
            TableAdcret = TableAdc;
            LastIndex = i;
        }
    }
    
    /*MIN*/
    TableAdc = CompareAdc[LastIndex * 2] << 8;
    TableAdc += CompareAdc[LastIndex * 2 + 1];
    TableAdc /= 1000;
    Min_ADC = TableAdc;
    /*MAX*/
    TableAdc = CompareAdc[LastIndex * 2 - 2 ] << 8;
    TableAdc += CompareAdc[LastIndex * 2 - 1];
    TableAdc /= 1000;
    Max_ADC = TableAdc;

    
    step = ((Max_ADC - Min_ADC) / 10);
    
//    Min_ADC = Bluecell_round(Min_ADC);
//    CurrentAdc = Bluecell_round(CurrentAdc);
//    printf("1:STEP : %f , %f  > %f > %f \r\n",step,Max_ADC,CurrentAdc,Min_ADC);
    for(double d = 0; d < 1; d += 0.1){
        CurrRet = CurrentAdc - Min_ADC;
        if(tempret >= CurrRet & CurrRet > 0){
//            printf("(%f >= %f)\r\n",tempret,CurrRet);
            tempret = CurrRet;
//            printf("2:STEP : %f , %f  > %f > %f \r\n",step,Max_ADC,CurrentAdc,Min_ADC);
            Min_ADC += step;
            dot = d;
        }
   }    
//    printf("dot : %f \r\n",dot);
    dot = AutoControl_Save[LastIndex] - dot;
    
//    printf("AutoControl_Save[LastIndex]:%d + dot:%f : %f \r\n",AutoControl_Save[LastIndex] + dot);
//    printf(" %f  > %f > %f \r\n",Max_ADC,CurrentAdc,Min_ADC);
    return dot;
}
#else
#if 0 // PYJ.2020.05.15_BEGIN -- 
int8_t AutoControl_ADC_Compare(double CurrentAdc,uint8_t* CompareAdc,uint8_t size){
    double ret = 0xFF,CurrRet = 0,TableAdc; 
    uint8_t LastIndex = 0;
    for(int i =0; i < size / 2; i++){
        TableAdc = CompareAdc[i * 2] << 8;
        TableAdc += CompareAdc[i * 2 + 1];
        TableAdc /= 1000;
//        printf("TableAdc[%d] : %f \r\n",i,TableAdc);
        CurrRet = TableAdc - CurrentAdc;

        if(CurrRet < 0){
            CurrRet = (CurrRet * -2) + CurrRet;
        }
        
        if(ret > CurrRet){
            ret = CurrRet;
            LastIndex = i;
        }
        
    }
    return AutoControl_Save[LastIndex];
}
#else
double AutoControl_ADC_Compare(double CurrentAdc,uint8_t* CompareAdc,uint8_t size,int8_t* RefTable_Data){
    double ret = 0xFF,CurrRet = 0,TableAdc,NextTableAdc; 
    double Vitual_array[10] = {0,};
    double step = 0;
    uint8_t LastIndex = 0;
    uint8_t dot = 0;
    double Lastdata = 0;    
//   printf("size: %d \r\n",size);
    for(int i =0; i < size / 2; i++){
        TableAdc = CompareAdc[i * 2] << 8;
        TableAdc += CompareAdc[i * 2 + 1];
        if(TableAdc == 0)
            continue;
        TableAdc /= 1000;

        NextTableAdc = CompareAdc[i * 2 + 2] << 8;
        NextTableAdc += CompareAdc[i * 2 + 3];
        NextTableAdc /= 1000;        
        Lastdata = TableAdc;
//        printf("TableAdc[%d] : %f \r\n",i,TableAdc);
//        CurrRet = TableAdc - CurrentAdc;

        step = (TableAdc - NextTableAdc) * 0.1;
        for(int a = 0; a < 10; a++){
            Vitual_array[a] = TableAdc - (step * a);
            if(Vitual_array[a] >= CurrentAdc){
                CurrRet = (Vitual_array[a]) - (CurrentAdc);
            }else{
                CurrRet = (CurrentAdc) - (Vitual_array[a]);
            }
//            printf("Vitual_array[%d] : %f \r\n",a,Vitual_array[a]);
//            if(CurrRet < 0){
//                CurrRet = (CurrRet * -2) + CurrRet;
//            }
            
            if(ret > CurrRet){
                ret = CurrRet;
                LastIndex = i;
                dot = a;
            }
        }
        
    }
    TableAdc = CompareAdc[0] << 8;
    TableAdc += CompareAdc[1];
    TableAdc /= 1000;    

    if(Lastdata > CurrentAdc)
        return RefTable_Data[(size / 2) - 1]; 
    
    if(CurrentAdc < TableAdc){
#if 0 // PYJ.2020.06.26_BEGIN -- 
        for(int i = 0; i < sizeof(ALC_dBm_t); i++)
            printf("ref Tabe[%d]: %d \r\n",i,RefTable_Data[i]);
        printf("LastIndex : %d  / dot : %d  TableAdc : %f \r\n",LastIndex,dot,(RefTable_Data[LastIndex] - (dot * 0.1)));
#endif // PYJ.2020.06.26_END -- 
        return (RefTable_Data[LastIndex] - (dot * 0.1));
    }
    else{
//        printf("CurrentAdc : %f     TableAdc : %f \r\n",CurrentAdc,TableAdc);
        return (RefTable_Data[0]);
    }
}

double AGC_AutoControl_ADC_Compare(double CurrentAdc,uint8_t* CompareAdc,uint8_t size,int8_t* RefTable_Data){
    double ret = 3.3,CurrRet = 0,TableAdc,NextTableAdc; 
    double Vitual_array[10] = {0,};
    double step = 0;
    uint8_t LastIndex = 0;
    uint8_t dot = 0;
    double Lastdata = 0;
    double Compare_Data = 0;
    double first_data = (((CompareAdc[0] << 8) | CompareAdc[1]) * 0.001);
    for(int i =0; i < size; i++){
        TableAdc = (((CompareAdc[i * 2] << 8) | CompareAdc[i * 2 + 1]) * 0.001);
        Lastdata = TableAdc;
        
        NextTableAdc = CompareAdc[i * 2 + 2] << 8;
        NextTableAdc += CompareAdc[i * 2 + 3];
        NextTableAdc /= 1000;        
//        printf("TableAdc[%d] : %f \r\n",i,TableAdc);
        Vitual_array[0] = TableAdc;
//        CurrRet = TableAdc - CurrentAdc;
        if(TableAdc >= NextTableAdc){
            step = (TableAdc - NextTableAdc)* 0.1;
        }else{
            step = (NextTableAdc - TableAdc) * 0.1;
        }
        for(int a = 0; a < 10; a++){
                if(size - 1 != i){
                    Vitual_array[a] = TableAdc - (step * a);
                }
                if(Vitual_array[a] >= CurrentAdc){
                    CurrRet = Vitual_array[a] - CurrentAdc;
                }else{
                    CurrRet = CurrentAdc - Vitual_array[a];
                }
//            CurrRet = (Vitual_array[a]) - (CurrentAdc);
//                printf("Vitual_array[%d] : %f  ERROR RATE : %f \r\n",a,Vitual_array[a],CurrRet);
//            Compare_Data *= 1000;

//            if(CurrRet < 0){
//                CurrRet = (CurrRet * -2) + CurrRet;
//            }
            
            if(ret > CurrRet){
                ret = CurrRet;
                LastIndex = i;
//                if(LastIndex == 30 && CurrentAdc != 0 ){
//                    printf("TableAdc[%d] : %f  step : %f  x a : %d\r\n",i,TableAdc,step,a);
//                    for(int k = 0; k < 10; k++)
//                        printf("Vitual_array[%d] : %f \r\n",k,Vitual_array[k]);
//                }
//                printf("ret : %f CurrRet  : %f  CurrentAdc : %f  %d.Vitual_array[a] : %f dot : %d\r\n",ret,CurrRet,CurrentAdc,i,Vitual_array[a],dot);
                dot = a;
            }
           if(size - 1 == i){
//                printf("size - 1 : %d  i : %d \r\n",size -1 , i);
                break;
            }               
        }
        
    }
    if(Lastdata >= CurrentAdc){
//        for(int i = 0; i < size; i++){
//            printf("RefTable_Data[%d] : %d \r\n",i,RefTable_Data[i]);        
//        }
//        printf("RefTable_Data[%d] : %d \r\n",size,RefTable_Data[(LastIndex )]);
        return RefTable_Data[LastIndex ];
    }
//        printf("CurrentAdc : %f     TableAdc : %f \r\n",CurrentAdc,TableAdc);
//        for(int a = 0; a < sizeof(AGC_dBm_t); a++)
//            printf("AutoControl_Save[%d] : %d \r\n",a,AutoControl_Save[a]);
    if(first_data <= CurrentAdc){
//        printf("(RefTable_Data[0]) : %d \r\n",(RefTable_Data[0]));
        return (RefTable_Data[0]);
    }else{
//        printf("Nomal _Table Data %f",(RefTable_Data[LastIndex] - (dot * 0.1)));
//        printf("LastIndex : %d  / dot : %d  TableAdc : %f \r\n",LastIndex,dot,(RefTable_Data[LastIndex] - (dot * 0.1)));
        return (RefTable_Data[LastIndex] - (dot * 0.1));
    }
}

#endif // PYJ.2020.05.15_END -- 

#endif // PYJ.2020.05.12_END -- 
#if 0 // PYJ.2020.05.21_BEGIN -- 
int32_t MinusConvert(uint8_t Temp_h, int32_t Value){
    int32_t ret;
    if((((bluecell_Currdatastatus.ATT_ALC1_MAX_H << 8) & 0xFF00) & 0xF000) == 0xF000){
        
        Value = 0x0000FFFF - (Value & 0x0000FFFF);
        Value += 0x01;
        Value *= -1;
    }
    Value /= 100;
    ret = Value;
     
    return ret;
}
#endif // PYJ.2020.05.21_END -- 


uint8_t ALC_AlarmSet[ALC_Alarm_UL_Index_MAX] = {0,};
int16_t ALC_Calc(uint8_t num,double CurrAtten ,int8_t threshold,double CurrDet){
    double ret = 0;
    int8_t result = 0;
//    CurrAtten *= -1;
    if(CurrDet == threshold){
        return 0;
    }
//    ret = CurrDet - threshold;
#if 0 // PYJ.2020.05.25_BEGIN -- 
    if(CurrAtten >= 20){
        if(CurrDet - threshold < 0){
            if(CurrAtten + (CurrDet - threshold) > 0){
//                ret = CurrAtten + (CurrDet - threshold);
                printf("5. %f : %f  %d\r\n",ret,CurrDet,threshold);
            }
            else{
                ret = CurrAtten * -1;
                printf("6. %f : %f  %d\r\n",ret,CurrDet,threshold);
            }
        }else{
            ALC_AlarmSet[num] = true;
        }
        printf("4. %f : %f  %d\r\n",ret,CurrDet,threshold);
        return ret;
    }
#endif // PYJ.2020.05.25_END -- 
    
#if 0 // PYJ.2020.06.20_BEGIN -- 
    if(CurrDet < threshold){
          ret =  CurrDet - threshold;
          printf("1. %f : %f - %d\r\n",ret,CurrDet,threshold);
//          if(((ret * 10) % 10 ) != 0)
              ret = Bluecell_TestPro(ret);
        printf("ret = %f \r\n",ret);

    }
    else if(CurrDet > threshold){
        ret = CurrDet - threshold;
        printf("2. %f : %f  %d\r\n",ret,CurrDet,threshold);    
//        if(((ret * 10) % 10 ) != 0)
           ret = Bluecell_TestPro(ret);
        
    }
   
    printf("Result : ret = %f \r\n",ret);
#if 0 // PYJ.2020.06.20_BEGIN -- 
    if(CurrAtten + ret >= 0){
        ret = CurrAtten * -1;
        printf("3. ret0 : %f \r\n",ret);
    }else{
        ALC_AlarmSet[num] = false;  
    }
#endif // PYJ.2020.06.20_END -- 
    ret *= -1;
    if(CurrAtten < 0){
        if(CurrAtten < ret){
            ret += CurrAtten;
        }
    }
#endif // PYJ.2020.06.20_END -- 
    if(threshold < CurrDet){
        ret = CurrDet - threshold ;
//        printf("1. %f : %f - %d\r\n",ret,CurrDet,threshold);

        
//        printf("2. %f : %f - %d\r\n",ret,CurrDet,threshold);
        result = Bluecell_TestPro2(ret /*+( CurrAtten * -1)*/);
//        printf("2.5. Ret : %d \r\n",result);
        result *= -1;  
//        printf("3. Ret : %d \r\n",result);
//        if(CurrAtten <= -20)
//            ALC_AlarmSet[num] = true;
    }
    else if(threshold -2 > CurrDet ){
        if(CurrAtten < 0){
            ret =  (threshold - 2) - CurrDet ;// -27 ///// - 29
//            printf("%f  =  %d - %f\r\n",ret,(threshold - 2),CurrDet);
//            printf("CurrAtten : %f\r\n",CurrAtten);
            result = Bluecell_TestPro2(ret);
//            printf("3.ret : %d\r\n",result);
            result += CurrAtten;
            if(CurrAtten < 0){
                int8_t tmp = CurrAtten * - 1;
            }
            result = CurrAtten + 1;
            result *= -1;     
             
//            printf("4.ret : %d\r\n",result);
//            ALC_AlarmSet[num] = false; 

        }
         
    }


    
    if(result < -20){
//        printf("5. ret1 : %f \r\n",ret);
        ret = -20;
        
    }else{
        if(result > 0){
//            printf("6. ret1 : %f \r\n",ret);
            result = 0;
        }
       
    }
//    printf("ret7 : %f \r\n",ret);
    return result * 10;
}
#define UL_DL_DATASEND_MULTIPLE 10
void ALC_Alarm_TimerSet(uint8_t num,int16_t threshold,int16_t CurrDet,int16_t Atten,int16_t MainAtten){
    int16_t ret =0;
    int16_t CurrAtten = 0; 
    int16_t M_Atten = 0;
    M_Atten = (MainAtten * 0.1);
//    printf("MainAtten : %d \r\n",MainAtten);
    CurrAtten = Atten * 0.1; // ALC ATTEN
        if(CurrAtten + M_Atten >= -18){
            ALC_AlarmSet[num] = false;
//            printf("Alarm 3 \r\n");                
        }    
        else if(threshold <= CurrDet){
            ret = CurrDet - threshold ;
            ret = Bluecell_TestPro(ret +( CurrAtten * 0.1 * -1));
            ret *= -1;  
//            printf("CurrAtten : %d   M_Atten : %d \r\n",CurrAtten,M_Atten);
            if(CurrAtten + M_Atten <= -20){
                ALC_AlarmSet[num] = true;
//                printf("Alarm 1 \r\n");
            }
        }
        else if(threshold -2 > CurrDet){
            if(CurrAtten < 0){
                ret =  (threshold - 2) - CurrDet ;// -27 ///// - 29
                ret = Bluecell_TestPro(ret);
                ret += CurrAtten;
                ALC_AlarmSet[num] = false; 
//                printf("Alarm 2 \r\n");                
            }
        }
//        printf("threshold : %d \r\n",threshold);
//        printf("Curr Atten : %d    Main Atten : %d    Thre : %d    CurrDet : %d \r\n",
//        CurrAtten,MainAtten,threshold,CurrDet);
//        printf("ALC_AlarmSet[%d] %d \r\n",num,ALC_AlarmSet[num]);
}
double HFR_CntUpCalc(double ret){
    double origin = ret;
    int16_t calctmp = 0;
//    printf("+++++++++++++++++++++++++++++++++++++++++\r\n");
    ret *= -1;
//    printf("CALC VALUE : %f \r\n",ret);
    ret *= 10;
    calctmp = ret;
//    printf("1. ret : %f \r\n",ret);
    calctmp %= 10;
//    printf("2. ret : %f \r\n",ret);
    
    
    if(calctmp >= 5){
//        printf("minus return \r\n");
        origin = (origin -1) + (calctmp  * 0.1);
    }else{
        origin += (calctmp  * 0.1);
//        printf("ZERO return \r\n");        
    }
//    printf("HFR RET : %f \r\n",origin);
    return origin;
}
typedef enum{
    ULO_ALC_H = 0,
    ULO_ALC_L,
};
   
void ALC_Package_Operate(uint8_t*ULO_ADC_Level,uint8_t* ULO_Level,DET_TABLEUL_st*      UL_Table,uint8_t TableIndex,uint8_t* ALC_Atten,uint8_t* UL_Main_Atten,uint8_t* GainOffset,uint8_t* retrycnt ){
    /*static int16_t PrevLimitdata[ALC_Alarm_UL_Index_MAX] = {0,};
    static int8_t* ALC_Table;
    int16_t tmpcalc = 0;
    static int16_t PrevIwillGiveAtten[ALC_Alarm_UL_Index_MAX] ={0,};*/
    int16_t Gain_Atten = 0;
    double ret = 0;
    double CurrentATTENVALUE = 0;
    int16_t Limitdata = 0;
    double ResdBm = 0;
    int16_t ResultData = 0;
    int16_t IwillGiveAtten = 0;
    int16_t UL_Atten = 0;
    int16_t Main_Atten = 0;
    int16_t GiveAttenPlusULAtten = 0;

    if(*retrycnt > 0)
        return;
    
    UL_Atten = ALC_Atten[ULO_ALC_H] << 8 | ALC_Atten[ULO_ALC_L];
    Main_Atten = UL_Main_Atten[ULO_ALC_H] << 8 | UL_Main_Atten[ULO_ALC_L];
    Gain_Atten = GainOffset[ULO_ALC_H] << 8 | GainOffset[ULO_ALC_L];
//    printf("Curr Main Atten : %d \r\n",Main_Atten);
//    printf("Curr Gain Atten : %d \r\n",Gain_Atten);

    /*Threas Hold Value*/
    Limitdata = (( bluecell_Currdatastatus.ULO_ALC_Threshold_H << 8) & 0xFF00) ;
    Limitdata +=  bluecell_Currdatastatus.ULO_ALC_Threshold_L ;
    Limitdata *= 0.1;   
    /*ADC Value*/
    ret  =  ((ULO_ADC_Level[ULO_ALC_H] << 8 | ULO_ADC_Level[ULO_ALC_L]) * 0.001);
    /*Curr UL Value*/
    ResdBm = AutoControl_ADC_Compare(ret,&UL_Table->Table_Det_15_dBm_H,UL_Table->Table_Length * 2,&UL_DET_Table_ref[TableIndex][TABLE_MAX_VALUE]);
    //ret 현재 Voltage 값 출력
    //ret 에 따른 현재 DBM 구현

    CurrentATTENVALUE = PE43711_Double(ALC_Atten[ULO_ALC_H],ALC_Atten[ULO_ALC_L]);

//    printf("=============ALC ON =====START================\r\n");
//    printf("Current UL ADC VALUE : %f \r\n",ret);
//    printf("ResdBm : UL%d : %f \r\n",TableIndex + 1,ResdBm);    
//    printf("ORIGIN ResdBm : %f  %d\r\n",ResdBm,Main_Atten);
//    printf("After ResdBm : %f \r\n",ResdBm);

    ResdBm = HFR_CntUpCalc(ResdBm); //+ bluecell_Currdatastatus.UL_Det_Path_Offset[TableIndex];;
    ResultData = ResdBm;
//    printf("HFR CALC RET : %d \r\n",ResultData);
    ULO_Level[ULO_ALC_H] = (ResultData & 0xFF00) >> 8;
    ULO_Level[ULO_ALC_L] = (ResultData & 0x00FF);    
    Limitdata += (Main_Atten * 0.1);
//    printf("Limitdata : %d | ResultData : %d \r\n",Limitdata,ResultData);
    ALC_Alarm_TimerSet(TableIndex,Limitdata,ResultData,UL_Atten,Main_Atten);
    IwillGiveAtten = ALC_Calc(TableIndex,CurrentATTENVALUE,Limitdata,ResdBm);
//    printf("STEP 1 : I WILL GIVE ATTEN  %d \r\n",IwillGiveAtten);
    IwillGiveAtten += UL_Atten;
//    printf("STEP 2 : I WILL GIVE ATTEN PLUS  ALC ATTEN  %d \r\n",IwillGiveAtten);    
    if(ResdBm <= (Limitdata - 1)){
        if(IwillGiveAtten <= -10){
            IwillGiveAtten += 10;
        }
    }
    GiveAttenPlusULAtten = IwillGiveAtten + (Main_Atten );
    if(GiveAttenPlusULAtten <= - 200){
        IwillGiveAtten = -200 + ((Main_Atten * -1));
    }
    if(IwillGiveAtten <= -200){
        IwillGiveAtten = -200;
    }  
    if(IwillGiveAtten >= 0){
        IwillGiveAtten = 0;
    }       
//    printf(" UL_Atten: %d I WILL GIVE ATTEN  : %d \r\n", UL_Atten,IwillGiveAtten);  
//    printf("ADC : %f CURR ATT : %f  Threas : %d : I WILL GIVE ATTEN  : %d \r\n",ret,ResdBm , Limitdata,IwillGiveAtten);  
//    printf("==================END================\r\n");          
    
//    if( (IwillGiveAtten > 0) || (CurrentATTENVALUE >= (IwillGiveAtten))){
//    IwillGiveAtten *= 10;
    ALC_Atten[ULO_ALC_H] = (((uint16_t)((IwillGiveAtten)) & 0xFF00) >> 8);
    ALC_Atten[ULO_ALC_L] = ((uint16_t)(IwillGiveAtten)) & 0x00FF;
    CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
//    }


}
void UL_Curr_Level(uint8_t*ULO_ADC_Level,uint8_t* ULO_Level,DET_TABLEUL_st*      UL_Table,uint8_t TableIndex){
double ret = 0;
double ResdBm = 0;
int16_t ResultData = 0;


    ret  =  ((ULO_ADC_Level[ULO_ALC_H] << 8 | ULO_ADC_Level[ULO_ALC_L]) * 0.001);
    /*Curr UL Value*/
    ResdBm = AutoControl_ADC_Compare(ret,&UL_Table->Table_Det_15_dBm_H,UL_Table->Table_Length * 2,&UL_DET_Table_ref[TableIndex][TABLE_MAX_VALUE]);
    //ret 현재 Voltage 값 출력
    //ret 에 따른 현재 DBM 구현
    ResdBm = HFR_CntUpCalc(ResdBm);
    ResultData = ResdBm;// + bluecell_Currdatastatus.UL_Det_Path_Offset[TableIndex];
//    printf("HFR CALC RET : %d \r\n",ResultData);
    ULO_Level[ULO_ALC_H] = (ResultData & 0xFF00) >> 8;
    ULO_Level[ULO_ALC_L] = (ResultData & 0x00FF);  


//    
//    ResultData = ResdBm;
//    ULO_Level[ULO_ALC_H] = (ResultData & 0xFF00) >> 8;
//    ULO_Level[ULO_ALC_L] = (ResultData & 0x00FF);
//    printf("============ALC_OFF======START================\r\n");
//    printf("Current UL ADC VALUE : %f \r\n",ret);
//    printf("ResdBm : UL1 : %f \r\n",ResdBm);
//    printf("ResdBm  : %x /////  bluecell_Currdatastatus.ULO_Level1_H : %x \r\n",ResultData,ULO_Level[ULO_ALC_H]);
//    printf("ResdBm  : %x /////  bluecell_Currdatastatus.ULO_Level1_L : %x \r\n",ResultData,ULO_Level[ULO_ALC_L]);            
//    printf("==================END================\r\n");
}

void ALC_Function(){ //DL 
    //double Volt_Calc_val = 3.3 / 4095;
    //double tempret = 0;
    double ret = 0;
   // double CurrnALCValue = 0;
    double CurrentATTENVALUE = 0;
   uint8_t tempcurratten = 0;
  //  int32_t CurrnALC_MAX_SettingValue = 0;
  //  int32_t CurrnALC_MIN_SettingValue = 0;
  //  int32_t ALC_Result = 0;
/*    int16_t Limitdata = 0;
    static int16_t PrevLimitdata[ALC_Alarm_UL_Index_MAX] = {0,};
    double ResdBm = 0;
    int16_t ResultData = 0;
    int16_t PrevResultData[ALC_Alarm_UL_Index_MAX] = {0,};    
    int16_t IwillGiveAtten = 0;
    static int8_t* ALC_Table;
    int16_t tmpcalc = 0;
    static int16_t PrevIwillGiveAtten[ALC_Alarm_UL_Index_MAX] ={0,};*/
//    uint8_t tempadc[256];

    int16_t UL_Atten[ALC_Alarm_UL_Index_MAX] = {0,};
    int16_t Main_Atten[ALC_Alarm_UL_Index_MAX] = {0,};
    
//    Bluecell_StructCpy(&AutoControl_Save[0],&UL_DET_Table_ref[TABLE_MAX_VALUE],sizeof(ALC_dBm_t));
//    Bluecell_StructCpy(&tempadc[0],&Det_UL1.Table_Det_15_dBm_H,sizeof(DET_TABLEUL_st));
    if(ALCTimerCnt > 500){
        if(bluecell_Currdatastatus.ULO_ALC_ON_OFF == true){
            UL_Atten[ALC_Alarm_UL1_Index] = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_L;
            UL_Atten[ALC_Alarm_UL2_Index] = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_L;
            UL_Atten[ALC_Alarm_UL3_Index] = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_L;
            UL_Atten[ALC_Alarm_UL4_Index] = bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_H << 8 | bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_L;
            Main_Atten[ALC_Alarm_UL1_Index] = bluecell_Currdatastatus.ATT_UL1_H << 8 | bluecell_Currdatastatus.ATT_UL1_L;
            Main_Atten[ALC_Alarm_UL2_Index] = bluecell_Currdatastatus.ATT_UL2_H << 8 | bluecell_Currdatastatus.ATT_UL2_L;
            Main_Atten[ALC_Alarm_UL3_Index] = bluecell_Currdatastatus.ATT_UL3_H << 8 | bluecell_Currdatastatus.ATT_UL3_L;
            Main_Atten[ALC_Alarm_UL4_Index] = bluecell_Currdatastatus.ATT_UL4_H << 8 | bluecell_Currdatastatus.ATT_UL4_L;
            
        ALC_Package_Operate(&bluecell_Currdatastatus.ULO_P1_Level1_H,
                            &bluecell_Currdatastatus.ULO_Level1_H,
                            &Det_UL1.Table_Det_15_dBm_H,
                            ALC_Alarm_UL1_Index,
                            &bluecell_Currdatastatus.MBIC_ULO_ALC_Atten1_H,
                            &bluecell_Currdatastatus.ATT_UL1_H,
                            &bluecell_Currdatastatus.bluecell_User_UL1_H,
                            &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count1);
#if 1 // PYJ.2020.07.16_BEGIN -- 
        ALC_Package_Operate(&bluecell_Currdatastatus.ULO_P2_Level2_H,
                            &bluecell_Currdatastatus.ULO_Level2_H,
                            &Det_UL2.Table_Det_15_dBm_H,
                            ALC_Alarm_UL2_Index,
                            &bluecell_Currdatastatus.MBIC_ULO_ALC_Atten2_H,
                            &bluecell_Currdatastatus.ATT_UL2_H,
                            &bluecell_Currdatastatus.bluecell_User_UL2_H,
                            &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count2);
        ALC_Package_Operate(&bluecell_Currdatastatus.ULO_P3_Level3_H,
                            &bluecell_Currdatastatus.ULO_Level3_H,
                            &Det_UL3.Table_Det_15_dBm_H,
                            ALC_Alarm_UL3_Index,
                            &bluecell_Currdatastatus.MBIC_ULO_ALC_Atten3_H,
                            &bluecell_Currdatastatus.ATT_UL3_H,
                            &bluecell_Currdatastatus.bluecell_User_UL3_H,
                            &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count3);
        ALC_Package_Operate(&bluecell_Currdatastatus.ULO_P4_Level4_H,
                            &bluecell_Currdatastatus.ULO_Level4_H,
                            &Det_UL4.Table_Det_15_dBm_H,
                            ALC_Alarm_UL4_Index,
                            &bluecell_Currdatastatus.MBIC_ULO_ALC_Atten4_H,
                            &bluecell_Currdatastatus.ATT_UL4_H,
                            &bluecell_Currdatastatus.bluecell_User_UL4_H,
                            &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count4);
#endif // PYJ.2020.07.16_END -- 
        
//                 HAL_Delay(1000);
            //}
            ALCTimerCnt = 0;
        }
        else{




#if 0 // PYJ.2020.06.21_BEGIN -- 
                        printf("=========ALC_OFF=========START================\r\n");
                        printf("Current UL ADC VALUE : %f \r\n",ret);
                        printf("ResdBm : UL2 : %f \r\n",ResdBm);
                        printf("ResdBm  : %x /////  bluecell_Currdatastatus.ULO_Level2_H : %x \r\n",ResultData,bluecell_Currdatastatus.ULO_Level2_H);
                        printf("ResdBm  : %x /////  bluecell_Currdatastatus.ULO_Level2_L : %x \r\n",ResultData,bluecell_Currdatastatus.ULO_Level2_L);            
                        printf("==================END================\r\n");
#endif // PYJ.2020.06.21_END -- 


        }
        UL_Curr_Level(&bluecell_Currdatastatus.ULO_P1_Level1_H,
                      &bluecell_Currdatastatus.ULO_Level1_H,
                      &Det_UL1.Table_Det_15_dBm_H,
                       ALC_Alarm_UL1_Index);
        UL_Curr_Level(&bluecell_Currdatastatus.ULO_P2_Level2_H,
                      &bluecell_Currdatastatus.ULO_Level2_H,
                      &Det_UL2.Table_Det_15_dBm_H,
                       ALC_Alarm_UL2_Index);
        UL_Curr_Level(&bluecell_Currdatastatus.ULO_P3_Level3_H,
                      &bluecell_Currdatastatus.ULO_Level3_H,
                      &Det_UL3.Table_Det_15_dBm_H,
                       ALC_Alarm_UL3_Index);
        UL_Curr_Level(&bluecell_Currdatastatus.ULO_P4_Level4_H,
                      &bluecell_Currdatastatus.ULO_Level4_H,
                      &Det_UL4.Table_Det_15_dBm_H,
                       ALC_Alarm_UL4_Index);             
    }
}
//-15 ~ -5
int8_t AGC_Calc(int8_t threshold,int8_t CurrDet){
    int8_t Attenret = 0;
    if(threshold > CurrDet)
        return Attenret;
    
    if(threshold != CurrDet){
        Attenret = (threshold - CurrDet) * -1;
    }
//    printf("Attenret : %d \r\n",Attenret);
    return Attenret;
}


//bool AGC_AlarmTimerSet[AGC_Alarm_DL_Index_MAX] = {false,};
void AGC_Alarm_Check(uint8_t Path_Index,double AGC_Det,uint8_t* AGC_Table,uint16_t CurrAtten){
    double TableAdc = 0;
    double PrevTableAdc = 0;
    double step = 0;

    TableAdc = AGC_Table[0] << 8;
    TableAdc += AGC_Table[1];
    TableAdc /= 1000;

    
    PrevTableAdc = AGC_Table[2] << 8;
    PrevTableAdc += AGC_Table[3];
    PrevTableAdc /= 1000;
    
    step = TableAdc - PrevTableAdc;
    

    if(AGC_Det > TableAdc + step){/*Alarm Enable*/
//        AGC_AlarmSet[Path_Index] = true; /*Alarm Check val*/
//        AGC_AlarmTimerSet[Path_Index] = false;/*Alarm Timer Setting Val*/
//        AGCAlarmTimerCnt[Path_Index] = 0;/*Alarm Time Cnt Val*/
//        printf("AGC ALARM ON %d \r\n",Path_Index + 1);
    }else{/*Alarm Disable*/
//        if(AGC_AlarmSet[Path_Index] == true && CurrAtten <= 18){/*Alarm Disalbe Condition*/
//            AGC_AlarmTimerSet[Path_Index] = true;
//        }else{/*Alarm Disalbe Fail*/
//            AGC_AlarmTimerSet[Path_Index] = false;
//            AGCAlarmTimerCnt[Path_Index] = 0;
//        }
//        if(AGCAlarmTimerCnt[Path_Index] > 3000){
//            AGC_AlarmSet[Path_Index] = false;
//        }
    }

}


#if 1 // PYJ.2020.06.27_BEGIN -- 
void AGC_Package_Operate(uint8_t* Threshold,uint8_t* DL_MainAtten,uint8_t Tableindex,uint8_t* DLI_ADC_Level,uint8_t* DLI_Level,DET_TABLEDL_st* DL_Table,uint8_t* FRBT){
        double ret = 0;
        int8_t ResdBm = 0;
        int16_t CurrAtten = 0;
        int16_t Levelret = 0;
        int i = 0;
        int16_t Limitdata = 0;
        int16_t IwillgiveAtten = 0;
        int16_t ResultData = 0;
        int8_t* AGC_Table;// = &DL_DET_Table_ref[MBIC_Table_DL1_INDEX][TABLE_MAX_VALUE];
        int16_t FRBT_Atten = 0;


        
        FRBT_Atten =  FRBT[DLI_AGC_H] << 8 | FRBT[DLI_AGC_L];   
        FRBT_Atten *= 0.1;
        
        Limitdata = Threshold[DLI_AGC_H] << 8;
        Limitdata += Threshold[DLI_AGC_L];
        Limitdata *= 0.1; 

        AGC_Table = &DL_DET_Table_ref[Tableindex][TABLE_MAX_VALUE];
        ret  = DLI_ADC_Level[DLI_AGC_H] << 8;
        ret += DLI_ADC_Level[DLI_AGC_L];
        ret *= 0.001;

        CurrAtten = (int16_t)(DL_MainAtten[DLI_AGC_H] << 8 |  DL_MainAtten[DLI_AGC_L]);
        CurrAtten *= 0.1;
        ResdBm = (int8_t)Bluecell_TestPro(AGC_AutoControl_ADC_Compare(ret,&DL_Table->Table_Det5_dBm_H,DL_Table->Table_Length,AGC_Table));
//        ResdBm += bluecell_Currdatastatus.DL_Det_ALL_Offset;
        DLI_Level[DLI_AGC_H] = ((int16_t)ResdBm & 0xFF00) >> 8;
        DLI_Level[DLI_AGC_L] = ((int16_t)ResdBm & 0x00FF);
        for(i = 0; i < sizeof(AGC_dBm_t); i++){
            if(AGC_Table[i] == ResdBm)
                break;
        }
        IwillgiveAtten = AGC_Calc(Limitdata,ResdBm);
        IwillgiveAtten *= -1;
//        printf("==================================\r\n");
//        printf("Curr ATTEN %d \r\n",CurrAtten );
//        printf("Current DL% ADC VALUE : %f \r\n",Tableindex+1,ret);
//        printf("ResdBm : DL%d : %d \r\n",Tableindex+1,ResdBm);
//        printf("I WILL GIVE YOU ATTEN  : %d\r\n",IwillgiveAtten);
//        printf("AGC  : %d\r\n",Limitdata);
        if((CurrAtten) < IwillgiveAtten)
            IwillgiveAtten = (CurrAtten );

        if(ResdBm > Limitdata &&  DL_PrevIwillgiveAtten[Tableindex] > IwillgiveAtten){
//            printf("IwillgiveAtten : %d \r\n",IwillgiveAtten);
            DL_PrevIwillgiveAtten[Tableindex] = IwillgiveAtten;
            IwillgiveAtten = (DL_AGC_StartAtten[Tableindex]*0.1) + IwillgiveAtten;
//            printf("WILLATTEN RET : %d \r\n",IwillgiveAtten);
            AGC_Alarm_Check(AGC_Alarm_DL1_Index + Tableindex,ret,&DL_Table->Table_Det5_dBm_H,IwillgiveAtten);

            DL_MainAtten[DLI_AGC_H] = (((IwillgiveAtten * 10) & 0xFF00) >> 8) ;
            DL_MainAtten[DLI_AGC_L] = (((IwillgiveAtten * 10) & 0x00FF));   
            CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);
        }
        else if(bluecell_Currdatastatus.DLI_FRBT_Status == FRBT_RUNNING){
            if(CurrAtten == FRBT_Atten)
                return;
            
            if(CurrAtten + ResdBm <= Limitdata - 1){
                IwillgiveAtten = ((CurrAtten) + 1);
                
                DL_PrevIwillgiveAtten[Tableindex] = IwillgiveAtten;
                DL_MainAtten[DLI_AGC_H] = (((IwillgiveAtten * 10) & 0xFF00) >> 8) ;
                DL_MainAtten[DLI_AGC_L] = (((IwillgiveAtten * 10) & 0x00FF));   
                CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);            
            }
        }
        

}
#endif // PYJ.2020.06.27_END -- 
typedef enum{
    DL_Level_H,
    DL_Level_L,        
};
void DL_Det_Function(uint8_t Table_Num,uint8_t* CurrADC_Level,DET_TABLEDL_st* DL_Table,uint8_t* Level){
    double ret = 0;//  
    uint8_t* AGC_Table;
    int16_t Levelret = 0;    
    AGC_Table = &DL_DET_Table_ref[Table_Num][TABLE_MAX_VALUE];
    ret = (((CurrADC_Level[DL_Level_H] << 8) | CurrADC_Level[DL_Level_L]) * 0.001);
//    printf("DL_Table->Table_Length : %d \r\n",DL_Table->Table_Length);                
    Levelret = (int16_t)Bluecell_TestPro(AGC_AutoControl_ADC_Compare(ret,&DL_Table->Table_Det5_dBm_H,DL_Table->Table_Length,AGC_Table));
//    Levelret += bluecell_Currdatastatus.DL_Det_ALL_Offset;

//    printf("Levelret %d : %d \r\n",Table_Num + 1,Levelret);
    Level[DL_Level_H] = (Levelret & 0xFF00) >> 8;
    Level[DL_Level_L] = (Levelret & 0x00FF);
    
}
void AGC_Function(){//DL
    /*double ret = 0;
    int8_t ResdBm = 0;
    int16_t Levelret = 0;
    int i = 0;
    int16_t IwillgiveAtten = 0;
    int16_t ResultData = 0;
    static int8_t* AGC_Table;// = &DL_DET_Table_ref[MBIC_Table_DL1_INDEX][TABLE_MAX_VALUE];*/

    int16_t Limitdata = 0;
    int16_t DL_Curr_Atten[AGC_Alarm_DL_Index_MAX] = {
        bluecell_Currdatastatus.ATT_DL1_H  << 8 | bluecell_Currdatastatus.ATT_DL1_L,
        bluecell_Currdatastatus.ATT_DL2_H  << 8 | bluecell_Currdatastatus.ATT_DL2_L,
        bluecell_Currdatastatus.ATT_DL3_H  << 8 | bluecell_Currdatastatus.ATT_DL3_L,
        bluecell_Currdatastatus.ATT_DL4_H  << 8 | bluecell_Currdatastatus.ATT_DL4_L,        
    };
         
    if(AGCTimerCnt > 500){
        

        if(bluecell_Currdatastatus.DLI_AGC_ON_OFF == true){
            
            Limitdata = (( bluecell_Currdatastatus.DLI_AGC_Threshold_H << 8) & 0xFF00) ;
            Limitdata +=  bluecell_Currdatastatus.DLI_AGC_Threshold_L ;
            Limitdata /= 10; 
        DL_Curr_Atten[AGC_Alarm_DL1_Index] = 
            bluecell_Currdatastatus.ATT_DL1_H  << 8 | bluecell_Currdatastatus.ATT_DL1_L;
        DL_Curr_Atten[AGC_Alarm_DL2_Index] = 
            bluecell_Currdatastatus.ATT_DL2_H  << 8 | bluecell_Currdatastatus.ATT_DL2_L;
        DL_Curr_Atten[AGC_Alarm_DL3_Index] = 
            bluecell_Currdatastatus.ATT_DL3_H  << 8 | bluecell_Currdatastatus.ATT_DL3_L;        
        DL_Curr_Atten[AGC_Alarm_DL4_Index] = 
            bluecell_Currdatastatus.ATT_DL4_H  << 8 | bluecell_Currdatastatus.ATT_DL4_L; 
        for(int k = 0; k < AGC_Alarm_DL_Index_MAX; k++){
            if(DL_Curr_Atten[AGC_Alarm_DL1_Index+k] <= -150)
                DL_Curr_Atten[AGC_Alarm_DL1_Index+k] = -150;
//            printf("DL_Curr_Atten%d : %d \r\n",k+1,DL_Curr_Atten[AGC_Alarm_DL1_Index+k] * 0.1);
            if((DL_Curr_Atten[AGC_Alarm_DL1_Index+k] * 0.1) <= -15   ){
//                printf("DL_Curr_Atten%d : %d Alarm TRue\r\n",k+1,DL_Curr_Atten[AGC_Alarm_DL1_Index+k]);
                AGC_AlarmSet[AGC_Alarm_DL1_Index+k] = true;
            }else{
                AGC_AlarmSet[AGC_Alarm_DL1_Index+k] = false;
            }
        }
        AGC_Package_Operate(&bluecell_Currdatastatus.DLI_AGC_Threshold_H,
                            &bluecell_Currdatastatus.ATT_DL1_H,
                            AGC_Alarm_DL1_Index,
                            &bluecell_Currdatastatus.DLI_P1_Level1_H,
                            &bluecell_Currdatastatus.DLI_Level1_H,
                            &Det_DL1.Table_Det5_dBm_H                        ,
                            &bluecell_Currdatastatus.DLI_FRBT_Atten1_H);
        AGC_Package_Operate(&bluecell_Currdatastatus.DLI_AGC_Threshold_H,
                            &bluecell_Currdatastatus.ATT_DL2_H,
                            AGC_Alarm_DL2_Index,
                            &bluecell_Currdatastatus.DLI_P2_Level2_H,
                            &bluecell_Currdatastatus.DLI_Level2_H,
                            &Det_DL2.Table_Det5_dBm_H                        ,
                            &bluecell_Currdatastatus.DLI_FRBT_Atten2_H);
        AGC_Package_Operate(&bluecell_Currdatastatus.DLI_AGC_Threshold_H,
                            &bluecell_Currdatastatus.ATT_DL3_H,
                            AGC_Alarm_DL3_Index,
                            &bluecell_Currdatastatus.DLI_P3_Level3_H,
                            &bluecell_Currdatastatus.DLI_Level3_H,
                            &Det_DL3.Table_Det5_dBm_H                        ,
                            &bluecell_Currdatastatus.DLI_FRBT_Atten3_H);
        AGC_Package_Operate(&bluecell_Currdatastatus.DLI_AGC_Threshold_H,
                            &bluecell_Currdatastatus.ATT_DL4_H,
                            AGC_Alarm_DL4_Index,
                            &bluecell_Currdatastatus.DLI_P4_Level4_H,
                            &bluecell_Currdatastatus.DLI_Level4_H,
                            &Det_DL4.Table_Det5_dBm_H,
                            &bluecell_Currdatastatus.DLI_FRBT_Atten4_H);    

        }
        DL_Det_Function(MBIC_Table_DL1_INDEX,&bluecell_Currdatastatus.DLI_P1_Level1_H,&Det_DL1.Table_Det5_dBm_H,&bluecell_Currdatastatus.DLI_Level1_H);
        DL_Det_Function(MBIC_Table_DL2_INDEX,&bluecell_Currdatastatus.DLI_P2_Level2_H,&Det_DL2.Table_Det5_dBm_H,&bluecell_Currdatastatus.DLI_Level2_H);
        DL_Det_Function(MBIC_Table_DL3_INDEX,&bluecell_Currdatastatus.DLI_P3_Level3_H,&Det_DL3.Table_Det5_dBm_H,&bluecell_Currdatastatus.DLI_Level3_H);
        DL_Det_Function(MBIC_Table_DL4_INDEX,&bluecell_Currdatastatus.DLI_P4_Level4_H,&Det_DL4.Table_Det5_dBm_H,&bluecell_Currdatastatus.DLI_Level4_H);        
        AGCTimerCnt = 0;
    }
}

void DLI_LevelAlarmCheck(){
    //double temp = 0;
    //double ret = 0;
    //int8_t ResdBm[4] = {0,};

    /*********************DL LEVEL LOW START****************************/
    if(DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL1_Index] >= MBIC_ON_MAINTAIN_SEC
     &&ADC_Alarm_DL_Low_Set[DET_Alarm_DL1_Index] == true){
        bluecell_Currdatastatus.ALARM_DLI_Level |= ALARM_DLI_P1_LEVEL_LOW;
        bluecell_Currdatastatus.DLI_Level_Low_Alarm1 = true;

    }else{/**/
        if(DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL1_Index] >= MBIC_OFF_MAINTAIN_SEC){
            bluecell_Currdatastatus.ALARM_DLI_Level &= ~ALARM_DLI_P1_LEVEL_LOW;
            bluecell_Currdatastatus.DLI_Level_Low_Alarm1 = false;
        }
    }

    if(DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL2_Index] >= MBIC_ON_MAINTAIN_SEC
     &&ADC_Alarm_DL_Low_Set[DET_Alarm_DL2_Index] == true){
        bluecell_Currdatastatus.ALARM_DLI_Level |= ALARM_DLI_P2_LEVEL_LOW;
        bluecell_Currdatastatus.DLI_Level_Low_Alarm2 = true;

    }else{
        if(DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL2_Index] >= MBIC_OFF_MAINTAIN_SEC){
            bluecell_Currdatastatus.ALARM_DLI_Level &= ~ALARM_DLI_P2_LEVEL_LOW;
            bluecell_Currdatastatus.DLI_Level_Low_Alarm2 = false;
        }
    }

    if(DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL3_Index] >= MBIC_ON_MAINTAIN_SEC
     &&ADC_Alarm_DL_Low_Set[DET_Alarm_DL3_Index] == true){
        bluecell_Currdatastatus.ALARM_DLI_Level |= ALARM_DLI_P3_LEVEL_LOW;
        bluecell_Currdatastatus.DLI_Level_Low_Alarm3 = true;

    }else{
        if(DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL3_Index] >= MBIC_OFF_MAINTAIN_SEC){
            bluecell_Currdatastatus.ALARM_DLI_Level &= ~ALARM_DLI_P3_LEVEL_LOW;
            bluecell_Currdatastatus.DLI_Level_Low_Alarm3 = false;
        }
    }

    if(DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL4_Index] >= MBIC_ON_MAINTAIN_SEC
     &&ADC_Alarm_DL_Low_Set[DET_Alarm_DL4_Index] == true){
        bluecell_Currdatastatus.ALARM_DLI_Level |= ALARM_DLI_P4_LEVEL_LOW;
        bluecell_Currdatastatus.DLI_Level_Low_Alarm4 = true;

    }else{
        if(DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL4_Index] >= MBIC_OFF_MAINTAIN_SEC){
            bluecell_Currdatastatus.ALARM_DLI_Level &= ~ALARM_DLI_P4_LEVEL_LOW;
            bluecell_Currdatastatus.DLI_Level_Low_Alarm4 = false;
        }
    }     

    /*********************DL LEVEL HIGH START***************************/
    if(DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL1_Index] >= MBIC_ON_MAINTAIN_SEC
    &&ADC_Alarm_DL_High_Set[DET_Alarm_DL1_Index] == true){
        bluecell_Currdatastatus.ALARM_DLI_Level |= ALARM_DLI_P1_LEVEL_HIGH;
        bluecell_Currdatastatus.DLI_Level_High_Alarm1 = true;

    }else{/**/
        if(DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL1_Index] >= MBIC_OFF_MAINTAIN_SEC){
            bluecell_Currdatastatus.ALARM_DLI_Level &= ~ALARM_DLI_P1_LEVEL_HIGH;
            bluecell_Currdatastatus.DLI_Level_High_Alarm1 = false;
        }
    }

    if(DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL2_Index] >= MBIC_ON_MAINTAIN_SEC
    &&ADC_Alarm_DL_High_Set[DET_Alarm_DL2_Index] == true){
        bluecell_Currdatastatus.ALARM_DLI_Level |= ALARM_DLI_P2_LEVEL_HIGH;
        bluecell_Currdatastatus.DLI_Level_High_Alarm2 = true;

    }else{
        if(DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL2_Index] >= MBIC_OFF_MAINTAIN_SEC){
            bluecell_Currdatastatus.ALARM_DLI_Level &= ~ALARM_DLI_P2_LEVEL_HIGH;
            bluecell_Currdatastatus.DLI_Level_High_Alarm2 = false;
        }
    }

    if(DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL3_Index] >= MBIC_ON_MAINTAIN_SEC
    &&ADC_Alarm_DL_High_Set[DET_Alarm_DL3_Index] == true){
        bluecell_Currdatastatus.ALARM_DLI_Level |= ALARM_DLI_P3_LEVEL_HIGH;
        bluecell_Currdatastatus.DLI_Level_High_Alarm3 = true;

    }else{
        if(DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL3_Index] >= MBIC_OFF_MAINTAIN_SEC){
            bluecell_Currdatastatus.ALARM_DLI_Level &= ~ALARM_DLI_P3_LEVEL_HIGH;
            bluecell_Currdatastatus.DLI_Level_High_Alarm3 = false;
        }
    }

    if(DET_DL_High_On_AlarmTimerCnt[DET_Alarm_DL4_Index] >= MBIC_ON_MAINTAIN_SEC
    &&ADC_Alarm_DL_High_Set[DET_Alarm_DL4_Index] == true){
        bluecell_Currdatastatus.ALARM_DLI_Level |= ALARM_DLI_P4_LEVEL_HIGH;
        bluecell_Currdatastatus.DLI_Level_High_Alarm4 = true;

    }else{
        if(DET_DL_High_Off_AlarmTimerCnt[DET_Alarm_DL4_Index] >= MBIC_OFF_MAINTAIN_SEC){
            bluecell_Currdatastatus.ALARM_DLI_Level &= ~ALARM_DLI_P4_LEVEL_HIGH;
            bluecell_Currdatastatus.DLI_Level_High_Alarm4 = false;
        }
    }      
}
void ULO_LevelAlarmCheck(){
    //double temp = 0;
    //double ret = 0;
    //int8_t ResdBm[4] = {0,};
        if(DET_UL_On_AlarmTimerCnt[DET_Alarm_UL1_Index] >= MBIC_ON_MAINTAIN_SEC
         &&ADC_Alarm_UL_Set[DET_Alarm_UL1_Index] == true){
            bluecell_Currdatastatus.ALARM_ULO_Level |= ALARM_ULO_P1_LEVEL_HIGH;
            bluecell_Currdatastatus.ULO_Level_High_Alarm1 = true;
        
        }else{/**/
            if(DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL1_Index] >= MBIC_OFF_MAINTAIN_SEC){
                bluecell_Currdatastatus.ALARM_ULO_Level &= ~ALARM_ULO_P1_LEVEL_HIGH;
                bluecell_Currdatastatus.ULO_Level_High_Alarm1 = false;
            }
        }
        
        if(DET_UL_On_AlarmTimerCnt[DET_Alarm_UL2_Index] >= MBIC_ON_MAINTAIN_SEC
         &&ADC_Alarm_UL_Set[DET_Alarm_UL2_Index] == true){
            bluecell_Currdatastatus.ALARM_ULO_Level |= ALARM_ULO_P2_LEVEL_HIGH;
            bluecell_Currdatastatus.ULO_Level_High_Alarm2 = true;
        
        }else{
            if(DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL2_Index] >= MBIC_OFF_MAINTAIN_SEC){
                bluecell_Currdatastatus.ALARM_ULO_Level &= ~ALARM_ULO_P2_LEVEL_HIGH;
                bluecell_Currdatastatus.ULO_Level_High_Alarm2 = false;
            }
        }
        
        if(DET_UL_On_AlarmTimerCnt[DET_Alarm_UL3_Index] >= MBIC_ON_MAINTAIN_SEC
         &&ADC_Alarm_UL_Set[DET_Alarm_UL3_Index] == true){
            bluecell_Currdatastatus.ALARM_ULO_Level |= ALARM_ULO_P3_LEVEL_HIGH;
            bluecell_Currdatastatus.ULO_Level_High_Alarm3 = true;
        
        }else{
            if(DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL3_Index] >= MBIC_OFF_MAINTAIN_SEC){
                bluecell_Currdatastatus.ALARM_ULO_Level &= ~ALARM_ULO_P3_LEVEL_HIGH;
                bluecell_Currdatastatus.ULO_Level_High_Alarm3 = false;
            }
        }
        
        if(DET_UL_On_AlarmTimerCnt[DET_Alarm_UL4_Index] >= MBIC_ON_MAINTAIN_SEC
         &&ADC_Alarm_UL_Set[DET_Alarm_UL4_Index] == true){
            bluecell_Currdatastatus.ALARM_ULO_Level |= ALARM_ULO_P4_LEVEL_HIGH;
            bluecell_Currdatastatus.ULO_Level_High_Alarm4 = true;
        
        }else{
            if(DET_UL_Off_AlarmTimerCnt[DET_Alarm_UL4_Index] >= MBIC_OFF_MAINTAIN_SEC){
                bluecell_Currdatastatus.ALARM_ULO_Level &= ~ALARM_ULO_P4_LEVEL_HIGH;
                bluecell_Currdatastatus.ULO_Level_High_Alarm4 = false;
            }
        }   


}
typedef enum{
    DL_Shutdown_H = 0,
    DL_Shutdown_L, 
};

void DL_Shutdown_Operate(uint8_t index,uint8_t* path,uint8_t* retrycnt,uint8_t* ShutdownAlarm,uint8_t* MainAtten){
    GPIO_TypeDef *Port = 0;
    uint16_t Pin = 0;
    uint8_t AlarmFlag = 0;


    switch(index){
        case DET_Alarm_DL1_Shutdown_Index:
            Port = PATH_EN_DL1_GPIO_Port;
            Pin = PATH_EN_DL1_Pin;
            AlarmFlag = ALARM_DLI_SHUTDOWN_P1;
            break;
        case DET_Alarm_DL2_Shutdown_Index:
            Port = PATH_EN_DL2_GPIO_Port;
            Pin = PATH_EN_DL2_Pin;   
            AlarmFlag = ALARM_DLI_SHUTDOWN_P2;
            break;
        case DET_Alarm_DL3_Shutdown_Index:
            Port = PATH_EN_DL3_GPIO_Port;
            Pin = PATH_EN_DL3_Pin;       
            AlarmFlag = ALARM_DLI_SHUTDOWN_P3;
            break;
        case DET_Alarm_DL4_Shutdown_Index:            
            Port = PATH_EN_DL4_GPIO_Port;
            Pin = PATH_EN_DL4_Pin;        
            AlarmFlag = ALARM_DLI_SHUTDOWN_P4;
//            printf("Timer : %d   | Retry Cnt : %d | PrevMBIC_DL_ShutdownCount[%d] %d | MBIC_DL_ShutdownCount[%d] %d | DL_PathUserHandl[index] %d \r\n",DET_DL_Shutdown_Off_AlarmTimerCnt[index],(*retrycnt),index + 1,PrevMBIC_DL_ShutdownCount[index],index + 1,MBIC_DL_ShutdownCount[index],DL_PathUserHandl[index]);
            break;
    }
    if((*retrycnt) < 3
        /*&& (PrevMBIC_DL_ShutdownCount[index] != MBIC_DL_ShutdownCount[index])*/
        && DET_DL_Shutdown_Off_AlarmTimerCnt[index] >= MBIC_RECOVERY_SHUTDOWN_MAINTAIN_SEC
        && DL_PathUserHandl[index] == false
        && (*retrycnt) > 0){
        HAL_GPIO_WritePin(Port,Pin,GPIO_PIN_SET);//CLOCK
        *path = true;            
        MainAtten[DL_Shutdown_H] = 0xFF;
        MainAtten[DL_Shutdown_L] = 0xFF;
        PrevMBIC_DL_ShutdownCount[index] = MBIC_DL_ShutdownCount[index];
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus); 
    }
    else if(MBIC_DL_ShutdownCount[index] == 3
        && DET_DL_Shutdown_Off_AlarmTimerCnt[index] >= MBIC_RECOVERY_LAST_SHUTDOWN_MAINTAIN_SEC
        && DL_PathUserHandl[index] == false){
        HAL_GPIO_WritePin(Port,Pin,GPIO_PIN_SET);//CLOCK
        *path = true;            
        MainAtten[DL_Shutdown_H] = 0xFF;
        MainAtten[DL_Shutdown_L] = 0xFF;
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus); 
    }                  
    if(DET_DL_Shutdown_On_AlarmTimerCnt[index] >= MBIC_ON_SHUTDOWN_MAINTAIN_SEC)
    {
        /*Shutdown 5sec Alarm*/
        HAL_GPIO_WritePin(Port,Pin,GPIO_PIN_RESET);//CLOCK      
//        printf("SHUTDOWN ON DL %d\r\n",index + 1);
        *path = false;
        (*retrycnt)++;
        DET_DL_Shutdown_On_AlarmTimerCnt[index] = 0;
        
        if((*retrycnt) >= RETRYCNT_MAX){
            (*retrycnt) = RETRYCNT_MAX;
            bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN |= AlarmFlag;
            *ShutdownAlarm       = true;
        }
    }
    else{
        if(DET_DL_Shutdown_Off_AlarmTimerCnt[index] >= MBIC_OFF_MAINTAIN_SEC
            && (*retrycnt) != RETRYCNT_MAX){
            bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN &= ~AlarmFlag;
            *ShutdownAlarm       = false;            
        }
    } 


}
void DLI_ShutdownAlarmCheck()
{
    if(bluecell_Currdatastatus.DLI_Shutdown_ON_OFF == true){
         
        /***************************************************************************************************************/
        /*                                             SHUTDOWN DL1                                                    */
        /***************************************************************************************************************/  
        DL_Shutdown_Operate(DET_Alarm_DL1_Shutdown_Index,
                                &bluecell_Currdatastatus.ATT_DL1_PATH,
                                &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count1,
                                &bluecell_Currdatastatus.DLI_Shutdown_Alarm1,
                                &bluecell_Prevdatastatus.ATT_DL1_H);
        DL_Shutdown_Operate(DET_Alarm_DL2_Shutdown_Index,
                                &bluecell_Currdatastatus.ATT_DL2_PATH,
                                &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count2,
                                &bluecell_Currdatastatus.DLI_Shutdown_Alarm2,
                                &bluecell_Prevdatastatus.ATT_DL2_H);
        DL_Shutdown_Operate(DET_Alarm_DL3_Shutdown_Index,
                                &bluecell_Currdatastatus.ATT_DL3_PATH,
                                &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count3,
                                &bluecell_Currdatastatus.DLI_Shutdown_Alarm3,
                                &bluecell_Prevdatastatus.ATT_DL3_H);
        DL_Shutdown_Operate(DET_Alarm_DL4_Shutdown_Index,
                                &bluecell_Currdatastatus.ATT_DL4_PATH,
                                &bluecell_Currdatastatus.DLI_Shutdown_Retry_Count4,
                                &bluecell_Currdatastatus.DLI_Shutdown_Alarm4,
                                &bluecell_Prevdatastatus.ATT_DL4_H);
        
    }
    else{
            bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN = 0;
            bluecell_Currdatastatus.DLI_Shutdown_Alarm1 = false;            
            bluecell_Currdatastatus.DLI_Shutdown_Alarm2 = false;            
            bluecell_Currdatastatus.DLI_Shutdown_Alarm3 = false;            
            bluecell_Currdatastatus.DLI_Shutdown_Alarm4 = false;
    }
}
typedef enum{
    UL_Shutdown_H,
    UL_Shutdown_L,        
};

void UL_Shutdown_Operate(uint8_t Index,uint8_t* Path,uint8_t* PrevATT,uint8_t* RetryCnt,uint8_t* ShutdownAlarm,uint8_t AlarmFlag){
    GPIO_TypeDef *Port = 0;
    uint16_t Pin = 0;


    switch(Index){
        case DET_Alarm_UL1_Shutdown_Index: 
        Port = PATH_EN_UL1_GPIO_Port;
        Pin = PATH_EN_UL1_Pin;  
        break;
        case DET_Alarm_UL2_Shutdown_Index: 
        Port = PATH_EN_UL2_GPIO_Port;
        Pin = PATH_EN_UL2_Pin;  
        break;
        case DET_Alarm_UL3_Shutdown_Index: 
        Port = PATH_EN_UL3_GPIO_Port;
        Pin = PATH_EN_UL3_Pin;  
        break;            
        case DET_Alarm_UL4_Shutdown_Index: 
        Port = PATH_EN_UL4_GPIO_Port;
        Pin = PATH_EN_UL4_Pin;  
//        printf("Timer : %d   | Retry Cnt : %d |  \r\n",DET_UL_Shutdown_Off_AlarmTimerCnt[Index],(*RetryCnt),Index + 1,PrevMBIC_UL_ShutdownCount[Index],Index + 1,MBIC_UL_ShutdownCount[Index]);        
        break;

    }
    
    if((*RetryCnt) < 3
//        && (PrevMBIC_UL_ShutdownCount[Index] != MBIC_UL_ShutdownCount[Index])
        && DET_UL_Shutdown_Off_AlarmTimerCnt[Index] >= MBIC_RECOVERY_SHUTDOWN_MAINTAIN_SEC
        && (*RetryCnt) > 0){
        HAL_GPIO_WritePin(Port,Pin,GPIO_PIN_SET);//CLOCK
//        printf();
        *Path = true;            
        PrevATT[UL_Shutdown_H] = 0xFF;
        PrevATT[UL_Shutdown_L] = 0xFF;
        PrevMBIC_UL_ShutdownCount[Index] = MBIC_UL_ShutdownCount[Index];
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus); 
    }
    else if((*RetryCnt) == 3
        && DET_UL_Shutdown_Off_AlarmTimerCnt[Index] >= MBIC_RECOVERY_LAST_SHUTDOWN_MAINTAIN_SEC){
        HAL_GPIO_WritePin(Port,Pin,GPIO_PIN_SET);//CLOCK
        *Path = true;            
        PrevATT[UL_Shutdown_H] = 0xFF;
        PrevATT[UL_Shutdown_L] = 0xFF;
        CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus); 
    }                  
    if(DET_UL_Shutdown_On_AlarmTimerCnt[Index] >= MBIC_ON_SHUTDOWN_MAINTAIN_SEC)
    {
        /*Shutdown 5sec Alarm*/
        HAL_GPIO_WritePin(Port,Pin,GPIO_PIN_RESET);//CLOCK      
        *Path = false;
        (*RetryCnt)++;
        DET_UL_Shutdown_On_AlarmTimerCnt[Index] = 0;
        
        if((*RetryCnt) >= RETRYCNT_MAX){
            (*RetryCnt) = RETRYCNT_MAX;
            bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN |= AlarmFlag;
            *ShutdownAlarm       = true;
        }else{
        }

    }
    else{
        if(DET_UL_Shutdown_Off_AlarmTimerCnt[Index] >= MBIC_OFF_MAINTAIN_SEC
            && (*RetryCnt) != RETRYCNT_MAX){
            bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN &= ~AlarmFlag;
            *ShutdownAlarm       = false;            
        }
    } 

}

void ULO_ShutdownAlarmCheck(){
   // double temp = 0;
    //double ret = 0;
   // int8_t ResdBm[4] = {0,};


//        if(ALC_AlarmSet[ALC_Alarm_UL1_Index] == true
//         &&ALC_On_AlarmTimerCnt[ALC_Alarm_UL1_Index] >= MBIC_ON_MAINTAIN_SEC){
//            printf("ALARM_ALC_P1 OCCUR\r\n");
//            bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm |= ALARM_ALC_P1;
//            bluecell_Currdatastatus.ULO_ALC_Alarm1       = true;
//        }else{
//            if(ALC_On_AlarmTimerCnt[ALC_Alarm_UL1_Index] >= MBIC_OFF_MAINTAIN_SEC){
//                bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm &= ~ALARM_ALC_P1;
//                bluecell_Currdatastatus.ULO_ALC_Alarm1       = false;            
//            }
//        }
        
    if(bluecell_Currdatastatus.ULO_Shutdown_ON_OFF == true){
#if 1 // PYJ.2020.06.19_BEGIN --
#if 1 // PYJ.2020.07.01_BEGIN -- 
    UL_Shutdown_Operate(DET_Alarm_UL1_Shutdown_Index,
                            &bluecell_Currdatastatus.ATT_UL1_PATH,
                            &bluecell_Prevdatastatus.ATT_UL1_H,
                            &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count1,
                            &bluecell_Currdatastatus.ULO_Shutdown_Alarm1,
                            ALARM_ULO_SHUTDOWN_P1);
    UL_Shutdown_Operate(DET_Alarm_UL2_Shutdown_Index,
                            &bluecell_Currdatastatus.ATT_UL2_PATH,
                            &bluecell_Prevdatastatus.ATT_UL2_H,
                            &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count2,
                            &bluecell_Currdatastatus.ULO_Shutdown_Alarm2,
                            ALARM_ULO_SHUTDOWN_P2);
    UL_Shutdown_Operate(DET_Alarm_UL3_Shutdown_Index,
                    &bluecell_Currdatastatus.ATT_UL3_PATH,
                    &bluecell_Prevdatastatus.ATT_UL3_H,
                    &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count3,
                    &bluecell_Currdatastatus.ULO_Shutdown_Alarm3,
                    ALARM_ULO_SHUTDOWN_P3);
    UL_Shutdown_Operate(DET_Alarm_UL4_Shutdown_Index,
                            &bluecell_Currdatastatus.ATT_UL4_PATH,
                            &bluecell_Prevdatastatus.ATT_UL4_H,
                            &bluecell_Currdatastatus.ULO_Shutdown_Retry_Count4,
                            &bluecell_Currdatastatus.ULO_Shutdown_Alarm4,
                            ALARM_ULO_SHUTDOWN_P4);
#else


        
#endif // PYJ.2020.07.01_END -- 

#if 0 // PYJ.2020.06.21_BEGIN -- 
#endif // PYJ.2020.06.21_END -- 
#endif // PYJ.2020.06.19_END -- 

    }
    else{
            bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN = 0;
            bluecell_Currdatastatus.ULO_Shutdown_Retry_Count1 = 0;
            bluecell_Currdatastatus.ULO_Shutdown_Retry_Count2 = 0;
            bluecell_Currdatastatus.ULO_Shutdown_Retry_Count3 = 0;
            bluecell_Currdatastatus.ULO_Shutdown_Retry_Count4 = 0;            
            bluecell_Currdatastatus.ULO_Shutdown_Alarm1 = false;            
            bluecell_Currdatastatus.ULO_Shutdown_Alarm2 = false;            
            bluecell_Currdatastatus.ULO_Shutdown_Alarm3 = false;            
            bluecell_Currdatastatus.ULO_Shutdown_Alarm4 = false;

    }
}


void ULO_ALCAlarmCheck(){
    //double temp = 0;
    //double ret = 0;
    //int8_t ResdBm[4] = {0,};
    if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
        return;
    
    if(bluecell_Currdatastatus.ULO_ALC_ON_OFF == true){
        if(ALC_AlarmSet[ALC_Alarm_UL1_Index] == true
         &&ALC_On_AlarmTimerCnt[ALC_Alarm_UL1_Index] >= MBIC_ON_MAINTAIN_SEC){
//            printf("ALARM_ALC_P1 OCCUR\r\n");

                bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm |= ALARM_ALC_P1;
                bluecell_Currdatastatus.ULO_ALC_Alarm1       = true;
        }else{
            if(ALC_Off_AlarmTimerCnt[ALC_Alarm_UL1_Index] >= MBIC_OFF_MAINTAIN_SEC){
                bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm &= ~ALARM_ALC_P1;
                bluecell_Currdatastatus.ULO_ALC_Alarm1       = false;            
            }
        }
        if(ALC_AlarmSet[ALC_Alarm_UL2_Index] == true
         &&ALC_On_AlarmTimerCnt[ALC_Alarm_UL2_Index] >= MBIC_ON_MAINTAIN_SEC){
//            printf("ALARM_ALC_P2 OCCUR\r\n");
            bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm |= ALARM_ALC_P2;
            bluecell_Currdatastatus.ULO_ALC_Alarm2       = true;
        }else{
            if(ALC_Off_AlarmTimerCnt[ALC_Alarm_UL2_Index] >= MBIC_OFF_MAINTAIN_SEC){
                bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm &= ~ALARM_ALC_P2;
                bluecell_Currdatastatus.ULO_ALC_Alarm2       = false;            
            }
        }
        if(ALC_AlarmSet[ALC_Alarm_UL3_Index] == true
         &&ALC_On_AlarmTimerCnt[ALC_Alarm_UL3_Index] >= MBIC_ON_MAINTAIN_SEC){
//            printf("ALARM_ALC_P3 OCCUR\r\n");
            bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm |= ALARM_ALC_P3;
            bluecell_Currdatastatus.ULO_ALC_Alarm3       = true;
        }else{
            if(ALC_Off_AlarmTimerCnt[ALC_Alarm_UL3_Index] >= MBIC_OFF_MAINTAIN_SEC){
                bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm &= ~ALARM_ALC_P3;
                bluecell_Currdatastatus.ULO_ALC_Alarm3       = false;            
            }
        }
        if(ALC_AlarmSet[ALC_Alarm_UL4_Index] == true
         &&ALC_On_AlarmTimerCnt[ALC_Alarm_UL4_Index] >= MBIC_ON_MAINTAIN_SEC){
//            printf("ALARM_ALC_P4 OCCUR\r\n");
            bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm |= ALARM_ALC_P4;
            bluecell_Currdatastatus.ULO_ALC_Alarm4       = true;
        }else{
            if(ALC_Off_AlarmTimerCnt[ALC_Alarm_UL4_Index] >= MBIC_OFF_MAINTAIN_SEC){
                bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm &= ~ALARM_ALC_P4;
                bluecell_Currdatastatus.ULO_ALC_Alarm4       = false;            
            }
        }        
    }

}
void DLI_AGCAlarmCheck(){
    //double temp = 0;
    //double ret = 0;
    //int8_t ResdBm[4] = {0,};
    if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
        return;

//    if(DET_DL_Low_On_AlarmTimerCnt[DET_Alarm_DL1_Index] >= MBIC_ON_MAINTAIN_SEC
//     &&ADC_Alarm_DL_Low_Set[DET_Alarm_DL1_Index] == true){
//        bluecell_Currdatastatus.ALARM_DLI_Level |= ALARM_DLI_P1_LEVEL_LOW;
//        bluecell_Currdatastatus.DLI_Level_Low_Alarm1 = true;
//
//    }else{/**/
//        if(DET_DL_Low_Off_AlarmTimerCnt[DET_Alarm_DL1_Index] >= MBIC_OFF_MAINTAIN_SEC){
//            bluecell_Currdatastatus.ALARM_DLI_Level &= ~ALARM_DLI_P1_LEVEL_LOW;
//            bluecell_Currdatastatus.DLI_Level_Low_Alarm1 = false;
//        }
//    }

    if(bluecell_Currdatastatus.DLI_AGC_ON_OFF == true){
//        printf("bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm : %x \r\n",bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm);
        if(AGC_AlarmSet[AGC_Alarm_DL1_Index] == true
         &&AGC_On_AlarmTimerCnt[AGC_Alarm_DL1_Index] >= MBIC_ON_MAINTAIN_SEC){
//            printf("ALARM_AGC_P1 OCCUR\r\n");
            bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm |= ALARM_AGC_P1;
            bluecell_Currdatastatus.DLI_AGC_Alarm1       = true;
        }else{
            if(AGC_Off_AlarmTimerCnt[AGC_Alarm_DL1_Index] >= MBIC_OFF_MAINTAIN_SEC){
                bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm &= ~ALARM_AGC_P1;
                bluecell_Currdatastatus.DLI_AGC_Alarm1       = false;            
            }
        }
        if(AGC_AlarmSet[AGC_Alarm_DL2_Index] == true
         &&AGC_On_AlarmTimerCnt[AGC_Alarm_DL2_Index] >= MBIC_ON_MAINTAIN_SEC){
//            printf("ALARM_AGC_P2 OCCUR\r\n");
            bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm |= ALARM_AGC_P2;
            bluecell_Currdatastatus.DLI_AGC_Alarm2       = true;
        }else{
            if(AGC_Off_AlarmTimerCnt[AGC_Alarm_DL2_Index] >= MBIC_OFF_MAINTAIN_SEC){
                bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm &= ~ALARM_AGC_P2;
                bluecell_Currdatastatus.DLI_AGC_Alarm2       = false;            
            }
        }
        if(AGC_AlarmSet[AGC_Alarm_DL3_Index] == true
         &&AGC_On_AlarmTimerCnt[AGC_Alarm_DL3_Index] >= MBIC_ON_MAINTAIN_SEC){
//            printf("ALARM_AGC_P3 OCCUR\r\n");
            bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm |= ALARM_AGC_P3;
            bluecell_Currdatastatus.DLI_AGC_Alarm3       = true;
        }else{
            if(AGC_Off_AlarmTimerCnt[AGC_Alarm_DL3_Index] >= MBIC_OFF_MAINTAIN_SEC){
                bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm &= ~ALARM_AGC_P3;
                bluecell_Currdatastatus.DLI_AGC_Alarm3       = false;            
            }
        }
        if(AGC_AlarmSet[AGC_Alarm_DL4_Index] == true
         &&AGC_On_AlarmTimerCnt[AGC_Alarm_DL4_Index] >= MBIC_ON_MAINTAIN_SEC){
//            printf("ALARM_AGC_P4 OCCUR\r\n");
            bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm |= ALARM_AGC_P4;
            bluecell_Currdatastatus.DLI_AGC_Alarm4       = true;
        }else{
            if(AGC_Off_AlarmTimerCnt[AGC_Alarm_DL4_Index] >= MBIC_OFF_MAINTAIN_SEC){
                bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm &= ~ALARM_AGC_P4;
                bluecell_Currdatastatus.DLI_AGC_Alarm4       = false;            
            }
        }        
    }
    else{
        bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm = 0;
        bluecell_Currdatastatus.DLI_AGC_Alarm4       = false;            
    }
}
void Temp_HighAlarmCheck(){
    //double temp = 0;
    //double ret = 0;
    //int8_t ResdBm[4] = {0,};
    if(bluecell_Currdatastatus.Carrier_ON_OFF == false)
        return;
    
    if(bluecell_Currdatastatus.Temp_High_Threshold <= (bluecell_Currdatastatus.DET_TEMP )){
        bluecell_Currdatastatus.Temp_High_Alarm = true;
        if(Alarm_Temp_TimerOnCnt > MBIC_ON_MAINTAIN_SEC){
            bluecell_Currdatastatus.ALARM_TEMP_HIGH |= ENVIRONMENT_TEMPHIGH;
        }
    }else{
        if(bluecell_Currdatastatus.ALARM_TEMP_HIGH == ENVIRONMENT_TEMPHIGH){
            if(bluecell_Currdatastatus.Temp_High_Threshold - 2 >= (bluecell_Currdatastatus.DET_TEMP )){
                bluecell_Currdatastatus.Temp_High_Alarm = false;        
                if( Alarm_Temp_TimerOffCnt > MBIC_OFF_MAINTAIN_SEC){
//                    printf("1 Alarm TEMP OFF Curr : %d  Limit : %d \r\n",(bluecell_Currdatastatus.DET_TEMP ),bluecell_Currdatastatus.Temp_High_Threshold);
                    bluecell_Currdatastatus.ALARM_TEMP_HIGH &= ~ENVIRONMENT_TEMPHIGH;
                }
            }
        }
    }

}

#if 0 // PYJ.2020.06.28_BEGIN -- 
#endif // PYJ.2020.06.28_END -- 
typedef enum{
    FRBT_H = 0,
    FRBT_L,        

};

/*
uint8_t DLI_FRBT_D_Day;
uint8_t DLI_FRBT_Status;
*/
void FRBT_Tracking_Package(uint8_t Index, uint8_t* FRBT,uint8_t* DL_MainAtten,uint8_t path){
    int16_t DL_Atten = 0;
    int16_t FRBT_Atten = 0;

    if(path == false)
        return;
    
    FRBT_Atten = FRBT[FRBT_H] << 8 | FRBT[FRBT_L];    
    DL_Atten = DL_MainAtten[FRBT_H] << 8 | DL_MainAtten[FRBT_L];
    if(FRBT_Atten == DL_Atten){
//        printf("Tracking Return %d \r\n ");
//        printf("FRBT_Atten : %d DL_Atten :  %d \r\n",FRBT_Atten,DL_Atten);        
        return;
    }
    
//    printf("FRBT_Atten : %d DL_Atten :  %d \r\n",FRBT_Atten,DL_Atten);
    
    FRBT[FRBT_H] = DL_MainAtten[FRBT_H];
    FRBT[FRBT_L] = DL_MainAtten[FRBT_L];        

}

void SelfTest_TimerOff(uint8_t num,uint8_t* selftest){
    GPIO_TypeDef *Port = 0;
    uint16_t Pin = 0;
    GPIO_TypeDef *_Port = 0;
    uint16_t _Pin = 0;   
    if((*selftest) == false || SelfTestLifeCnt[num] < MBIC_RECOVERY_SELFTEST_TIMER_SEC){
        return;
    }
    switch(num){
        case SelfTest1:
        _Port = _PATH_SW1_GPIO_Port;
        _Pin = _PATH_SW1_Pin;
        
        Port = PATH_SW1_GPIO_Port;
        Pin =  PATH_SW1_Pin;        
        break;
        case SelfTest2:
        _Port = _PATH_SW2_GPIO_Port;
        _Pin = _PATH_SW2_Pin;
        
        Port = PATH_SW2_GPIO_Port;
        Pin =  PATH_SW2_Pin;        
        break;
        case SelfTest3:
        _Port = _PATH_SW3_GPIO_Port;
        _Pin = _PATH_SW3_Pin;
        
        Port = PATH_SW3_GPIO_Port;
        Pin =  PATH_SW3_Pin;        
        break;
        case SelfTest4:
        _Port = _PATH_SW4_GPIO_Port;
        _Pin = _PATH_SW4_Pin;
        
        Port = PATH_SW4_GPIO_Port;
        Pin =  PATH_SW4_Pin;        
        break;        
    }
    *selftest = false;
    HAL_GPIO_WritePin(_Port,_Pin,GPIO_PIN_RESET);//CLOCK
    HAL_GPIO_WritePin(Port,Pin,GPIO_PIN_SET);//CLOCK
    
}

void SelfTest_Ctrl(uint8_t num,uint8_t val,uint8_t* selftest,uint8_t* DL_Atten,uint8_t* UL_Atten){
    GPIO_TypeDef *Port = 0;
    uint16_t Pin = 0;
    GPIO_TypeDef *_Port = 0;
    uint16_t _Pin = 0;   
    
    switch(num){
        case SelfTest1:
        _Port = _PATH_SW1_GPIO_Port;
        _Pin = _PATH_SW1_Pin;
        
        Port = PATH_SW1_GPIO_Port;
        Pin =  PATH_SW1_Pin;   
        break;
        case SelfTest2:
        _Port = _PATH_SW2_GPIO_Port;
        _Pin = _PATH_SW2_Pin;
        
        Port = PATH_SW2_GPIO_Port;
        Pin =  PATH_SW2_Pin;        
        break;
        case SelfTest3:
        _Port = _PATH_SW3_GPIO_Port;
        _Pin = _PATH_SW3_Pin;
        
        Port = PATH_SW3_GPIO_Port;
        Pin =  PATH_SW3_Pin;        
        break;
        case SelfTest4:
        _Port = _PATH_SW4_GPIO_Port;
        _Pin = _PATH_SW4_Pin;
        
        Port = PATH_SW4_GPIO_Port;
        Pin =  PATH_SW4_Pin;        
        break;        
    }
    if(*selftest == val)
        return;
        
    if(val == true){
        Selftest_DL_PrevAttenSave[num * 2]         = DL_Atten[Atten_H];
        Selftest_DL_PrevAttenSave[((num * 2) + 1)] = DL_Atten[Atten_L];
        Selftest_UL_PrevAttenSave[num * 2]         = UL_Atten[Atten_H];
        Selftest_UL_PrevAttenSave[((num * 2) + 1)] = UL_Atten[Atten_L];
//        for(int i =0; i< 8; i++)
//            printf("Selftest_UL_PrevAttenSave[%d] : %x \r\n",i,Selftest_UL_PrevAttenSave[i]);        
        DL_Atten[Atten_H] = 0;
        DL_Atten[Atten_L] = 0;
        UL_Atten[Atten_H] = 0;
        UL_Atten[Atten_L] = 0;          
        HAL_GPIO_WritePin(_Port,_Pin,GPIO_PIN_SET);//CLOCK
        HAL_GPIO_WritePin(Port,Pin,GPIO_PIN_RESET);//CLOCK
    }else{
        DL_Atten[Atten_H] = Selftest_DL_PrevAttenSave[num * 2];
        DL_Atten[Atten_L] = Selftest_DL_PrevAttenSave[((num * 2) + 1)];    
        UL_Atten[Atten_H] = Selftest_UL_PrevAttenSave[num * 2];
        UL_Atten[Atten_L] = Selftest_UL_PrevAttenSave[((num * 2) + 1)];    
//        for(int i =0; i< 8; i++)
//            printf("Selftest_UL_PrevAttenSave[%d] : %x \r\n",i,Selftest_UL_PrevAttenSave[i]);        

        HAL_GPIO_WritePin(_Port,_Pin,GPIO_PIN_RESET);//CLOCK
        HAL_GPIO_WritePin(Port,Pin,GPIO_PIN_SET);//CLOCK
    }
    CompareAttenData(bluecell_Currdatastatus,bluecell_Prevdatastatus);       
    *selftest = val;
    
}

void SelfTestTimer_Operate()
{
    SelfTest_TimerOff(SelfTest1,&bluecell_Currdatastatus.Selftest1);
    SelfTest_TimerOff(SelfTest2,&bluecell_Currdatastatus.Selftest2);
    SelfTest_TimerOff(SelfTest3,&bluecell_Currdatastatus.Selftest3);
    SelfTest_TimerOff(SelfTest4,&bluecell_Currdatastatus.Selftest4);
}
void FRBT_Operate(){

    if(bluecell_Currdatastatus.DLI_FRBT_D_Day == 0  || bluecell_Currdatastatus.DLI_AGC_ON_OFF == false){    /*AGC ON ONLY*/
        bluecell_Currdatastatus.DLI_FRBT_Status = FRBT_IDEL;
//        printf("AGC OFF \r\n");
        return;
    }
    
    /*Time Calc*/
    if(FRBT_Day_Inc == bluecell_Currdatastatus.DLI_FRBT_D_Day
    && StartTimeFRBT_Day[DLI_FRBT_Time_Hour]  <= FRBT_Day[DLI_FRBT_Time_Hour]    
    && StartTimeFRBT_Day[DLI_FRBT_Time_Minute]  <= FRBT_Day[DLI_FRBT_Time_Minute]    
    && StartTimeFRBT_Day[DLI_FRBT_Time_Second]  <= FRBT_Day[DLI_FRBT_Time_Second]
    && bluecell_Currdatastatus.DLI_FRBT_Status == FRBT_TRACKING)
    {
        bluecell_Currdatastatus.DLI_FRBT_Status = FRBT_RUNNING;
//        printf("FRBT Running Start \r\n");
    }
    
    if(bluecell_Currdatastatus.DLI_FRBT_Status == FRBT_TRACKING){
        FRBT_Tracking_Package(DET_Alarm_DL1_Index,&bluecell_Currdatastatus.DLI_FRBT_Atten1_H,&bluecell_Currdatastatus.ATT_DL1_H,bluecell_Currdatastatus.ATT_DL1_PATH);
        FRBT_Tracking_Package(DET_Alarm_DL2_Index,&bluecell_Currdatastatus.DLI_FRBT_Atten2_H,&bluecell_Currdatastatus.ATT_DL2_H,bluecell_Currdatastatus.ATT_DL2_PATH);
        FRBT_Tracking_Package(DET_Alarm_DL3_Index,&bluecell_Currdatastatus.DLI_FRBT_Atten3_H,&bluecell_Currdatastatus.ATT_DL3_H,bluecell_Currdatastatus.ATT_DL3_PATH);
        FRBT_Tracking_Package(DET_Alarm_DL4_Index,&bluecell_Currdatastatus.DLI_FRBT_Atten4_H,&bluecell_Currdatastatus.ATT_DL4_H,bluecell_Currdatastatus.ATT_DL4_PATH);
//        printf("Tracking ... \r\n");
    }
}
void LED_Alarm_Check(){
    if(bluecell_Currdatastatus.ALARM_TESTMODE == false){
#if 0 // PYJ.2020.08.18_BEGIN -- 
      if(  (bluecell_Currdatastatus.ALARM_TEMP_HIGH      > 0 && bluecell_Currdatastatus.ALARM_MASK1 != false) 
        || (bluecell_Currdatastatus.ALARM_DLI_Level      > 0 && bluecell_Currdatastatus.ALARM_MASK2 != false)
        || (bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN  > 0 && bluecell_Currdatastatus.ALARM_MASK3 != false)
        || (bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm  > 0 && bluecell_Currdatastatus.ALARM_MASK3 != false)
        || (bluecell_Currdatastatus.ALARM_ULO_Level      > 0 && bluecell_Currdatastatus.ALARM_MASK4 != false)
        || (bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm  > 0 && bluecell_Currdatastatus.ALARM_MASK5 != false)
        || (bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN  > 0 && bluecell_Currdatastatus.ALARM_MASK5 != false))
        {
    //        AlarmTimerOnSet = true;
    //        AlarmTimerOffSet = false;
    //        if(AlarmTimerOnCnt > 3000){
                Alarm_LED_OnSet  = true;
    //        }
        }else{
    //        AlarmTimerOffSet = true;// False 
    //        if(AlarmTimerOffCnt > 10000){
    //            AlarmTimerOnSet = false;
                Alarm_LED_OnSet = false;
    //            printf("=================AlarmTimerOffCnt=================\r\n");
    //        }
        }
#else
          if(  (bluecell_Currdatastatus.ALARM_TEMP_HIGH      > 0 && bluecell_Currdatastatus.ALARM_MASK1 != false) 
            || (bluecell_Currdatastatus.ALARM_DLI_Level      > 0 && bluecell_Currdatastatus.ALARM_MASK2 != false)
            || (bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN  > 0 && bluecell_Currdatastatus.ALARM_MASK3 != false)
            || (bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm  > 0 && bluecell_Currdatastatus.ALARM_MASK3 != false)
            || (bluecell_Currdatastatus.ALARM_ULO_Level      > 0 && bluecell_Currdatastatus.ALARM_MASK4 != false)
            || (bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm  > 0 && bluecell_Currdatastatus.ALARM_MASK5 != false)
            || (bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN  > 0 && bluecell_Currdatastatus.ALARM_MASK5 != false))
            {
                    Alarm_LED_OnSet  = true;
            }else{
                    Alarm_LED_OnSet = false;
            }

#endif // PYJ.2020.08.18_END -- 
    }
    else{
        if(bluecell_Currdatastatus.ALARM_Test_Dummy1         > 0 
        || bluecell_Currdatastatus.ALARM_Test_Dummy2         > 0
        || bluecell_Currdatastatus.ALARM_Test_Dummy3         > 0
        || bluecell_Currdatastatus.ALARM_Test_Dummy4         > 0
        || bluecell_Currdatastatus.ALARM_Test_Dummy5         > 0)
        {
            Alarm_LED_OnSet  = true;
        }
        else{
            Alarm_LED_OnSet = false;
        }

}

}
void Alarm_Check(){
   // double temp = 0;
   // double ret = 0;
   // int8_t ResdBm[4] = {0,};


  
    LED_Alarm_Check();
    Temp_HighAlarmCheck();
    DLI_AGCAlarmCheck();
    ULO_ALCAlarmCheck();
    ULO_ShutdownAlarmCheck();
    DLI_ShutdownAlarmCheck();   
    DLI_LevelAlarmCheck();
    ULO_LevelAlarmCheck();
}

typedef struct{
    uint8_t Temperature_Status ;
    uint8_t DLI_Path4_Low ;
    uint8_t DLI_Path3_Low ;
    uint8_t DLI_Path2_Low ;
    uint8_t DLI_Path1_Low ;    

    uint8_t DLI_Path4_High ;
    uint8_t DLI_Path3_High ;
    uint8_t DLI_Path2_High ;
    uint8_t DLI_Path1_High ;    

    uint8_t DLI_Path1_AGC ;    
    uint8_t DLI_Path2_AGC ;    
    uint8_t DLI_Path3_AGC ;    
    uint8_t DLI_Path4_AGC ;    
    uint8_t DLI_Path1_Shutdown ;    
    uint8_t DLI_Path2_Shutdown ;    
    uint8_t DLI_Path3_Shutdown ;    
    uint8_t DLI_Path4_Shutdown ;    

    uint8_t ULO_Path4_High ;
    uint8_t ULO_Path3_High ;
    uint8_t ULO_Path2_High ;
    uint8_t ULO_Path1_High ;    

    uint8_t ULO_Path1_ALC ;    
    uint8_t ULO_Path2_ALC ;    
    uint8_t ULO_Path3_ALC ;    
    uint8_t ULO_Path4_ALC ;    
    uint8_t ULO_Path1_Shutdown ;    
    uint8_t ULO_Path2_Shutdown ;    
    uint8_t ULO_Path3_Shutdown ;    
    uint8_t ULO_Path4_Shutdown ;    
}Alarm_Report_t;
Alarm_Report_t Curr_Alarm_Status_Save;

void Alarm_Compare(uint8_t* Prev_Data,uint8_t* Curr_data,uint16_t mode,uint8_t flag){

    if(*Prev_Data != *Curr_data){
//        printf("Data Report Occur !!\r\n");
        if(*Curr_data & flag){
            Alarm_Report_Send(mode,true);
        }
        else{
            Alarm_Report_Send(mode,false);
        }
        *Prev_Data = *Curr_data;
    }

}
void AlarmLog_Report(){

    if(AlarmReport_TimerCnt < 100)
        return;
    else
        AlarmReport_TimerCnt = 0;
    Alarm_Compare(&Curr_Alarm_Status_Save.Temperature_Status,&bluecell_Currdatastatus.ALARM_TEMP_HIGH,Temp_High,0x80);

#if 1 // PYJ.2020.08.18_BEGIN -- 
    Alarm_Compare(&Curr_Alarm_Status_Save.DLI_Path4_Low,&bluecell_Currdatastatus.ALARM_DLI_Level,DLI_P4_Level_Low,0x80);
    Alarm_Compare(&Curr_Alarm_Status_Save.DLI_Path3_Low,&bluecell_Currdatastatus.ALARM_DLI_Level,DLI_P3_Level_Low,0x40);
    Alarm_Compare(&Curr_Alarm_Status_Save.DLI_Path2_Low,&bluecell_Currdatastatus.ALARM_DLI_Level,DLI_P2_Level_Low,0x20);
    Alarm_Compare(&Curr_Alarm_Status_Save.DLI_Path1_Low,&bluecell_Currdatastatus.ALARM_DLI_Level,DLI_P1_Level_Low,0x10);
    Alarm_Compare(&Curr_Alarm_Status_Save.DLI_Path4_High,&bluecell_Currdatastatus.ALARM_DLI_Level,DLI_P4_Level_High,0x08);    
    Alarm_Compare(&Curr_Alarm_Status_Save.DLI_Path4_High,&bluecell_Currdatastatus.ALARM_DLI_Level,DLI_P3_Level_High,0x04);
    Alarm_Compare(&Curr_Alarm_Status_Save.DLI_Path4_High,&bluecell_Currdatastatus.ALARM_DLI_Level,DLI_P2_Level_High,0x02);
    Alarm_Compare(&Curr_Alarm_Status_Save.DLI_Path4_High,&bluecell_Currdatastatus.ALARM_DLI_Level,DLI_P1_Level_High,0x01);


    Alarm_Compare(&Curr_Alarm_Status_Save.DLI_Path1_AGC,&bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm,DLI_P4_AGC_Alarm,0x80);
    Alarm_Compare(&Curr_Alarm_Status_Save.DLI_Path2_AGC,&bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm,DLI_P3_AGC_Alarm,0x40);
    Alarm_Compare(&Curr_Alarm_Status_Save.DLI_Path3_AGC,&bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm,DLI_P2_AGC_Alarm,0x20);
    Alarm_Compare(&Curr_Alarm_Status_Save.DLI_Path4_AGC,&bluecell_Currdatastatus.ALARM_DLI_AGC_Alarm,DLI_P1_AGC_Alarm,0x10);
    Alarm_Compare(&Curr_Alarm_Status_Save.DLI_Path1_Shutdown,&bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN,DLI_P4_Shutdown_Alarm,0x08);
    Alarm_Compare(&Curr_Alarm_Status_Save.DLI_Path2_Shutdown,&bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN,DLI_P3_Shutdown_Alarm,0x04);
    Alarm_Compare(&Curr_Alarm_Status_Save.DLI_Path3_Shutdown,&bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN,DLI_P2_Shutdown_Alarm,0x02);
    Alarm_Compare(&Curr_Alarm_Status_Save.DLI_Path4_Shutdown,&bluecell_Currdatastatus.ALARM_DLI_SHTUTDOWN,DLI_P1_Shutdown_Alarm,0x01);

    Alarm_Compare(&Curr_Alarm_Status_Save.ULO_Path1_High,&bluecell_Currdatastatus.ALARM_ULO_Level,ULO_P4_Level_High,0x08);
    Alarm_Compare(&Curr_Alarm_Status_Save.ULO_Path2_High,&bluecell_Currdatastatus.ALARM_ULO_Level,ULO_P3_Level_High,0x04);
    Alarm_Compare(&Curr_Alarm_Status_Save.ULO_Path3_High,&bluecell_Currdatastatus.ALARM_ULO_Level,ULO_P2_Level_High,0x02);
    Alarm_Compare(&Curr_Alarm_Status_Save.ULO_Path4_High,&bluecell_Currdatastatus.ALARM_ULO_Level,ULO_P1_Level_High,0x01);

    Alarm_Compare(&Curr_Alarm_Status_Save.ULO_Path1_ALC,&bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm,ULO_P4_ALC_Alarm,0x80);
    Alarm_Compare(&Curr_Alarm_Status_Save.ULO_Path2_ALC,&bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm,ULO_P3_ALC_Alarm,0x40);
    Alarm_Compare(&Curr_Alarm_Status_Save.ULO_Path3_ALC,&bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm,ULO_P2_ALC_Alarm,0x20);
    Alarm_Compare(&Curr_Alarm_Status_Save.ULO_Path4_ALC,&bluecell_Currdatastatus.ALARM_ULO_ALC_Alarm,ULO_P1_ALC_Alarm,0x10);

    Alarm_Compare(&Curr_Alarm_Status_Save.ULO_Path1_Shutdown,&bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN,ULO_P4_Shutdown,0x08);
    Alarm_Compare(&Curr_Alarm_Status_Save.ULO_Path2_Shutdown,&bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN,ULO_P3_Shutdown,0x04);
    Alarm_Compare(&Curr_Alarm_Status_Save.ULO_Path3_Shutdown,&bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN,ULO_P2_Shutdown,0x02);
    Alarm_Compare(&Curr_Alarm_Status_Save.ULO_Path4_Shutdown,&bluecell_Currdatastatus.ALARM_ULO_SHTUTDOWN,ULO_P1_Shutdown,0x01);
#endif // PYJ.2020.08.18_END -- 

}
