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

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_apc_8psk.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   RF 8PSK APC 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  _RF_APC_8PSK_H_
  68. #include "rf_apc_8psk.h"
  69. #endif
  70. #include "man_fdm.h"
  71. #include "man_active.h"
  72. // form
  73. #include "form_RFTool.h"
  74. #include "form_main.h" // for GSM 850
  75. // misc
  76. #include "misc.h"
  77. #ifndef  _FT_UTILS_H_
  78. #include "ft_utils.h"
  79. #endif
  80. #ifndef  _BAND_UTILS_H_
  81. #include "band_utils.h"
  82. #endif
  83. // NVRAM
  84. #ifndef  _NVRAM_VER_H_
  85. #include "nvram_ver.h"
  86. #endif
  87. //===========================================================================
  88. extern TfrmMainSel *frmMainSel;  // for GSM 850
  89. static CRFAPC8PSK*  rf_apc_8psk_ptr;
  90. static bool g_bIsRunning;
  91. //===========================================================================
  92. static const char  SUBBAND_NAME[][32] =
  93. {
  94.    "EPSK GSM900 level, ramp",
  95.    "EPSK DCS1800 level, ramp",
  96.    "EPSK PCS1900 level, ramp",
  97.    "EPSK GSM850 level, ramp",
  98. };
  99. //--------------------------------------------------------------------------
  100. static const char  SUBBAND_NAME_WORD3[32] =
  101. {
  102.    "RENESAS WORD3"
  103. };
  104. //--------------------------------------------------------------------------
  105. static const char  SUBBAND_NAME_WORD6S[32] =
  106. {
  107.    "RENESAS WORD6S"
  108. };
  109. //===========================================================================
  110. static const char  BAND_NAME1[4][12] =
  111. {  "GSM",
  112.    "DCS",
  113.    "PCS",
  114.    "GSM850"
  115. };
  116. //---------------------------------------------------------------------------
  117. static const char  BAND_NAME2[4][12] =
  118. {  "GSM900",
  119.    "DCS1800",
  120.    "PCS1900",
  121.    "GSM850"
  122. };
  123. //---------------------------------------------------------------------------
  124. static const int  LOWEST_POWER[] =
  125. {  5, 0, 0, 5  };
  126. //---------------------------------------------------------------------------
  127. static const char  BAND_PCL_COMMENT[4][128] =
  128. {  "   /*  5,  7,  9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35 dBm                        */n",
  129.    "   /*    0,  2,  4,  6,  8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 dBm                      */n",
  130.    "   /*    0,  2,  4,  6,  8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 dBm                      */n",
  131.    "   /*  5,  7,  9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35 dBm                        */n"
  132. };
  133. //===========================================================================
  134. static  void  REQ_ReadApcFromNVRAM(void)
  135. {
  136.    rf_apc_8psk_ptr->REQ_ReadApcFromNVRAM();
  137. }
  138. //---------------------------------------------------------------------------
  139. static void  CNF_ReadApcFromNVRAM(void)
  140. {
  141.    rf_apc_8psk_ptr->CNF_ReadApcFromNVRAM();
  142. }
  143. //---------------------------------------------------------------------------
  144. static  void  REQ_WriteApcToNVRAM(void)
  145. {
  146.     rf_apc_8psk_ptr->REQ_WriteApcToNVRAM( );
  147. }
  148. //---------------------------------------------------------------------------
  149. static  void  CNF_WriteApcToNVRAM(void)
  150. {
  151.     rf_apc_8psk_ptr->CNF_WriteApcToNVRAM();
  152. }
  153. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  154. static void REQ_ReadVbiasFromNVRAM(void)
  155. {
  156.     rf_apc_8psk_ptr->REQ_ReadVbiasFromNVRAM();
  157. }
  158. //---------------------------------------------------------------------------
  159. static void CNF_ReadVbiasFromNVRAM(void)
  160. {
  161.     rf_apc_8psk_ptr->CNF_ReadVbiasFromNVRAM();
  162. }
  163. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  164. static void REQ_WriteVbiasToNVRAM(void)
  165. {
  166.     rf_apc_8psk_ptr->REQ_WriteVbiasToNVRAM();
  167. }
  168. //---------------------------------------------------------------------------
  169. static void CNF_WriteVbiasToNVRAM(void)
  170. {
  171.     rf_apc_8psk_ptr->CNF_WriteVbiasToNVRAM();
  172. }
  173. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  174. static void REQ_ReadAD6546CoefFromNVRAM(void)
  175. {
  176.     rf_apc_8psk_ptr->REQ_ReadAD6546CoefFromNVRAM();
  177. }
  178. //---------------------------------------------------------------------------
  179. static void CNF_ReadAD6546CoefFromNVRAM(void)
  180. {
  181.     rf_apc_8psk_ptr->CNF_ReadAD6546CoefFromNVRAM();
  182. }
  183. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  184. static void REQ_WriteAD6546CoefToNVRAM(void)
  185. {
  186.     rf_apc_8psk_ptr->REQ_WriteAD6546CoefToNVRAM();
  187. }
  188. //---------------------------------------------------------------------------
  189. static void CNF_WriteAD6546CoefToNVRAM(void)
  190. {
  191.     rf_apc_8psk_ptr->CNF_WriteAD6546CoefToNVRAM();
  192. }
  193. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  194. static void  CNF_ReadB5PFromNVRAM(void)
  195. {
  196.    rf_apc_8psk_ptr->CNF_ReadB5PFromNVRAM();
  197. }
  198. //---------------------------------------------------------------------------
  199. static  void  CNF_WriteB5PToNVRAM(void)
  200. {
  201.    rf_apc_8psk_ptr->CNF_WriteB5PToNVRAM();
  202. }
  203. //---------------------------------------------------------------------------
  204. static void REQ_SetW6sImmediateBSI(void)
  205. {
  206.     rf_apc_8psk_ptr->REQ_SetW6sImmediateBSI();
  207. }
  208. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  209. static void REQ_EPSK_SetRampApcLevel(void)
  210. {
  211.     rf_apc_8psk_ptr->REQ_EPSK_SetRampApcLevel();
  212. }
  213. //---------------------------------------------------------------------------
  214. static void REQ_RfEPSKSetRampTable(void)
  215. {
  216.     rf_apc_8psk_ptr->REQ_RfEPSKSetRampTable();
  217. }
  218. //---------------------------------------------------------------------------
  219. static void Query_RfEPSKSetRampTable(void)
  220. {
  221.     rf_apc_8psk_ptr->Query_RfEPSKSetRampTable();
  222. }
  223. //===========================================================================
  224. CRFAPC8PSK::CRFAPC8PSK(void)
  225. {
  226.     g_bIsRunning = false;
  227.     ConfirmCallback = 0;
  228.     ApcBufSize = 0;
  229.     ApcBuf = NULL;
  230.     m_VbiasBufSize = 0;
  231.     m_VbiasBuf = NULL;
  232.     B5PBufSize = 0;
  233.     B5PBuf = NULL;
  234.     m_iAD6546BufSize = 0;
  235.     m_cAD6546Buf = NULL;
  236. }
  237. //---------------------------------------------------------------------------
  238. CRFAPC8PSK::~CRFAPC8PSK()
  239. {
  240.     g_bIsRunning = false;
  241.     ConfirmCallback = 0;
  242.     if (ApcBuf)
  243.     {
  244.         delete [] ApcBuf;
  245.         ApcBuf = NULL;
  246.     }
  247.     if (B5PBuf)
  248.     {
  249.         delete [] B5PBuf;
  250.         B5PBuf = NULL;
  251.     }
  252.     if (m_VbiasBuf)
  253.     {
  254.         delete [] m_VbiasBuf;
  255.         m_VbiasBuf = NULL;
  256.     }
  257.     if (m_cAD6546Buf)
  258.     {
  259.         delete [] m_cAD6546Buf;
  260.         m_cAD6546Buf = NULL;
  261.     }
  262. }
  263. //---------------------------------------------------------------------------
  264. void  CRFAPC8PSK::REQ_Stop(void)
  265. {
  266.    if(!g_bIsRunning)  return;
  267.    NVRAMMan->REQ_Stop();
  268.    Confirm(METAAPP_STOP);
  269.    g_bIsRunning = false;
  270. }
  271. //---------------------------------------------------------------------------
  272. void CRFAPC8PSK::Confirm(E_METAAPP_RESULT_T confirm_state)
  273. {
  274.    if(!g_bIsRunning)  return;
  275.    if(ConfirmCallback==0)  return;
  276.    m_eConfirmState = confirm_state;
  277.    ActiveMan->SetActiveFunction( ConfirmCallback );
  278. }
  279. //===========================================================================
  280. //static int   NVRAM_APC_LOWEST_POWER[] =
  281. //{  5, 0, 0, 5 };
  282. //---------------------------------------------------------------------------
  283. //static char  NVRAM_RAMPNAME[][32] =
  284. //{
  285. //   "L1_RAMPTABLE_GSM900",
  286. //   "L1_RAMPTABLE_DCS1800",
  287. //   "L1_RAMPTABLE_PCS1900",
  288. //   "L1_RAMPTABLE_GSM850",
  289. //};
  290. //===========================================================================
  291. void CRFAPC8PSK::REQ_Read_APC_From_NVRAM_Start(unsigned int rf_id)
  292. {
  293.     rf_apc_8psk_ptr = this;
  294.     g_bIsRunning = true;
  295.     m_uiRfModId  = rf_id;
  296.    // m_VbiasSupport = vbias_support;
  297.     CurWRBand = BANDSEL_GSM900;
  298.     m_bSingleBand = true;
  299.     m_bDownloadTrigger = false;
  300.     REQ_ReadApcFromNVRAM();
  301. }
  302. //-------------------------------------
  303. void CRFAPC8PSK::REQ_ReadApcFromNVRAM(void)
  304. {
  305.     int  band = CurWRBand;
  306.     META_RESULT MetaResult;
  307.     if(!g_bIsRunning)  return;
  308.     if( NULL == ApcBuf )
  309.     {
  310.         MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_L1_EPSK_RAMPTABLE_GSM900_LID", &ApcBufSize);
  311.         if (MetaResult != META_SUCCESS)
  312.         {
  313.             Confirm(METAAPP_FAIL);
  314.             return;
  315.         }
  316.         ApcBuf = new char[ApcBufSize];
  317.     }
  318.     NVRAMMan->ConfirmCallback = ::CNF_ReadApcFromNVRAM;
  319.     switch (band)
  320.     {
  321.         case BANDSEL_GSM850:
  322.         {
  323.             NVRAMMan->REQ_ReadNVRAM_Start("NVRAM_EF_L1_EPSK_RAMPTABLE_GSM850_LID",
  324.                                             1,
  325.                                             ApcBufSize,
  326.                                             ApcBuf);
  327.         }
  328.         break;
  329.         case BANDSEL_GSM900:
  330.         {
  331.          NVRAMMan->REQ_ReadNVRAM_Start("NVRAM_EF_L1_EPSK_RAMPTABLE_GSM900_LID",
  332.                                           1,
  333.                                           ApcBufSize,
  334.                                           ApcBuf);
  335.         }
  336.         break;
  337.         case BANDSEL_DCS1800:
  338.         {
  339.             NVRAMMan->REQ_ReadNVRAM_Start("NVRAM_EF_L1_EPSK_RAMPTABLE_DCS1800_LID",
  340.                                           1,
  341.                                           ApcBufSize,
  342.                                           ApcBuf);
  343.         }
  344.         break;
  345.         case BANDSEL_PCS1900:
  346.         {
  347.             NVRAMMan->REQ_ReadNVRAM_Start("NVRAM_EF_L1_EPSK_RAMPTABLE_PCS1900_LID",
  348.                                           1,
  349.                                           ApcBufSize,
  350.                                           ApcBuf);
  351.         }
  352.         break;
  353.     }
  354. }
  355. //-------------------------------------
  356. void  CRFAPC8PSK::CNF_ReadApcFromNVRAM(void)
  357. {
  358.     int  band = CurWRBand;
  359.     META_RESULT MetaResult;
  360.     if(!g_bIsRunning)  return;
  361.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  362.     switch (state)
  363.     {
  364.         case METAAPP_SUCCESS:
  365.         {
  366.             if (m_bDownloadTrigger)
  367.             {
  368.                 if (!frmMainSel->cbGSM850->Checked)
  369.                 {
  370.                     if ((BANDSEL_PCS1900 == band) | m_bSingleBand)
  371.                     {
  372.                         if (!m_bSingleBand)
  373.                         {
  374.                             CurWRBand = BANDSEL_GSM900;
  375.                         }
  376.                         REQ_WriteApcToNVRAM();
  377.                     }
  378.                     else
  379.                     {
  380.                         CurWRBand++;
  381.                         ActiveMan->SetActiveFunction(::REQ_ReadApcFromNVRAM);
  382.                     }
  383.                 }
  384.                 else
  385.                 {
  386.                     if ((BANDSEL_GSM850 == band) | m_bSingleBand)
  387.                     {
  388.                         if (!m_bSingleBand)
  389.                         {
  390.                             CurWRBand = BANDSEL_GSM900;
  391.                         }
  392.                         REQ_WriteApcToNVRAM();
  393.                     }
  394.                     else
  395.                     {
  396.                         CurWRBand++;
  397.                         ActiveMan->SetActiveFunction( ::REQ_ReadApcFromNVRAM );
  398.                     }
  399.                 }
  400.             }
  401.             else
  402.             {
  403.                 int i;
  404.                 int idata;
  405.                 MetaResult = META_NVRAM_Decompose_rampTable(&m_sEpskRamp.s_ramp_table[band],
  406.                                                                 ApcBuf,
  407.                                                                 ApcBufSize);
  408.                 if (MetaResult != META_SUCCESS)
  409.                 {
  410.                     Confirm(METAAPP_FAIL);
  411.                     return;
  412.                 }
  413.                 //else
  414.                // {
  415.                //     MetaResult = META_NVRAM_Decompose_rampTable(&m_sEpskRamp.s_ramp_table,
  416.                //                                                 ApcBuf,
  417.                //                                                 ApcBufSize);
  418.                    // m_sEpskRamp.s_ramp_table[band].rampData.lowest_power = ramp_table.rampData.lowest_power;
  419.                    // for (int i=0; i<MAX_APC_PCL_NUM; i++)
  420.                    // {
  421.                    //     m_sEpskRamp.s_ramp_table[band].rampData.power[i] = ramp_table.rampData.power[i];
  422.                    //     m_sEpskRamp.s_ramp_table[band].rampData.ramp[i]  = ramp_table.rampData.ramp[i];
  423.                    // }
  424.                    // for (int i=0; i<ARFCN_SECTION_NUM; i++)
  425.                    // {
  426.                    //     m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i] = ramp_table.rampData.arfcn_weight[i];
  427.                    // }
  428.                    // for (int i=0; i<APC_BATTERY_COMP_NUM; i++)
  429.                    // {
  430.                    //     for (int j=0; j<APC_BATTERY_COMP_NUM; j++)
  431.                    //     {
  432.                    //         m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[i][j] = ramp_table.rampData.battery_compensate[i][j];
  433.                    //     }
  434.                    // }
  435.                    // m_sEpskRamp.s_ramp_table[band].rampData.tx_afc_offset = ramp_table.rampData.tx_afc_offset;
  436.                // }
  437.                 m_usHighApcDcOffset[band] = (m_sEpskRamp.s_ramp_table[band].rampData.lowest_power>>8)&0x000003FF;
  438.                 m_ucInterslotLowestDAC[band] = (m_sEpskRamp.s_ramp_table[band].rampData.lowest_power>>18)&0x000000FF;
  439.                 m_sEpskRamp.s_ramp_table[band].rampData.lowest_power &=0x0FF;
  440.                 for (i=0; i<12; i++)
  441.                 {
  442.                     idata = m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].mid_level;
  443.                     m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].mid_level = POWER2PCL(band, idata);
  444.                     if (m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].max_arfcn==32767)
  445.                     {
  446.                         m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].max_arfcn = -1;
  447.                     }
  448.                 }
  449.                 bool isAllBCEqualZero = true;
  450.                 for (i=0; i<3; i++)
  451.                 {
  452.                     for(int j=0; j<3; j++)
  453.                     {
  454.                         if (m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[i][j] != 0)
  455.                         {
  456.                             isAllBCEqualZero = false;
  457.                             break;
  458.                         }
  459.                     }
  460.                 }
  461.                 if (isAllBCEqualZero)
  462.                 {
  463.                     for (i=0; i<3; i++)
  464.                     {
  465.                         for (int j=0; j<3; j++)
  466.                         {
  467.                             m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[i][j] = BATTERY_COMPENSATE_SCALE;
  468.                         }
  469.                     }
  470.                 }
  471.                 if (!frmMainSel->cbGSM850->Checked)
  472.                 {
  473.                     if (BANDSEL_GSM900 == band)
  474.                     {
  475.                        m_sEpskRamp.s_ramp_table[band].rampData.power[15] = m_sEpskRamp.s_ramp_table[band].rampData.power[14];
  476.                     }
  477.                 }
  478.                 else
  479.                 {
  480.                     if ((BANDSEL_GSM900 == band) || (BANDSEL_GSM850 == band))
  481.                     {
  482.                   m_sEpskRamp.s_ramp_table[band].rampData.power[15] = m_sEpskRamp.s_ramp_table[band].rampData.power[14];
  483.                     }
  484.                 }
  485.                 //bool vbias_support = NVRAMMan->Get_VbiasSupport();
  486.                 if (!frmMainSel->cbGSM850->Checked)
  487.                 {
  488.                     if (BANDSEL_PCS1900 == band)
  489.                     {
  490.                         if ((RF_ID_AERO2E  == m_uiRfModId) ||
  491.                             (RF_ID_MT6140A == m_uiRfModId) ||
  492.                             (RF_ID_MT6140B == m_uiRfModId) ||
  493.                             (RF_ID_MT6140C == m_uiRfModId) ||
  494.                             (RF_ID_MT6140D == m_uiRfModId)
  495.                            )
  496.                         {
  497.                             REQ_ReadVbiasFromNVRAM();
  498.                         }
  499.                         else if (RF_ID_AD6546 == m_uiRfModId)
  500.                         {
  501.                             REQ_ReadAD6546CoefFromNVRAM();
  502.                         }
  503.                         else
  504.                         {
  505.                             Confirm(METAAPP_SUCCESS);
  506.                         }
  507.                     }
  508.                     else
  509.                     {
  510.                         CurWRBand++;
  511.                         ActiveMan->SetActiveFunction(::REQ_ReadApcFromNVRAM);
  512.                     }
  513.                 }
  514.                 else
  515.                 {
  516.                     if (BANDSEL_GSM850 == band)
  517.                     {
  518.                         if ((RF_ID_AERO2E  == m_uiRfModId) ||
  519.                             (RF_ID_MT6140A == m_uiRfModId) ||
  520.                             (RF_ID_MT6140B == m_uiRfModId) ||
  521.                             (RF_ID_MT6140C == m_uiRfModId) ||
  522.                             (RF_ID_MT6140D == m_uiRfModId)
  523.                            )
  524.                         {
  525.                             REQ_ReadVbiasFromNVRAM();
  526.                         }
  527.                         else if (RF_ID_AD6546 == m_uiRfModId)
  528.                         {
  529.                             REQ_ReadAD6546CoefFromNVRAM();
  530.                         }
  531.                         else
  532.                         {
  533.                             Confirm(METAAPP_SUCCESS);
  534.                         }
  535.                     }
  536.                     else
  537.                     {
  538.                         CurWRBand++;
  539.                         ActiveMan->SetActiveFunction(::REQ_ReadApcFromNVRAM);
  540.                     }
  541.                 }
  542.             }
  543.         }
  544.         break;
  545.         default:
  546.         {
  547.             Confirm(state);
  548.         }
  549.         break;
  550.     }
  551. }
  552. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  553. void CRFAPC8PSK::REQ_Write_APC_To_NVRAM_Start(unsigned int rf_id)
  554. {
  555.     rf_apc_8psk_ptr = this;
  556.     g_bIsRunning = true;
  557.     m_uiRfModId  = rf_id;
  558.     //m_VbiasSupport = vbias_support;
  559.     CurWRBand = BANDSEL_GSM900;
  560.     m_bDownloadTrigger = true;
  561.     m_bSingleBand = false;
  562.     REQ_ReadVbiasFromNVRAM();
  563. }
  564. //-------------------------------------
  565. void CRFAPC8PSK::REQ_Write_APC_To_NVRAM_Single_Band_Start(unsigned int rf_id, int band)
  566. {
  567.     rf_apc_8psk_ptr = this;
  568.     g_bIsRunning = true;
  569.     m_uiRfModId  = rf_id;
  570.     //m_VbiasSupport = vbias_support;
  571.     CurWRBand = band;
  572.     m_bDownloadTrigger = true;
  573.     m_bSingleBand = true;
  574.     REQ_ReadVbiasFromNVRAM();
  575. }
  576. //-------------------------------------
  577. void CRFAPC8PSK::REQ_WriteApcToNVRAM(void)
  578. {
  579.     if (!g_bIsRunning)
  580.     {
  581.         return;
  582.     }
  583.     META_RESULT MetaResult;
  584.     int  i, j;
  585.     int  idata;
  586.     int  band = CurWRBand;
  587.     if (NULL == ApcBuf)
  588.     {
  589.         MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_L1_EPSK_RAMPTABLE_GSM900_LID", &ApcBufSize);
  590.         if (MetaResult != META_SUCCESS)
  591.         {
  592.             Confirm(METAAPP_FAIL);
  593.             return;
  594.         }
  595.         ApcBuf = new  char[ApcBufSize];
  596.     }
  597.     if (BANDSEL_GSM900 == band || BANDSEL_GSM850 == band)
  598.     {
  599.         m_sEpskRamp.s_ramp_table[band].rampData.power[15] = m_sEpskRamp.s_ramp_table[band].rampData.power[14];
  600.     }
  601.     m_sEpskRamp.s_ramp_table[band].rampData.lowest_power = NVRAM_APC_LOWEST_POWER[band]       |
  602.                                              ((m_usHighApcDcOffset[band]&0x3FF)<<8) |
  603.                                              m_ucInterslotLowestDAC[band]<<18;
  604.     for (i=0; i<12; i++)
  605.     {
  606.         idata = m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].mid_level;
  607.         m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].mid_level = PCL2POWER(band, idata);
  608.     }
  609.    // if (vbias_support)
  610.    // {
  611.         MetaResult = META_NVRAM_Compose_rampTable(&m_sEpskRamp.s_ramp_table[band],
  612.                                                   ApcBuf,
  613.                                                   ApcBufSize);
  614.         if (MetaResult != META_SUCCESS)
  615.         {
  616.             Confirm(METAAPP_FAIL);
  617.             return;
  618.         }
  619.    // }
  620.   //  else
  621.    // {
  622.    //     l1cal_rampTable_T ramp_table;
  623.    //
  624.    //     ramp_table.rampData.lowest_power = m_sEpskRamp.s_ramp_table[band].rampData.lowest_power;
  625.    //     for (int i=0; i<MAX_APC_PCL_NUM; i++)
  626.    //     {
  627.    //         ramp_table.rampData.power[i] = m_sEpskRamp.s_ramp_table[band].rampData.power[i];
  628.     //        ramp_table.rampData.ramp[i]  = m_sEpskRamp.s_ramp_table[band].rampData.ramp[i];
  629.     //    }
  630.     //
  631.     //    for (int i=0; i<ARFCN_SECTION_NUM; i++)
  632.     //    {
  633.     //        ramp_table.rampData.arfcn_weight[i] = m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i];
  634.     //    }
  635.     //
  636.     //    for (int i=0; i<APC_BATTERY_COMP_NUM; i++)
  637.     //    {
  638.     //        for (int j=0; j<APC_BATTERY_COMP_NUM; j++)
  639.     //        {
  640.     //            ramp_table.rampData.battery_compensate[i][j] = m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[i][j];
  641.     //        }
  642.     //    }
  643.     //    ramp_table.rampData.tx_afc_offset = m_sEpskRamp.s_ramp_table[band].rampData.tx_afc_offset;
  644.     //    MetaResult = META_NVRAM_Compose_rampTable(&ramp_table,
  645.     //                                          ApcBuf,
  646.     //                                         ApcBufSize );
  647.     //}
  648.     m_sEpskRamp.s_ramp_table[band].rampData.lowest_power &= 0x0FF;
  649.     for (i=0; i<12; i++)
  650.     {
  651.         idata = m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].mid_level;
  652.         m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].mid_level = POWER2PCL(band, idata);
  653.     }
  654.     if (MetaResult != META_SUCCESS)
  655.     {
  656.         Confirm(METAAPP_FAIL);
  657.         return;
  658.     }
  659.     NVRAMMan->ConfirmCallback = ::CNF_WriteApcToNVRAM;
  660.     switch(band)
  661.     {
  662.         case BANDSEL_GSM850:
  663.         {
  664.             unsigned short lid_ver;
  665.             MetaResult = META_NVRAM_GetLIDVersion("NVRAM_EF_L1_EPSK_RAMPTABLE_GSM850_LID", &lid_ver);
  666.             if (lid_ver > NVRAM_EF_L1_EPSK_RAMPTABLE_GSM850_LID_VERNO)
  667.             {
  668.                 Confirm(METAAPP_NVRAM_LID_VER_NOT_SUPPORT);
  669.                 return;
  670.             }
  671.             NVRAMMan->REQ_WriteNVRAM_Start("NVRAM_EF_L1_EPSK_RAMPTABLE_GSM850_LID",
  672.                                             1,
  673.                                             ApcBufSize,
  674.                                             ApcBuf);
  675.         }
  676.         break;
  677.         case BANDSEL_GSM900:
  678.         {
  679.             unsigned short lid_ver;
  680.             MetaResult = META_NVRAM_GetLIDVersion("NVRAM_EF_L1_EPSK_RAMPTABLE_GSM900_LID", &lid_ver);
  681.             if (lid_ver > NVRAM_EF_L1_EPSK_RAMPTABLE_GSM900_LID_VERNO)
  682.             {
  683.                 Confirm(METAAPP_NVRAM_LID_VER_NOT_SUPPORT);
  684.                 return;
  685.             }
  686.             NVRAMMan->REQ_WriteNVRAM_Start("NVRAM_EF_L1_EPSK_RAMPTABLE_GSM900_LID",
  687.                                             1,
  688.                                             ApcBufSize,
  689.                                             ApcBuf);
  690.         }
  691.         break;
  692.         case BANDSEL_DCS1800:
  693.         {
  694.             unsigned short lid_ver;
  695.             MetaResult = META_NVRAM_GetLIDVersion("NVRAM_EF_L1_EPSK_RAMPTABLE_DCS1800_LID", &lid_ver);
  696.             if (lid_ver > NVRAM_EF_L1_EPSK_RAMPTABLE_DCS1800_LID_VERNO)
  697.             {
  698.                 Confirm(METAAPP_NVRAM_LID_VER_NOT_SUPPORT);
  699.                 return;
  700.             }
  701.             NVRAMMan->REQ_WriteNVRAM_Start("NVRAM_EF_L1_EPSK_RAMPTABLE_DCS1800_LID",
  702.                                             1,
  703.                                             ApcBufSize,
  704.                                             ApcBuf);
  705.         }
  706.         break;
  707.         case BANDSEL_PCS1900:
  708.         {
  709.             unsigned short lid_ver;
  710.             MetaResult = META_NVRAM_GetLIDVersion("NVRAM_EF_L1_EPSK_RAMPTABLE_PCS1900_LID", &lid_ver);
  711.             if (lid_ver > NVRAM_EF_L1_EPSK_RAMPTABLE_PCS1900_LID_VERNO)
  712.             {
  713.                 Confirm(METAAPP_NVRAM_LID_VER_NOT_SUPPORT);
  714.                 return;
  715.             }
  716.             NVRAMMan->REQ_WriteNVRAM_Start("NVRAM_EF_L1_EPSK_RAMPTABLE_PCS1900_LID",
  717.                                             1,
  718.                                             ApcBufSize,
  719.                                             ApcBuf );
  720.         }
  721.         break;
  722.     }
  723. }
  724. //-------------------------------------
  725. void  CRFAPC8PSK::CNF_WriteApcToNVRAM(void)
  726. {
  727.     int  band = CurWRBand;
  728.     if(!g_bIsRunning)  return;
  729.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  730.     if (state == METAAPP_SUCCESS)
  731.     {
  732.         if (frmMainSel->cbGSM850->Checked)
  733.         {
  734.             if( (band==BANDSEL_GSM850)||(m_bSingleBand) )
  735.             {
  736.                 if ((RF_ID_AERO2E  == m_uiRfModId) ||
  737.                     (RF_ID_MT6140A == m_uiRfModId) ||
  738.                     (RF_ID_MT6140B == m_uiRfModId) ||
  739.                     (RF_ID_MT6140C == m_uiRfModId) ||
  740.                     (RF_ID_MT6140D == m_uiRfModId)
  741.                    )
  742.                 {
  743.                     REQ_WriteVbiasToNVRAM();
  744.                 }
  745.                 else if (RF_ID_AD6546 == m_uiRfModId)
  746.                 {
  747.                     REQ_WriteAD6546CoefToNVRAM();
  748.                 }
  749.                 else
  750.                 {
  751.                     Confirm(METAAPP_SUCCESS);
  752.                 }
  753.             }
  754.             else
  755.             {
  756.                 CurWRBand++;
  757.                 ActiveMan->SetActiveFunction(::REQ_WriteApcToNVRAM);
  758.             }
  759.         }
  760.         else
  761.         {
  762.             if( (band==BANDSEL_PCS1900)||(m_bSingleBand) )
  763.             {
  764.                 if ((RF_ID_AERO2E  == m_uiRfModId) ||
  765.                     (RF_ID_MT6140A == m_uiRfModId) ||
  766.                     (RF_ID_MT6140B == m_uiRfModId) ||
  767.                     (RF_ID_MT6140C == m_uiRfModId) ||
  768.                     (RF_ID_MT6140D == m_uiRfModId)
  769.                    )
  770.                 {
  771.                     REQ_WriteVbiasToNVRAM();
  772.                 }
  773.                 else if (RF_ID_AD6546 == m_uiRfModId)
  774.                 {
  775.                     REQ_WriteAD6546CoefToNVRAM();
  776.                 }
  777.                 else
  778.                 {
  779.                     Confirm(METAAPP_SUCCESS);
  780.                 }
  781.             }
  782.             else
  783.             {
  784.                 CurWRBand++;
  785.                 REQ_WriteApcToNVRAM();
  786.             }
  787.         }
  788.     }
  789.     else
  790.     {   Confirm(state);
  791.     }
  792. }
  793. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  794. void CRFAPC8PSK::REQ_ReadVbiasFromNVRAM(void)
  795. {
  796.     if (!g_bIsRunning)
  797.     {
  798.         return;
  799.     }
  800.     if (NULL == m_VbiasBuf)
  801.     {
  802.         META_RESULT MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_L1_RFSPECIALCOEF_LID", &m_VbiasBufSize);
  803.         if (MetaResult != META_SUCCESS)
  804.         {
  805.             Confirm(METAAPP_FAIL);
  806.             return;
  807.         }
  808.         m_VbiasBuf = new char[m_VbiasBufSize];
  809.     }
  810.     NVRAMMan->ConfirmCallback = ::CNF_ReadVbiasFromNVRAM;
  811.     NVRAMMan->REQ_ReadNVRAM_Start("NVRAM_EF_L1_RFSPECIALCOEF_LID",
  812.                                   1,
  813.                                   m_VbiasBufSize,
  814.                                   m_VbiasBuf);
  815. }
  816. //------------------------------------------------
  817. void CRFAPC8PSK::CNF_ReadVbiasFromNVRAM(void)
  818. {
  819.     if (!g_bIsRunning)
  820.     {
  821.         return;
  822.     }
  823.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  824.     switch (state)
  825.     {
  826.         case METAAPP_SUCCESS:
  827.         {
  828.             if (m_bDownloadTrigger)
  829.             {
  830.                 REQ_WriteApcToNVRAM();
  831.             }
  832.             else
  833.             {
  834.                 META_RESULT MetaResult = META_NVRAM_Decompose_MT6140tx_PaVbias(&m_sEpskRamp.s_pa_vbias,
  835.                                                                      m_VbiasBuf,
  836.                                                                      m_VbiasBufSize);
  837.                 if (MetaResult != META_SUCCESS)
  838.                 {
  839.                     Confirm(METAAPP_FAIL);
  840.                     return;
  841.                 }
  842.                // ActiveMan->SetActiveFunction(::REQ_Finish);
  843.                 Confirm(METAAPP_SUCCESS);
  844.             }
  845.         }
  846.         break;
  847.         default:
  848.         {
  849.             Confirm(state);
  850.         }
  851.         break;
  852.     }
  853. }
  854. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  855. void CRFAPC8PSK::REQ_WriteVbiasToNVRAM(void)
  856. {
  857.     if (!g_bIsRunning)
  858.     {
  859.         return;
  860.     }
  861.     META_RESULT MetaResult;
  862.     if (NULL == m_VbiasBuf)
  863.     {
  864.         MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_L1_RFSPECIALCOEF_LID", &m_VbiasBufSize);
  865.         if (MetaResult != META_SUCCESS)
  866.         {
  867.             Confirm(METAAPP_FAIL);
  868.             return;
  869.         }
  870.         m_VbiasBuf = new char[m_VbiasBufSize];
  871.     }
  872.     MetaResult = META_NVRAM_Compose_MT6140tx_PaVbias(&m_sEpskRamp.s_pa_vbias,
  873.                                                            m_VbiasBuf,
  874.                                                            m_VbiasBufSize);
  875.     if (MetaResult != META_SUCCESS)
  876.     {
  877.         Confirm(METAAPP_FAIL);
  878.         return;
  879.     }
  880.     unsigned short lid_ver;
  881.     MetaResult = META_NVRAM_GetLIDVersion("NVRAM_EF_L1_RFSPECIALCOEF_LID", &lid_ver);
  882.     if (lid_ver > NVRAM_EF_L1_RFSPECIALCOEF_LID_VERNO)
  883.     {
  884.         Confirm(METAAPP_NVRAM_LID_VER_NOT_SUPPORT);
  885.         return;
  886.     }
  887.     NVRAMMan->ConfirmCallback = ::CNF_WriteVbiasToNVRAM;
  888.     NVRAMMan->REQ_WriteNVRAM_Start("NVRAM_EF_L1_RFSPECIALCOEF_LID",
  889.                                    1,
  890.                                    m_VbiasBufSize,
  891.                                    m_VbiasBuf);
  892. }
  893. //------------------------------------------------
  894. void CRFAPC8PSK::CNF_WriteVbiasToNVRAM(void)
  895. {
  896.     if (!g_bIsRunning)
  897.     {
  898.         return;
  899.     }
  900.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  901.     Confirm(state);
  902. }
  903. //===========================================================================
  904. //////////////////////   AD6546 NVRAM read/write   //////////////////////////
  905. //===========================================================================
  906. void CRFAPC8PSK::REQ_ReadAD6546CoefFromNVRAM(void)
  907. {
  908.     if (!g_bIsRunning)
  909.     {
  910.         return;
  911.     }
  912.     if (NULL == m_cAD6546Buf)
  913.     {
  914.         META_RESULT MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_L1_RFSPECIALCOEF_LID", &m_iAD6546BufSize);
  915.         if (MetaResult != META_SUCCESS)
  916.         {
  917.             Confirm(METAAPP_FAIL);
  918.             return;
  919.         }
  920.         m_cAD6546Buf = new char[m_iAD6546BufSize];
  921.     }
  922.     NVRAMMan->ConfirmCallback = ::CNF_ReadAD6546CoefFromNVRAM;
  923.     NVRAMMan->REQ_ReadNVRAM_Start("NVRAM_EF_L1_RFSPECIALCOEF_LID",
  924.                                   1,
  925.                                   m_iAD6546BufSize,
  926.                                   m_cAD6546Buf);
  927. }
  928. //------------------------------------------------
  929. void CRFAPC8PSK::CNF_ReadAD6546CoefFromNVRAM(void)
  930. {
  931.     if (!g_bIsRunning)
  932.     {
  933.         return;
  934.     }
  935.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  936.     switch (state)
  937.     {
  938.         case METAAPP_SUCCESS:
  939.         {
  940.             if (m_bDownloadTrigger)
  941.             {
  942.                 REQ_WriteApcToNVRAM();
  943.             }
  944.             else
  945.             {
  946.                 META_RESULT MetaResult = META_NVRAM_Decompose_ad6546tx(&m_sEpskRamp.s_ad6546,
  947.                                                                        m_cAD6546Buf,
  948.                                                                        m_iAD6546BufSize);
  949.                 if (MetaResult != META_SUCCESS)
  950.                 {
  951.                     Confirm(METAAPP_FAIL);
  952.                     return;
  953.                 }
  954.                // ActiveMan->SetActiveFunction(::REQ_Finish);
  955.                 Confirm(METAAPP_SUCCESS);
  956.             }
  957.         }
  958.         break;
  959.         default:
  960.         {
  961.             Confirm(state);
  962.         }
  963.         break;
  964.     }
  965. }
  966. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  967. void CRFAPC8PSK::REQ_WriteAD6546CoefToNVRAM(void)
  968. {
  969.     if (!g_bIsRunning)
  970.     {
  971.         return;
  972.     }
  973.     META_RESULT MetaResult;
  974.     if (NULL == m_cAD6546Buf)
  975.     {
  976.         MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_L1_RFSPECIALCOEF_LID", &m_iAD6546BufSize);
  977.         if (MetaResult != META_SUCCESS)
  978.         {
  979.             Confirm(METAAPP_FAIL);
  980.             return;
  981.         }
  982.         m_cAD6546Buf = new char[m_iAD6546BufSize];
  983.     }
  984.     MetaResult = META_NVRAM_Compose_ad6546tx(&m_sEpskRamp.s_ad6546,
  985.                                                      m_cAD6546Buf,
  986.                                                      m_iAD6546BufSize);
  987.     if (MetaResult != META_SUCCESS)
  988.     {
  989.         Confirm(METAAPP_FAIL);
  990.         return;
  991.     }
  992.     unsigned short lid_ver;
  993.     MetaResult = META_NVRAM_GetLIDVersion("NVRAM_EF_L1_RFSPECIALCOEF_LID", &lid_ver);
  994.     if (lid_ver > NVRAM_EF_L1_RFSPECIALCOEF_LID_VERNO)
  995.     {
  996.         Confirm(METAAPP_NVRAM_LID_VER_NOT_SUPPORT);
  997.         return;
  998.     }
  999.     NVRAMMan->ConfirmCallback = ::CNF_WriteVbiasToNVRAM;
  1000.     NVRAMMan->REQ_WriteNVRAM_Start("NVRAM_EF_L1_RFSPECIALCOEF_LID",
  1001.                                    1,
  1002.                                    m_iAD6546BufSize,
  1003.                                    m_cAD6546Buf);
  1004. }
  1005. //------------------------------------------------
  1006. void CRFAPC8PSK::CNF_WriteAD6546CoefToNVRAM(void)
  1007. {
  1008.     if (!g_bIsRunning)
  1009.     {
  1010.         return;
  1011.     }
  1012.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  1013.     Confirm(state);
  1014. }
  1015. //===========================================================================
  1016. void  CRFAPC8PSK::Compose_wordC3(sC3Mode c3mode, unsigned int &wordC3)
  1017. {
  1018.     wordC3 = (c3mode.uc_tn << 11) | (c3mode.uc_to << 7) | ( 0x06 << 3 ) | ADDR_WORD_C3;
  1019. }
  1020. //---------------------------------------------------------------------------
  1021. void  CRFAPC8PSK::DeCompose_wordC3(unsigned int wordC3, sC3Mode& c3mode)
  1022. {
  1023.     c3mode.uc_tn = (wordC3 >> 11) & 0x3F;
  1024.     c3mode.uc_to = (wordC3 >> 7) & 0x0F;
  1025.     c3mode.uc_pm = (wordC3 >> 3) & 0x0F;
  1026.     c3mode.uc_addr = (wordC3 ) & 0x07;
  1027. }
  1028. //---------------------------------------------------------------------------
  1029. void  CRFAPC8PSK::Compose_word6_4_0(sBVW0 &bvw0, unsigned int &word6_4_0)
  1030. {
  1031.     word6_4_0 = (bvw0.uc_ap<<20) | (bvw0.uc_as<<17) | (bvw0.uc_ao<<11) | (bvw0.uc_bd<<6) | ADDR_BV_WORD_6_4_0;
  1032. }
  1033. //---------------------------------------------------------------------------
  1034. void  CRFAPC8PSK::Compose_word6_5_0(sBVW0 &bvw0, unsigned int &word6_5_0)
  1035. {
  1036.     word6_5_0 = (bvw0.uc_ap<<20) | (bvw0.uc_as<<17) | (bvw0.uc_ao<<11) | (bvw0.uc_bd<<6) | ADDR_BV_WORD_6_5_0;
  1037. }
  1038. //---------------------------------------------------------------------------
  1039. void  CRFAPC8PSK::Compose_word6_6_0(sBVW0 &bvw0, unsigned int &word6_6_0)
  1040. {
  1041.     word6_6_0 = (bvw0.uc_ap<<20) | (bvw0.uc_as<<17) | (bvw0.uc_ao<<11) | (bvw0.uc_bd<<6) | ADDR_BV_WORD_6_6_0;
  1042. }
  1043. //---------------------------------------------------------------------------
  1044. void  CRFAPC8PSK::Compose_word6_7_0(sBVW0 &bvw0, unsigned int &word6_7_0)
  1045. {
  1046.     word6_7_0 = (bvw0.uc_ap<<20) | (bvw0.uc_as<<17) | (bvw0.uc_ao<<11) | (bvw0.uc_bd<<6) | ADDR_BV_WORD_6_7_0;
  1047. }
  1048. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1049. void  CRFAPC8PSK::DeCompose_word6_x_0(unsigned int &word6_x_0, sBVW0 &bvw6x0)
  1050. {
  1051.     bvw6x0.uc_ap = word6_x_0>>20 & 0x07;
  1052.     bvw6x0.uc_as = word6_x_0>>17 & 0x07;
  1053.     bvw6x0.uc_ao = word6_x_0>>11 & 0x3F;
  1054.     bvw6x0.uc_bd = word6_x_0>>6  & 0x1F;
  1055. }
  1056. //===========================================================================
  1057. void  CRFAPC8PSK::REQ_Read_B5P_From_NVRAM( void )
  1058. {
  1059.     rf_apc_8psk_ptr = this;
  1060.     g_bIsRunning = true;
  1061.     if( NULL == B5PBuf )
  1062.     {
  1063.         META_RESULT MetaResult = META_NVRAM_GetRecLen( "NVRAM_EF_L1_RFSPECIALCOEF_LID",
  1064.                                           &B5PBufSize );;
  1065.         if(MetaResult!=META_SUCCESS)
  1066.         {  Confirm( METAAPP_FAIL );  return;  }
  1067.         B5PBuf = new  char[B5PBufSize];
  1068.     }
  1069.     NVRAMMan->ConfirmCallback = ::CNF_ReadB5PFromNVRAM;
  1070.     NVRAMMan->REQ_ReadNVRAM_Start( "NVRAM_EF_L1_RFSPECIALCOEF_LID",
  1071.                                    1, // only one record
  1072.                                    B5PBufSize,
  1073.                                    B5PBuf );
  1074. }
  1075. //-------------------------------------
  1076. void  CRFAPC8PSK::CNF_ReadB5PFromNVRAM( void )
  1077. {
  1078.     if(!g_bIsRunning)  return;
  1079.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  1080.     if(state==METAAPP_SUCCESS)
  1081.     {
  1082.         int  i;
  1083.         int  idata;
  1084.         META_RESULT MetaResult = META_NVRAM_Decompose_BRIGHT5P_RFSpecialCoef( &b5p_coef,
  1085.                                                       B5PBuf,
  1086.                                                       B5PBufSize );
  1087.         if (MetaResult != META_SUCCESS)
  1088.         {
  1089.             Confirm(METAAPP_FAIL);
  1090.             return;
  1091.         }
  1092.         Confirm(METAAPP_SUCCESS);
  1093.     }
  1094.     else
  1095.     {
  1096.         Confirm(state);
  1097.     }
  1098. }
  1099. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1100. void  CRFAPC8PSK::REQ_Write_B5P_To_NVRAM( void )
  1101. {
  1102.     rf_apc_8psk_ptr = this;
  1103.     g_bIsRunning = true;
  1104.     if( NULL == B5PBuf )
  1105.     {
  1106.         META_RESULT MetaResult = META_NVRAM_GetRecLen( "NVRAM_EF_L1_RFSPECIALCOEF_LID",
  1107.                                           &B5PBufSize );;
  1108.         if(MetaResult!=META_SUCCESS)
  1109.         {  Confirm( METAAPP_FAIL );  return;  }
  1110.         B5PBuf = new  char[B5PBufSize];
  1111.     }
  1112.     META_RESULT MetaResult = META_NVRAM_Compose_BRIGHT5P_RFSpecialCoef(&b5p_coef, B5PBuf, B5PBufSize );
  1113.     if(MetaResult!=META_SUCCESS)
  1114.     {   Confirm( METAAPP_FAIL );  return;  }
  1115.     NVRAMMan->ConfirmCallback = ::CNF_WriteApcToNVRAM;
  1116.     NVRAMMan->REQ_WriteNVRAM_Start( "NVRAM_EF_L1_RFSPECIALCOEF_LID",
  1117.                                             1, // only 1 record
  1118.                                             B5PBufSize,
  1119.                                             B5PBuf );
  1120. }
  1121. //-------------------------------------
  1122. void  CRFAPC8PSK::CNF_WriteB5PToNVRAM( void )
  1123. {
  1124.     if(!g_bIsRunning)  return;
  1125.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  1126.     Confirm(state);
  1127. }
  1128. //===========================================================================
  1129. //////////////////////////////////  INI file   //////////////////////////////
  1130. //===========================================================================
  1131. static const AnsiString KEY_NAME_INTERSLOT_LOWEST_DAC = "Interslot lowest DAC";
  1132. static const AnsiString asSECTION_NAME_VBIAS = "PA Vbias";
  1133. static const AnsiString asKEY_NAME_Band[] = {"GSM900 band", "DCS1800 band", "PCS1900 band", "GSM850 band"};
  1134. static const AnsiString asKEY_NAME_VBIAS = "Vbias";
  1135. static const AnsiString asKEY_NAME_VBIAS_PCL = "Vbias PCL";
  1136. static const AnsiString asSECTION_NAME_AD6546 = "AD6546 Parameters";
  1137. static const AnsiString asKEY_NAME_SKEW = "Refdet slope skew";
  1138. static const AnsiString asKEY_NAME_FB_DAC = "AM FB DAC";
  1139. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1140. bool  CRFAPC8PSK::ApcGSM850SectionExist( char *filename )
  1141. {
  1142.     TIniFile   *ini_file;
  1143.     ini_file = new TIniFile( filename );
  1144.     if( ini_file == NULL ) return false;
  1145.     if( ini_file->SectionExists(  "GSM850 level, ramp" )  )
  1146.     {
  1147.             return true;
  1148.     }
  1149.     return false;
  1150. }
  1151. //----------------------------------------------------------------------------
  1152. bool CRFAPC8PSK::ApcGSM900SectionExist( char *filename )
  1153. {
  1154.     TIniFile   *ini_file;
  1155.     ini_file = new TIniFile( filename );
  1156.     if( ini_file == NULL ) return false;
  1157.     if( ini_file->SectionExists( "GSM900 level, ramp" )  )
  1158.     {
  1159.             return true;
  1160.     }
  1161.     return false;
  1162. }
  1163. //----------------------------------------------------------------------------
  1164. bool  CRFAPC8PSK::ApcDCS1800SectionExist( char *filename )
  1165. {
  1166.     TIniFile   *ini_file;
  1167.     ini_file = new TIniFile( filename );
  1168.     if( ini_file == NULL ) return false;
  1169.     if( ini_file->SectionExists(  "DCS1800 level, ramp" )  )
  1170.     {
  1171.             return true;
  1172.     }
  1173.     return false;
  1174. }
  1175. //----------------------------------------------------------------------------
  1176. bool  CRFAPC8PSK::ApcPCS1900SectionExist( char *filename )
  1177. {
  1178.     TIniFile   *ini_file;
  1179.     ini_file = new TIniFile( filename );
  1180.     if( ini_file == NULL ) return false;
  1181.     if( ini_file->SectionExists(  "PCS1900 level, ramp" )  )
  1182.     {
  1183.             return true;
  1184.     }
  1185.     return false;
  1186. }
  1187. //----------------------------------------------------------------------------
  1188. bool  CRFAPC8PSK::ApcSectionExist( char *filename, int band )
  1189. {
  1190.     int         total_band_num;
  1191.     TIniFile   *ini_file;
  1192.     ini_file = new TIniFile( filename );
  1193.     if( ini_file == NULL ) return false;
  1194.     if( ini_file->SectionExists( (AnsiString) SUBBAND_NAME[band] ) )
  1195.     {
  1196.         return true;
  1197.     }
  1198.     return false;
  1199. }
  1200. //----------------------------------------------------------------------------
  1201. bool  CRFAPC8PSK::AnyApcSectionExist( char *filename )
  1202. {
  1203.     int         total_band_num;
  1204.     TIniFile   *ini_file;
  1205.     ini_file = new TIniFile( filename );
  1206.     if( ini_file == NULL ) return false;
  1207.    // frmMainSel->Get_FinalBandSupport( band_support );
  1208.     if(frmMainSel->cbGSM850->Checked)
  1209.    // if( band_support.GSM850 )
  1210.     {   total_band_num = 4;
  1211.     }
  1212.     else
  1213.     {
  1214.         total_band_num = 3;
  1215.     }
  1216.     for(int band = 0; band<total_band_num; band++)
  1217.     {
  1218.         if( ini_file->SectionExists( (AnsiString) SUBBAND_NAME[band] ) )
  1219.         {
  1220.             return true;
  1221.         }
  1222.     }
  1223.     return false;
  1224. }
  1225. //----------------------------------------------------------------------------
  1226. bool  CRFAPC8PSK::RenesasWord3SectionExist( char *filename )
  1227. {
  1228.     TIniFile   *ini_file;
  1229.     ini_file = new TIniFile( filename );
  1230.     if( ini_file == NULL ) return false;
  1231.     if( ini_file->SectionExists(  "RENESAS WORD3" )  )
  1232.     {
  1233.             return true;
  1234.     }
  1235.     return false;
  1236. }
  1237. //----------------------------------------------------------------------------
  1238. bool  CRFAPC8PSK::RenesasWord6sSectionExist( char *filename )
  1239. {
  1240.     int         total_band_num;
  1241.     TIniFile   *ini_file;
  1242.     ini_file = new TIniFile( filename );
  1243.     if( ini_file == NULL ) return false;
  1244.     if( ini_file->SectionExists(  "RENESAS WORD6S" )  )
  1245.     {
  1246.             return true;
  1247.     }
  1248.     return false;
  1249. }
  1250. //-----------------------------------------------------------------------------
  1251. bool  CRFAPC8PSK::REQ_Read_APC_From_File_Single_Band(char *filename, unsigned int rf_id, int band)
  1252. {
  1253.     TIniFile   *ini_file;
  1254.     AnsiString  asdata;
  1255.     char        ini_section[128];
  1256.     char        str[2048];
  1257.     unsigned char ucdata[MAX_PA_VBIAS_NUM];
  1258.     short       sdata[16];
  1259.     int         idata[16];
  1260.     unsigned short usdata[MAX_APC_PCL_NUM];
  1261.     float       fdata[16];
  1262.     int         total_band_num;
  1263.     ini_file = new TIniFile(filename);
  1264.     if (NULL == ini_file)
  1265.     {
  1266.         return false;
  1267.     }
  1268.     m_uiRfModId  = rf_id;
  1269.     // Vbias
  1270.     if ((RF_ID_AERO2E  == rf_id) ||
  1271.         (RF_ID_MT6140A == rf_id) ||
  1272.         (RF_ID_MT6140B == rf_id) ||
  1273.         (RF_ID_MT6140C == rf_id) ||
  1274.         (RF_ID_MT6140D == rf_id)
  1275.        )
  1276.     {
  1277.         pa_vbias* p_pa_vibas[] =
  1278.         {
  1279.             m_sEpskRamp.s_pa_vbias.data.GSM900_pa_vbias,
  1280.             m_sEpskRamp.s_pa_vbias.data.DCS1800_pa_vbias,
  1281.             m_sEpskRamp.s_pa_vbias.data.PCS1900_pa_vbias,
  1282.             m_sEpskRamp.s_pa_vbias.data.GSM850_pa_vbias
  1283.         };
  1284.         // vbias PCL
  1285.         AnsiString as_KEY_NAME = asKEY_NAME_Band[band] + " " + asKEY_NAME_VBIAS_PCL;
  1286.         asdata = ini_file->ReadString(asSECTION_NAME_VBIAS,
  1287.                                       as_KEY_NAME,
  1288.                                       "-1,-1,-1,-1,-1,-1,-1,-1,");
  1289.         String_To_Array_short(asdata.c_str(), sdata, MAX_PA_VBIAS_NUM);
  1290.         for (int j=0; j<MAX_PA_VBIAS_NUM; j++)
  1291.         {
  1292.             (*(p_pa_vibas[band]+j)).pcl_index = sdata[j];
  1293.         }
  1294.         // vbias
  1295.         as_KEY_NAME = asKEY_NAME_Band[band] + " " + asKEY_NAME_VBIAS;
  1296.         asdata = ini_file->ReadString(asSECTION_NAME_VBIAS,
  1297.                                       as_KEY_NAME,
  1298.                                       "0,0,0,0,0,0,0,0,");
  1299.         String_To_Array_UnsignedChar(asdata.c_str(), ucdata, MAX_PA_VBIAS_NUM);
  1300.         for (int j=0; j<MAX_PA_VBIAS_NUM; j++)
  1301.         {
  1302.             (*(p_pa_vibas[band]+j)).pa_vbias1 = ucdata[j];
  1303.         }
  1304.     }
  1305.     else if (RF_ID_AD6546 == rf_id)
  1306.     {
  1307.         m_sEpskRamp.s_ad6546.REFDET_SLOPE_SKEW = ini_file->ReadInteger(asSECTION_NAME_AD6546,
  1308.                                                                        asKEY_NAME_SKEW,
  1309.                                                                        0
  1310.                                                                        );
  1311.         m_sEpskRamp.s_ad6546.AM_FB_DAC = ini_file->ReadInteger(asSECTION_NAME_AD6546,
  1312.                                                                        asKEY_NAME_FB_DAC,
  1313.                                                                        0
  1314.                                                                        );
  1315.     }
  1316.     // TX power level
  1317.     asdata = ini_file->ReadString(SUBBAND_NAME[band],
  1318.                                      "TX power level",
  1319.                                      "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0");
  1320.     strcpy(str, asdata.c_str());
  1321.     String_To_Array_UnsignedShort(str, usdata, MAX_APC_PCL_NUM);
  1322.     for (int i=0; i<MAX_APC_PCL_NUM; i++)
  1323.     {
  1324.         m_sEpskRamp.s_ramp_table[band].rampData.power[i] = usdata[i];
  1325.     }
  1326.     // ramp
  1327.     for (int pcl=0; pcl<MAX_APC_PCL_NUM; pcl++)
  1328.     {
  1329.         sprintf(ini_section, "profile %d ramp up", pcl );
  1330.         asdata = ini_file->ReadString( SUBBAND_NAME[band],
  1331.                                          ini_section,
  1332.                                          "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0");
  1333.             strcpy(str, asdata.c_str());
  1334.             String_To_Array_int(str, idata, 16 );
  1335.             for (int i=0; i<16; i++)
  1336.             {
  1337.                 m_sEpskRamp.s_ramp_table[band].rampData.ramp[pcl].point[0][i] = idata[i];
  1338.             }
  1339.             sprintf( ini_section, "profile %d ramp down", pcl );
  1340.             asdata = ini_file->ReadString( SUBBAND_NAME[band],
  1341.                                         ini_section,
  1342.                                         "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0");
  1343.             strcpy( str, asdata.c_str() );
  1344.             String_To_Array_int(str, idata, 16 );
  1345.             for (int i=0; i<16; i++)
  1346.             {
  1347.                 m_sEpskRamp.s_ramp_table[band].rampData.ramp[pcl].point[1][i] = idata[i];
  1348.             }
  1349.         }
  1350.         asdata = ini_file->ReadString( SUBBAND_NAME[band],
  1351.                                      "Subband max arfcn",
  1352.                                      "-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1");
  1353.         strcpy( str, asdata.c_str() );
  1354.         String_To_Array_int( str, idata, 11 );
  1355.         idata[11] = -1;
  1356.         for (int i=0; i<12; i++)
  1357.         {
  1358.             m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].max_arfcn = idata[i];
  1359.         }
  1360.         asdata = ini_file->ReadString( SUBBAND_NAME[band],
  1361.                                      "Subband mid level",
  1362.                                      "0,0,0,0,0,0,0,0,0,0,0");
  1363.         strcpy(str, asdata.c_str());
  1364.         String_To_Array_int(str, idata, 11);
  1365.         idata[11] = 0;
  1366.         for (int i=0; i<12; i++)
  1367.         {
  1368.             m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].mid_level = idata[i];
  1369.         }
  1370.         if (RF_ID_A60111A != rf_id)
  1371.         {
  1372.             // Subband high weight
  1373.             asdata = ini_file->ReadString(SUBBAND_NAME[band],
  1374.                                           "Subband high weight",
  1375.                                           "1,1,1,1,1,1,1,1,1,1,1");
  1376.             strcpy(str, asdata.c_str());
  1377.             String_To_Array_float(str, fdata, 11);
  1378.             fdata[11] = 0.0;
  1379.             for (int i=0; i<12; i++)
  1380.             {
  1381.                 m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].hi_weight = (unsigned short)(fdata[i]*WEIGHT_SCALE);
  1382.             }
  1383.             // Subband low weight
  1384.             asdata = ini_file->ReadString(SUBBAND_NAME[band],
  1385.                                           "Subband low weight",
  1386.                                           "1,1,1,1,1,1,1,1,1,1,1"
  1387.                                          );
  1388.             strcpy(str, asdata.c_str());
  1389.             String_To_Array_float(str, fdata, 11);
  1390.             fdata[11] = 0.0;
  1391.             for (int i=0; i<12; i++)
  1392.             {
  1393.                 m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].low_weight = (unsigned short) (fdata[i]*WEIGHT_SCALE);
  1394.             }
  1395.         }
  1396.         else
  1397.         {
  1398.             // Subband high weight
  1399.             asdata = ini_file->ReadString(SUBBAND_NAME[band],
  1400.                                           "Subband high weight",
  1401.                                           "1,1,1,1,1,1,1,1,1,1,1");
  1402.             strcpy(str, asdata.c_str());
  1403.             String_To_Array_short(str, sdata, 11);
  1404.             sdata[11] = 0;
  1405.             for (int i=0; i<12; i++)
  1406.             {
  1407.                 m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].hi_weight = (unsigned short)(sdata[i] + A60111A_WEIGHT_OFFSET);
  1408.             }
  1409.             // Subband low weight
  1410.             asdata = ini_file->ReadString(SUBBAND_NAME[band],
  1411.                                           "Subband low weight",
  1412.                                           "1,1,1,1,1,1,1,1,1,1,1"
  1413.                                          );
  1414.             strcpy(str, asdata.c_str());
  1415.             String_To_Array_short(str, sdata, 11);
  1416.             sdata[11] = 0.0;
  1417.             for (int i=0; i<12; i++)
  1418.             {
  1419.                 m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].low_weight = (unsigned short) (sdata[i] + A60111A_WEIGHT_OFFSET);
  1420.             }
  1421.         }
  1422.         // battery compensate
  1423.         asdata = ini_file->ReadString(SUBBAND_NAME[band],
  1424.                                       "Battery compensate, low voltage, low temperature",
  1425.                                       "1.0");
  1426.         m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[LOW_VOLTAGE_INDEX][LOW_TEMPERATURE_INDEX] =
  1427.         atof(asdata.c_str()) * BATTERY_COMPENSATE_SCALE;
  1428.         asdata = ini_file->ReadString(SUBBAND_NAME[band],
  1429.                                       "Battery compensate, low voltage, mid temperature",
  1430.                                       "1.0");
  1431.         m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[LOW_VOLTAGE_INDEX][MID_TEMPERATURE_INDEX] =
  1432.         atof(asdata.c_str()) * BATTERY_COMPENSATE_SCALE;
  1433.         asdata = ini_file->ReadString(SUBBAND_NAME[band],
  1434.                                       "Battery compensate, low voltage, high temperature",
  1435.                                       "1.0");
  1436.         m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[LOW_VOLTAGE_INDEX][HIGH_TEMPERATURE_INDEX] =
  1437.         atof(asdata.c_str()) * BATTERY_COMPENSATE_SCALE;
  1438.         asdata = ini_file->ReadString(SUBBAND_NAME[band],
  1439.                                       "Battery compensate, mid voltage, low temperature",
  1440.                                       "1.0");
  1441.         m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[MID_VOLTAGE_INDEX][LOW_TEMPERATURE_INDEX] =
  1442.         atof(asdata.c_str()) * BATTERY_COMPENSATE_SCALE;
  1443.         asdata = ini_file->ReadString(SUBBAND_NAME[band],
  1444.                                       "Battery compensate, mid voltage, mid temperature",
  1445.                                       "1.0");
  1446.         m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[MID_VOLTAGE_INDEX][MID_TEMPERATURE_INDEX] =
  1447.         atof(asdata.c_str()) * BATTERY_COMPENSATE_SCALE;
  1448.         asdata = ini_file->ReadString(SUBBAND_NAME[band],
  1449.                                       "Battery compensate, mid voltage, high temperature",
  1450.                                       "1.0");
  1451.         m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[MID_VOLTAGE_INDEX][HIGH_TEMPERATURE_INDEX] =
  1452.         atof(asdata.c_str()) * BATTERY_COMPENSATE_SCALE;
  1453.         asdata = ini_file->ReadString(SUBBAND_NAME[band],
  1454.                                       "Battery compensate, high voltage, low temperature",
  1455.                                       "1.0");
  1456.         m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[HIGH_VOLTAGE_INDEX][LOW_TEMPERATURE_INDEX] =
  1457.         atof(asdata.c_str()) * BATTERY_COMPENSATE_SCALE;
  1458.         asdata = ini_file->ReadString(SUBBAND_NAME[band],
  1459.                                       "Battery compensate, high voltage, mid temperature",
  1460.                                       "1.0");
  1461.         m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[HIGH_VOLTAGE_INDEX][MID_TEMPERATURE_INDEX] =
  1462.         atof(asdata.c_str()) * BATTERY_COMPENSATE_SCALE;
  1463.         asdata = ini_file->ReadString(SUBBAND_NAME[band],
  1464.                                       "Battery compensate, high voltage, high temperature",
  1465.                                       "1.0");
  1466.         m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[HIGH_VOLTAGE_INDEX][HIGH_TEMPERATURE_INDEX] =
  1467.         atof(asdata.c_str()) * BATTERY_COMPENSATE_SCALE;
  1468.         // CAP ID compensate
  1469.         m_sEpskRamp.s_ramp_table[band].rampData.tx_afc_offset = ini_file->ReadInteger( SUBBAND_NAME[band],
  1470.                                                                        "TX AFC DAC offset",
  1471.                                                                        0);
  1472.         m_ucInterslotLowestDAC[band] = ini_file->ReadInteger( SUBBAND_NAME[band],
  1473.                                                                        KEY_NAME_INTERSLOT_LOWEST_DAC,
  1474.                                                                        0);
  1475.     if (BANDSEL_GSM900 == band || BANDSEL_GSM850 == band)
  1476.     {
  1477.         m_sEpskRamp.s_ramp_table[band].rampData.power[15] = m_sEpskRamp.s_ramp_table[band].rampData.power[14];
  1478.     }
  1479.     delete  ini_file;
  1480.     return true;
  1481. }
  1482. //-----------------------------------------------------------------------------
  1483. bool  CRFAPC8PSK::REQ_Read_APC_From_File(char *filename, unsigned int rf_id)
  1484. {
  1485.     TIniFile   *ini_file;
  1486.     AnsiString  asdata;
  1487.     char        ini_section[128];
  1488.     char        str[2048];
  1489.     int         idata[16];
  1490.     unsigned short usdata[MAX_APC_PCL_NUM];
  1491.     float       fdata[16];
  1492.     int         i, pcl, band;
  1493.     int         total_band_num;
  1494.     m_uiRfModId  = rf_id;
  1495.     if(frmMainSel->cbGSM850->Checked)
  1496.     {   total_band_num = 4;
  1497.     }
  1498.     else
  1499.     {
  1500.         total_band_num = 3;
  1501.     }
  1502.     for (band = 0; band<total_band_num; band++)
  1503.     {
  1504.         if (!REQ_Read_APC_From_File_Single_Band(filename, rf_id, band))
  1505.         {
  1506.             return false;
  1507.         }
  1508.     }
  1509.     return true;
  1510. }
  1511. //===========================================================================
  1512. bool  CRFAPC8PSK::REQ_Write_APC_To_File_Single_Band(char *filename, unsigned int rf_id, int band)
  1513. {
  1514.     TIniFile   *ini_file;
  1515.     AnsiString  asdata;
  1516.     char        ini_section[128];
  1517.     char        str[2048];
  1518.     unsigned char ucdata[MAX_PA_VBIAS_NUM];
  1519.     short sdata[16];
  1520.     int         idata[16];
  1521.     unsigned short usdata[MAX_APC_PCL_NUM];
  1522.     float       fdata[16];
  1523.     ini_file = new TIniFile(filename);
  1524.     if (NULL == ini_file)
  1525.     {
  1526.         return  false;
  1527.     }
  1528.     
  1529.     // Vbias
  1530.     if ((RF_ID_AERO2E  == rf_id) ||
  1531.         (RF_ID_MT6140A == rf_id) ||
  1532.         (RF_ID_MT6140B == rf_id) ||
  1533.         (RF_ID_MT6140C == rf_id) ||
  1534.         (RF_ID_MT6140D == rf_id)
  1535.        )
  1536.     {
  1537.         pa_vbias* p_pa_vibas[] =
  1538.         {
  1539.             m_sEpskRamp.s_pa_vbias.data.GSM900_pa_vbias,
  1540.             m_sEpskRamp.s_pa_vbias.data.DCS1800_pa_vbias,
  1541.             m_sEpskRamp.s_pa_vbias.data.PCS1900_pa_vbias,
  1542.             m_sEpskRamp.s_pa_vbias.data.GSM850_pa_vbias
  1543.         };
  1544.         // vbias PCL
  1545.         for (int j=0; j<MAX_PA_VBIAS_NUM; j++)
  1546.         {
  1547.             sdata[j] = (*(p_pa_vibas[band]+j)).pcl_index;
  1548.         }
  1549.         AnsiString as_KEY_NAME = asKEY_NAME_Band[band] + " " + asKEY_NAME_VBIAS_PCL;
  1550.         Array_To_String_short(str, sdata, MAX_PA_VBIAS_NUM, ',');
  1551.         ini_file->WriteString(asSECTION_NAME_VBIAS,
  1552.                               as_KEY_NAME,
  1553.                               str);
  1554.         // vbias
  1555.         for (int j=0; j<MAX_PA_VBIAS_NUM; j++)
  1556.         {
  1557.             ucdata[j] = (*(p_pa_vibas[band]+j)).pa_vbias1;
  1558.         }
  1559.         as_KEY_NAME = asKEY_NAME_Band[band] + " " + asKEY_NAME_VBIAS;
  1560.         Array_To_String_UnsignedChar(str, ucdata, MAX_PA_VBIAS_NUM, ',');
  1561.         ini_file->WriteString(asSECTION_NAME_VBIAS,
  1562.                               as_KEY_NAME,
  1563.                               str);
  1564.     }
  1565.     else if (RF_ID_AD6546 == rf_id)
  1566.     {
  1567.         ini_file->WriteString(asSECTION_NAME_AD6546,
  1568.                               asKEY_NAME_SKEW,
  1569.                               IntToStr(m_sEpskRamp.s_ad6546.REFDET_SLOPE_SKEW)
  1570.                               );
  1571.         ini_file->WriteString(asSECTION_NAME_AD6546,
  1572.                                asKEY_NAME_FB_DAC,
  1573.                                IntToStr(m_sEpskRamp.s_ad6546.AM_FB_DAC)
  1574.                                );
  1575.     }
  1576.     if ((BANDSEL_GSM900 == band) || (BANDSEL_GSM850 == band))
  1577.     {
  1578.         m_sEpskRamp.s_ramp_table[band].rampData.power[15] = m_sEpskRamp.s_ramp_table[band].rampData.power[14];
  1579.     }
  1580.     m_uiRfModId  = rf_id;
  1581.     // TX power level
  1582.     for (int i=0; i<MAX_APC_PCL_NUM; i++)
  1583.     {
  1584.         usdata[i] = m_sEpskRamp.s_ramp_table[band].rampData.power[i];
  1585.     }
  1586.     Array_To_String_UnsignedShort(str, usdata, MAX_APC_PCL_NUM, ',');
  1587.     ini_file->WriteString(SUBBAND_NAME[band],
  1588.                                "TX power level",
  1589.                                str );
  1590.     for (int pcl=0; pcl<16; pcl++)
  1591.     {
  1592.         for (int i=0; i<16; i++)
  1593.         {
  1594.             idata[i] = m_sEpskRamp.s_ramp_table[band].rampData.ramp[pcl].point[0][i];
  1595.         }
  1596.         Array_To_String_int(str, idata, 16, ',');
  1597.         sprintf(ini_section, "profile %d ramp up", pcl);
  1598.         ini_file->WriteString(SUBBAND_NAME[band],
  1599.                               ini_section,
  1600.                               str
  1601.                               );
  1602.         for (int i=0; i<16; i++)
  1603.         {
  1604.             idata[i] = m_sEpskRamp.s_ramp_table[band].rampData.ramp[pcl].point[1][i];
  1605.         }
  1606.         Array_To_String_int(str, idata, 16, ',');
  1607.         sprintf(ini_section, "profile %d ramp down", pcl);
  1608.         ini_file->WriteString(SUBBAND_NAME[band],
  1609.                               ini_section,
  1610.                               str);
  1611.     }
  1612.     for (int i=0; i<11; i++)
  1613.     {
  1614.         idata[i] = m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].max_arfcn;
  1615.     }
  1616.     idata[11] = -1;
  1617.     Array_To_String_int(str, idata, 11, ',');
  1618.     ini_file->WriteString(SUBBAND_NAME[band],
  1619.                           "Subband max arfcn",
  1620.                           str);
  1621.     for (int i=0; i<11; i++)
  1622.     {
  1623.         idata[i] = m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].mid_level;
  1624.     }
  1625.     idata[11] = 0;
  1626.     Array_To_String_int(str, idata, 11, ',');
  1627.     ini_file->WriteString(SUBBAND_NAME[band],
  1628.                           "Subband mid level",
  1629.                           str);
  1630.     if (RF_ID_A60111A != rf_id)
  1631.     {
  1632.         for (int i=0; i<11; i++)
  1633.         {
  1634.             fdata[i] = m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].hi_weight*1.0/WEIGHT_SCALE;
  1635.         }
  1636.         fdata[11] = 0;
  1637.         Array_To_String_float(str, fdata, 11, ',');
  1638.         ini_file->WriteString(SUBBAND_NAME[band],
  1639.                               "Subband high weight",
  1640.                               str);
  1641.         for (int i=0; i<11; i++)
  1642.         {
  1643.             fdata[i] = m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].low_weight*1.0/WEIGHT_SCALE;
  1644.         }
  1645.         fdata[11] = 0;
  1646.         Array_To_String_float(str, fdata, 11, ',');
  1647.         ini_file->WriteString(SUBBAND_NAME[band],
  1648.                               "Subband low weight",
  1649.                               str);
  1650.     }
  1651.     else
  1652.     {
  1653.         for (int i=0; i<11; i++)
  1654.         {
  1655.             sdata[i] = (short) (m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].hi_weight - A60111A_WEIGHT_OFFSET);
  1656.         }
  1657.         sdata[11] = 0;
  1658.         Array_To_String_short(str, sdata, 11, ',');
  1659.         ini_file->WriteString(SUBBAND_NAME[band],
  1660.                               "Subband high weight",
  1661.                               str);
  1662.         for (int i=0; i<11; i++)
  1663.         {
  1664.             sdata[i] = (short) (m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].low_weight  - A60111A_WEIGHT_OFFSET);
  1665.         }
  1666.         sdata[11] = 0;
  1667.         Array_To_String_short(str, sdata, 11, ',');
  1668.         ini_file->WriteString(SUBBAND_NAME[band],
  1669.                               "Subband low weight",
  1670.                               str);
  1671.     }
  1672.     // battery compensate
  1673.     ini_file->WriteString(SUBBAND_NAME[band],
  1674.                           "Battery compensate, low voltage, low temperature",
  1675.                           Double_To_AnsiString((long)(m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[LOW_VOLTAGE_INDEX][LOW_TEMPERATURE_INDEX]*1.0/BATTERY_COMPENSATE_SCALE*1000+0.5)/1000.0));
  1676.     ini_file->WriteString(SUBBAND_NAME[band],
  1677.                           "Battery compensate, low voltage, mid temperature",
  1678.                           Double_To_AnsiString((long)(m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[LOW_VOLTAGE_INDEX][MID_TEMPERATURE_INDEX]*1.0/BATTERY_COMPENSATE_SCALE*1000+0.5)/1000.0));
  1679.     ini_file->WriteString(SUBBAND_NAME[band],
  1680.                           "Battery compensate, low voltage, high temperature",
  1681.                           Double_To_AnsiString((long)(m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[LOW_VOLTAGE_INDEX][HIGH_TEMPERATURE_INDEX]*1.0/BATTERY_COMPENSATE_SCALE*1000+0.5)/1000.0));
  1682.     ini_file->WriteString(SUBBAND_NAME[band],
  1683.                           "Battery compensate, mid voltage, low temperature",
  1684.                           Double_To_AnsiString((long)(m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[MID_VOLTAGE_INDEX][LOW_TEMPERATURE_INDEX]*1.0/BATTERY_COMPENSATE_SCALE*1000+0.5)/1000.0));
  1685.     ini_file->WriteString(SUBBAND_NAME[band],
  1686.                           "Battery compensate, mid voltage, mid temperature",
  1687.                           Double_To_AnsiString((long)(m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[MID_VOLTAGE_INDEX][MID_TEMPERATURE_INDEX]*1.0/BATTERY_COMPENSATE_SCALE*1000+0.5)/1000.0));
  1688.     ini_file->WriteString(SUBBAND_NAME[band],
  1689.                           "Battery compensate, mid voltage, high temperature",
  1690.                           Double_To_AnsiString((long)(m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[MID_VOLTAGE_INDEX][HIGH_TEMPERATURE_INDEX]*1.0/BATTERY_COMPENSATE_SCALE*1000+0.5)/1000.0));
  1691.     ini_file->WriteString(SUBBAND_NAME[band],
  1692.                           "Battery compensate, high voltage, low temperature",
  1693.                           Double_To_AnsiString((long)(m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[HIGH_VOLTAGE_INDEX][LOW_TEMPERATURE_INDEX]*1.0/BATTERY_COMPENSATE_SCALE*1000+0.5)/1000.0));
  1694.     ini_file->WriteString(SUBBAND_NAME[band],
  1695.                           "Battery compensate, high voltage, mid temperature",
  1696.                           Double_To_AnsiString((long)(m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[HIGH_VOLTAGE_INDEX][MID_TEMPERATURE_INDEX]*1.0/BATTERY_COMPENSATE_SCALE*1000+0.5)/1000.0));
  1697.     ini_file->WriteString(SUBBAND_NAME[band],
  1698.                           "Battery compensate, high voltage, high temperature",
  1699.                           Double_To_AnsiString((long)(m_sEpskRamp.s_ramp_table[band].rampData.battery_compensate[HIGH_VOLTAGE_INDEX][HIGH_TEMPERATURE_INDEX]*1.0/BATTERY_COMPENSATE_SCALE*1000+0.5)/1000.0));
  1700.     ini_file->WriteString(SUBBAND_NAME[band],
  1701.                           "TX AFC DAC offset",
  1702.                           m_sEpskRamp.s_ramp_table[band].rampData.tx_afc_offset);
  1703.     ini_file->WriteString(SUBBAND_NAME[band],
  1704.                           KEY_NAME_INTERSLOT_LOWEST_DAC,
  1705.                           m_ucInterslotLowestDAC[band]);
  1706.     delete ini_file;
  1707.     return  true;
  1708. }
  1709. //--------------------------------------------------------------------------
  1710. bool CRFAPC8PSK::REQ_Write_APC_To_File(char *filename, unsigned int rf_id)
  1711. {
  1712.     TIniFile   *ini_file;
  1713.     AnsiString  asdata;
  1714.     char        ini_section[128];
  1715.     char        str[2048];
  1716.     int         idata[16];
  1717.     unsigned short usdata[MAX_APC_PCL_NUM];
  1718.     float       fdata[16];
  1719.     int         i, pcl, band;
  1720.     int         total_band_num;
  1721.     if( frmMainSel->cbGSM850->Checked )
  1722.     {  total_band_num = 4;
  1723.     }
  1724.     else
  1725.     {
  1726.       total_band_num = 3;
  1727.     }
  1728.     for (band = 0; band<total_band_num; band++)
  1729.     {
  1730.         if (!REQ_Write_APC_To_File_Single_Band(filename, rf_id, band))
  1731.         {
  1732.             return false;
  1733.         }
  1734.     }
  1735.     return true;
  1736. }
  1737. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1738. bool CRFAPC8PSK::REQ_Read_Word3_From_File( char *filename )
  1739. {
  1740.     TIniFile   *ini_file;
  1741.     ini_file = new TIniFile( filename );
  1742.     if( ini_file == NULL )  return  false;
  1743.     b5p_coef.tx.c3mode = ini_file->ReadInteger( SUBBAND_NAME_WORD3, "c3mode",0);
  1744.     b5p_coef.tx.wordC3 = ini_file->ReadInteger( SUBBAND_NAME_WORD3, "WordC3",0);
  1745.     delete  ini_file;
  1746.     return  true;
  1747. }
  1748. //---------------------------------------------------------------------------
  1749. bool  CRFAPC8PSK::REQ_Write_Word3_To_File( char *filename )
  1750. {
  1751.     TIniFile   *ini_file;
  1752.     ini_file = new TIniFile( filename );
  1753.     if( ini_file == NULL )  return  false;
  1754.     ini_file->WriteString(SUBBAND_NAME_WORD3, "c3mode", b5p_coef.tx.c3mode );
  1755.     ini_file->WriteString(SUBBAND_NAME_WORD3, "WordC3", b5p_coef.tx.wordC3 );
  1756.     delete  ini_file;
  1757.     return  true;
  1758. }
  1759. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1760. bool  CRFAPC8PSK::REQ_Read_Word6s_From_File( char *filename  )
  1761. {
  1762.     TIniFile   *ini_file;
  1763.     ini_file = new TIniFile( filename );
  1764.     if( ini_file == NULL )  return  false;
  1765.     b5p_coef.tx.bvmode = ini_file->ReadInteger( SUBBAND_NAME_WORD6S,"bvmode",0);
  1766.     b5p_coef.tx.word6_4_0 = ini_file->ReadInteger( SUBBAND_NAME_WORD6S,"W6-4-0",0);
  1767.     b5p_coef.tx.word6_5_0 = ini_file->ReadInteger( SUBBAND_NAME_WORD6S,"W6-5-0",0);
  1768.     b5p_coef.tx.word6_6_0 = ini_file->ReadInteger( SUBBAND_NAME_WORD6S,"W6-6-0",0);
  1769.     b5p_coef.tx.word6_7_0 = ini_file->ReadInteger( SUBBAND_NAME_WORD6S,"W6-7-0",0);
  1770.     delete  ini_file;
  1771.     return  true;
  1772. }
  1773. //---------------------------------------------------------------------------
  1774. bool  CRFAPC8PSK::REQ_Read_W64_From_File( TIniFile   *ini_file )
  1775. {
  1776. #if 0
  1777.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1778.                              "BD",
  1779.                              );
  1780.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1781.                              "AO",
  1782.                              );
  1783.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1784.                              "AS",
  1785.                              );
  1786.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1787.                              "AP",
  1788.                              );
  1789.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1790.                              "KAG",
  1791.                              );
  1792.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1793.                              "KSG",
  1794.                              );
  1795. #endif
  1796.     return true;
  1797. }
  1798. //---------------------------------------------------------------------------
  1799. bool  CRFAPC8PSK::REQ_Read_W65_From_File( TIniFile   *ini_file )
  1800. {
  1801. #if 0
  1802.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1803.                              "BD",
  1804.                              );
  1805.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1806.                              "AO",
  1807.                              );
  1808.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1809.                              "AS",
  1810.                              );
  1811.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1812.                              "AP",
  1813.                              );
  1814.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1815.                              "KAD",
  1816.                              );
  1817.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1818.                              "KSD",
  1819.                              );
  1820. #endif
  1821.     return true;
  1822. }
  1823. //---------------------------------------------------------------------------
  1824. bool CRFAPC8PSK::REQ_Read_W66_From_File( TIniFile   *ini_file )
  1825. {
  1826. #if 0
  1827.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1828.                              "BD",
  1829.                              );
  1830.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1831.                              "AO",
  1832.                              );
  1833.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1834.                              "AS",
  1835.                              );
  1836.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1837.                              "AP",
  1838.                              );
  1839.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1840.                              "VRE",
  1841.                              );
  1842.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1843.                              "VOF",
  1844.                              );
  1845.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1846.                              "ARE",
  1847.                              );
  1848.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1849.                              "AOF",
  1850.                              );
  1851. #endif
  1852.     return true;
  1853. }
  1854. //---------------------------------------------------------------------------
  1855. bool CRFAPC8PSK::REQ_Read_W67_From_File( TIniFile   *ini_file )
  1856. {
  1857. #if 0
  1858.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1859.                              "BD",
  1860.                              );
  1861.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1862.                              "AO",
  1863.                              );
  1864.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1865.                              "AS",
  1866.                              );
  1867.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1868.                              "AP",
  1869.                              );
  1870. #endif
  1871.     return true;
  1872. }
  1873. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1874. bool  CRFAPC8PSK::REQ_Write_Word6s_To_File( char *filename )
  1875. {
  1876.     TIniFile   *ini_file;
  1877.     ini_file = new TIniFile( filename );
  1878.     if( ini_file == NULL )  return  false;
  1879.     ini_file->WriteString( SUBBAND_NAME_WORD6S,"bvmode",b5p_coef.tx.bvmode);
  1880.     ini_file->WriteString( SUBBAND_NAME_WORD6S,"W6-4-0",b5p_coef.tx.word6_4_0);
  1881.     ini_file->WriteString( SUBBAND_NAME_WORD6S,"W6-5-0",b5p_coef.tx.word6_5_0);
  1882.     ini_file->WriteString( SUBBAND_NAME_WORD6S,"W6-6-0",b5p_coef.tx.word6_6_0);
  1883.     ini_file->WriteString( SUBBAND_NAME_WORD6S,"W6-7-0",b5p_coef.tx.word6_7_0);
  1884.     delete  ini_file;
  1885.     return  true;
  1886. }
  1887. //---------------------------------------------------------------------------
  1888. bool CRFAPC8PSK::REQ_Write_W64_To_File( TIniFile   *ini_file )
  1889. {
  1890. #if 0
  1891.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1892.                              "BD",
  1893.                              );
  1894.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1895.                              "AO",
  1896.                              );
  1897.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1898.                              "AS",
  1899.                              );
  1900.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1901.                              "AP",
  1902.                              );
  1903.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1904.                              "KAG",
  1905.                              );
  1906.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1907.                              "KSG",
  1908.                              );
  1909. #endif
  1910.     return true;
  1911. }
  1912. //---------------------------------------------------------------------------
  1913. bool CRFAPC8PSK::REQ_Write_W65_To_File( TIniFile   *ini_file )
  1914. {
  1915. #if 0
  1916.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1917.                              "BD",
  1918.                              );
  1919.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1920.                              "AO",
  1921.                              );
  1922.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1923.                              "AS",
  1924.                              );
  1925.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1926.                              "AP",
  1927.                              );
  1928.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1929.                              "KAD",
  1930.                              );
  1931.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1932.                              "KSD",
  1933.                              );
  1934. #endif
  1935.     return true;
  1936. }
  1937. //---------------------------------------------------------------------------
  1938. bool  CRFAPC8PSK::REQ_Write_W66_To_File( TIniFile   *ini_file )
  1939. {
  1940. #if 0
  1941.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1942.                              "BD",
  1943.                              );
  1944.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1945.                              "AO",
  1946.                              );
  1947.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1948.                              "AS",
  1949.                              );
  1950.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1951.                              "AP",
  1952.                              );
  1953.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1954.                              "VRE",
  1955.                              );
  1956.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1957.                              "VOF",
  1958.                              );
  1959.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1960.                              "ARE",
  1961.                              );
  1962.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1963.                              "AOF",
  1964.                                 );
  1965. #endif
  1966.     return true;
  1967. }
  1968. //---------------------------------------------------------------------------
  1969. bool CRFAPC8PSK::REQ_Write_W67_To_File( TIniFile   *ini_file )
  1970. {
  1971. #if 0
  1972.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1973.                              "BD",
  1974.                              );
  1975.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1976.                              "AO",
  1977.                              );
  1978.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1979.                              "AS",
  1980.                              );
  1981.     ini_file->WriteString( SUBBAND_NAME_BV[band],
  1982.                              "AP",
  1983.                              );
  1984. #endif
  1985.     return true;
  1986. }
  1987. //---------------------------------------------------------------------------
  1988. bool CRFAPC8PSK::REQ_Write_To_M12193(char *filename, unsigned int rf_id)
  1989. {
  1990.    FILE *fs;
  1991.    int  arfcn, loss;
  1992.    int  band, profile, i;
  1993.    fs = fopen( filename, "a+t" );
  1994.    if(fs==0)  return(false);
  1995.    fprintf( fs, "/*----------------------------------------*/n");
  1996.    fprintf( fs, "/* Calibration data for power ramp        */n");
  1997.    fprintf( fs, "/*----------------------------------------*/n");
  1998.    fprintf( fs, "n");
  1999.    fprintf( fs, "#define  APC_DC_OFFSET   %dn", m_usHighApcDcOffset);
  2000.    for(band=0; band<3; band++)
  2001.    {
  2002.       fprintf( fs, "n");
  2003.       fprintf( fs, "/* %s....................................................................*/n", BAND_NAME2[band] );
  2004.       fprintf( fs, "n");
  2005.       fprintf( fs, "sRAMPDATA  %s_RampData =n", BAND_NAME1[band] );
  2006.       fprintf( fs, "{n");
  2007.       fprintf( fs, "   /*-------------------------------------------------------------------------------------------*/n");
  2008.       fprintf( fs, "   /* lowest power */n");
  2009.       fprintf( fs, "   ((APC_DC_OFFSET)<<8) | %d,n", LOWEST_POWER[band] );
  2010.       fprintf( fs, "   /*-------------------------------------------------------------------------------------------*/n");
  2011.       fprintf( fs, "   /* power level  */n");
  2012.       fprintf( fs, "%s", BAND_PCL_COMMENT[band] );
  2013.       fprintf( fs, "   { ");
  2014.   for(i=0; i<15; i++)  fprintf( fs, "%3d,", m_sEpskRamp.s_ramp_table[band].rampData.power[i] );
  2015.   fprintf( fs, "%3d },n", m_sEpskRamp.s_ramp_table[band].rampData.power[15] );
  2016.       fprintf( fs, "   /*-------------------------------------------------------------------------------------------*/n");
  2017.       fprintf( fs, "   {n");
  2018.       for( profile=0; profile<16; profile++ )
  2019.       {
  2020.          fprintf( fs, "      /* profile %2d : %2d dBm | p00,p01,p02,p03,p04,p05,p06,p07,p08,p09,p10,p11,p12,p13,p14,p15  */n", profile, LOWEST_POWER[band]+2*profile);
  2021.          fprintf( fs, "      {  /* ramp up   */ {  { ");
  2022.  for(i=0; i<15; i++)  fprintf( fs, "%3d,", m_sEpskRamp.s_ramp_table[band].rampData.ramp[profile].point[0][i] );
  2023.  fprintf( fs, "%3d },n", m_sEpskRamp.s_ramp_table[band].rampData.ramp[profile].point[0][15] );
  2024.          fprintf( fs, "         /* ramp down */    { ");
  2025.  for(i=0; i<15; i++)  fprintf( fs, "%3d,", m_sEpskRamp.s_ramp_table[band].rampData.ramp[profile].point[1][i] );
  2026.  fprintf( fs, "%3d }  }n", m_sEpskRamp.s_ramp_table[band].rampData.ramp[profile].point[1][15] );
  2027.          fprintf( fs, "      }, /*-------------------------------------------------------------------------------------*/n");
  2028.       }
  2029.       fprintf( fs, "   },n");
  2030.       fprintf( fs, "   /* ARFCN WEIGHT */n");
  2031.       fprintf( fs, "   {  /* max arfcn , mid_level ,  hi_weight   ,  lo_weight   */n");
  2032.       for(i=0; i<11; i++)
  2033.     {  int  arfcn = m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].max_arfcn;
  2034.          if( (arfcn<0)||(arfcn>1023) )    break;
  2035.  int  mid_level = PCL2POWER(band, m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].mid_level);
  2036.  int  hi_weight = m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].hi_weight;
  2037.  int  lo_weight = m_sEpskRamp.s_ramp_table[band].rampData.arfcn_weight[i].low_weight;
  2038.                  double d_weight_scale = (RF_ID_A60111A == rf_id) ? WEIGHT_SCALE : 1.0;
  2039.          fprintf( fs, "      {    %4d    ,    %2d     , WEIGHT(%.3f), WEIGHT(%.3f) },n", arfcn, mid_level, (float)(1.0*hi_weight/d_weight_scale), (float)(1.0*lo_weight/d_weight_scale));
  2040.       }
  2041.       fprintf( fs, "      /*------------------------------------------------------*/n");
  2042.       fprintf( fs, "      { TABLE_END }n");
  2043.       fprintf( fs, "   },n");
  2044.       fprintf( fs, "};n");
  2045.       fprintf( fs, "n");
  2046.    }
  2047.    fprintf( fs, "/*..........................................................................*/n");
  2048.    fprintf( fs, "n");
  2049.    fprintf( fs, "sRAMPDATA*  RampData[] =n");
  2050.    fprintf( fs, "{n");
  2051.    fprintf( fs, "   0,                                 /* FrequencyBand400 (not support)  */n");
  2052.    fprintf( fs, "   0,                                 /* FrequencyBand850 (not support)  */n");
  2053.    fprintf( fs, "   &GSM_RampData,                     /* FrequencyBand900                */n");
  2054.    fprintf( fs, "   &DCS_RampData,                     /* FrequencyBand1800               */n");
  2055.    fprintf( fs, "   &PCS_RampData,                     /* FrequencyBand1900               */n");
  2056.    fprintf( fs, "};n");
  2057.    fprintf( fs, "n");
  2058.    fprintf( fs, "#undef  APC_DC_OFFSETn");
  2059.    fclose(fs);
  2060.    return(true);
  2061. }
  2062. #if 0
  2063. //----------------------------------------------------------------------------
  2064. bool CRFAPC8PSK::Req_SetWord3ToReg( RF_BRIGHT5P_Coef_T &rf_mod_coef )
  2065. {
  2066.     b5p_coef = rf_mod_coef;
  2067.     MetaResult = META_Rf_BRIGHT5P_SetSpecialCoef_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, &b5p_coef);
  2068.     if(MetaResult!=META_SUCCESS)
  2069.     {
  2070.         Confirm( METAAPP_FAIL );
  2071.         return false;
  2072.     }
  2073.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  2074.     return true;
  2075. }
  2076. #endif
  2077. //----------------------------------------------------------------------------
  2078. bool CRFAPC8PSK::Req_SetB5PToReg(RF_BRIGHT5P_Coef_T rf_mod_coef)
  2079. {
  2080.     b5p_coef = rf_mod_coef;
  2081.     META_RESULT MetaResult = META_Rf_BRIGHT5P_SetSpecialCoef_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, &b5p_coef);
  2082.     if(MetaResult!=META_SUCCESS)
  2083.     {
  2084.         Confirm( METAAPP_FAIL );
  2085.         return false;
  2086.     }
  2087.     Confirm(METAAPP_SUCCESS);
  2088.     return true;
  2089. }
  2090. //-----------------------------------------------------------------------------
  2091. bool CRFAPC8PSK::Set_RenesasCoef(RF_BRIGHT5P_Coef_T rf_mod_coef)
  2092. {
  2093.     b5p_coef = rf_mod_coef;
  2094.     return true;
  2095. }
  2096. //-----------------------------------------------------------------------------
  2097. bool CRFAPC8PSK::Get_RenesasCoef( RF_BRIGHT5P_Coef_T &rf_mod_coef )
  2098. {
  2099.     rf_mod_coef = b5p_coef;
  2100.     return true;
  2101. }
  2102. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2103. bool CRFAPC8PSK::Get_BvMode( void )
  2104. {
  2105.     return b5p_coef.tx.bvmode;
  2106. }
  2107. //-----------------------------------------------------------------------------
  2108. void CRFAPC8PSK::Set_BvMode( unsigned int bvmode )
  2109. {
  2110.     b5p_coef.tx.bvmode = bvmode;
  2111. }
  2112. //-----------------------------------------------------------------------------
  2113. void CRFAPC8PSK::REQ_SetW6sImmediateBSI_Start( unsigned int w6s )
  2114. {
  2115.     W6S = w6s;
  2116.     ActiveMan->SetActiveFunction( ::REQ_SetW6sImmediateBSI );
  2117. }
  2118. //-----------------------------------------------------------------------------
  2119. void CRFAPC8PSK::REQ_SetW6sImmediateBSI( void )
  2120. {
  2121.     META_RESULT MetaResult = META_Rf_SetRFImmediateBSI_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, W6S);
  2122.     if (MetaResult != META_SUCCESS)
  2123.     {
  2124.         Confirm(METAAPP_FAIL);
  2125.         return;
  2126.     }
  2127.     Confirm(METAAPP_SUCCESS);
  2128. }
  2129. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2130. void CRFAPC8PSK::REQ_RfEPSKSetRampTable_Start( int band_idx )
  2131. {
  2132.     rf_apc_8psk_ptr = this;
  2133.     g_bIsRunning = true;
  2134.     CurWRBand = band_idx;
  2135.     ActiveMan->SetActiveFunction( ::REQ_RfEPSKSetRampTable );
  2136. }
  2137. //-------------------------------------------------------------------------
  2138. bool CRFAPC8PSK::REQ_RfEPSKSetRampTable( void )
  2139. {
  2140. #if 0
  2141.     FrequencyBand  freqband = ApcBandIdx_To_FreqBand(CurWRBand);
  2142.     META_RESULT  MetaResult = META_Rf_EPSK_SetRampTable_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, freqband, &m_sEpskRamp.s_ramp_table[CurWRBand]);
  2143.     if(MetaResult!=META_SUCCESS)
  2144.     {
  2145.         if( MetaResult!=META_TIMEOUT )
  2146.         {   Confirm( METAAPP_FAIL );  return false;  }
  2147.         else
  2148.         {   Confirm( METAAPP_TIMEOUT );  return false;  }
  2149.     }
  2150.     ActiveMan->SetActiveFunction( ::REQ_Finish );
  2151. #endif
  2152.     return  true;
  2153. }
  2154. //===========================================================================
  2155. void CRFAPC8PSK::REQ_EPSK_SetRampApcLevel_Start(RfSetRampApcLevel_Req *req)
  2156. {
  2157.     rf_apc_8psk_ptr = this;
  2158.     g_bIsRunning = true;
  2159.     m_pRfSetApcDac = req;
  2160.     ActiveMan->SetActiveFunction( ::REQ_EPSK_SetRampApcLevel );
  2161. }
  2162. //--------------------------------------------------------------------------
  2163. void CRFAPC8PSK::REQ_EPSK_SetRampApcLevel( void )
  2164. {
  2165.     if(!g_bIsRunning)  return;
  2166.     META_RESULT  MetaResult = META_Rf_EPSK_SetRampApcLevel_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, m_pRfSetApcDac);
  2167.     if(MetaResult!=META_SUCCESS)
  2168.     {
  2169.         if( MetaResult!=META_TIMEOUT )
  2170.         {   Confirm( METAAPP_FAIL );  return;  }
  2171.         else
  2172.         {   Confirm( METAAPP_TIMEOUT );  return;  }
  2173.     }
  2174.     Confirm(METAAPP_SUCCESS);
  2175. }
  2176. //===========================================================================
  2177. /////////////////////////        Query         //////////////////////////////
  2178. //===========================================================================
  2179. void CRFAPC8PSK::Query_RfEPSKSetRampTable_Start( bool &RfEPSKSetRampTableSupport )
  2180. {
  2181.     rf_apc_8psk_ptr = this;
  2182.     g_bIsRunning = true;
  2183.     p_rf_epsk_set_ramp_table_support = &RfEPSKSetRampTableSupport;
  2184.     ActiveMan->SetActiveFunction( ::Query_RfEPSKSetRampTable );
  2185. }
  2186. //-------------------------------------------------------------------------
  2187. bool CRFAPC8PSK::Query_RfEPSKSetRampTable( void )
  2188. {
  2189.     META_RESULT  MetaResult = META_QueryIfFunctionSupportedByTarget_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, "META_Rf_EPSK_SetRampTable");
  2190.     if(MetaResult!=META_SUCCESS)
  2191.     {
  2192.         *p_rf_epsk_set_ramp_table_support = false;
  2193.         if( MetaResult!=META_TIMEOUT )
  2194.         {   Confirm( METAAPP_FAIL );  return false;  }
  2195.         else
  2196.         {   Confirm( METAAPP_TIMEOUT );  return false;  }
  2197.     }
  2198.     *p_rf_epsk_set_ramp_table_support = true;
  2199.     Confirm(METAAPP_SUCCESS);
  2200.     return  true;
  2201. }
  2202. //============================================================================
  2203. //////////////////////////  Global  information   ////////////////////////////
  2204. //============================================================================
  2205. E_METAAPP_RESULT_T CRFAPC8PSK::Get_ConfirmState( void )
  2206. {
  2207.     return  m_eConfirmState;
  2208. }
  2209. #if 0
  2210. //---------------------------------------------------------------------------
  2211. unsigned short CRFAPC8PSK::Get_HighApcDcOffset(int band_idx)
  2212. {
  2213.     return m_usHighApcDcOffset[band_idx];
  2214. }
  2215. //----------------------------------------------------------------------------
  2216. void CRFAPC8PSK::Set_HighApcDcOffset(int band_idx, unsigned short high_apc_dc_offset)
  2217. {
  2218.     m_usHighApcDcOffset[band_idx] = high_apc_dc_offset;
  2219. }
  2220. #endif
  2221. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2222. S_EPSK_RAMP_T* CRFAPC8PSK::Get_ApcProfile(void)
  2223. {
  2224.     return  &m_sEpskRamp;
  2225. }
  2226. //---------------------------------------------------------------------------
  2227. void CRFAPC8PSK::Set_ApcProfile(S_EPSK_RAMP_T apc_profile)
  2228. {
  2229.     m_sEpskRamp = apc_profile;
  2230. }
  2231. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2232. unsigned short CRFAPC8PSK::Get_ApcProfilePower( int band_idx, int pcl_idx )
  2233. {
  2234.     return  m_sEpskRamp.s_ramp_table[band_idx].rampData.power[pcl_idx];
  2235. }
  2236. //---------------------------------------------------------------------------
  2237. void CRFAPC8PSK::Set_ApcProfilePower( int band_idx, int pcl_idx, unsigned short power )
  2238. {
  2239.     m_sEpskRamp.s_ramp_table[band_idx].rampData.power[pcl_idx] = power;
  2240. }
  2241. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2242. short CRFAPC8PSK::Get_TxAfcOffset( int band_idx, int pcl_idx )
  2243. {
  2244.     return  m_sEpskRamp.s_ramp_table[band_idx].rampData.tx_afc_offset;
  2245. }
  2246. //---------------------------------------------------------------------------
  2247. void CRFAPC8PSK::Set_TxAfcOffset( int band_idx, short tx_afc_offset )
  2248. {
  2249.     m_sEpskRamp.s_ramp_table[band_idx].rampData.tx_afc_offset = tx_afc_offset;
  2250. }
  2251. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2252. unsigned char CRFAPC8PSK::Get_InterslotLowestDAC( int band_idx )
  2253. {   return m_ucInterslotLowestDAC[band_idx];
  2254. }
  2255. //----------------------------------------------------------------------------
  2256. void CRFAPC8PSK::Set_InterslotLowestDAC( int band_idx, unsigned char dac )
  2257. {   m_ucInterslotLowestDAC[band_idx] = dac;
  2258. }