rf_pm.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:91k
源码类别:

MTK

开发平台:

C++ Builder

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  *   rf_pm.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   RF power measurement source
  48.  *
  49.  * Author:
  50.  * -------
  51.  *  Andy Ueng (mtk00490)
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * $Revision$
  58.  * $Modtime$
  59.  * $Log$
  60.  * 
  61.  *------------------------------------------------------------------------------
  62.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  63.  *============================================================================
  64.  ****************************************************************************/
  65. #include <IniFiles.hpp>
  66. #pragma hdrstop
  67. //#ifndef _FORM_RFTOOL_H_
  68. //#include "form_RFTool.h"
  69. //#endif
  70. #ifndef _FORM_MAIN_H_
  71. #include "form_main.h"
  72. #endif
  73. #ifndef  _RF_PM_H_
  74. #include "rf_pm.h"
  75. #endif
  76. #include "man_active.h"
  77. #include "man_fdm.h"
  78. // misc
  79. #ifndef  _FT_UTILS_H_
  80. #include "ft_utils.h"
  81. #endif
  82. // NVRAM
  83. #ifndef  _NVRAM_VER_H_
  84. #include "nvram_ver.h"
  85. #endif
  86. static const  SKY74045_RCX_MIN =  -127;
  87. static const  SKY74045_RCX_MAX =   127;
  88. static const  SKY74117_RCX_MIN =  -63;
  89. static const  SKY74117_RCX_MAX =   63;
  90. //===========================================================================
  91. static CRFPM*  rf_pm_ptr;
  92. static bool g_bIsRunning;
  93. static const char  SUBBAND_NAME[][32] =
  94. {
  95.    "GSM400 Sub band, IP2",
  96.    "GSM850 Sub band, IP2",
  97.    "GSM900 Sub band, IP2",
  98.    "DCS1800 Sub band, IP2",
  99.    "PCS1900 Sub band, IP2",
  100. };
  101. //===========================================================================
  102. static void  REQ_SelectBand( void )
  103. {  rf_pm_ptr->REQ_SelectBand( );
  104. }
  105. //------------------------------------------------------------------------------
  106. static void __stdcall CNF_SelectBand(const unsigned char cnf, const short token, void *usrData)
  107. {
  108.     rf_pm_ptr->CNF_SelectBand(cnf, token, NULL);
  109. }
  110. //------------------------------------------------------------------------------
  111. static void  REQ_PowerMeasurement(void)
  112. {
  113.     rf_pm_ptr->REQ_PowerMeasurement();
  114. }
  115. //------------------------------------------------------------------------------
  116. static void __stdcall CNF_PowerMeasurement(const RfPm_Cnf *cnf, const short token, void *usrData)
  117. {
  118.     rf_pm_ptr->CNF_PowerMeasurement(cnf, token, usrData);
  119. }
  120. //----------------------------------------------------------------------------
  121. static void CNF_ReadIP2RegFromNVRAM(void)
  122. {
  123.     rf_pm_ptr->CNF_ReadIP2RegFromNVRAM();
  124. }
  125. //----------------------------------------------------------------------------
  126. static void CNF_WriteIP2RegToNVRAM(void)
  127. {
  128.     rf_pm_ptr->CNF_WriteIP2RegToNVRAM();
  129. }
  130. //----------------------------------------------------------------------------
  131. static void Set_Sky74117IP2MagToReg(void)
  132. {
  133.     rf_pm_ptr->Set_Sky74117IP2MagToReg();
  134. }
  135. //----------------------------------------------------------------------------
  136. static void Set_Sky74117IP2Gsm850ToReg(void)
  137. {
  138.     rf_pm_ptr->Set_Sky74117IP2Gsm850ToReg();
  139. }
  140. //----------------------------------------------------------------------------
  141. static void Set_Sky74117IP2Gsm900ToReg(void)
  142. {
  143.     rf_pm_ptr->Set_Sky74117IP2Gsm900ToReg();
  144. }
  145. //----------------------------------------------------------------------------
  146. static void Set_Sky74117IP2Dcs1800ToReg(void)
  147. {
  148.     rf_pm_ptr->Set_Sky74117IP2Dcs1800ToReg();
  149. }
  150. //----------------------------------------------------------------------------
  151. static void Set_Sky74117IP2Pcs1900ToReg(void)
  152. {
  153.     rf_pm_ptr->Set_Sky74117IP2Pcs1900ToReg();
  154. }
  155. //----------------------------------------------------------------------------
  156. static void Set_Sky74117IP2PolToReg(void)
  157. {
  158.     rf_pm_ptr->Set_Sky74117IP2PolToReg();
  159. }
  160. //----------------------------------------------------------------------------
  161. static void Get_AcodeFromReg(void)
  162. {
  163.     rf_pm_ptr->Get_AcodeFromReg();
  164. }
  165. //----------------------------------------------------------------------------
  166. static void Get_BCcodeFromReg(void)
  167. {
  168.     rf_pm_ptr->Get_BCcodeFromReg();
  169. }
  170. //----------------------------------------------------------------------------
  171. static void Set_BCcodeToReg(void)
  172. {
  173.     rf_pm_ptr->Set_BCcodeToReg();
  174. }
  175. //----------------------------------------------------------------------------
  176. static void Get_ABCcodeFromReg(void)
  177. {
  178.     rf_pm_ptr->Get_ABCcodeFromReg();
  179. }
  180. //----------------------------------------------------------------------------
  181. static  void  Set_MT6139CW2ToReg( void )
  182. {
  183.     rf_pm_ptr->Set_MT6139CW2ToReg();
  184. }
  185. //----------------------------------------------------------------------------
  186. static  void  Get_MT6139CW7FromReg( void )
  187. {
  188.     rf_pm_ptr->Get_MT6139CW7FromReg();
  189. }
  190. //----------------------------------------------------------------------------
  191. static  void  Set_MT6139CW7ToReg( void )
  192. {
  193.     rf_pm_ptr->Set_MT6139CW7ToReg();
  194. }
  195. //----------------------------------------------------------------------------
  196. static  void  Set_MT6139CW8ToReg( void )
  197. {
  198.     rf_pm_ptr->Set_MT6139CW8ToReg();
  199. }
  200. //----------------------------------------------------------------------------
  201. static  void Get_MT6139CW9FromReg(void )
  202. {
  203.     rf_pm_ptr->Get_MT6139CW9FromReg();
  204. }
  205. //----------------------------------------------------------------------------
  206. static  void  Set_MT6139CW9ToReg(void )
  207. {
  208.     rf_pm_ptr->Set_MT6139CW9ToReg();
  209. }
  210. //----------------------------------------------------------------------------
  211. static  void  Set_MT6139CoefToReg(void )
  212. {
  213.     rf_pm_ptr->Set_MT6139CoefToReg();
  214. }
  215. //----------------------------------------------------------------------------
  216. static void  REQ_TimeOut( void )
  217. {  rf_pm_ptr->REQ_TimeOut();
  218. }
  219. //----------------------------------------------------------------------------
  220. static void  REQ_Finish( void )
  221. {  rf_pm_ptr->REQ_Finish();
  222. }
  223. //===========================================================================
  224. CRFPM::CRFPM( void )
  225. {
  226.     g_bIsRunning = false;
  227.     ConfirmCallback = 0;
  228.     RFReq_PM = NULL;
  229.     EvalPmrcx_I_sky[0]  = 0;
  230.     EvalPmrcx_I_sky[1]  = 0;
  231.     EvalPmrcx_Q_sky[0]  = 0;
  232.     EvalPmrcx_Q_sky[1]  = 0;
  233.     EvalDC_I_sky[0] = 0;
  234.     EvalDC_I_sky[1] = 0;
  235.     EvalDC_Q_sky[0] = 0;
  236.     EvalDC_Q_sky[1] = 0;
  237.     m_uiIP2BufSize = 0;
  238.     m_cIP2Buf = 0;
  239.     // reserved
  240.     mt6139_cw7.uc_reserved = 0x00;
  241.     mt6139_cw8.uc_reserved = 0x00;
  242.     mt6139_cw9.uc_reserved = 0x0F;
  243. }
  244. //---------------------------------------------------------------------------
  245. CRFPM::~CRFPM()
  246. {
  247.    g_bIsRunning = false;
  248.    ConfirmCallback = 0;
  249.    if(  RFReq_PM != NULL)
  250.    {
  251.        delete RFReq_PM;
  252.        RFReq_PM = NULL;
  253.    }
  254.    if(m_cIP2Buf)
  255.    {
  256.       delete [] m_cIP2Buf;
  257.       m_cIP2Buf = NULL;
  258.    }
  259. }
  260. //---------------------------------------------------------------------------
  261. void  CRFPM::REQ_Finish( void )
  262. {
  263.    if(!g_bIsRunning)  return;
  264.    Confirm( METAAPP_SUCCESS );
  265. }
  266. //---------------------------------------------------------------------------
  267. void  CRFPM::REQ_Stop( void )
  268. {
  269.    if(!g_bIsRunning)  return;
  270.    META_Cancel_r( m_META_HANDLE_Obj.Get_MainHandle(), RFID_PM );
  271.    Confirm( METAAPP_STOP );
  272. }
  273. //---------------------------------------------------------------------------
  274. void  CRFPM::REQ_TimeOut( void )
  275. {
  276.    if(!g_bIsRunning)  return;
  277.    META_Cancel_r( m_META_HANDLE_Obj.Get_MainHandle(), RFID_PM );
  278.    Confirm( METAAPP_TIMEOUT );
  279. }
  280. //---------------------------------------------------------------------------
  281. void  CRFPM::Confirm(E_METAAPP_RESULT_T confirm_state)
  282. {
  283.    if(!g_bIsRunning)  return;
  284.    
  285.    if( METAAPP_SECTION_OK != confirm_state )
  286.         g_bIsRunning = false;
  287.    if(ConfirmCallback==0)  return;
  288.    m_eConfirmState = confirm_state;
  289.    ActiveMan->SetActiveFunction( ConfirmCallback );
  290. }
  291. //===========================================================================
  292. void  CRFPM::REQ_Start( int band, int arfcn, int pm_per_frame, unsigned int pm_count, unsigned int rfmod_id, bool dnpwr_on, int gain_min, int gain_max, int gain_step )
  293. {
  294.     rf_pm_ptr = this;
  295.     g_bIsRunning = true;
  296.          Band = band;
  297.         Arfcn = arfcn;
  298.    PMPerFrame = pm_per_frame;
  299.       PMCount = pm_count;
  300.       GainMin = gain_min;
  301.       GainMax = gain_max;
  302.      GainStep = gain_step;
  303.    if(GainStep==0)  GainMax = GainMin-1;
  304.    CurPmCount = PMCount;
  305.       CurGain = GainMin;
  306.       m_uiFinalRfid = rfmod_id;
  307.       DnPwrOn = dnpwr_on;
  308.    ActiveMan->SetActiveFunction( ::REQ_SelectBand );
  309. }
  310. //---------------------------------------------------------------------------
  311. void  CRFPM::REQ_SelectBand( void )
  312. {
  313.    if(!g_bIsRunning)  return;
  314.    unsigned char selected_pcs1900;
  315.    if(Band==BANDSEL_PCS1900)
  316.       selected_pcs1900 = 1;
  317.    else
  318.       selected_pcs1900 = 0;
  319.    META_RESULT MetaResult = META_Rf_SelectFrequencyBand1900_r( m_META_HANDLE_Obj.Get_MainHandle(), selected_pcs1900, ::CNF_SelectBand, &RFID_PM, NULL );
  320.    if(MetaResult!=META_SUCCESS)
  321.    {  Confirm( METAAPP_FAIL );  return;  }
  322. }
  323. //-------------------------------------
  324. void __stdcall CRFPM::CNF_SelectBand(const unsigned char cnf, const short token, void *usrData)
  325. {
  326.    if(!g_bIsRunning)  return;
  327.    if(cnf==false)
  328.    {  Confirm( METAAPP_FAIL );  return;  }
  329.    HasMeasured = false;
  330.    ActiveMan->SetActiveFunction( ::REQ_PowerMeasurement );
  331. }
  332. //---------------------------------------------------------------------------
  333. void  CRFPM::REQ_PowerMeasurement( void )
  334. {
  335.    if(!g_bIsRunning)  return;
  336.    if( HasMeasured )
  337.    {
  338.       Confirm( METAAPP_SECTION_OK );
  339.    }
  340.    if( PMCount==-1 )  /* infinit PM */
  341.    {  CurPmCount = 2001;
  342.    }
  343.    if( CurPmCount==0 )
  344.    {  CurGain += GainStep;
  345.       if( CurGain>GainMax )
  346.       {  REQ_Finish();
  347.          return;
  348.       }
  349.       CurPmCount = PMCount;
  350.    }
  351.    if(  RFReq_PM == NULL)
  352.    {
  353.        RFReq_PM = new RfPm_Req;
  354.    }
  355.    RFReq_PM->arfcn            = Arfcn;
  356.    RFReq_PM->sampleNoPerFrame = PMPerFrame;
  357.    RFReq_PM->gain             = CurGain;
  358.    if( CurPmCount>2000 )
  359.    {
  360.      // RFReq_PM->frames = (int)(1.0*2000/PMPerFrame+0.99);
  361.      // CurPmCount -= 2000;
  362.         RFReq_PM->frames = 2000/PMPerFrame;
  363.         CurPmCount -= PMPerFrame * RFReq_PM->frames;
  364.    }
  365.    else
  366.    {  //RFReq_PM->frames = (int)(1.0*CurPmCount/PMPerFrame+0.99);
  367.       RFReq_PM->frames = CurPmCount/PMPerFrame;
  368.       CurPmCount = 0;
  369.    }
  370.    META_RESULT MetaResult = META_Rf_PM_r( m_META_HANDLE_Obj.Get_MainHandle(), RFReq_PM, ::CNF_PowerMeasurement, &RFID_PM, NULL );
  371.    if(MetaResult!=META_SUCCESS)
  372.    {  Confirm( METAAPP_FAIL );  return;  }
  373. }
  374. //-------------------------------------
  375. void __stdcall CRFPM::CNF_PowerMeasurement( const RfPm_Cnf *cnf, const short token, void *usrData )
  376. {
  377.     if(!g_bIsRunning)  return;
  378.     FrequencyBand  FreqBand = Get_FreqBandFromBandIndex(Band);
  379.     HasMeasured = true;
  380.     if(cnf->ok == STATUS_PM_OK)
  381.     {
  382.         RFCnf_PM = *cnf;
  383.         if( RF_ID_SKY74045 == m_uiFinalRfid )
  384.         {
  385.             if( cnf->extra_info.valid && cnf->extra_info.validSamples)
  386.             {
  387.                 EvalPmrcx_I_sky[0]  = EvalPmrcx_I_sky[1];
  388.                 EvalPmrcx_Q_sky[0]  = EvalPmrcx_Q_sky[1];
  389.                 EvalPmrcx_I_sky[1]  = c_sky74045_coef.rx.coef[FreqBand].icorrection;
  390.                 EvalPmrcx_Q_sky[1]  = c_sky74045_coef.rx.coef[FreqBand].qcorrection;
  391.                 EvalDC_I_sky[0] = EvalDC_I_sky[1];
  392.                 EvalDC_Q_sky[0] = EvalDC_Q_sky[1];
  393.                 EvalDC_I_sky[1] = cnf->extra_info.iOffset;
  394.                 EvalDC_Q_sky[1] = cnf->extra_info.qOffset;
  395.             }
  396.         }
  397.         else if( RF_ID_SKY74117 == m_uiFinalRfid || RF_ID_SKY74400 == m_uiFinalRfid )
  398.         {
  399.             if( cnf->extra_info.valid && cnf->extra_info.validSamples)
  400.             {
  401.                 EvalPmrcx_I_sky[0]  = EvalPmrcx_I_sky[1];
  402.                 EvalPmrcx_Q_sky[0]  = EvalPmrcx_Q_sky[1];
  403.                 EvalPmrcx_I_sky[1]  = mc_sky74117_coef.rx.coef[FreqBand].icorrection;
  404.                 EvalPmrcx_Q_sky[1]  = mc_sky74117_coef.rx.coef[FreqBand].qcorrection;
  405.                 EvalDC_I_sky[0] = EvalDC_I_sky[1];
  406.                 EvalDC_Q_sky[0] = EvalDC_Q_sky[1];
  407.                 EvalDC_I_sky[1] = cnf->extra_info.iOffset;
  408.                 EvalDC_Q_sky[1] = cnf->extra_info.qOffset;
  409.             }
  410.         }
  411.         else if( RF_ID_MT6139B == m_uiFinalRfid ||
  412.                  RF_ID_MT6139C == m_uiFinalRfid ||
  413.                  RF_ID_MT6139E == m_uiFinalRfid ||
  414.                  RF_ID_MT6140A == m_uiFinalRfid ||
  415.                  RF_ID_MT6140B == m_uiFinalRfid
  416.                )
  417.         {
  418.             if( DnPwrOn )
  419.             {
  420.                // EvalAcodeI_mt[0]  = EvalAcodeI_mt[1];
  421.                // EvalAcodeQ_mt[0]  = EvalAcodeQ_mt[1];
  422.                 EvalAmcodeI_mt[0] = EvalAmcodeI_mt[1];
  423.                 EvalAmcodeQ_mt[0] = EvalAmcodeQ_mt[1];
  424.                // EvalAcodeI_mt[1]  = uc_mt6139_coef.rx.coef[FreqBand].acodeI;
  425.                // EvalAcodeQ_mt[1]  = uc_mt6139_coef.rx.coef[FreqBand].acodeQ;
  426.                 EvalAmcodeI_mt[1]  = uc_mt6139_coef.rx.coef[FreqBand].amcodeI;
  427.                 EvalAmcodeQ_mt[1]  = uc_mt6139_coef.rx.coef[FreqBand].amcodeQ;
  428.                // EvalMdcOn_AcodeI_mt[0] = EvalMdcOn_AcodeI_mt[1];
  429.                // EvalMdcOn_AcodeQ_mt[0] = EvalMdcOn_AcodeQ_mt[1];
  430.                 EvalMdcOn_AmcodeI_mt[0]= EvalMdcOn_AmcodeI_mt[1];
  431.                 EvalMdcOn_AmcodeQ_mt[0]= EvalMdcOn_AmcodeQ_mt[1];
  432.                // EvalMdcOn_AcodeI_mt[1] = cnf->extra_info.iOffset;
  433.                // EvalMdcOn_AcodeQ_mt[1] = cnf->extra_info.qOffset;
  434.                 EvalMdcOn_AmcodeI_mt[1] = cnf->extra_info.iOffset;
  435.                 EvalMdcOn_AmcodeQ_mt[1] = cnf->extra_info.qOffset;
  436.             }
  437.             else
  438.             {
  439.                // EvalMdcOff_AcodeI_mt[0] = EvalMdcOff_AcodeI_mt[1];
  440.                // EvalMdcOff_AcodeQ_mt[0] = EvalMdcOff_AcodeQ_mt[1];
  441.                 EvalMdcOff_AmcodeI_mt[0]= EvalMdcOff_AmcodeI_mt[1];
  442.                 EvalMdcOff_AmcodeQ_mt[0]= EvalMdcOff_AmcodeQ_mt[1];
  443.               // EvalMdcOff_AcodeI_mt[1] = cnf->extra_info.iOffset;
  444.               //  EvalMdcOff_AcodeQ_mt[1] = cnf->extra_info.qOffset;
  445.                 EvalMdcOff_AmcodeI_mt[1] = cnf->extra_info.iOffset;
  446.                 EvalMdcOff_AmcodeQ_mt[1] = cnf->extra_info.qOffset;
  447.             }
  448.         }
  449.     }
  450.     else
  451.     {
  452.         Confirm( METAAPP_FAIL );  return;
  453.     }
  454.     ActiveMan->SetActiveFunction( ::REQ_PowerMeasurement );
  455. }
  456. //===========================================================================
  457. void CRFPM::REQ_Read_IP2Reg_From_NVRAM_Start(unsigned int rfmod_id)
  458. {
  459.     rf_pm_ptr = this;
  460.     g_bIsRunning = true;
  461.     m_bDownloadTrigger = false;
  462.     m_uiFinalRfid = rfmod_id;
  463.     REQ_Read_IP2Reg_From_NVRAM();
  464. }
  465. //----------------------------------------------------------------------------
  466. void CRFPM::REQ_Read_IP2Reg_From_NVRAM(void)
  467. {
  468.     if (!g_bIsRunning)
  469.     {
  470.         return;
  471.     }
  472.     if (NULL == m_cIP2Buf)
  473.     {
  474.         META_RESULT MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_L1_RFSPECIALCOEF_LID", (int *) &m_uiIP2BufSize);
  475.         if (MetaResult != META_SUCCESS)
  476.         {
  477.             Confirm(METAAPP_FAIL);
  478.             return;
  479.         }
  480.         m_cIP2Buf = new char[m_uiIP2BufSize];
  481.     }
  482.     NVRAMMan->ConfirmCallback = ::CNF_ReadIP2RegFromNVRAM;
  483.     NVRAMMan->REQ_ReadNVRAM_Start("NVRAM_EF_L1_RFSPECIALCOEF_LID",
  484.                                   1,
  485.                                   m_uiIP2BufSize,
  486.                                   m_cIP2Buf
  487.                                 );
  488. }
  489. //-------------------------------------
  490. void CRFPM::CNF_ReadIP2RegFromNVRAM(void)
  491. {
  492.     if (!g_bIsRunning)
  493.     {
  494.         return;
  495.     }
  496.     META_RESULT MetaResult;
  497.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  498.     if (METAAPP_SUCCESS == state)
  499.     {
  500.         if (m_bDownloadTrigger)
  501.         {
  502.             REQ_Write_IP2Reg_To_NVRAM();
  503.         }
  504.         else
  505.         {
  506.             switch (m_uiFinalRfid)
  507.             {
  508.                 case RF_ID_SKY74045:
  509.                 {
  510.                     MetaResult = META_NVRAM_Decompose_SKY74045_RFSpecialCoef(&sky74045_coef, m_cIP2Buf, m_uiIP2BufSize);
  511.                     if(MetaResult != META_SUCCESS)
  512.                     {
  513.                         Confirm(METAAPP_FAIL);
  514.                         return;
  515.                     }
  516.                     Sky74045_Coef_ui2c(sky74045_coef, c_sky74045_coef);
  517.                 }
  518.                 break;
  519.                 case RF_ID_SKY74117:
  520.                 case RF_ID_SKY74400:
  521.                 {
  522.                     MetaResult = META_NVRAM_Decompose_SKY74117_RFSpecialCoef(&m_sky74117_coef, m_cIP2Buf, m_uiIP2BufSize);
  523.                     if (MetaResult != META_SUCCESS)
  524.                     {
  525.                         Confirm(METAAPP_FAIL);
  526.                         return;
  527.                     }
  528.                     Sky74117_Coef_ui2c(m_sky74117_coef, mc_sky74117_coef);
  529.                 }
  530.                 break;
  531.                 case RF_ID_MT6139B:
  532.                 case RF_ID_MT6139C:
  533.                 case RF_ID_MT6139E:
  534.                 case RF_ID_MT6140A:
  535.                 case RF_ID_MT6140B:
  536.                 {
  537.                     MetaResult = META_NVRAM_Decompose_MT6139B_RFSpecialCoef(&mt6139_coef, m_cIP2Buf, m_uiIP2BufSize);
  538.                     if (MetaResult != META_SUCCESS)
  539.                     {
  540.                         Confirm(METAAPP_FAIL);
  541.                         return;
  542.                     }
  543.                     MT6139_Coef_ui2uc(mt6139_coef, uc_mt6139_coef);
  544.                 }
  545.                 break;
  546.             }
  547.             ActiveMan->SetActiveFunction( ::REQ_Finish );
  548.         }
  549.     }
  550.     else
  551.     {   Confirm(state);
  552.     }
  553. }
  554. //===========================================================================
  555. void CRFPM::REQ_Write_IP2Reg_To_NVRAM_Start(unsigned int rfmod_id)
  556. {
  557.     rf_pm_ptr = this;
  558.     g_bIsRunning = true;
  559.     m_bDownloadTrigger = true;
  560.     m_uiFinalRfid = rfmod_id;
  561.     REQ_Read_IP2Reg_From_NVRAM();
  562. }
  563. //---------------------------------------------------------------------------
  564. void CRFPM::REQ_Write_IP2Reg_To_NVRAM(void)
  565. {
  566.     if (!g_bIsRunning)
  567.     {
  568.         return;
  569.     }
  570.     META_RESULT  MetaResult;
  571.     unsigned short lid_ver;
  572.     MetaResult = META_NVRAM_GetLIDVersion("NVRAM_EF_L1_RFSPECIALCOEF_LID", &lid_ver);
  573.     if (lid_ver > NVRAM_EF_L1_RFSPECIALCOEF_LID_VERNO)
  574.     {
  575.         Confirm(METAAPP_NVRAM_LID_VER_NOT_SUPPORT);
  576.         return;
  577.     }
  578.     if (NULL == m_cIP2Buf)
  579.     {
  580.         META_RESULT MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_L1_RFSPECIALCOEF_LID", (int *) &m_uiIP2BufSize);
  581.         if (MetaResult!=META_SUCCESS)
  582.         {
  583.             Confirm(METAAPP_FAIL);
  584.             return;
  585.         }
  586.         m_cIP2Buf = new char[m_uiIP2BufSize];
  587.     }
  588.     switch (m_uiFinalRfid)
  589.     {
  590.         case RF_ID_SKY74045:
  591.         {
  592.             Sky74045_Coef_c2ui(  c_sky74045_coef, sky74045_coef );
  593.             MetaResult = META_NVRAM_Compose_SKY74045_RFSpecialCoef(&sky74045_coef, m_cIP2Buf, m_uiIP2BufSize);
  594.         }
  595.         break;
  596.         case RF_ID_SKY74117:
  597.         case RF_ID_SKY74400:
  598.         {
  599.             Sky74117_Coef_c2ui(  mc_sky74117_coef, m_sky74117_coef );
  600.             MetaResult = META_NVRAM_Compose_SKY74117_RFSpecialCoef(&m_sky74117_coef, m_cIP2Buf, m_uiIP2BufSize);
  601.         }
  602.         break;
  603.         case RF_ID_MT6139B:
  604.         case RF_ID_MT6139C:
  605.         case RF_ID_MT6139E:
  606.         case RF_ID_MT6140A:
  607.         case RF_ID_MT6140B:
  608.         {
  609.             MT6139_Coef_uc2ui( uc_mt6139_coef, mt6139_coef );
  610.             MetaResult = META_NVRAM_Compose_MT6139B_RFSpecialCoef(&mt6139_coef, m_cIP2Buf, m_uiIP2BufSize);
  611.         }
  612.         break;
  613.         default:
  614.         break;
  615.     }
  616.     if (MetaResult != META_SUCCESS)
  617.     {
  618.         Confirm(METAAPP_FAIL);
  619.         return;
  620.     }
  621.     NVRAMMan->ConfirmCallback = ::CNF_WriteIP2RegToNVRAM;
  622.     NVRAMMan->REQ_WriteNVRAM_Start("NVRAM_EF_L1_RFSPECIALCOEF_LID",
  623.                                   1,
  624.                                     m_uiIP2BufSize,
  625.                                     m_cIP2Buf );
  626. }
  627. //-------------------------------------
  628. void CRFPM::CNF_WriteIP2RegToNVRAM(void)
  629. {
  630.     if (!g_bIsRunning)
  631.     {
  632.         return;
  633.     }
  634.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  635.     Confirm(state);
  636. }
  637. #if 0
  638. //==============================================================================
  639. bool  CRFPM::AnyRxLossSectionExist( char *filename )
  640. {
  641.     int         FrequencyBandStart;
  642.     TIniFile   *ini_file;
  643.     ini_file = new TIniFile( filename );
  644.     if( ini_file == NULL ) return false;
  645.    // frmMainSel->Get_FinalBandSupport( band_support );
  646.     if(frmMainSel->cbGSM850->Checked)
  647.    // if( band_support.GSM850 )
  648.     {
  649.         FrequencyBandStart = FrequencyBand850;
  650.     }
  651.     else
  652.     {   FrequencyBandStart = FrequencyBand900;
  653.     }
  654.     for(int band = FrequencyBandStart; band<=FrequencyBand1900; band++)
  655.     {
  656.         if( ini_file->SectionExists( (AnsiString) SUBBAND_NAME[band] ) )
  657.         {
  658.             return true;
  659.         }
  660.     }
  661.     return false;
  662. }
  663. #endif
  664. //==============================================================================
  665. bool  CRFPM::AnyIP2SectionExist( char *filename )
  666. {
  667.     TIniFile   *ini_file;
  668.     ini_file = new TIniFile( filename );
  669.     if( ini_file == NULL ) return false;
  670.     if( ini_file->SectionExists( "GSM850 Sub band, IP2" )  ||
  671.         ini_file->SectionExists( "GSM900 Sub band, IP2" )  ||
  672.         ini_file->SectionExists( "DCS1800 Sub band, IP2" ) ||
  673.         ini_file->SectionExists( "PCS1900 Sub band, IP2" )
  674.       )
  675.     {
  676.         return true;
  677.     }
  678.     return false;
  679. }
  680. //--------------------------------------------------------------------------
  681. bool  CRFPM::REQ_Read_IP2Reg_From_File( char *filename, unsigned int rfmod_id )
  682. {
  683.     TIniFile   *ini_file;
  684.     int         band;
  685.     int         FrequencyBandStart;
  686.     ini_file = new TIniFile( filename );
  687.     if( ini_file == NULL ) return false;
  688.    // frmMainSel->Get_FinalBandSupport( band_support );
  689.     if(frmMainSel->cbGSM850->Checked)
  690.    // if( band_support.GSM850 )
  691.     {
  692.         FrequencyBandStart = FrequencyBand850;
  693.     }
  694.     else
  695.     {   FrequencyBandStart = FrequencyBand900;
  696.     }
  697.     switch( rfmod_id )
  698.     {
  699.         case RF_ID_SKY74045:
  700.         {
  701.             for( band = FrequencyBandStart; band<=FrequencyBand1900; band++)
  702.             {
  703.                  c_sky74045_coef.rx.coef[band].icorrection = ini_file->ReadInteger( SUBBAND_NAME[band],
  704.                                                                                     "icorrection",
  705.                                                                                     0);
  706.                  c_sky74045_coef.rx.coef[band].qcorrection = ini_file->ReadInteger( SUBBAND_NAME[band],
  707.                                                                                     "qcorrection",
  708.                                                                                     0);
  709.             }
  710.         }
  711.         break;
  712.         case RF_ID_SKY74117:
  713.         case RF_ID_SKY74400:
  714.         {
  715.             for( band = FrequencyBandStart; band<=FrequencyBand1900; band++)
  716.             {
  717.                  mc_sky74117_coef.rx.coef[band].icorrection = ini_file->ReadInteger( SUBBAND_NAME[band],
  718.                                                                                     "icorrection",
  719.                                                                                     0);
  720.                  mc_sky74117_coef.rx.coef[band].qcorrection = ini_file->ReadInteger( SUBBAND_NAME[band],
  721.                                                                                     "qcorrection",
  722.                                                                                     0);
  723.             }
  724.         }
  725.         break;
  726.         case RF_ID_MT6139B:
  727.         case RF_ID_MT6139C:
  728.         case RF_ID_MT6139E:
  729.         case RF_ID_MT6140A:
  730.         case RF_ID_MT6140B:
  731.         {
  732.             for( band = FrequencyBandStart; band<=FrequencyBand1900; band++)
  733.             {
  734.                 uc_mt6139_coef.rx.coef[band].acodeI = ini_file->ReadInteger( SUBBAND_NAME[band],
  735.                                                                            "acodeI",
  736.                                                                            0);
  737.                 uc_mt6139_coef.rx.coef[band].amcodeI = ini_file->ReadInteger( SUBBAND_NAME[band],
  738.                                                                            "amcodeI",
  739.                                                                            0);
  740.                 uc_mt6139_coef.rx.coef[band].acodeQ = ini_file->ReadInteger( SUBBAND_NAME[band],
  741.                                                                            "acodeQ",
  742.                                                                            0);
  743.                 uc_mt6139_coef.rx.coef[band].amcodeQ = ini_file->ReadInteger( SUBBAND_NAME[band],
  744.                                                                            "amcodeQ",
  745.                                                                            0);
  746.             }
  747.             uc_mt6139_coef.rx.rxamcalmode = ini_file->ReadInteger( "IP2 control",
  748.                                                                            "rxamcalmode",
  749.                                                                            RXAMCALMODE_MT6139C_NORMAL);
  750.                                                                            
  751.         }
  752.         break;
  753.        // case RF_ID_BRIGHT5P:
  754.         default:
  755.         break;
  756.     }
  757.     delete  ini_file;
  758.     return true;
  759. }
  760. //===========================================================================
  761. bool  CRFPM::REQ_Write_IP2Reg_To_File_Single_Band( char *filename,  unsigned int rfmod_id, int band )
  762. {
  763.     TIniFile   *ini_file;
  764.     int         FrequencyBandStart;
  765.     ini_file = new TIniFile( filename );
  766.     if( ini_file == NULL ) return false;
  767.     switch( rfmod_id )
  768.     {
  769.         case RF_ID_SKY74045:
  770.         {
  771.             ini_file->WriteString( SUBBAND_NAME[band],
  772.                                     "icorrection",
  773.                                     c_sky74045_coef.rx.coef[band].icorrection );
  774.             ini_file->WriteString( SUBBAND_NAME[band],
  775.                                            "qcorrection",
  776.                                            c_sky74045_coef.rx.coef[band].qcorrection );
  777.         }
  778.         break;
  779.         case RF_ID_SKY74117:
  780.         case RF_ID_SKY74400:
  781.         {
  782.             ini_file->WriteString( SUBBAND_NAME[band],
  783.                                     "icorrection",
  784.                                     mc_sky74117_coef.rx.coef[band].icorrection );
  785.             ini_file->WriteString( SUBBAND_NAME[band],
  786.                                            "qcorrection",
  787.                                            mc_sky74117_coef.rx.coef[band].qcorrection );
  788.         }
  789.         break;
  790.         case RF_ID_MT6139B:
  791.         case RF_ID_MT6139C:
  792.         case RF_ID_MT6139E:
  793.         case RF_ID_MT6140A:
  794.         case RF_ID_MT6140B:
  795.         {
  796.             ini_file->WriteString( SUBBAND_NAME[band],
  797.                                         "acodeI",
  798.                                         uc_mt6139_coef.rx.coef[band].acodeI );
  799.             ini_file->WriteString( SUBBAND_NAME[band],
  800.                                         "acodeQ",
  801.                                         uc_mt6139_coef.rx.coef[band].acodeQ );
  802.             ini_file->WriteString( SUBBAND_NAME[band],
  803.                                         "amcodeI",
  804.                                         uc_mt6139_coef.rx.coef[band].amcodeI );
  805.             ini_file->WriteString( SUBBAND_NAME[band],
  806.                                         "amcodeQ",
  807.                                         uc_mt6139_coef.rx.coef[band].amcodeQ );
  808.         }
  809.         break;
  810.         default:
  811.         break;
  812.     }
  813.     return true;
  814. }
  815. //---------------------------------------------------------------------------
  816. bool  CRFPM::REQ_Write_IP2Reg_RxAmCalMode_To_File( char *filename,  unsigned int rfmod_id )
  817. {
  818.     TIniFile   *ini_file;
  819.     int         FrequencyBandStart;
  820.     ini_file = new TIniFile( filename );
  821.     if( ini_file == NULL ) return false;
  822.     switch( rfmod_id )
  823.     {
  824.         case RF_ID_MT6139B:
  825.         case RF_ID_MT6139C:
  826.         case RF_ID_MT6139E:
  827.         case RF_ID_MT6140A:
  828.         case RF_ID_MT6140B:
  829.               ini_file->WriteString( "IP2 control",
  830.                                         "rxamcalmode",
  831.                                         uc_mt6139_coef.rx.rxamcalmode );
  832.         break;
  833.     }
  834.     return true;
  835. }
  836. //---------------------------------------------------------------------------
  837. bool CRFPM::REQ_Write_IP2Reg_To_File(char *filename, unsigned int rfmod_id)
  838. {
  839.     TIniFile   *ini_file;
  840.     int         band;
  841.     int         FrequencyBandStart;
  842.     ini_file = new TIniFile(filename);
  843.     if (NULL == ini_file)
  844.     {
  845.         return false;
  846.     }
  847.   //  frmMainSel->Get_FinalBandSupport( band_support );
  848.     if(frmMainSel->cbGSM850->Checked)
  849.    // if( band_support.GSM850 )
  850.     {
  851.         FrequencyBandStart = FrequencyBand850;
  852.     }
  853.     else
  854.     {   FrequencyBandStart = FrequencyBand900;
  855.     }
  856.     switch( rfmod_id )
  857.     {
  858.         case RF_ID_SKY74045:
  859.         {
  860.             for( band = FrequencyBandStart; band<=FrequencyBand1900; band++)
  861.             {
  862.                     ini_file->WriteString( SUBBAND_NAME[band],
  863.                                            "icorrection",
  864.                                            c_sky74045_coef.rx.coef[band].icorrection );
  865.                     ini_file->WriteString( SUBBAND_NAME[band],
  866.                                            "qcorrection",
  867.                                            c_sky74045_coef.rx.coef[band].qcorrection );
  868.             }
  869.         }
  870.         break;
  871.         case RF_ID_SKY74117:
  872.         case RF_ID_SKY74400:
  873.         {
  874.             for( band = FrequencyBandStart; band<=FrequencyBand1900; band++)
  875.             {
  876.                     ini_file->WriteString( SUBBAND_NAME[band],
  877.                                            "icorrection",
  878.                                            mc_sky74117_coef.rx.coef[band].icorrection );
  879.                     ini_file->WriteString( SUBBAND_NAME[band],
  880.                                            "qcorrection",
  881.                                            mc_sky74117_coef.rx.coef[band].qcorrection );
  882.             }
  883.         }
  884.         break;
  885.         case RF_ID_MT6139B:
  886.         case RF_ID_MT6139C:
  887.         case RF_ID_MT6139E:
  888.         case RF_ID_MT6140A:
  889.         case RF_ID_MT6140B:
  890.         {
  891.             for( band = FrequencyBandStart; band<=FrequencyBand1900; band++)
  892.             {
  893.                 ini_file->WriteString( SUBBAND_NAME[band],
  894.                                         "acodeI",
  895.                                         uc_mt6139_coef.rx.coef[band].acodeI );
  896.                 ini_file->WriteString( SUBBAND_NAME[band],
  897.                                         "acodeQ",
  898.                                         uc_mt6139_coef.rx.coef[band].acodeQ );
  899.                 ini_file->WriteString( SUBBAND_NAME[band],
  900.                                         "amcodeI",
  901.                                         uc_mt6139_coef.rx.coef[band].amcodeI );
  902.                 ini_file->WriteString( SUBBAND_NAME[band],
  903.                                         "amcodeQ",
  904.                                         uc_mt6139_coef.rx.coef[band].amcodeQ );
  905.             }
  906.             ini_file->WriteString( "IP2 control",
  907.                                         "rxamcalmode",
  908.                                         uc_mt6139_coef.rx.rxamcalmode );
  909.         }
  910.         break;
  911.         default:
  912.         break;
  913.     }
  914.     return true;
  915. }
  916. //==============================================================================
  917. bool  CRFPM::Sky74045_Coef_c2ui( c_RFMod_Sky74045_Coef_T &c_sky74045_coef, RF_SKY74045_Coef_T &ui_sky74045_coef)
  918. {
  919.     unsigned char icorrection;
  920.     unsigned char qcorrection;
  921.     AnsiString as_correction;
  922.     for(int i=0; i<sizeof(c_sky74045_coef.rx.coef)/sizeof(c_sky74045_coef.rx.coef[0]); i++)
  923.     {
  924.         if( c_sky74045_coef.rx.coef[i].icorrection < 0 )
  925.         {
  926.             as_correction = IntToStr( c_sky74045_coef.rx.coef[i].icorrection );
  927.             AnsiString_To_msbUnsignedChar( as_correction, icorrection, -127, 127 );
  928.             ui_sky74045_coef.rx.coef[i].icorrection = (unsigned int)  icorrection;
  929.         }
  930.         else
  931.         {
  932.             ui_sky74045_coef.rx.coef[i].icorrection = c_sky74045_coef.rx.coef[i].icorrection & 0x0000007f;
  933.         }
  934.         if( c_sky74045_coef.rx.coef[i].qcorrection < 0 )
  935.         {
  936.             as_correction = IntToStr( c_sky74045_coef.rx.coef[i].qcorrection );
  937.             AnsiString_To_msbUnsignedChar( as_correction, qcorrection, -127, 127 );
  938.             ui_sky74045_coef.rx.coef[i].qcorrection = (unsigned int)  qcorrection;
  939.         }
  940.         else
  941.         {
  942.             ui_sky74045_coef.rx.coef[i].qcorrection = c_sky74045_coef.rx.coef[i].qcorrection & 0x0000007f;
  943.         }
  944.     }
  945.     return true;
  946. }
  947. //------------------------------------------------------------------------------
  948. bool  CRFPM::Sky74045_Coef_ui2c( RF_SKY74045_Coef_T &ui_sky74045_coef, c_RFMod_Sky74045_Coef_T &c_sky74045_coef)
  949. {
  950.     signed char icorrection;
  951.     signed char qcorrection;
  952.     AnsiString as_correction;
  953.     for(int i=0; i<sizeof(ui_sky74045_coef.rx.coef)/sizeof(ui_sky74045_coef.rx.coef[0]); i++)
  954.     {
  955.         if( ui_sky74045_coef.rx.coef[i].icorrection & 0x00000080 )
  956.         {
  957.             icorrection = ui_sky74045_coef.rx.coef[i].icorrection  & 0x0000007F;
  958.             as_correction = IntToStr( icorrection );
  959.             as_correction = "-" + as_correction;
  960.             c_sky74045_coef.rx.coef[i].icorrection = as_correction.ToInt();
  961.         }
  962.         else
  963.         {
  964.             c_sky74045_coef.rx.coef[i].icorrection = ui_sky74045_coef.rx.coef[i].icorrection & 0x0000007f;
  965.         }
  966.         if( ui_sky74045_coef.rx.coef[i].qcorrection & 0x00000080 )
  967.         {
  968.             qcorrection = ui_sky74045_coef.rx.coef[i].qcorrection  & 0x0000007F;
  969.             as_correction = IntToStr( qcorrection );
  970.             as_correction = "-" + as_correction;
  971.             c_sky74045_coef.rx.coef[i].qcorrection = as_correction.ToInt();
  972.         }
  973.         else
  974.         {
  975.             c_sky74045_coef.rx.coef[i].qcorrection = ui_sky74045_coef.rx.coef[i].qcorrection & 0x0000007f;
  976.         }
  977.     }
  978.     return true;
  979. }
  980. //==============================================================================
  981. void  CRFPM::Sky74117_Coef_c2ui( c_RFMod_Sky74117_Coef_T &c_sky74117_coef, RF_SKY74117_Coef_T &ui_sky74117_coef)
  982. {
  983.     unsigned char icorrection;
  984.     unsigned char qcorrection;
  985.     AnsiString as_correction;
  986.     for(int i=0; i<sizeof(c_sky74117_coef.rx.coef)/sizeof(c_sky74117_coef.rx.coef[0]); i++)
  987.     {
  988.         if( c_sky74117_coef.rx.coef[i].icorrection < 0 )
  989.         {
  990.             as_correction = IntToStr( c_sky74117_coef.rx.coef[i].icorrection );
  991.             as_correction = as_correction.SubString(2, as_correction.Length()-1);
  992.             ui_sky74117_coef.rx.coef[i].icorrection = (unsigned int) as_correction.ToInt();
  993.             ui_sky74117_coef.rx.pol[i].ipol = 1;
  994.         }
  995.         else
  996.         {
  997.             ui_sky74117_coef.rx.coef[i].icorrection = (unsigned int) c_sky74117_coef.rx.coef[i].icorrection & 0x0000007f;
  998.             ui_sky74117_coef.rx.pol[i].ipol = 0;
  999.         }
  1000.         if( c_sky74117_coef.rx.coef[i].qcorrection < 0 )
  1001.         {
  1002.             as_correction = IntToStr( c_sky74117_coef.rx.coef[i].qcorrection );
  1003.             as_correction = as_correction.SubString(2, as_correction.Length()-1);
  1004.             ui_sky74117_coef.rx.coef[i].qcorrection = (unsigned int) as_correction.ToInt();
  1005.             ui_sky74117_coef.rx.pol[i].qpol = 1;
  1006.         }
  1007.         else
  1008.         {
  1009.             ui_sky74117_coef.rx.coef[i].qcorrection = (unsigned int) c_sky74117_coef.rx.coef[i].qcorrection & 0x0000007f;
  1010.             ui_sky74117_coef.rx.pol[i].qpol = 0;
  1011.         }
  1012.     }
  1013. }
  1014. //------------------------------------------------------------------------------
  1015. void  CRFPM::Sky74117_Coef_ui2c( RF_SKY74117_Coef_T &ui_sky74117_coef, c_RFMod_Sky74117_Coef_T &c_sky74117_coef)
  1016. {
  1017.     signed char icorrection;
  1018.     signed char qcorrection;
  1019.     AnsiString as_correction;
  1020.     for(int i=0; i<sizeof(ui_sky74117_coef.rx.coef)/sizeof(ui_sky74117_coef.rx.coef[0]); i++)
  1021.     {
  1022.         if( ui_sky74117_coef.rx.pol[i].ipol ) // negtive
  1023.         {
  1024.             icorrection = ui_sky74117_coef.rx.coef[i].icorrection;
  1025.             as_correction = IntToStr( icorrection );
  1026.             as_correction = "-" + as_correction;
  1027.             c_sky74117_coef.rx.coef[i].icorrection = as_correction.ToInt();
  1028.         }
  1029.         else
  1030.         {
  1031.             c_sky74117_coef.rx.coef[i].icorrection = ui_sky74117_coef.rx.coef[i].icorrection;
  1032.         }
  1033.         if( ui_sky74117_coef.rx.pol[i].qpol ) // negtive
  1034.         {
  1035.             qcorrection = ui_sky74117_coef.rx.coef[i].qcorrection;
  1036.             as_correction = IntToStr( qcorrection );
  1037.             as_correction = "-" + as_correction;
  1038.             c_sky74117_coef.rx.coef[i].qcorrection = as_correction.ToInt();
  1039.         }
  1040.         else
  1041.         {
  1042.             c_sky74117_coef.rx.coef[i].qcorrection = ui_sky74117_coef.rx.coef[i].qcorrection;
  1043.         }
  1044.     }
  1045.     
  1046. }
  1047. //------------------------------------------------------------------------------
  1048. void  CRFPM::MT6139_Coef_uc2ui( uc_RFMod_MT6139_Coef_T &uc_mt6139_coef, RF_MT6139B_Coef_T &ui_mt6139_coef)
  1049. {
  1050.     for(int i=0; i<sizeof(uc_mt6139_coef.rx.coef)/sizeof(uc_mt6139_coef.rx.coef[0]); i++)
  1051.     {
  1052.         ui_mt6139_coef.rx.coef[i].acode = (uc_mt6139_coef.rx.coef[i].acodeI<<6 | uc_mt6139_coef.rx.coef[i].acodeQ) & 0x0FFF;
  1053.         ui_mt6139_coef.rx.coef[i].amcode = (uc_mt6139_coef.rx.coef[i].amcodeI<<8 | uc_mt6139_coef.rx.coef[i].amcodeQ) & 0xFFFF;
  1054.     }
  1055.     ui_mt6139_coef.rx.rxamcalmode = uc_mt6139_coef.rx.rxamcalmode;
  1056.     
  1057. }
  1058. //------------------------------------------------------------------------------
  1059. void  CRFPM::MT6139_Coef_ui2uc( RF_MT6139B_Coef_T &ui_mt6139_coef, uc_RFMod_MT6139_Coef_T &uc_mt6139_coef)
  1060. {
  1061.     for(int i=0; i<sizeof(ui_mt6139_coef.rx.coef)/sizeof(ui_mt6139_coef.rx.coef[0]); i++)
  1062.     {
  1063.         uc_mt6139_coef.rx.coef[i].acodeI = (ui_mt6139_coef.rx.coef[i].acode >> 6) & 0x3F;
  1064.         uc_mt6139_coef.rx.coef[i].acodeQ = (ui_mt6139_coef.rx.coef[i].acode) & 0x3F;
  1065.         uc_mt6139_coef.rx.coef[i].amcodeI = (ui_mt6139_coef.rx.coef[i].amcode >> 8) & 0xFF;
  1066.         uc_mt6139_coef.rx.coef[i].amcodeQ = (ui_mt6139_coef.rx.coef[i].amcode) & 0xFF;
  1067.     }
  1068.     uc_mt6139_coef.rx.rxamcalmode = ui_mt6139_coef.rx.rxamcalmode;
  1069. }
  1070. //------------------------------------------------------------------------------
  1071. signed char  CRFPM::Get_realcoefofcx( unsigned char cx, unsigned int rfid )
  1072. {
  1073.     int i_realcoef;
  1074.     signed char c_realcoef;
  1075.     if( (unsigned int) RF_ID_SKY74045 == rfid )
  1076.     {
  1077.         if (cx <= 127)
  1078.     i_realcoef =  (cx * (-1)) & 0xFF;
  1079.         else
  1080.             i_realcoef = (255-cx) & 0xFF;
  1081.     }
  1082.     else if( (unsigned int) RF_ID_SKY74117 == rfid || (unsigned int) RF_ID_SKY74400 == rfid )
  1083.     {
  1084.         if (cx <= 63)
  1085.     i_realcoef =  (cx * (-1)) & 0xFF;
  1086.         else
  1087.             i_realcoef = (127-cx) & 0xFF;
  1088.     }
  1089.     c_realcoef = (signed char) i_realcoef & 0xFF;
  1090.     return c_realcoef;
  1091. }
  1092. //------------------------------------------------------------------------------
  1093. unsigned char  CRFPM::Get_cxofrealcoef( signed char realcoef, unsigned int rfid )
  1094. {
  1095.     unsigned char cx;
  1096.     if( (unsigned int) RF_ID_SKY74045 == rfid )
  1097.     {
  1098.         if (realcoef < 0)
  1099.     cx = (unsigned char) realcoef * (-1);
  1100.         else
  1101.             cx = 255-realcoef;
  1102.     }
  1103.     else if( (unsigned int) RF_ID_SKY74117 == rfid || (unsigned int) RF_ID_SKY74400 == rfid )
  1104.     {
  1105.         if (realcoef < 0)
  1106.     cx = (unsigned char) realcoef * (-1);
  1107.         else
  1108.             cx = 127-realcoef;
  1109.     }
  1110.     return cx;
  1111. }
  1112. //------------------------------------------------------------------------------
  1113. bool  CRFPM::Get_cxofDC0( IP2vsDC_T  &ip2vsdc, unsigned char &cx )
  1114. {
  1115.     if( (ip2vsdc.c1 - ip2vsdc.c0) == 0 )  return false;
  1116.     int slope = (ip2vsdc.DC1 - ip2vsdc.DC0) / (ip2vsdc.c1 - ip2vsdc.c0);
  1117.     int offset = ip2vsdc.DC0 - slope*ip2vsdc.c0;
  1118.     cx = - offset/slope;
  1119.     return true;
  1120. }
  1121. //------------------------------------------------------------------------------
  1122. bool CRFPM::Evaluate_sky74045(signed char &rcx_I, signed char &rcx_Q, unsigned int rfid)
  1123. {
  1124.     unsigned char c0_I = Get_cxofrealcoef(EvalPmrcx_I_sky[0], rfid);
  1125.     unsigned char c1_I = Get_cxofrealcoef(EvalPmrcx_I_sky[1], rfid);
  1126.     unsigned char c0_Q = Get_cxofrealcoef(EvalPmrcx_Q_sky[0], rfid);
  1127.     unsigned char c1_Q = Get_cxofrealcoef(EvalPmrcx_Q_sky[1], rfid);
  1128.     int  f0_I = EvalDC_I_sky[0];
  1129.     int  f1_I = EvalDC_I_sky[1];
  1130.     int  f0_Q = EvalDC_Q_sky[0];
  1131.     int  f1_Q = EvalDC_Q_sky[1];
  1132.     rcx_I = 0;
  1133.     rcx_Q = 0;
  1134.     if ((c1_I - c0_I) == 0 && (c1_Q - c0_Q)==0)
  1135.     {
  1136.         return false;
  1137.     }
  1138.     if ((c1_I - c0_I) != 0)
  1139.     {
  1140.         float slope_I = 1.0*(f1_I - f0_I) / (c1_I - c0_I);
  1141.         int offset_I = f0_I - slope_I*c0_I;
  1142.         if (slope_I != 0)
  1143.         {
  1144.             unsigned char cx_I = - offset_I/slope_I;
  1145.             rcx_I = Get_realcoefofcx( cx_I, rfid );
  1146.             if (rcx_I < SKY74045_RCX_MIN)
  1147.             {
  1148.                 rcx_I = SKY74045_RCX_MIN;
  1149.             }
  1150.         }
  1151.     }
  1152.     if ((c1_Q - c0_Q) != 0)
  1153.     {
  1154.         float slope_Q = 1.0*(f1_Q - f0_Q) / (c1_Q - c0_Q);
  1155.         int offset_Q = f0_Q - slope_Q*c0_Q;
  1156.         if (slope_Q != 0)
  1157.         {
  1158.             unsigned char cx_Q = - offset_Q/slope_Q;
  1159.             rcx_Q = Get_realcoefofcx( cx_Q, rfid );
  1160.             if (rcx_Q < SKY74045_RCX_MIN)
  1161.             {
  1162.                 rcx_Q = SKY74045_RCX_MIN;
  1163.             }
  1164.         }
  1165.     }
  1166.     return true;
  1167. }
  1168. //------------------------------------------------------------------------------
  1169. bool CRFPM::Evaluate_sky74117( signed char &rcx_I, signed char &rcx_Q, unsigned int rfid )
  1170. {
  1171.     unsigned char  c0_I = Get_cxofrealcoef(EvalPmrcx_I_sky[0], rfid);
  1172.     unsigned char  c1_I = Get_cxofrealcoef(EvalPmrcx_I_sky[1], rfid);
  1173.     unsigned char  c0_Q = Get_cxofrealcoef(EvalPmrcx_Q_sky[0], rfid);
  1174.     unsigned char  c1_Q = Get_cxofrealcoef(EvalPmrcx_Q_sky[1], rfid);
  1175.     int  f0_I = EvalDC_I_sky[0];
  1176.     int  f1_I = EvalDC_I_sky[1];
  1177.     int  f0_Q = EvalDC_Q_sky[0];
  1178.     int  f1_Q = EvalDC_Q_sky[1];
  1179.     rcx_I = 0;
  1180.     rcx_Q = 0;
  1181.     if( (c1_I - c0_I) == 0 && (c1_Q - c0_Q)==0 )  return false;
  1182.     if( (c1_I - c0_I) != 0 )
  1183.     {
  1184.         float  slope_I = 1.0*(f1_I - f0_I) / (c1_I - c0_I);
  1185.         int  offset_I = f0_I - slope_I*c0_I;
  1186.         if( slope_I != 0 )
  1187.         {
  1188.             unsigned char cx_I =  - offset_I/slope_I;
  1189.             rcx_I = Get_realcoefofcx( cx_I, rfid );
  1190.             if( rcx_I < SKY74117_RCX_MIN ) rcx_I = SKY74117_RCX_MIN;
  1191.             else if( rcx_I > SKY74117_RCX_MAX ) rcx_I = SKY74117_RCX_MAX;
  1192.         }
  1193.     }
  1194.     if( (c1_Q - c0_Q) != 0 )
  1195.     {
  1196.         float  slope_Q = 1.0*(f1_Q - f0_Q) / (c1_Q - c0_Q);
  1197.         int  offset_Q = f0_Q - slope_Q*c0_Q;
  1198.         if( slope_Q != 0 )
  1199.         {
  1200.             unsigned char cx_Q =  - offset_Q/slope_Q;
  1201.             rcx_Q = Get_realcoefofcx( cx_Q, rfid );
  1202.             if( rcx_Q < SKY74117_RCX_MIN ) rcx_Q = SKY74117_RCX_MIN;
  1203.             else if( rcx_Q > SKY74117_RCX_MAX ) rcx_Q = SKY74117_RCX_MAX;
  1204.         }
  1205.     }
  1206.     return true;
  1207. }
  1208. //------------------------------------------------------------------------------
  1209. bool CRFPM::Evaluate_mt6139( unsigned char &AcodeI0, unsigned char &AcodeQ0,
  1210.                              unsigned char &AmcodeI0, unsigned char &AmcodeQ0 )
  1211. {
  1212.     unsigned char  c0_AcodeI = EvalAcodeI_mt[0];
  1213.     unsigned char  c0_AcodeQ = EvalAcodeQ_mt[0];
  1214.     unsigned char  c1_AcodeI = EvalAcodeI_mt[1];
  1215.     unsigned char  c1_AcodeQ = EvalAcodeQ_mt[1];
  1216.     unsigned char  c0_AmcodeI = EvalAmcodeI_mt[0];
  1217.     unsigned char  c0_AmcodeQ = EvalAmcodeQ_mt[0];
  1218.     unsigned char  c1_AmcodeI = EvalAmcodeI_mt[1];
  1219.     unsigned char  c1_AmcodeQ = EvalAmcodeQ_mt[1];
  1220.   //  EvalDC_AcodeI_mt[0] = EvalMdcOn_AcodeI_mt[0];
  1221.    // EvalDC_AcodeI_mt[1] = EvalMdcOn_AcodeI_mt[1];
  1222.    // EvalDC_AcodeQ_mt[0] = EvalMdcOn_AcodeQ_mt[0];
  1223.    // EvalDC_AcodeQ_mt[1] = EvalMdcOn_AcodeQ_mt[1];
  1224.     EvalDC_AmcodeI_mt[0] = EvalMdcOn_AmcodeI_mt[0]-EvalMdcOff_AmcodeI_mt[0];
  1225.     EvalDC_AmcodeI_mt[1] = EvalMdcOn_AmcodeI_mt[1]-EvalMdcOff_AmcodeI_mt[1];
  1226.     EvalDC_AmcodeQ_mt[0] = EvalMdcOn_AmcodeQ_mt[0]-EvalMdcOff_AmcodeQ_mt[0];
  1227.     EvalDC_AmcodeQ_mt[1] = EvalMdcOn_AmcodeQ_mt[1]-EvalMdcOff_AmcodeQ_mt[1];
  1228.    // int  f0_AcodeI = EvalDC_AcodeI_mt[0];
  1229.    // int  f1_AcodeI = EvalDC_AcodeI_mt[1];
  1230.   //  int  f0_AcodeQ = EvalDC_AcodeQ_mt[0];
  1231.    // int  f1_AcodeQ = EvalDC_AcodeQ_mt[1];
  1232.     int  f0_AmcodeI = EvalDC_AmcodeI_mt[0];
  1233.     int  f1_AmcodeI = EvalDC_AmcodeI_mt[1];
  1234.     int  f0_AmcodeQ = EvalDC_AmcodeQ_mt[0];
  1235.     int  f1_AmcodeQ = EvalDC_AmcodeQ_mt[1];
  1236.     AcodeI0 = 0;
  1237.     AcodeQ0 = 0;
  1238.     AmcodeI0 = 0;
  1239.     AmcodeQ0 = 0;
  1240.     if( (c0_AcodeI - c1_AcodeI) == 0 && (c0_AcodeQ - c1_AcodeQ)==0 &&
  1241.         (c0_AmcodeI - c1_AmcodeI)==0 && (c0_AmcodeQ - c1_AmcodeQ)==0 )  return false;
  1242.     // AcodeI0
  1243.     AcodeI0 = ( c1_AcodeI + c0_AcodeI)/2;
  1244.     if( AcodeI0 > 63 ) AcodeI0 = 63;
  1245.     //if( (c1_AcodeI - c0_AcodeI) != 0 )
  1246.    // {
  1247.    //     float  slope_AcodeI = 1.0*(f1_AcodeI - f0_AcodeI) / (c1_AcodeI - c0_AcodeI);
  1248.     //    int  offset_AcodeI = f0_AcodeI - slope_AcodeI*c0_AcodeI;
  1249.    //     if( slope_AcodeI != 0 )
  1250.    //     {
  1251.    //         AcodeI0 =  - offset_AcodeI/slope_AcodeI;
  1252.    //     }
  1253.    // }
  1254.     // AcodeQ0
  1255.     AcodeQ0 = ( c1_AcodeQ + c0_AcodeQ)/2;
  1256.     if( AcodeQ0 > 63 ) AcodeQ0 = 63;
  1257. //    if( (c1_AcodeQ - c0_AcodeQ) != 0 )
  1258. //    {
  1259. //        float  slope_AcodeQ = 1.0*(f1_AcodeQ - f0_AcodeQ) / (c1_AcodeQ - c0_AcodeQ);
  1260. //        int  offset_AcodeQ = f0_AcodeQ - slope_AcodeQ*c0_AcodeQ;
  1261. //        if( slope_AcodeQ != 0 )
  1262. //        {
  1263. //            AcodeQ0 =  - offset_AcodeQ/slope_AcodeQ;
  1264. //        }
  1265. //    }
  1266.     // AMcodeI0
  1267.     if( (c1_AmcodeI - c0_AmcodeI) != 0 )
  1268.     {
  1269.         float  slope_AmcodeI = 1.0*(f1_AmcodeI - f0_AmcodeI) / (c1_AmcodeI - c0_AmcodeI);
  1270.         int  offset_AmcodeI = f0_AmcodeI - slope_AmcodeI*c0_AmcodeI;
  1271.         if( slope_AmcodeI != 0 )
  1272.         {
  1273.             AmcodeI0 =  - offset_AmcodeI/slope_AmcodeI;
  1274.         }
  1275.     }
  1276.     // AMcodeQ0
  1277.     if( (c1_AmcodeQ - c0_AmcodeQ) != 0 )
  1278.     {
  1279.         float  slope_AmcodeQ = 1.0*(f1_AmcodeQ - f0_AmcodeQ) / (c1_AmcodeQ - c0_AmcodeQ);
  1280.         int  offset_AmcodeQ = f0_AmcodeQ - slope_AmcodeQ*c0_AmcodeQ;
  1281.         if( slope_AmcodeQ != 0 )
  1282.         {
  1283.             AmcodeQ0 =  - offset_AmcodeQ/slope_AmcodeQ;
  1284.         }
  1285.     }
  1286.     return true;
  1287. }
  1288. //==============================================================================
  1289. void  CRFPM::Set_Sky74045Coef( RF_SKY74045_Coef_T  &ui_sky74045_coef )
  1290. {
  1291.     sky74045_coef = ui_sky74045_coef;
  1292. }
  1293. //---------------------------------------------------------------------------
  1294. void  CRFPM::Set_MT6139Coef( RF_MT6139B_Coef_T &ui_mt6139_coef )
  1295. {
  1296.      mt6139_coef = ui_mt6139_coef;
  1297. }
  1298. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1299. void CRFPM::Get_cSky74045Coef( c_RFMod_Sky74045_Coef_T  &char_sky74045_coef )
  1300. {
  1301.     char_sky74045_coef = c_sky74045_coef;
  1302. }
  1303. //---------------------------------------------------------------------------
  1304. void  CRFPM::Set_cSky74045Coef( c_RFMod_Sky74045_Coef_T  &char_sky74045_coef )
  1305. {
  1306.     c_sky74045_coef = char_sky74045_coef;
  1307. }
  1308. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1309. void  CRFPM::Get_cSky74117Coef( c_RFMod_Sky74117_Coef_T  &c_sky74117_coef )
  1310. {
  1311.     c_sky74117_coef = mc_sky74117_coef;
  1312. }
  1313. //---------------------------------------------------------------------------
  1314. void  CRFPM::Set_cSky74117Coef( c_RFMod_Sky74117_Coef_T  &c_sky74117_coef )
  1315. {
  1316.     mc_sky74117_coef = c_sky74117_coef;
  1317. }
  1318. //----------------------------------------------------------------------------
  1319. void  CRFPM::Get_ucMT6139Coef( uc_RFMod_MT6139_Coef_T &uchar_mt6139_coef )
  1320. {
  1321.     uchar_mt6139_coef = uc_mt6139_coef;
  1322. }
  1323. //----------------------------------------------------------------------------
  1324. void  CRFPM::Set_ucMT6139Coef( uc_RFMod_MT6139_Coef_T &uchar_mt6139_coef )
  1325. {
  1326.     uc_mt6139_coef = uchar_mt6139_coef;
  1327. }
  1328. //----------------------------------------------------------------------------
  1329. void  CRFPM::Set_ucMT6139CoefExceptCalMode( uc_RFMod_MT6139_Coef_T &uchar_mt6139_coef )
  1330. {
  1331.     for(int i=0; i<sizeof(uc_mt6139_coef.rx.coef)/sizeof(uc_mt6139_coef.rx.coef[0]); i++)
  1332.     {
  1333.         uc_mt6139_coef.rx.coef[i].acodeI = uchar_mt6139_coef.rx.coef[i].acodeI;
  1334.         uc_mt6139_coef.rx.coef[i].acodeQ = uchar_mt6139_coef.rx.coef[i].acodeQ;
  1335.         uc_mt6139_coef.rx.coef[i].amcodeI = uchar_mt6139_coef.rx.coef[i].amcodeI;
  1336.         uc_mt6139_coef.rx.coef[i].amcodeQ = uchar_mt6139_coef.rx.coef[i].amcodeQ;
  1337.     }
  1338. }
  1339. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1340. void  CRFPM::Get_AcodeFromReg_Start( FrequencyBand  freq_band, uc_RFMod_MT6139_Coef_T &uc_mt6139_coef_par, unsigned int rf_id )
  1341. {
  1342.     rf_pm_ptr = this;
  1343.     g_bIsRunning = true;
  1344.     m_uiFinalRfid =  rf_id;
  1345.     m_FreqBand = freq_band;
  1346.     p_uc_mt6139_coef = &uc_mt6139_coef_par;
  1347.     ActiveMan->SetActiveFunction( ::Get_AcodeFromReg );
  1348. }
  1349. //----------------------------------------------------------------------------
  1350. void  CRFPM::Get_AcodeFromReg( void )
  1351. {
  1352.     if( ! g_bIsRunning )
  1353.     {   Confirm( METAAPP_FAIL );  return;  }
  1354.     unsigned int reg_data;
  1355.   //  unsigned int reg_addr=ADDR_AUXOUT_ACODE;
  1356.     // Acode
  1357.     META_RESULT  MetaResult = META_Rf_GetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, ADDR_MT6139_AUXOUT_CW2, &reg_data);
  1358.     if(MetaResult!=META_SUCCESS)
  1359.     {
  1360.         if( MetaResult!=META_TIMEOUT )
  1361.         {   Confirm( METAAPP_FAIL );  return;  }
  1362.         else
  1363.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  1364.     }
  1365.     uc_mt6139_coef.rx.coef[m_FreqBand].acodeI = (reg_data >> 15) & 0x3F;
  1366.     uc_mt6139_coef.rx.coef[m_FreqBand].acodeQ  = (reg_data >> 9)  & 0x3F;
  1367.     p_uc_mt6139_coef->rx.coef[m_FreqBand].acodeI = uc_mt6139_coef.rx.coef[m_FreqBand].acodeI;
  1368.     p_uc_mt6139_coef->rx.coef[m_FreqBand].acodeQ = uc_mt6139_coef.rx.coef[m_FreqBand].acodeQ;
  1369.     DeCompose_MT6139CW2( reg_data, mt6139_cw2, m_uiFinalRfid );
  1370.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  1371. }
  1372. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1373. void  CRFPM::Get_BCcodeFromReg_Start( FrequencyBand  freq_band, uc_RFMod_MT6139_Coef_T &uc_mt6139_coef_par, unsigned int rf_id  )
  1374. {
  1375.     rf_pm_ptr = this;
  1376.     g_bIsRunning = true;
  1377.     m_FreqBand = freq_band;
  1378.     p_uc_mt6139_coef = &uc_mt6139_coef_par;
  1379.     m_uiFinalRfid = rf_id;
  1380.     ActiveMan->SetActiveFunction( ::Get_BCcodeFromReg );
  1381. }
  1382. //----------------------------------------------------------------------------
  1383. void  CRFPM::Get_BCcodeFromReg( void )
  1384. {
  1385.     if( ! g_bIsRunning )
  1386.     {   Confirm( METAAPP_FAIL );  return;  }
  1387.     unsigned int reg_data;
  1388.     // B, C codeI
  1389.     META_RESULT  MetaResult = META_Rf_GetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, ADDR_MT6139_AUXOUT_CW8, &reg_data);
  1390.     if(MetaResult!=META_SUCCESS)
  1391.     {
  1392.        if( MetaResult!=META_TIMEOUT )
  1393.         {   Confirm( METAAPP_FAIL );  return;  }
  1394.         else
  1395.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  1396.     }
  1397.     uc_mt6139_coef.rx.coef[m_FreqBand].ccodeI = reg_data        & 0x7F;
  1398.     uc_mt6139_coef.rx.coef[m_FreqBand].bcodeI = (reg_data >> 7) & 0x7F;
  1399.     p_uc_mt6139_coef->rx.coef[m_FreqBand].ccodeI = uc_mt6139_coef.rx.coef[m_FreqBand].ccodeI;
  1400.     p_uc_mt6139_coef->rx.coef[m_FreqBand].bcodeI = uc_mt6139_coef.rx.coef[m_FreqBand].bcodeI;
  1401.     DeCompose_MT6139CW8( reg_data, mt6139_cw8, m_uiFinalRfid );
  1402.     // B, C codeQ
  1403.     MetaResult = META_Rf_GetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, ADDR_MT6139_AUXOUT_CW9, &reg_data);
  1404.     if(MetaResult!=META_SUCCESS)
  1405.     {
  1406.         if( MetaResult!=META_TIMEOUT )
  1407.         {   Confirm( METAAPP_FAIL );  return;  }
  1408.         else
  1409.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  1410.     }
  1411.     uc_mt6139_coef.rx.coef[m_FreqBand].ccodeQ = reg_data        & 0x7F;
  1412.     uc_mt6139_coef.rx.coef[m_FreqBand].bcodeQ = (reg_data >> 7) & 0x7F;
  1413.     p_uc_mt6139_coef->rx.coef[m_FreqBand].ccodeQ = uc_mt6139_coef.rx.coef[m_FreqBand].ccodeQ;
  1414.     p_uc_mt6139_coef->rx.coef[m_FreqBand].bcodeQ = uc_mt6139_coef.rx.coef[m_FreqBand].bcodeQ;
  1415.     DeCompose_MT6139CW9( reg_data, mt6139_cw9, m_uiFinalRfid );
  1416.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  1417. }
  1418. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1419. void CRFPM::Get_ABCcodeFromReg_Start( FrequencyBand  freq_band, uc_RFMod_MT6139_Coef_T &uc_mt6139_coef_par, unsigned int rf_id )
  1420. {
  1421.     rf_pm_ptr = this;
  1422.     g_bIsRunning = true;
  1423.     m_uiFinalRfid = rf_id;
  1424.     m_FreqBand = freq_band;
  1425.     p_uc_mt6139_coef = &uc_mt6139_coef_par;
  1426.     ActiveMan->SetActiveFunction( ::Get_ABCcodeFromReg );
  1427. }
  1428. //----------------------------------------------------------------------------
  1429. void  CRFPM::Get_ABCcodeFromReg( void )
  1430. {
  1431.     if( ! g_bIsRunning )
  1432.     {   Confirm( METAAPP_FAIL );  return;  }
  1433.     unsigned int reg_data;
  1434.   //  unsigned int reg_addr=ADDR_AUXOUT_ACODE;
  1435.     // Acode
  1436.     META_RESULT MetaResult = META_Rf_GetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, ADDR_MT6139_AUXOUT_CW2, &reg_data);
  1437.     if(MetaResult!=META_SUCCESS)
  1438.     {
  1439.         if( MetaResult!=META_TIMEOUT )
  1440.         {   Confirm( METAAPP_FAIL );  return;  }
  1441.         else
  1442.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  1443.     }
  1444.     uc_mt6139_coef.rx.coef[m_FreqBand].acodeI = (reg_data >> 15) & 0x3F;
  1445.     uc_mt6139_coef.rx.coef[m_FreqBand].acodeQ  = (reg_data >> 9)  & 0x3F;
  1446.     p_uc_mt6139_coef->rx.coef[m_FreqBand].acodeI = uc_mt6139_coef.rx.coef[m_FreqBand].acodeI;
  1447.     p_uc_mt6139_coef->rx.coef[m_FreqBand].acodeQ = uc_mt6139_coef.rx.coef[m_FreqBand].acodeQ;
  1448.     DeCompose_MT6139CW2( reg_data, mt6139_cw2, m_uiFinalRfid );
  1449.     // B, C codeI
  1450.     MetaResult = META_Rf_GetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, ADDR_MT6139_AUXOUT_CW8, &reg_data);
  1451.     if(MetaResult!=META_SUCCESS)
  1452.     {
  1453.         if( MetaResult!=META_TIMEOUT )
  1454.         {   Confirm( METAAPP_FAIL );  return;  }
  1455.         else
  1456.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  1457.     }
  1458.     uc_mt6139_coef.rx.coef[m_FreqBand].ccodeI = reg_data        & 0x7F;
  1459.     uc_mt6139_coef.rx.coef[m_FreqBand].bcodeI = (reg_data >> 7) & 0x7F;
  1460.     p_uc_mt6139_coef->rx.coef[m_FreqBand].ccodeI = uc_mt6139_coef.rx.coef[m_FreqBand].ccodeI;
  1461.     p_uc_mt6139_coef->rx.coef[m_FreqBand].bcodeI = uc_mt6139_coef.rx.coef[m_FreqBand].bcodeI;
  1462.     DeCompose_MT6139CW8( reg_data, mt6139_cw8, m_uiFinalRfid );
  1463.     // B, C codeQ
  1464.     MetaResult = META_Rf_GetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, ADDR_MT6139_AUXOUT_CW9, &reg_data);
  1465.     if(MetaResult!=META_SUCCESS)
  1466.     {
  1467.         if( MetaResult!=META_TIMEOUT )
  1468.         {   Confirm( METAAPP_FAIL );  return;  }
  1469.         else
  1470.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  1471.     }
  1472.     uc_mt6139_coef.rx.coef[m_FreqBand].ccodeQ = reg_data        & 0x7F;
  1473.     uc_mt6139_coef.rx.coef[m_FreqBand].bcodeQ = (reg_data >> 7) & 0x7F;
  1474.     p_uc_mt6139_coef->rx.coef[m_FreqBand].ccodeQ = uc_mt6139_coef.rx.coef[m_FreqBand].ccodeQ;
  1475.     p_uc_mt6139_coef->rx.coef[m_FreqBand].bcodeQ = uc_mt6139_coef.rx.coef[m_FreqBand].bcodeQ;
  1476.     DeCompose_MT6139CW9( reg_data, mt6139_cw9, m_uiFinalRfid );
  1477.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  1478. }
  1479. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1480. void  CRFPM::Set_MT6139CW2ToReg_Start( unsigned char mode_par, unsigned int rf_id )
  1481. {
  1482.     rf_pm_ptr = this;
  1483.     g_bIsRunning = true;
  1484.     m_uiFinalRfid = rf_id;
  1485.     mode = mode_par;
  1486.     ActiveMan->SetActiveFunction( ::Set_MT6139CW2ToReg );
  1487. }
  1488. //----------------------------------------------------------------------------
  1489. void  CRFPM::Set_MT6139CW2ToReg( void )
  1490. {
  1491.     if( ! g_bIsRunning )
  1492.     {   Confirm( METAAPP_FAIL );  return;  }
  1493.     unsigned int bsi_data;
  1494.     mt6139_cw2.uc_mode = mode;
  1495.     Compose_MT6139CW2( mt6139_cw2, bsi_data, m_uiFinalRfid );
  1496.     META_RESULT MetaResult = META_Rf_SetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, bsi_data);
  1497.     if(MetaResult!=META_SUCCESS)
  1498.     {
  1499.         if( MetaResult!=META_TIMEOUT )
  1500.         {   Confirm( METAAPP_FAIL );  return;  }
  1501.         else
  1502.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  1503.     }
  1504.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  1505. }
  1506. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1507. void  CRFPM::Set_BCcodeToReg_Start( FrequencyBand  freq_band, uc_RFMod_MT6139_Coef_T &uc_mt6139_coef_par, unsigned int rf_id )
  1508. {
  1509.     rf_pm_ptr = this;
  1510.     g_bIsRunning = true;
  1511.     m_FreqBand = freq_band;
  1512.     uc_mt6139_coef = uc_mt6139_coef_par;
  1513.     ActiveMan->SetActiveFunction( ::Set_BCcodeToReg );
  1514. }
  1515. //----------------------------------------------------------------------------
  1516. void  CRFPM::Set_BCcodeToReg( void )
  1517. {
  1518.     if( ! g_bIsRunning )
  1519.     {   Confirm( METAAPP_FAIL );  return;  }
  1520.     unsigned int bsi_data;
  1521.     // CW8
  1522.     mt6139_cw8.uc_dc_dac_bi = uc_mt6139_coef.rx.coef[m_FreqBand].bcodeI;
  1523.     mt6139_cw8.uc_dc_dac_ci = uc_mt6139_coef.rx.coef[m_FreqBand].ccodeI;
  1524.     Compose_MT6139CW8( mt6139_cw8, bsi_data, m_uiFinalRfid );
  1525.    // bsi_data = uc_mt6139_coef_par.rx.coef[FreqBand].bcodeI<<11 | uc_mt6139_coef_par.rx.coef[FreqBand].ccodeI<<4 | ADDR_MT6139_CW8;
  1526.     META_RESULT MetaResult = META_Rf_SetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, bsi_data);
  1527.     if(MetaResult!=META_SUCCESS)
  1528.     {
  1529.         if( MetaResult!=META_TIMEOUT )
  1530.         {   Confirm( METAAPP_FAIL );  return;  }
  1531.         else
  1532.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  1533.     }
  1534.     // CW9
  1535.     mt6139_cw9.uc_dc_dac_bq = uc_mt6139_coef.rx.coef[m_FreqBand].bcodeQ;
  1536.     mt6139_cw9.uc_dc_dac_cq = uc_mt6139_coef.rx.coef[m_FreqBand].ccodeQ;
  1537.     Compose_MT6139CW9( mt6139_cw9, bsi_data, m_uiFinalRfid );
  1538.    // bsi_data = uc_mt6139_coef_par.rx.coef[FreqBand].bcodeQ<<11 | uc_mt6139_coef_par.rx.coef[FreqBand].ccodeQ<<4 | ADDR_MT6139_CW9;
  1539.     MetaResult = META_Rf_SetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, bsi_data);
  1540.     if(MetaResult!=META_SUCCESS)
  1541.     {
  1542.         if( MetaResult!=META_TIMEOUT )
  1543.         {   Confirm( METAAPP_FAIL );  return;  }
  1544.         else
  1545.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  1546.     }
  1547.     #if 0
  1548.     uc_mt6139_coef.rx.coef[FreqBand].bcodeI = uc_mt6139_coef_par.rx.coef[FreqBand].bcodeI;
  1549.     uc_mt6139_coef.rx.coef[FreqBand].bcodeQ = uc_mt6139_coef_par.rx.coef[FreqBand].bcodeQ;
  1550.     uc_mt6139_coef.rx.coef[FreqBand].ccodeI = uc_mt6139_coef_par.rx.coef[FreqBand].ccodeI;
  1551.     uc_mt6139_coef.rx.coef[FreqBand].ccodeQ = uc_mt6139_coef_par.rx.coef[FreqBand].ccodeQ;
  1552.     #endif
  1553.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  1554.     
  1555. }
  1556. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1557. ////////////////////////////        CW2      /////////////////////////////////
  1558. //----------------------------------------------------------------------------
  1559. void  CRFPM::Compose_MT6139CW2( S_MT6139_CW2  &mt6139_cw2_par, unsigned int &bsi_data, unsigned int  rf_id )
  1560. {
  1561.     if( RF_ID_MT6139B == rf_id ||
  1562.         RF_ID_MT6139C == rf_id ||
  1563.         RF_ID_MT6139E == rf_id ||
  1564.         RF_ID_MT6140A == rf_id
  1565.       )
  1566.     {
  1567.         bsi_data = mt6139_cw2_par.uc_dc_dac_ai  << 19 |
  1568.                    mt6139_cw2_par.uc_dc_dac_aq  << 13 |
  1569.                    mt6139_cw2_par.uc_mode       << 10 |
  1570.                    mt6139_cw2_par.uc_gain_table <<  4 |
  1571.                    ADDR_MT6139_CW2;
  1572.     }
  1573.     else
  1574.     {
  1575.         bsi_data = mt6139_cw2_par.uc_dc_dac_ai  << 20 |
  1576.                    mt6139_cw2_par.uc_dc_dac_aq  << 14 |
  1577.                    mt6139_cw2_par.uc_auto_cal   << 13 |
  1578.                    mt6139_cw2_par.uc_mode       << 10 |
  1579.                    mt6139_cw2_par.uc_gain_table << 4 |
  1580.                    ADDR_MT6139_CW2;
  1581.     }
  1582. }
  1583. //----------------------------------------------------------------------------
  1584. void  CRFPM::DeCompose_MT6139CW2( unsigned int reg_data, S_MT6139_CW2  &mt6139_cw2_par, unsigned int  rf_id )
  1585. {
  1586.     if( RF_ID_MT6139B == rf_id ||
  1587.         RF_ID_MT6139C == rf_id ||
  1588.         RF_ID_MT6140A == rf_id
  1589.       )
  1590.     {
  1591.         mt6139_cw2_par.uc_dc_dac_ai        = (reg_data >> 15)  & 0x3F;
  1592.         mt6139_cw2_par.uc_dc_dac_aq        = (reg_data >>  9)  & 0x3F;
  1593.         mt6139_cw2_par.uc_mode             = (reg_data >>  6)  & 0x07;
  1594.         mt6139_cw2_par.uc_gain_table       = (reg_data      )  & 0x3F;
  1595.     }
  1596.     else
  1597.     {
  1598.         mt6139_cw2_par.uc_dc_dac_ai        = (reg_data >> 16)  & 0x3F;
  1599.         mt6139_cw2_par.uc_dc_dac_aq        = (reg_data >> 10)  & 0x3F;
  1600.         mt6139_cw2_par.uc_auto_cal         = (reg_data >>  9)  & 0x01;
  1601.         mt6139_cw2_par.uc_mode             = (reg_data >>  6)  & 0x07;
  1602.         mt6139_cw2_par.uc_gain_table       = (reg_data      )  & 0x3F;
  1603.     }
  1604. }
  1605. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1606. ////////////////////////////        CW7      /////////////////////////////////
  1607. //----------------------------------------------------------------------------
  1608. void  CRFPM::Compose_MT6139CW7( S_MT6139_CW7  &mt6139_cw7_par, unsigned int &bsi_data, unsigned int rf_id )
  1609. {
  1610.      if( RF_ID_MT6139B == rf_id ||
  1611.          RF_ID_MT6139C == rf_id
  1612.        )
  1613.      {
  1614.          bsi_data = (mt6139_cw7_par.uc_reserved<<18)         |
  1615.                    (mt6139_cw7_par.uc_lo_vsw<<15)           |
  1616.                    (mt6139_cw7_par.uc_lpf_corner<<14)       |
  1617.                    (mt6139_cw7_par.uc_auto_cal<<13)         |
  1618.                    (mt6139_cw7_par.uc_auto_gain_select<<12) |
  1619.                    (mt6139_cw7_par.uc_rx_gain<<4)           |
  1620.                    ADDR_MT6139_CW7;
  1621.      }
  1622.      else
  1623.      {
  1624.          bsi_data =(mt6139_cw7_par.uc_lpf_corner<<14)       |
  1625.                    (mt6139_cw7_par.uc_man_cal<<13)         |
  1626.                    (mt6139_cw7_par.uc_auto_gain_select<<12) |
  1627.                    (mt6139_cw7_par.uc_rx_gain<<4)           |
  1628.                    ADDR_MT6139_CW7;
  1629.      }
  1630. }
  1631. //----------------------------------------------------------------------------
  1632. void  CRFPM::DeCompose_MT6139CW7( unsigned int reg_data, S_MT6139_CW7  &mt6139_cw7_par, unsigned int rf_id )
  1633. {
  1634.     if( RF_ID_MT6139B == rf_id ||
  1635.          RF_ID_MT6139C == rf_id
  1636.        )
  1637.     {
  1638.         mt6139_cw7_par.uc_reserved         = (reg_data>>14) & 0x7F;
  1639.         mt6139_cw7_par.uc_lo_vsw           = (reg_data>>11) & 0x07;
  1640.         mt6139_cw7_par.uc_lpf_corner       = (reg_data>>10) & 0x01;
  1641.         mt6139_cw7_par.uc_auto_cal         = (reg_data>>9)  & 0x01;
  1642.         mt6139_cw7_par.uc_auto_gain_select = (reg_data>>8)  & 0x01;
  1643.         mt6139_cw7_par.uc_rx_gain          =  reg_data      & 0xFF;
  1644.     }
  1645.     else
  1646.     {
  1647.         mt6139_cw7_par.uc_lpf_corner       = (reg_data>>10) & 0x01;
  1648.         mt6139_cw7_par.uc_man_cal          = (reg_data>>9)  & 0x01;
  1649.         mt6139_cw7_par.uc_auto_gain_select = (reg_data>>8)  & 0x01;
  1650.         mt6139_cw7_par.uc_rx_gain          =  reg_data      & 0xFF;
  1651.     }
  1652. }
  1653. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1654. void  CRFPM::Set_MT6139CW7ToReg_Start( S_MT6139_CW7  &mt6139_cw7_par, unsigned int rf_id )
  1655. {
  1656.     rf_pm_ptr = this;
  1657.     g_bIsRunning = true;
  1658.     mt6139_cw7 = mt6139_cw7_par;
  1659.     ActiveMan->SetActiveFunction( ::Set_MT6139CW7ToReg );
  1660. }
  1661. //----------------------------------------------------------------------------
  1662. void  CRFPM::Set_MT6139CW7ToReg( void )
  1663. {
  1664.     if( ! g_bIsRunning )
  1665.     {   Confirm( METAAPP_FAIL );  return;  }
  1666.     unsigned int bsi_data;
  1667.     Compose_MT6139CW7( mt6139_cw7, bsi_data, m_uiFinalRfid );
  1668.     META_RESULT MetaResult = META_Rf_SetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, bsi_data);
  1669.     if(MetaResult!=META_SUCCESS)
  1670.     {
  1671.         if( MetaResult!=META_TIMEOUT )
  1672.         {   Confirm( METAAPP_FAIL );  return;  }
  1673.         else
  1674.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  1675.     }
  1676.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  1677. }
  1678. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1679. void  CRFPM::Get_MT6139CW7FromReg_Start( S_MT6139_CW7  &mt6139_cw7_par, unsigned int rfmod_id )
  1680. {
  1681.     rf_pm_ptr = this;
  1682.     g_bIsRunning = true;
  1683.     p_mt6139_cw7 = &mt6139_cw7_par;
  1684.     m_uiFinalRfid = rfmod_id;
  1685.     ActiveMan->SetActiveFunction( ::Get_MT6139CW7FromReg );
  1686. }
  1687. //----------------------------------------------------------------------------
  1688. void  CRFPM::Get_MT6139CW7FromReg( void )
  1689. {
  1690.     if( ! g_bIsRunning )
  1691.     {   Confirm( METAAPP_FAIL );  return;  }
  1692.     unsigned int reg_data;
  1693.     META_RESULT MetaResult = META_Rf_GetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, ADDR_MT6139_AUXOUT_CW7, &reg_data);
  1694.     if(MetaResult!=META_SUCCESS)
  1695.     {
  1696.         if( MetaResult!=META_TIMEOUT )
  1697.         {   Confirm( METAAPP_FAIL );  return;  }
  1698.         else
  1699.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  1700.     }
  1701.     DeCompose_MT6139CW7( reg_data, *p_mt6139_cw7, m_uiFinalRfid );
  1702.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  1703. }
  1704. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1705. ////////////////////////////        CW8      /////////////////////////////////
  1706. //----------------------------------------------------------------------------
  1707. void  CRFPM::Compose_MT6139CW8( S_MT6139_CW8  &mt6139_cw8_par, unsigned int &bsi_data, unsigned int rf_id )
  1708. {
  1709.     bsi_data = (mt6139_cw8_par.uc_reserved  << 18) |
  1710.                (mt6139_cw8_par.uc_dc_dac_bi << 11) |
  1711.                (mt6139_cw8_par.uc_dc_dac_ci <<  4) |
  1712.                 ADDR_MT6139_CW8;
  1713. }
  1714. //----------------------------------------------------------------------------
  1715. void  CRFPM::DeCompose_MT6139CW8( unsigned int reg_data, S_MT6139_CW8  &mt6139_cw8_par, unsigned int rf_id )
  1716. {
  1717.     mt6139_cw8_par.uc_reserved  = (reg_data>>14) & 0x7F;
  1718.     mt6139_cw8_par.uc_dc_dac_bi = (reg_data>>7 ) & 0x7F;
  1719.     mt6139_cw8_par.uc_dc_dac_ci = (reg_data    ) & 0x7F;
  1720. }
  1721. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1722. void  CRFPM::Set_MT6139CW8ToReg_Start( S_MT6139_CW8  &mt6139_cw8_par, unsigned int rf_id )
  1723. {
  1724.     rf_pm_ptr = this;
  1725.     g_bIsRunning = true;
  1726.     mt6139_cw8 = mt6139_cw8_par;
  1727.     ActiveMan->SetActiveFunction( ::Set_MT6139CW8ToReg );
  1728. }
  1729. //----------------------------------------------------------------------------
  1730. void  CRFPM::Set_MT6139CW8ToReg( void )
  1731. {
  1732.     unsigned int bsi_data;
  1733.     Compose_MT6139CW8( mt6139_cw8, bsi_data, m_uiFinalRfid );
  1734.     META_RESULT MetaResult = META_Rf_SetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, bsi_data);
  1735.     if(MetaResult!=META_SUCCESS)
  1736.     {
  1737.         if( MetaResult!=META_TIMEOUT )
  1738.         {   Confirm( METAAPP_FAIL );  return;  }
  1739.         else
  1740.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  1741.     }
  1742.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  1743. }
  1744. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1745. void  CRFPM::Get_MT6139CW8FromReg_Start( S_MT6139_CW8  &mt6139_cw8_par, unsigned int rf_id )
  1746. {
  1747.     rf_pm_ptr = this;
  1748.     g_bIsRunning = true;
  1749.     p_mt6139_cw8 = &mt6139_cw8_par;
  1750.     ActiveMan->SetActiveFunction( ::Get_MT6139CW7FromReg );
  1751. }
  1752. //----------------------------------------------------------------------------
  1753. void  CRFPM::Get_MT6139CW8FromReg( void )
  1754. {
  1755.     if( ! g_bIsRunning )
  1756.     {   Confirm( METAAPP_FAIL );  return;  }
  1757.     unsigned int reg_data;
  1758.     META_RESULT MetaResult = META_Rf_GetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, ADDR_MT6139_AUXOUT_CW8, &reg_data);
  1759.     if(MetaResult!=META_SUCCESS)
  1760.     {
  1761.         if( MetaResult!=META_TIMEOUT )
  1762.         {   Confirm( METAAPP_FAIL );  return;  }
  1763.         else
  1764.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  1765.     }
  1766.     DeCompose_MT6139CW8( reg_data, *p_mt6139_cw8, m_uiFinalRfid );
  1767.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  1768. }
  1769. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1770. ////////////////////////////        CW9      /////////////////////////////////
  1771. //----------------------------------------------------------------------------
  1772. void  CRFPM::Compose_MT6139CW9( S_MT6139_CW9  &mt6139_cw9_par, unsigned int &bsi_data, unsigned int rf_id )
  1773. {
  1774.     bsi_data = (mt6139_cw9_par.uc_reserved << 18) |
  1775.                (mt6139_cw9_par.uc_dc_dac_bq   << 11) |
  1776.                (mt6139_cw9_par.uc_dc_dac_cq   <<  4) |
  1777.                 ADDR_MT6139_CW9;
  1778. }
  1779. //----------------------------------------------------------------------------
  1780. void  CRFPM::DeCompose_MT6139CW9( unsigned int reg_data, S_MT6139_CW9  &mt6139_cw9_par, unsigned int rf_id )
  1781. {
  1782.     mt6139_cw9_par.uc_reserved  = (reg_data>>14) & 0x7F;
  1783.     mt6139_cw9_par.uc_dc_dac_bq = (reg_data>>7 ) & 0x7F;
  1784.     mt6139_cw9_par.uc_dc_dac_cq = (reg_data    ) & 0x7F;
  1785. }
  1786. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1787. void  CRFPM::Set_MT6139CW9ToReg_Start( S_MT6139_CW9  &mt6139_cw9_par, unsigned int rf_id )
  1788. {
  1789.     rf_pm_ptr = this;
  1790.     g_bIsRunning = true;
  1791.     mt6139_cw9 = mt6139_cw9_par;
  1792.     ActiveMan->SetActiveFunction( ::Set_MT6139CW9ToReg );
  1793. }
  1794. //----------------------------------------------------------------------------
  1795. void  CRFPM::Set_MT6139CW9ToReg( void )
  1796. {
  1797.     if( ! g_bIsRunning )
  1798.     {   Confirm( METAAPP_FAIL );  return;  }
  1799.     unsigned int bsi_data;
  1800.     Compose_MT6139CW9( mt6139_cw9, bsi_data, m_uiFinalRfid );
  1801.     META_RESULT MetaResult = META_Rf_SetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, bsi_data);
  1802.     if(MetaResult!=META_SUCCESS)
  1803.     {
  1804.         if( MetaResult!=META_TIMEOUT )
  1805.         {   Confirm( METAAPP_FAIL );  return;  }
  1806.         else
  1807.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  1808.     }
  1809.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  1810. }
  1811. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1812. void  CRFPM::Get_MT6139CW9FromReg_Start( S_MT6139_CW9  &mt6139_cw9_par, unsigned int rf_id )
  1813. {
  1814.     rf_pm_ptr = this;
  1815.     g_bIsRunning = true;
  1816.     p_mt6139_cw9 = &mt6139_cw9_par;
  1817.     ActiveMan->SetActiveFunction( ::Get_MT6139CW9FromReg );
  1818. }
  1819. //----------------------------------------------------------------------------
  1820. void  CRFPM::Get_MT6139CW9FromReg( void )
  1821. {
  1822.     if( ! g_bIsRunning )
  1823.     {   Confirm( METAAPP_FAIL );  return;  }
  1824.     unsigned int reg_data;
  1825.     META_RESULT MetaResult = META_Rf_GetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, ADDR_MT6139_AUXOUT_CW9, &reg_data);
  1826.     if(MetaResult!=META_SUCCESS)
  1827.     {
  1828.         if( MetaResult!=META_TIMEOUT )
  1829.         {   Confirm( METAAPP_FAIL );  return;  }
  1830.         else
  1831.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  1832.     }
  1833.     DeCompose_MT6139CW9( reg_data, *p_mt6139_cw9, m_uiFinalRfid );
  1834.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  1835. }
  1836. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1837. ////////////////////////////        CW10      ////////////////////////////////
  1838. //----------------------------------------------------------------------------
  1839. void  CRFPM::Set_MT6139AmcodeToReg_Start( S_MT6139_CW10  &mt6139_cw10_par, unsigned int rf_id )
  1840. {
  1841.     mt6139_cw10 = mt6139_cw10_par;
  1842. }
  1843. //----------------------------------------------------------------------------
  1844. void  CRFPM::Set_MT6139AmcodeToReg( S_MT6139_CW10  &mt6139_cw10_par, unsigned int rf_id )
  1845. {
  1846. #if 0
  1847.     unsigned int bsi_data;
  1848.     Compose_MT6139CW10( mt6139_cw10_par, bsi_data );
  1849.     MetaResult = META_Rf_SetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, bsi_data);
  1850.     if(MetaResult!=META_SUCCESS)
  1851.        return false;
  1852.     return true;
  1853. #endif
  1854. }
  1855. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1856. void  CRFPM::Set_MT6139CoefToReg_Start( uc_RFMod_MT6139_Coef_T &uc_mt6139_coef_par )
  1857. {
  1858.     rf_pm_ptr = this;
  1859.     g_bIsRunning = true;
  1860.     uc_mt6139_coef = uc_mt6139_coef_par;
  1861.     ActiveMan->SetActiveFunction( ::Set_MT6139CoefToReg );
  1862. }
  1863. //----------------------------------------------------------------------------
  1864. void  CRFPM::Set_MT6139CoefToReg( void )
  1865. {
  1866.     if( ! g_bIsRunning )
  1867.     {   Confirm( METAAPP_FAIL );  return;  }
  1868.     MT6139_Coef_uc2ui( uc_mt6139_coef, mt6139_coef);
  1869.     META_RESULT MetaResult = META_Rf_MT6139B_SetSpecialCoef_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, &mt6139_coef);
  1870.     if(MetaResult!=META_SUCCESS)
  1871.     {
  1872.         if( MetaResult!=META_TIMEOUT )
  1873.         {   Confirm( METAAPP_FAIL );  return;  }
  1874.         else
  1875.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  1876.     }
  1877.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  1878. }
  1879. //===========================================================================
  1880. ////////////////////////////   Sky74117 and Sky74400  ///////////////////////
  1881. //===========================================================================
  1882. void  CRFPM::Compose_Sky74117_Mag( FrequencyBand freqband, c_RFMod_Sky74117_Coef_T  &c_sky74117_coef, SKY74117_IP2CW_MAG  &sky74117_mag_par )
  1883. {
  1884.     RF_SKY74117_Coef_T ui_sky74117_coef;
  1885.     Sky74117_Coef_c2ui( c_sky74117_coef, ui_sky74117_coef);
  1886.     sky74117_mag_par.i_temp = 0;
  1887.     sky74117_mag_par.q_temp = 0;
  1888.     sky74117_mag_par.i_mag  = ui_sky74117_coef.rx.coef[freqband].icorrection;
  1889.     sky74117_mag_par.q_mag  = ui_sky74117_coef.rx.coef[freqband].qcorrection;
  1890. }
  1891. //---------------------------------------------------------------------------
  1892. void  CRFPM::Compose_Sky74117_Pol( c_RFMod_Sky74117_Coef_T  &c_sky74117_coef, SKY74117_IP2CW_POL  &sky74117_pol_par )
  1893. {
  1894.     RF_SKY74117_Coef_T ui_sky74117_coef;
  1895.     Sky74117_Coef_c2ui( c_sky74117_coef, ui_sky74117_coef);
  1896.     sky74117_pol_par.reserved     = 0;
  1897.     sky74117_pol_par.ip2_temp_ena = 0;
  1898.     sky74117_pol_par.i_pcs_pol    = (unsigned char) ui_sky74117_coef.rx.pol[FrequencyBand1900].ipol;
  1899.     sky74117_pol_par.i_dcs_pol    = (unsigned char) ui_sky74117_coef.rx.pol[FrequencyBand1800].ipol;
  1900.     sky74117_pol_par.i_gsm_pol    = (unsigned char) ui_sky74117_coef.rx.pol[FrequencyBand900 ].ipol;
  1901.     sky74117_pol_par.i_gsm850_pol = (unsigned char) ui_sky74117_coef.rx.pol[FrequencyBand850 ].ipol;
  1902.     sky74117_pol_par.q_pcs_pol    = (unsigned char) ui_sky74117_coef.rx.pol[FrequencyBand1900].qpol;
  1903.     sky74117_pol_par.q_dcs_pol    = (unsigned char) ui_sky74117_coef.rx.pol[FrequencyBand1800].qpol;
  1904.     sky74117_pol_par.q_gsm_pol    = (unsigned char) ui_sky74117_coef.rx.pol[FrequencyBand900 ].qpol;
  1905.     sky74117_pol_par.q_gsm850_pol = (unsigned char) ui_sky74117_coef.rx.pol[FrequencyBand850 ].qpol;
  1906.     sky74117_pol_par.ip2_coef     = 1;
  1907.     sky74117_pol_par.ip2_pol_cal  = 1;
  1908.     sky74117_pol_par.cal_ctrl     = 0;
  1909. }
  1910. //---------------------------------------------------------------------------
  1911. void  CRFPM::Compose_Sky74117_GSM850CW( SKY74117_IP2CW_MAG  &sky74117_mag_par, unsigned int &bsi_data )
  1912. {
  1913.     sky74117_mag_par.i_temp = 0;
  1914.     sky74117_mag_par.q_temp = 0;
  1915.     bsi_data = sky74117_mag_par.i_mag <<18 |
  1916.                sky74117_mag_par.q_mag <<12 |
  1917.                sky74117_mag_par.i_temp<< 9 |
  1918.                sky74117_mag_par.q_temp<< 6 |
  1919.                ADDR_SKY74117_IP2_GSM850;
  1920. }
  1921. //----------------------------------------------------------------------------
  1922. void  CRFPM::DeCompose_Sky74117_GSM850CW( unsigned int reg_data, SKY74117_IP2CW_MAG  &sky74117_mag_par)
  1923. {
  1924.     sky74117_mag_par.i_mag   = (reg_data>>18) & 0x3F;
  1925.     sky74117_mag_par.q_mag   = (reg_data>>12) & 0x3F;
  1926.     sky74117_mag_par.i_temp  = (reg_data>> 9) & 0x07;
  1927.     sky74117_mag_par.q_temp  = (reg_data>> 6) & 0x07;
  1928. }
  1929. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1930. void  CRFPM::Compose_Sky74117_GSM900CW( SKY74117_IP2CW_MAG  &sky74117_mag_par, unsigned int &bsi_data )
  1931. {
  1932.     sky74117_mag_par.i_temp = 0;
  1933.     sky74117_mag_par.q_temp = 0;
  1934.     bsi_data = sky74117_mag_par.i_mag <<18 |
  1935.                sky74117_mag_par.q_mag <<12 |
  1936.                sky74117_mag_par.i_temp<< 9 |
  1937.                sky74117_mag_par.q_temp<< 6 |
  1938.                ADDR_SKY74117_IP2_GSM900;
  1939. }
  1940. //----------------------------------------------------------------------------
  1941. void  CRFPM::DeCompose_Sky74117_GSM900CW( unsigned int reg_data, SKY74117_IP2CW_MAG  &sky74117_mag_par)
  1942. {
  1943.     sky74117_mag_par.i_mag   = (reg_data>>18) & 0x3F;
  1944.     sky74117_mag_par.q_mag   = (reg_data>>12) & 0x3F;
  1945.     sky74117_mag_par.i_temp  = (reg_data>> 9) & 0x07;
  1946.     sky74117_mag_par.q_temp  = (reg_data>> 6) & 0x07;
  1947. }
  1948. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1949. void  CRFPM::Compose_Sky74117_DCS1800CW( SKY74117_IP2CW_MAG  &sky74117_mag_par, unsigned int &bsi_data )
  1950. {
  1951.     sky74117_mag_par.i_temp = 0;
  1952.     sky74117_mag_par.q_temp = 0;
  1953.     bsi_data = sky74117_mag_par.i_mag <<18 |
  1954.                sky74117_mag_par.q_mag <<12 |
  1955.                sky74117_mag_par.i_temp<< 9 |
  1956.                sky74117_mag_par.q_temp<< 6 |
  1957.                ADDR_SKY74117_IP2_DCS1800;
  1958. }
  1959. //----------------------------------------------------------------------------
  1960. void  CRFPM::DeCompose_Sky74117_DCS1800CW( unsigned int reg_data, SKY74117_IP2CW_MAG  &sky74117_mag_par)
  1961. {
  1962.     sky74117_mag_par.i_mag   = (reg_data>>18) & 0x3F;
  1963.     sky74117_mag_par.q_mag   = (reg_data>>12) & 0x3F;
  1964.     sky74117_mag_par.i_temp  = (reg_data>> 9) & 0x07;
  1965.     sky74117_mag_par.q_temp  = (reg_data>> 6) & 0x07;
  1966. }
  1967. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1968. void  CRFPM::Compose_Sky74117_PCS1900CW( SKY74117_IP2CW_MAG  &sky74117_mag_par, unsigned int &bsi_data )
  1969. {
  1970.     sky74117_mag_par.i_temp = 0;
  1971.     sky74117_mag_par.q_temp = 0;
  1972.     bsi_data = sky74117_mag_par.i_mag <<18 |
  1973.                sky74117_mag_par.q_mag <<12 |
  1974.                sky74117_mag_par.i_temp<< 9 |
  1975.                sky74117_mag_par.q_temp<< 6 |
  1976.                ADDR_SKY74117_IP2_PCS1900;
  1977. }
  1978. //----------------------------------------------------------------------------
  1979. void  CRFPM::DeCompose_Sky74117_PCS1900CW( unsigned int reg_data, SKY74117_IP2CW_MAG  &sky74117_mag_par)
  1980. {
  1981.     sky74117_mag_par.i_mag   = (reg_data>>18) & 0x3F;
  1982.     sky74117_mag_par.q_mag   = (reg_data>>12) & 0x3F;
  1983.     sky74117_mag_par.i_temp  = (reg_data>> 9) & 0x07;
  1984.     sky74117_mag_par.q_temp  = (reg_data>> 6) & 0x07;
  1985. }
  1986. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1987. void  CRFPM::Compose_Sky74117_PolCW( SKY74117_IP2CW_POL  &sky74117_pol_par, unsigned int &bsi_data )
  1988. {
  1989.     sky74117_pol_par.reserved     = 0;
  1990.     sky74117_pol_par.ip2_temp_ena = 0;
  1991.     sky74117_pol_par.ip2_coef     = 1;
  1992.     sky74117_pol_par.ip2_pol_cal  = 1;
  1993.     sky74117_pol_par.cal_ctrl     = 0;
  1994.     bsi_data = sky74117_pol_par.reserved     <<20 |
  1995.                sky74117_pol_par.ip2_temp_ena <<19 |
  1996.                sky74117_pol_par.i_pcs_pol    <<18 |
  1997.                sky74117_pol_par.i_dcs_pol    <<17 |
  1998.                sky74117_pol_par.i_gsm_pol    <<16 |
  1999.                sky74117_pol_par.i_gsm850_pol <<15 |
  2000.                sky74117_pol_par.q_pcs_pol    <<14 |
  2001.                sky74117_pol_par.q_dcs_pol    <<13 |
  2002.                sky74117_pol_par.q_gsm_pol    <<12 |
  2003.                sky74117_pol_par.q_gsm850_pol <<11 |
  2004.                sky74117_pol_par.ip2_coef     <<10 |
  2005.                sky74117_pol_par.ip2_pol_cal  << 9 |
  2006.                sky74117_pol_par.cal_ctrl     << 6 |
  2007.                ADDR_SKY74117_IP2_POL;
  2008. }
  2009. //----------------------------------------------------------------------------
  2010. void  CRFPM::DeCompose_Sky74117_PolCW( unsigned int reg_data, SKY74117_IP2CW_POL  &sky74117_pol_par)
  2011. {
  2012.     sky74117_pol_par.reserved     = (reg_data>>20) & 0x0F;
  2013.     sky74117_pol_par.ip2_temp_ena = (reg_data>>19) & 0x01;
  2014.     sky74117_pol_par.i_pcs_pol    = (reg_data>>18) & 0x01;
  2015.     sky74117_pol_par.i_dcs_pol    = (reg_data>>17) & 0x01;
  2016.     sky74117_pol_par.i_gsm_pol    = (reg_data>>16) & 0x01;
  2017.     sky74117_pol_par.i_gsm850_pol = (reg_data>>15) & 0x01;
  2018.     sky74117_pol_par.q_pcs_pol    = (reg_data>>14) & 0x01;
  2019.     sky74117_pol_par.q_dcs_pol    = (reg_data>>13) & 0x01;
  2020.     sky74117_pol_par.q_gsm_pol    = (reg_data>>12) & 0x01;
  2021.     sky74117_pol_par.q_gsm850_pol = (reg_data>>11) & 0x01;
  2022.     sky74117_pol_par.ip2_coef     = (reg_data>>10) & 0x01;
  2023.     sky74117_pol_par.ip2_coef     = (reg_data>>10) & 0x01;
  2024. }
  2025. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2026. void  CRFPM::Set_Sky74117IP2MagToReg_Start( FrequencyBand freqband, SKY74117_IP2CW_MAG  &sky74117_mag_par )
  2027. {
  2028.     rf_pm_ptr = this;
  2029.     g_bIsRunning = true;
  2030.     m_FreqBand = freqband;
  2031.     m_sky74117_mag[freqband] = sky74117_mag_par;
  2032.     ActiveMan->SetActiveFunction( ::Set_Sky74117IP2MagToReg );
  2033. }
  2034. //----------------------------------------------------------------------------
  2035. void  CRFPM::Set_Sky74117IP2MagToReg( void )
  2036. {
  2037.     unsigned int bsi_data;
  2038.     switch( m_FreqBand )
  2039.     {
  2040.         case FrequencyBand850:
  2041.              Compose_Sky74117_GSM850CW( m_sky74117_mag[m_FreqBand], bsi_data );
  2042.         break;
  2043.         case FrequencyBand900:
  2044.              Compose_Sky74117_GSM900CW( m_sky74117_mag[m_FreqBand], bsi_data );
  2045.         break;
  2046.         case FrequencyBand1800:
  2047.              Compose_Sky74117_DCS1800CW( m_sky74117_mag[m_FreqBand], bsi_data );
  2048.         break;
  2049.         case FrequencyBand1900:
  2050.              Compose_Sky74117_PCS1900CW( m_sky74117_mag[m_FreqBand], bsi_data );
  2051.         break;
  2052.     }
  2053.     META_RESULT MetaResult = META_Rf_SetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 1500, bsi_data);
  2054.     if(MetaResult!=META_SUCCESS)
  2055.     {
  2056.         if( MetaResult!=META_TIMEOUT )
  2057.         {   Confirm( METAAPP_FAIL );  return;  }
  2058.         else
  2059.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  2060.     }
  2061.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  2062. }
  2063. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2064. void  CRFPM::Set_Sky74117IP2Gsm850ToReg_Start( SKY74117_IP2CW_MAG  &sky74117_mag_par )
  2065. {
  2066.     rf_pm_ptr = this;
  2067.     g_bIsRunning = true;
  2068.     m_sky74117_mag[FrequencyBand850] = sky74117_mag_par;
  2069.     ActiveMan->SetActiveFunction( ::Set_Sky74117IP2Gsm850ToReg );
  2070. }
  2071. //----------------------------------------------------------------------------
  2072. void  CRFPM::Set_Sky74117IP2Gsm850ToReg( void )
  2073. {
  2074.     unsigned int bsi_data;
  2075.     Compose_Sky74117_GSM850CW( m_sky74117_mag[FrequencyBand850], bsi_data );
  2076.     META_RESULT MetaResult = META_Rf_SetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 1500, bsi_data);
  2077.     if(MetaResult!=META_SUCCESS)
  2078.     {
  2079.         if( MetaResult!=META_TIMEOUT )
  2080.         {   Confirm( METAAPP_FAIL );  return;  }
  2081.         else
  2082.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  2083.     }
  2084.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  2085. }
  2086. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2087. void  CRFPM::Set_Sky74117IP2Gsm900ToReg_Start( SKY74117_IP2CW_MAG  &sky74117_mag_par )
  2088. {
  2089.     rf_pm_ptr = this;
  2090.     g_bIsRunning = true;
  2091.     m_sky74117_mag[FrequencyBand900] = sky74117_mag_par;
  2092.     ActiveMan->SetActiveFunction( ::Set_Sky74117IP2Gsm900ToReg );
  2093. }
  2094. //----------------------------------------------------------------------------
  2095. void  CRFPM::Set_Sky74117IP2Gsm900ToReg( void )
  2096. {
  2097.     unsigned int bsi_data;
  2098.     Compose_Sky74117_GSM850CW( m_sky74117_mag[FrequencyBand900], bsi_data );
  2099.     META_RESULT MetaResult = META_Rf_SetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 1500, bsi_data);
  2100.     if(MetaResult!=META_SUCCESS)
  2101.     {
  2102.         if( MetaResult!=META_TIMEOUT )
  2103.         {   Confirm( METAAPP_FAIL );  return;  }
  2104.         else
  2105.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  2106.     }
  2107.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  2108. }
  2109. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2110. void  CRFPM::Set_Sky74117IP2Dcs1800ToReg_Start( SKY74117_IP2CW_MAG  &sky74117_mag_par )
  2111. {
  2112.     rf_pm_ptr = this;
  2113.     g_bIsRunning = true;
  2114.     m_sky74117_mag[FrequencyBand1800] = sky74117_mag_par;
  2115.     ActiveMan->SetActiveFunction( ::Set_Sky74117IP2Dcs1800ToReg );
  2116. }
  2117. //----------------------------------------------------------------------------
  2118. void  CRFPM::Set_Sky74117IP2Dcs1800ToReg( void )
  2119. {
  2120.     unsigned int bsi_data;
  2121.     Compose_Sky74117_GSM850CW( m_sky74117_mag[FrequencyBand1800], bsi_data );
  2122.     META_RESULT MetaResult = META_Rf_SetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 1500, bsi_data);
  2123.     if(MetaResult!=META_SUCCESS)
  2124.     {
  2125.         if( MetaResult!=META_TIMEOUT )
  2126.         {   Confirm( METAAPP_FAIL );  return;  }
  2127.         else
  2128.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  2129.     }
  2130.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  2131. }
  2132. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2133. void  CRFPM::Set_Sky74117IP2Pcs1900ToReg_Start( SKY74117_IP2CW_MAG  &sky74117_mag_par )
  2134. {
  2135.     rf_pm_ptr = this;
  2136.     g_bIsRunning = true;
  2137.     m_sky74117_mag[FrequencyBand1900] = sky74117_mag_par;
  2138.     ActiveMan->SetActiveFunction( ::Set_Sky74117IP2Pcs1900ToReg );
  2139. }
  2140. //----------------------------------------------------------------------------
  2141. void  CRFPM::Set_Sky74117IP2Pcs1900ToReg( void )
  2142. {
  2143.     unsigned int bsi_data;
  2144.     Compose_Sky74117_GSM850CW( m_sky74117_mag[FrequencyBand1900], bsi_data );
  2145.     META_RESULT MetaResult = META_Rf_SetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 1500, bsi_data);
  2146.     if(MetaResult!=META_SUCCESS)
  2147.     {
  2148.         if( MetaResult!=META_TIMEOUT )
  2149.         {   Confirm( METAAPP_FAIL );  return;  }
  2150.         else
  2151.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  2152.     }
  2153.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  2154. }
  2155. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2156. void  CRFPM::Set_Sky74117IP2PolToReg_Start( SKY74117_IP2CW_POL  &sky74117_pol_par )
  2157. {
  2158.     rf_pm_ptr = this;
  2159.     g_bIsRunning = true;
  2160.     m_sky74117_pol = sky74117_pol_par;
  2161.     ActiveMan->SetActiveFunction( ::Set_Sky74117IP2PolToReg );
  2162. }
  2163. //----------------------------------------------------------------------------
  2164. void  CRFPM::Set_Sky74117IP2PolToReg( void )
  2165. {
  2166.     unsigned int bsi_data;
  2167.     Compose_Sky74117_PolCW( m_sky74117_pol, bsi_data );
  2168.     META_RESULT MetaResult = META_Rf_SetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 1500, bsi_data);
  2169.     if(MetaResult!=META_SUCCESS)
  2170.     {
  2171.         if( MetaResult!=META_TIMEOUT )
  2172.         {   Confirm( METAAPP_FAIL );  return;  }
  2173.         else
  2174.         {   Confirm( METAAPP_TIMEOUT );  return;   }
  2175.     }
  2176.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  2177. }
  2178. //===========================================================================
  2179. ////////////////////////////           Ouery         ////////////////////////
  2180. //===========================================================================
  2181. //---------------------------------------------------------------------------
  2182. unsigned char  CRFPM::Query_PM_Support_Start(void)
  2183. {
  2184.     rf_pm_ptr = this;
  2185.     g_bIsRunning = true;
  2186.     unsigned char pm_support_num;
  2187.     pm_support_num = Query_PM_Support();
  2188.     return pm_support_num;
  2189. }
  2190. //---------------------------------------------------------------------------
  2191. unsigned char  CRFPM::Query_PM_Support( void )
  2192. {
  2193. #if 0
  2194.     if(!g_bIsRunning)  return false;
  2195.     MetaResult = META_QueryIfFunctionSupportedByTarget_r(500, "META_Rf_SetBBTxCfg3");
  2196.     if( MetaResult != META_SUCCESS )
  2197.     {
  2198.         return false;
  2199.     }
  2200. #endif
  2201.     return 4;
  2202. }
  2203. //===========================================================================
  2204. ////////////////////////////   Global  information   ////////////////////////
  2205. //===========================================================================
  2206. //---------------------------------------------------------------------------
  2207. E_METAAPP_RESULT_T  CRFPM::Get_ConfirmState( void )
  2208. {
  2209.     return  m_eConfirmState;
  2210. }
  2211. //---------------------------------------------------------------------------
  2212. RfPm_Cnf  CRFPM::Get_RfPmCnf( void )
  2213. {
  2214.     return  RFCnf_PM;
  2215. }
  2216. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2217. c_RFMod_Sky74045_Coef_T  CRFPM::Get_c_sky74045_coef( void )
  2218. {
  2219.     return c_sky74045_coef;
  2220. }
  2221. //----------------------------------------------------------------------------
  2222. void  CRFPM::Set_c_sky74045_coef( c_RFMod_Sky74045_Coef_T c_sky74045_coef_par )
  2223. {
  2224.     c_sky74045_coef = c_sky74045_coef_par;
  2225. }
  2226. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2227. c_RFMod_Sky74117_Coef_T  CRFPM::Get_c_sky74117_coef( void )
  2228. {
  2229.     return mc_sky74117_coef;
  2230. }
  2231. //----------------------------------------------------------------------------
  2232. void  CRFPM::Set_c_sky74117_coef( c_RFMod_Sky74117_Coef_T c_sky74117_coef_par )
  2233. {
  2234.     mc_sky74117_coef = c_sky74117_coef_par;
  2235. }
  2236. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2237. uc_RFMod_MT6139_Coef_T  CRFPM::Get_uc_mt6139_coef( void )
  2238. {
  2239.     return uc_mt6139_coef;
  2240. }
  2241. //----------------------------------------------------------------------------
  2242. void  CRFPM::Set_uc_mt6139_coef_rxamcalmode( int mode )
  2243. {
  2244.     uc_mt6139_coef.rx.rxamcalmode = mode;
  2245. }