⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rf_apc.cpp

📁 关于MTK 的MATA开发工具的RF源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
         {  ActiveMan->SetActiveFunction( ::REQ_Finish );
         }
         else
         {
            CurWRBand++;
            ActiveMan->SetActiveFunction( ::REQ_WriteToNVRAM );
         }
      }
      else
      {
         if( (band==BANDSEL_PCS1900)||(IsSingleBand) )
         {  ActiveMan->SetActiveFunction( ::REQ_Finish );
         }
         else
         {
            CurWRBand++;
            ActiveMan->SetActiveFunction( ::REQ_WriteToNVRAM );
         }
      }
   }
   else if(state==STATE_NVRAM_TIMEOUT)
   {   Confirm( STATE_APC_TIMEOUT );
   }
   else if(state==STATE_NVRAM_STOP)
   {   Confirm( STATE_APC_STOP );
   }
   else
   {   Confirm( STATE_APC_FAIL );
   }
}
//===========================================================================

static const char  SUBBAND_NAME[][32] =
{
   "GSM900 level, ramp",
   "DCS1800 level, ramp",
   "PCS1900 level, ramp",
   "GSM850 level, ramp",
};

bool  CRFAPC::REQ_Read_From_File( char *filename )
{
   TIniFile   *ini_file;
   AnsiString  data;
   char        ini_section[128];
   char        str[2048];
   int         idata[16];
   float       fdata[16];
   int         i, pcl, band;
   int         total_band_num;
   
   ini_file = new TIniFile( filename );
   if(frmMainSel->cbGSM850->Checked)
   {  total_band_num = 4;
   }
   else
   {
      total_band_num = 3;
   }

   for( band = 0; band<total_band_num; band++)
   {
      data = ini_file->ReadString( SUBBAND_NAME[band],
                                   "APC dc offset",
                                   "0");
      strcpy( str, data.c_str() );
      String_To_Array_int( str, idata, 1 );
      ApcDcOffset = idata[0];

      data = ini_file->ReadString( SUBBAND_NAME[band],
                                   "TX power level",
                                   "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0");
      strcpy( str, data.c_str() );
      String_To_Array_int( str, idata, 16 );
      for( i=0; i<16; i++ )

        {  ApcProfile[band].rampData.power[i] = idata[i];  }
		
      for( pcl=0; pcl<16; pcl++)
      {
         sprintf( ini_section, "profile %d ramp up", pcl );
         data = ini_file->ReadString( SUBBAND_NAME[band],
                                      ini_section,
                                      "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0");
         strcpy( str, data.c_str() );
         String_To_Array_int( str, idata, 16 );
         for( i=0; i<16; i++ )

           {  ApcProfile[band].rampData.ramp[pcl].point[0][i] = idata[i];  }
		   
         sprintf( ini_section, "profile %d ramp down", pcl );
         data = ini_file->ReadString( SUBBAND_NAME[band],
                                      ini_section,
                                      "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0");
         strcpy( str, data.c_str() );
         String_To_Array_int( str, idata, 16 );
         for( i=0; i<16; i++ )

		   {  ApcProfile[band].rampData.ramp[pcl].point[1][i] = idata[i];  }
      }

      data = ini_file->ReadString( SUBBAND_NAME[band],
                                   "Subband max arfcn",
                                   "-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1");
      strcpy( str, data.c_str() );
      String_To_Array_int( str, idata, 11 );
      idata[11] = -1;
      for( i=0; i<12; i++ )

	    {  ApcProfile[band].rampData.arfcn_weight[i].max_arfcn = idata[i];  }

      data = ini_file->ReadString( SUBBAND_NAME[band],
                                   "Subband mid level",
                                   "0,0,0,0,0,0,0,0,0,0,0");
      strcpy( str, data.c_str() );
      String_To_Array_int( str, idata, 11 );
      idata[11] = 0;
      for( i=0; i<12; i++ )

	    {   ApcProfile[band].rampData.arfcn_weight[i].mid_level = idata[i];  }

      data = ini_file->ReadString( SUBBAND_NAME[band],
                                   "Subband high weight",
                                   "1,1,1,1,1,1,1,1,1,1,1");
      strcpy( str, data.c_str() );
      String_To_Array_float( str, fdata, 11 );
      fdata[11] = 0.0;
      for( i=0; i<12; i++ )
        {   ApcProfile[band].rampData.arfcn_weight[i].hi_weight = (int)(fdata[i]*WEIGHT_SCALE);  }

      data = ini_file->ReadString( SUBBAND_NAME[band],
                                   "Subband low weight",
                                   "1,1,1,1,1,1,1,1,1,1,1");
      strcpy( str, data.c_str() );
      String_To_Array_float( str, fdata, 11 );
      fdata[11] = 0.0;
      for( i=0; i<12; i++ )
	    {   ApcProfile[band].rampData.arfcn_weight[i].low_weight = (int)(fdata[i]*WEIGHT_SCALE);  }
   }

   delete  ini_file;

   band = BANDSEL_GSM900;

   ApcProfile[band].rampData.power[15] = ApcProfile[band].rampData.power[14];
   return( true );
}
//===========================================================================

bool  CRFAPC::REQ_Write_To_File( char *filename)
{
   TIniFile   *ini_file;
   AnsiString  data;
   char        ini_section[128];
   char        str[2048];
   int         idata[16];
   float       fdata[16];
   int         i, pcl, band;
   int         total_band_num;

   band = BANDSEL_GSM900;

   ApcProfile[band].rampData.power[15] = ApcProfile[band].rampData.power[14];


   ini_file = new TIniFile( filename );

   if(frmMainSel->cbGSM850->Checked)
   {  total_band_num = 4;
   }
   else
   {
      total_band_num = 3;
   }
   for( band = 0; band<total_band_num; band++)
   {
      idata[0] = ApcDcOffset;
      sprintf(str, "%d", idata[0] );
      ini_file->WriteString( SUBBAND_NAME[band],
                             "APC dc offset",
                             str );

      for( i=0; i<16; i++ )

        {  idata[i] = ApcProfile[band].rampData.power[i];  }
      Array_To_String_int( str, idata, 16, ',' );
      ini_file->WriteString( SUBBAND_NAME[band],
                             "TX power level",
                             str );

      for( pcl=0; pcl<16; pcl++)
      {
         for( i=0; i<16; i++ )

		   {  idata[i] = ApcProfile[band].rampData.ramp[pcl].point[0][i];  }
         Array_To_String_int( str, idata, 16, ',' );
         sprintf( ini_section, "profile %d ramp up", pcl );
         ini_file->WriteString( SUBBAND_NAME[band],
                                ini_section,
                                str);

         for( i=0; i<16; i++ )

		   {  idata[i] = ApcProfile[band].rampData.ramp[pcl].point[1][i];  }
         Array_To_String_int( str, idata, 16, ',' );
         sprintf( ini_section, "profile %d ramp down", pcl );
         ini_file->WriteString( SUBBAND_NAME[band],
                                ini_section,
                                str);
      }

      for( i=0; i<11; i++ )

	    {  idata[i] = ApcProfile[band].rampData.arfcn_weight[i].max_arfcn;  }
      idata[11] = -1;
      Array_To_String_int( str, idata, 11, ',' );
      ini_file->WriteString( SUBBAND_NAME[band],
                             "Subband max arfcn",
                             str);

      for( i=0; i<11; i++ )

	    {  idata[i] = ApcProfile[band].rampData.arfcn_weight[i].mid_level;  }
      idata[11] = 0;
      Array_To_String_int( str, idata, 11, ',' );
      ini_file->WriteString( SUBBAND_NAME[band],
                             "Subband mid level",
                             str);

      for( i=0; i<11; i++ )

	    {   fdata[i] = ApcProfile[band].rampData.arfcn_weight[i].hi_weight*1.0/WEIGHT_SCALE;  }
      fdata[11] = 0;
      Array_To_String_float( str, fdata, 11, ',' );
      ini_file->WriteString( SUBBAND_NAME[band],
                             "Subband high weight",
                             str);

      for( i=0; i<11; i++ )

	    {   fdata[i] = ApcProfile[band].rampData.arfcn_weight[i].low_weight*1.0/WEIGHT_SCALE;  }
      fdata[11] = 0;
      Array_To_String_float( str, fdata, 11, ',' );
      ini_file->WriteString( SUBBAND_NAME[band],
                             "Subband low weight",
                             str);
   }

   delete  ini_file;

   return( true );
}
//===========================================================================

static const char  BAND_NAME1[3][12] =
{  "GSM",
   "DCS",
   "PCS"
};

static const char  BAND_NAME2[3][12] =
{  "GSM900",
   "DCS1800",
   "PCS1900"
};

static const int  LOWEST_POWER[3] =
{  5, 0, 0  };

static const char  BAND_PCL_COMMENT[3][128] =
{  "   /*  5,  7,  9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35 dBm                        */\n",
   "   /*    0,  2,  4,  6,  8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 dBm                      */\n",
   "   /*    0,  2,  4,  6,  8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 dBm                      */\n",
};

bool  CRFAPC::REQ_Write_To_M12193( char *filename )
{
   FILE *fs;
   int  arfcn, loss;
   int  band, profile, i;

   fs = fopen( filename, "a+t" );
   if(fs==0)  return(false);

   fprintf( fs, "/*----------------------------------------*/\n");
   fprintf( fs, "/* Calibration data for power ramp        */\n");
   fprintf( fs, "/*----------------------------------------*/\n");
   fprintf( fs, "\n");
   fprintf( fs, "#define  APC_DC_OFFSET   %d\n", ApcDcOffset);

   for(band=0; band<3; band++)
   {
      fprintf( fs, "\n");
      fprintf( fs, "/* %s....................................................................*/\n", BAND_NAME2[band] );
      fprintf( fs, "\n");
      fprintf( fs, "sRAMPDATA  %s_RampData =\n", BAND_NAME1[band] );
      fprintf( fs, "{\n");
      fprintf( fs, "   /*-------------------------------------------------------------------------------------------*/\n");
      fprintf( fs, "   /* lowest power */\n");
      fprintf( fs, "   ((APC_DC_OFFSET)<<8) | %d,\n", LOWEST_POWER[band] );
      fprintf( fs, "   /*-------------------------------------------------------------------------------------------*/\n");
      fprintf( fs, "   /* power level  */\n");
      fprintf( fs, "%s", BAND_PCL_COMMENT[band] );
      fprintf( fs, "   { ");

	  for(i=0; i<15; i++)  fprintf( fs, "%3d,", ApcProfile[band].rampData.power[i] );

	  fprintf( fs, "%3d },\n", ApcProfile[band].rampData.power[15] );
      fprintf( fs, "   /*-------------------------------------------------------------------------------------------*/\n");
      fprintf( fs, "   {\n");
      for( profile=0; profile<16; profile++ )
      {
         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);
         fprintf( fs, "      {  /* ramp up   */ {  { ");

		 for(i=0; i<15; i++)  fprintf( fs, "%3d,", ApcProfile[band].rampData.ramp[profile].point[0][i] ); 

		 fprintf( fs, "%3d },\n", ApcProfile[band].rampData.ramp[profile].point[0][15] );
         fprintf( fs, "         /* ramp down */    { ");

		 for(i=0; i<15; i++)  fprintf( fs, "%3d,", ApcProfile[band].rampData.ramp[profile].point[1][i] );

		 fprintf( fs, "%3d }  }\n", ApcProfile[band].rampData.ramp[profile].point[1][15] );
         fprintf( fs, "      }, /*-------------------------------------------------------------------------------------*/\n");
      }
      fprintf( fs, "   },\n");
      fprintf( fs, "   /* ARFCN WEIGHT */\n");
      fprintf( fs, "   {  /* max arfcn , mid_level ,  hi_weight   ,  lo_weight   */\n");
      for(i=0; i<11; i++)

	    {  int  arfcn = ApcProfile[band].rampData.arfcn_weight[i].max_arfcn; 
         if( (arfcn<0)||(arfcn>1023) )    break;

		 int  mid_level = PCL2POWER(band, ApcProfile[band].rampData.arfcn_weight[i].mid_level);

		 int  hi_weight = ApcProfile[band].rampData.arfcn_weight[i].hi_weight;
       
		 int  lo_weight = ApcProfile[band].rampData.arfcn_weight[i].low_weight;
         fprintf( fs, "      {    %4d    ,    %2d     , WEIGHT(%.3f), WEIGHT(%.3f) },\n", arfcn, mid_level, (float)(1.0*hi_weight/WEIGHT_SCALE), (float)(1.0*lo_weight/WEIGHT_SCALE));
      }
      fprintf( fs, "      /*------------------------------------------------------*/\n");
      fprintf( fs, "      { TABLE_END }\n");
      fprintf( fs, "   },\n");
      fprintf( fs, "};\n");
      fprintf( fs, "\n");
   }
   fprintf( fs, "/*..........................................................................*/\n");
   fprintf( fs, "\n");
   fprintf( fs, "sRAMPDATA*  RampData[] =\n");
   fprintf( fs, "{\n");
   fprintf( fs, "   0,                                 /* FrequencyBand400 (not support)  */\n");
   fprintf( fs, "   0,                                 /* FrequencyBand850 (not support)  */\n");
   fprintf( fs, "   &GSM_RampData,                     /* FrequencyBand900                */\n");
   fprintf( fs, "   &DCS_RampData,                     /* FrequencyBand1800               */\n");
   fprintf( fs, "   &PCS_RampData,                     /* FrequencyBand1900               */\n");
   fprintf( fs, "};\n");
   fprintf( fs, "\n");
   fprintf( fs, "#undef  APC_DC_OFFSET\n");

   fclose(fs);

   return(true);

}
//===========================================================================
void CRFAPC::Req_Rf_SetRampApcLevel(FrequencyBand rf_band, int power_level, int apc_dac)
{
  IsRunning = true;
  RampApcLevelReq.rf_band = rf_band;
  RampApcLevelReq.power_level = power_level;
  RampApcLevelReq.apc_dac = apc_dac;
  MetaResult = META_Rf_SetRampApcLevel(&RampApcLevelReq, ::CNF_RfSetRampApcLevl, &RampApcLevelToken, NULL);
}

//-------------------------------------------------------------------------------------------------
void __stdcall CRFAPC::CNF_RfSetRampApcLevl(const unsigned char cnf, const short token, void *usrData)
{
 if(cnf == false)
   {  Confirm( STATE_APC_FAIL );  return;  }
 ActiveMan->SetActiveFunction( ::REQ_Finish );  
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -