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

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.  *  GSM_utils.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *  GSM utility 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. #ifndef  _GSM_UTILS_H_
  66. #include "gsm_utils.h"
  67. #endif
  68. #ifndef META_DLL_H
  69. #include "meta.h"
  70. #endif
  71. #ifndef _APCCAL_COMMON_H_
  72. #include "apccal_common.h"
  73. #endif
  74. #ifndef age1960_INCLUDE
  75. #include "age1960.h"
  76. #endif
  77. //--------------------------------------------------------------------------- 
  78. bool getCenterFreq(FrequencyBand Band, int ARFCN, bool isDownlink, double *CenterFreq)
  79. {
  80.     switch (Band)
  81.     {
  82.      case FrequencyBand850:
  83.         {
  84.          if (128<=ARFCN && ARFCN<=251)
  85.            {
  86.                 if (!isDownlink)
  87.                 {
  88.                     *CenterFreq = 824.2 + 0.2*(ARFCN-128);
  89.                }
  90.                else
  91.                {
  92.                    *CenterFreq = 824.2 + 0.2*(ARFCN-128) + 45.0;
  93.                }
  94.             }
  95.             else
  96.             {
  97.              return false;
  98.             }
  99.         }
  100.         break;
  101.      case FrequencyBand900:
  102.         {
  103.          if (0<=ARFCN && ARFCN<= 124) // PGSM, EGSM
  104.          {
  105.              if (!isDownlink)
  106.              {
  107.                  *CenterFreq = 890.0 + 0.2*ARFCN;
  108.              }
  109.              else
  110.              {
  111.                  *CenterFreq = 890.0 + 0.2*ARFCN + 45.0;
  112.              }
  113.            }
  114.          else if (955<=ARFCN && ARFCN<=1023) // EGSM, RGSM
  115.             {
  116.              if (!isDownlink)
  117.              {
  118.                  *CenterFreq = 890.0 + 0.2*(ARFCN-1024);
  119.              }
  120.              else
  121.              {
  122.                  *CenterFreq = 890.0 + 0.2*(ARFCN-1024) + 45.0;
  123.              }
  124.             }
  125.          else
  126.          {
  127.              return false;
  128.          }
  129.         }
  130.         break;
  131.      case FrequencyBand1800:
  132.         {
  133.          if (512<=ARFCN && ARFCN<=885)
  134.            {
  135.                 if( ! isDownlink )
  136.                 {
  137.                     *CenterFreq = 1710.2 + 0.2*(ARFCN-512);
  138.                }
  139.                else
  140.                {
  141.                    *CenterFreq = 1710.2 + 0.2*(ARFCN-512) + 95.0;
  142.                }
  143.             }
  144.             else
  145.             {
  146.              return false;
  147.             }
  148.         }
  149.         break;
  150.      case FrequencyBand1900:
  151.         {
  152.          if (512<=ARFCN && ARFCN<=810)
  153.            {
  154.                 if( ! isDownlink )
  155.                 {
  156.                     *CenterFreq = 1850.2 + 0.2*(ARFCN-512);
  157.                }
  158.                else
  159.                {
  160.                    *CenterFreq = 1850.2 + 0.2*(ARFCN-512) + 80.0;
  161.                }
  162.             }
  163.             else
  164.             {
  165.              return false;
  166.             }
  167.         }
  168.         break;
  169.     }
  170.     return true;
  171. }
  172. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  173. bool MindBm_To_PCL( FrequencyBand FreqBand, int min_dBm, int &pcl )
  174. {
  175.     switch( FreqBand )
  176.     {
  177.         case FrequencyBand850:
  178.         case FrequencyBand900:
  179.         {
  180.             if( min_dBm > 33 || min_dBm < 5)  return false;
  181.             pcl = GSM900_FIRST_PCL - min_dBm/2 + 2;
  182.         }
  183.         break;
  184.         case FrequencyBand1800:
  185.         case FrequencyBand1900:
  186.         {
  187.             if( min_dBm > 30 || min_dBm < 0 )  return false;
  188.             pcl = DCS1800_FIRST_PCL - min_dBm/2;
  189.         }
  190.         break;
  191.         default:
  192.            return false;
  193.     }
  194.     return true;
  195. }
  196. //--------------------------------------------------------------------------
  197. bool PCL_To_MindBm( FrequencyBand FreqBand, int pcl, int &min_dBm )
  198. {
  199.     switch( FreqBand )
  200.     {
  201.         case FrequencyBand850:
  202.         case FrequencyBand900:
  203.         {
  204.             if( pcl < GSM900_LAST_PCL || pcl > GSM900_FIRST_PCL )  return false;
  205.             min_dBm = ( GSM900_FIRST_PCL + 2 - pcl ) * 2 + 1;
  206.         }
  207.         break;
  208.         case FrequencyBand1800:
  209.         case FrequencyBand1900:
  210.         {
  211.             if( pcl < DCS1800_LAST_PCL || pcl > DCS1800_FIRST_PCL )  return false;
  212.             min_dBm = ( DCS1800_FIRST_PCL - pcl ) * 2;
  213.         }
  214.         break;
  215.     }
  216.     return true;
  217. }
  218. //---------------------------------------------------------------------------
  219. bool PCL_To_PCLIndex(E_BANDSEL BandSel, short pcl, short &pcl_idx)
  220. {
  221.     switch (BandSel)
  222.     {
  223.         case BANDSEL_GSM850:
  224.         case BANDSEL_GSM900:
  225.         {
  226.             if ((pcl >= GSM900_LAST_PCL) && (pcl <= GSM900_FIRST_PCL))
  227.             {
  228.                 pcl_idx = GSM900_FIRST_PCL - pcl;
  229.             }
  230.             else
  231.             {
  232.                 return false;
  233.             }
  234.         }
  235.         break;
  236.         case BANDSEL_DCS1800:
  237.         case BANDSEL_PCS1900:
  238.         {
  239.             if ((pcl >= DCS1800_LAST_PCL) && (pcl <= DCS1800_FIRST_PCL))
  240.             {
  241.                 pcl_idx = DCS1800_FIRST_PCL - pcl;
  242.             }
  243.             else
  244.             {
  245.                 return false;
  246.             }
  247.         }
  248.         break;
  249.         default:
  250.         {
  251.             return false;
  252.         }
  253.     }
  254.     return true;
  255. }
  256. //---------------------------------------------------------------------------
  257. bool PCLIndex_To_PCL(E_BANDSEL BandSel, short pcl_idx, short &pcl)
  258. {
  259.     switch (BandSel)
  260.     {
  261.         case BANDSEL_GSM850:
  262.         case BANDSEL_GSM900:
  263.         {
  264.             if ((pcl_idx >= 0) && (pcl < TOTAL_GSM_PCL_NUM))
  265.             {
  266.                 pcl = GSM900_LAST_PCL + pcl_idx;
  267.             }
  268.             else
  269.             {
  270.                 return false;
  271.             }
  272.         }
  273.         break;
  274.         case BANDSEL_DCS1800:
  275.         case BANDSEL_PCS1900:
  276.         {
  277.             if ((pcl_idx >= 0) && (pcl < TOTAL_DCS_PCL_NUM))
  278.             {
  279.                 pcl = DCS1800_LAST_PCL + pcl_idx;
  280.             }
  281.             else
  282.             {
  283.                 return false;
  284.             }
  285.         }
  286.         break;
  287.         default:
  288.         {
  289.             return false;
  290.         }
  291.     }
  292.     return true;
  293. }
  294. //===========================================================================
  295. //////////////////////////////  Channel   ///////////////////////////////////
  296. //---------------------------------------------------------------------------
  297. short Get_SeperateChannel(int vi_band, short arfcn)
  298. {
  299.     short sep_arfcn;
  300.     switch( vi_band )
  301.     {
  302.         case age1960_GSM850_BAND:
  303.         {
  304.             if( arfcn != (int)age1960_GSM850_MIN_CH )
  305.             {
  306.                 sep_arfcn = age1960_GSM850_MIN_CH;
  307.             }
  308.             else
  309.             {
  310.                 sep_arfcn = age1960_GSM850_MAX_CH;
  311.             }
  312.         }
  313.         break;
  314.         case age1960_PGSM_BAND:
  315.         {
  316.             if( arfcn != (int)age1960_EGSM_MIN_CH_1 )
  317.             {
  318.                 sep_arfcn = age1960_EGSM_MIN_CH_1;
  319.             }
  320.             else
  321.             {
  322.                 sep_arfcn = age1960_EGSM_MAX_CH_1;
  323.             }
  324.         }
  325.         break;
  326.         case age1960_EGSM_BAND:
  327.         {
  328.             if( arfcn != (int)age1960_EGSM_MIN_CH_2 )
  329.             {
  330.                 sep_arfcn = age1960_EGSM_MIN_CH_2;
  331.             }
  332.             else
  333.             {
  334.                 sep_arfcn = age1960_EGSM_MAX_CH_2;
  335.             }
  336.         }
  337.         break;
  338.         case age1960_DCS1800_BAND:
  339.         {
  340.             if( arfcn != (int)age1960_DCS1800_MIN_CH )
  341.             {
  342.                 sep_arfcn = age1960_DCS1800_MIN_CH;
  343.             }
  344.             else
  345.             {
  346.                 sep_arfcn = age1960_DCS1800_MAX_CH;
  347.             }
  348.         }
  349.         break;
  350.         case age1960_PCS1900_BAND:
  351.         {
  352.             if( arfcn != (int)age1960_PCS1900_MIN_CH )
  353.             {
  354.                 sep_arfcn = age1960_PCS1900_MIN_CH;
  355.             }
  356.             else
  357.             {
  358.                 sep_arfcn = age1960_PCS1900_MAX_CH;
  359.             }
  360.         }
  361.         break;
  362.     }
  363.     return sep_arfcn;
  364. }