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

📄 measure.cpp

📁 这是一个手机校准程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:

	// set Broadcast control channel arfcn 
		age1960_cmd(vi_instr, "CALL:FUNC:DOWN BCH");
		age1960_BCHARFCN(vi_instr, age1960_CELL_1, channel, age1960_CURRENT_BAND, VI_TRUE);
		age1960_amplitudeOffset(vi_instr, freq_offset, loss_offset, 1);
		age1960_cellPower(vi_instr, age1960_CELL_1, -85.0, 0.0);
// set TSC0
    age1960_burstType(vi_instr,age1960_TSC0_BURST);

    } // end if HP tester

  //Select operation mode for HP8922
	else if(tester_type==HP8922)
		{
//------------------- HP8922
    GpibWrt("DISPLAY:SCREEN CELL1");
	  switch(band)
      {
	    case GSM:
		    GpibWrt("CONF:RADIO 'GSM900'");
		    break;
	    case DCS:
		    GpibWrt("CONF:RADIO 'DCS1800'");
		    break;
	    case PCS:
		    GpibWrt("CONF:RADIO 'PCS1900'");
		    break;
	    default: break;
      }

	  Sleep(6000);

	// set Broadcast control channel arfcn 
	  sprintf(buf,"CCON:SCEL1:ARFCN %d",channel);
	  GpibWrt(buf);
	  Sleep(2500);

	// Set expected input signal channel number
	  sprintf(buf, "RFANALYZER:ARFCN %d",channel);
	  GpibWrt(buf);	
	  Sleep(1000);

  // Turn cable loss on
    sprintf(buf,"CONFIGURE:OFLEVEL:MODE 'ON'"); 
    GpibWrt(buf);
  // Set cable loss
    sprintf(buf,"CONFIGURE:OFLEVEL:RFINOUT %f",cable_loss); 
    GpibWrt(buf);

  // check to make sure it all happened
    sprintf(buf,"CONFIGURE:OFLEVEL:MODE?"); 
    GpibWrt(buf);
    GpibRd(buf);

    sprintf(buf,"CONFIGURE:OFLEVEL:RFINOUT?"); 
    GpibWrt(buf);
    GpibWrt(buf);

	  GpibWrt("CW:PMZERO");
    } // end if HP tester

//------------------- CMU200
  else if(tester_type==CM200)
    {
	  
	sprintf(buf0,"SENSE:RFANALYZER:CHAN %dCH",channel);
  // sprintf(buf0,"SENSE:RFANALYZER:CHAN %d",channel);   //weidg
    sprintf(buf1,"SENSE:RFANALYZER:TSEQ GSM0");

    GpibWrt(buf0);

	GpibWrt("*OPC?");
    GpibRd(buf);
    
	GpibWrt(buf1);
    GpibWrt("SENSE:LEVEL:MAX 35");

    if(band==GSM)
      {
     sprintf(buf,"SOURCE:RFG:FREQ:CHAN %dCH",channel);
     // sprintf(buf,"SOURCE:RFG:FREQ:CHAN %d",channel);    //weidg
      GpibWrt(IdCM200_GSM900_NS,buf);

	  GpibWrt("*OPC?");
      GpibRd(buf);

      GpibWrt(IdCM200_GSM900_NS,"CONF:RFG:MOD:TRAN CONT");
      GpibWrt(IdCM200_GSM900_NS,"CONF:RFG:MOD:BIT:SEL OFF");

     GpibWrt(IdCM200_GSM900_NS,"CONF:POW:CONT SCAL,1");              //weidg 
     GpibWrt(IdCM200_GSM900_NS,"CONF:POW:CONT:REP SING,NONE,NONE");  //weidg 
   
     GpibWrt(IdCM200_GSM900_NS,"CONF:MOD:CONT SCAL,1");              //weidg   
     GpibWrt(IdCM200_GSM900_NS,"CONF:MOD:CONT:REP SING,NONE,NONE");  //weidg 
     
	 GpibWrt(IdCM200_GSM900_NS,"CONF:POW:TIME:MODE GSM");  //weidg 
    
      GpibWrt(IdCM200_GSM900_NS,"SENS:LEV:MODE MAN");
     
	  GpibWrt(IdCM200_GSM900_NS,"TRIG:SEQ:SOUR IFP");   //weidg Trigger Source
 	  GpibWrt(IdCM200_GSM900_NS,"TRIG:SEQ:THR LOW");   //weidg Trigger Source
//	  GpibWrt(IdCM200_GSM900_NS,"TRIG:SEQ:SLOPE POSITIVE");   //weidg Trigger Source


	  GpibWrt(IdCM200_GSM900_NS,"OUTPUT RF2");
      GpibWrt(IdCM200_GSM900_NS,"INPUT RF2");
      GpibWrt(IdCM200_GSM900_NS,"*OPC?");
      GpibRd(buf);
  
      GpibWrt(IdCM200_GSM900_NS,"INIT:RFG");
       
      GpibWrt(IdCM200_GSM900_NS,"INIT:POW");
      GpibWrt(IdCM200_GSM900_NS,"INIT:SPOW"); //spow
    
      sprintf(buf,"SENSE:CORRECTION:LOSS:INPUT2 %f",-1.0*cable_loss);
      GpibWrt(IdCM200_GSM900_NS,buf);
      sprintf(buf,"SENSE:CORRECTION:LOSS:OUTPUT2 %f",-1.0*cable_loss);
      GpibWrt(IdCM200_GSM900_NS,buf);
      GpibWrt(IdCM200_GSM900_NS,"*OPC?");
      GpibRd(buf);
      }
    else if(band==DCS)
      {
      sprintf(buf,"SOURCE:RFG:FREQ:CHAN %dCH",channel);

      GpibWrt(IdCM200_GSM1800_NS,buf);

	  GpibWrt("*OPC?");
      GpibRd(buf);

      GpibWrt(IdCM200_GSM1800_NS,"CONF:RFG:MOD:TRAN CONT");
      GpibWrt(IdCM200_GSM1800_NS,"CONF:RFG:MOD:BIT:SEL OFF");
      GpibWrt(IdCM200_GSM1800_NS,"CONF:POW:TIME:MODE GSM");            //weidg 

      GpibWrt(IdCM200_GSM1800_NS,"CONF:POW:CONT SCAL,1");               //weidg 
      GpibWrt(IdCM200_GSM1800_NS,"CONF:POW:CONT:REP SING,NONE,NONE");  //weidg 
   
       GpibWrt(IdCM200_GSM1800_NS,"CONF:MOD:CONT SCAL,1");             //weidg   
       GpibWrt(IdCM200_GSM1800_NS,"CONF:MOD:CONT:REP SING,NONE,NONE");  //weidg 

       GpibWrt(IdCM200_GSM1800_NS,"SENS:LEV:MODE MAN");

      GpibWrt(IdCM200_GSM1800_NS,"TRIG:SEQ:SOUR IFP");   //weidg Trigger Source
 	  GpibWrt(IdCM200_GSM1800_NS,"TRIG:SEQ:THR LOW");   //weidg Trigger Source
//	  GpibWrt(IdCM200_GSM1800_NS,"TRIG:SEQ:SLOP POS");   //weidg Trigger Source
      
	  GpibWrt(IdCM200_GSM1800_NS,"OUTPUT RF2");
      GpibWrt(IdCM200_GSM1800_NS,"INPUT RF2");
  
      GpibWrt(IdCM200_GSM1800_NS,"*OPC?");
      GpibRd(buf);
      GpibWrt(IdCM200_GSM1800_NS,"INIT:RFG");
      GpibWrt(IdCM200_GSM1800_NS,"INIT:POW");
      GpibWrt(IdCM200_GSM1800_NS,"INIT:SPOW"); 

      sprintf(buf,"SENSE:CORRECTION:LOSS:INPUT2 %f",-1.0*cable_loss);
      GpibWrt(IdCM200_GSM1800_NS,buf);
      sprintf(buf,"SENSE:CORRECTION:LOSS:OUTPUT2 %f",-1.0*cable_loss);
      GpibWrt(IdCM200_GSM1800_NS,buf);
      GpibWrt(IdCM200_GSM1800_NS,"*OPC?");
      GpibRd(buf);
      }
    else if(band==PCS)
      {
    sprintf(buf,"SOURCE:RFG:FREQ:CHAN %dCH",channel);
   
      GpibWrt(IdCM200_GSM1900_NS,buf);

	  GpibWrt("*OPC?");
      GpibRd(buf);

      GpibWrt(IdCM200_GSM1900_NS,"CONF:RFG:MOD:TRAN CONT");
      GpibWrt(IdCM200_GSM1900_NS,"CONF:RFG:MOD:BIT:SEL OFF");
      GpibWrt(IdCM200_GSM1900_NS,"CONF:POW:TIME:MODE GSM");  //weidg 
    
      GpibWrt(IdCM200_GSM1900_NS,"CONF:POW:CONT SCAL,1");               //weidg 
      GpibWrt(IdCM200_GSM1900_NS,"CONF:POW:CONT:REP SING,NONE,NONE");  //weidg 
   
       GpibWrt(IdCM200_GSM1900_NS,"CONF:MOD:CONT SCAL,1");             //weidg   
       GpibWrt(IdCM200_GSM1900_NS,"CONF:MOD:CONT:REP SING,NONE,NONE");  //weidg 

       GpibWrt(IdCM200_GSM1900_NS,"SENS:LEV:MODE MAN");
       
	  GpibWrt(IdCM200_GSM1900_NS,"TRIG:SEQ:SOUR IFP");   //weidg Trigger Source
 	  GpibWrt(IdCM200_GSM1900_NS,"TRIG:SEQ:THR LOW");   //weidg Trigger Source
//	  GpibWrt(IdCM200_GSM1900_NS,"TRIG:SEQ:SLOP POS");   //weidg Trigger Source

	   GpibWrt(IdCM200_GSM1900_NS,"OUTPUT RF2");
      GpibWrt(IdCM200_GSM1900_NS,"INPUT RF2");
  
      GpibWrt(IdCM200_GSM1900_NS,"*OPC?");
      GpibRd(buf);
      GpibWrt(IdCM200_GSM1900_NS,"INIT:RFG");
      GpibWrt(IdCM200_GSM1900_NS,"INIT:POW");
      GpibWrt(IdCM200_GSM1900_NS,"INIT:SPOW"); 

      sprintf(buf,"SENSE:CORRECTION:LOSS:INPUT2 %f",-1.0*cable_loss);
      GpibWrt(IdCM200_GSM1900_NS,buf);
      sprintf(buf,"SENSE:CORRECTION:LOSS:OUTPUT2 %f",-1.0*cable_loss);
      GpibWrt(IdCM200_GSM1900_NS,buf);
      GpibWrt(IdCM200_GSM1900_NS,"*OPC?");
      GpibRd(buf);
      }
    } // end if Rohde & Schwarz tester
   
	return TRUE;
  }


//***************
//------------- GetFreqOffset
// note that channel and band aren't used - this routine assumes that the channel and band
// have been initialized elsewhere for the instrument.
// returns FALSE on error
//***************
BOOL measure::GetFreqOffset(float *offset)
  {
  Int8 buf[256];
  float dummy1,dummy2,dummy3,dummy5,dummy6,dummy7,dummy8,dummy9,dummy10,dummy11;
  char dummy4[20];
  unsigned stat,Auto;
  char log_msg[256];
  unsigned i,j;    //weidg
  double measured_cmu;   //weidg cmu
  double diff;           //weidg cmu 
  double diff1;          //weidg cmu
  double expected_power; //weidg cmu

  if(tester_type==AGT8960)
    {
		ViInt32		Integrity;
		ViReal64	RMSError, PeakError, FreqError;

		age1960_readPFER_Q(vi_instr, &Integrity, &RMSError, &PeakError, &FreqError);
		sprintf(log_msg,"Querying freq offset: integrity=%d, rms_phase_error=%f, peak_phase_error=%f, freq_error=%f",
            Integrity,RMSError,PeakError,FreqError);
    LogGPIB(log_msg);
    *offset = (float)FreqError;
		if(Integrity==2)
      {
      stat=1;
      }
		else
      {
      stat=0;
      }
    }

  else if(tester_type==HP8922)
    {
//Initialize the Freqency measurement
    GpibWrt("DISPLAY:DSPANALYZER:VIEW 'PHASEMAIN'");
	  Sleep(100);
// Read the Frequency offset from IdHP8922		offset1
    GpibWrt("MEASURE:DSP:PHASE:ERROR:FREQUENCY?");
	  Sleep(500);
    GpibRd(buf);
    *offset = (float)atof(buf);
    if(strlen(buf)==0)
      {
      stat=0;
      }
    else
      {
      stat=1;
      }
    GpibWrt("DISPLAY:SCREEN CELL1");
    }

//--------------------- CMU200
  else if(tester_type==CM200)
    {
     //  ibloc(IdCM200_BASE);
     // Sleep(500);  //was 500

       // Read the Frequency offset from CMU200
        expected_power=20;
        measured_cmu=999;
        diff=expected_power-measured_cmu;
		stat=TRUE;
		
		i=0;
	    strcpy(buf,"NAN");
        diff1=0;
		stat=0;
		Auto=1;
	    while ( ((stat==0) && ( i<=1 )) || (((diff>=5.5) || (diff<=1)) && ((expected_power+12)>=0)&&(i<=1)) || ((Auto==1) && (i<=1)))
		{
            expected_power=expected_power-diff1+5;
			if (expected_power<=-12 )
			{  
				expected_power=-12;
			} 
			if (expected_power>=39 )
			{   
				expected_power=39;
			} 
			
			sprintf(buf,"SENSE:LEVEL:MAX %f",expected_power);
			GpibWrt(buf);
			GpibWrt("*OPC?");
            GpibRd(buf);
			GpibWrt("READ:POW?");  
			GpibRd(buf);

			measured_cmu=C_parse(buf,1);
			if( fabs(measured_cmu+9999999.99)<1)
			{ 
		        stat=0;
			} 
		    else
			{ 
		        stat=1;
			} 
            Auto=0;
			if(stat==0)
			{ 
				 GpibWrt("SENSE:LEV:MODE AUTOMATIC");
				 Auto=1;
				 Sleep(50);
				 GpibWrt("READ:POW?");  
				 GpibRd(buf);
		         measured_cmu=C_parse(buf,1);
				 if( fabs(measured_cmu+9999999.99)<1)
				 {  
					 stat=0;
				 } 
				 else
				 { 
					 stat=1;
				 } 
						
				 if(stat!=1)
				 {
				    stat=0;
					j=0;
					strcpy(buf,"NAN");
					while ( (strstr(buf,"NAN")) && ( j<=1 ))
					{ 
						GpibWrt("READ:SPOW?");
			            Sleep(50);
						GpibRd(buf);
						j++;
					}
						
					if(strstr(buf,"NAN"))
					{
						measured_cmu=-9999999.99;
					}
					else
					{
						measured_cmu=(float)atof(buf);
					 	stat=1;
					}
				 }
				 else
				 {
				    stat=1;
				 }
				 GpibWrt("SENSE:LEV:MODE MANUAL");
						
			}
		    if ( (stat==0) && (Auto==1))
			{
				diff=10;
			}
            else
			{
			    diff=expected_power-measured_cmu;
			}
			diff1=diff;
			i++;
            
		}
		if( fabs(measured_cmu+9999999.99)<1)
		{
		    sprintf(buf,"SENSE:LEVEL:MAX 35");
		}
		else
        {
			sprintf(buf,"SENSE:LEVEL:MAX %f",measured_cmu+5);
		}
		GpibWrt(buf);
		GpibWrt("*OPC?");
        GpibRd(buf);
		Sleep(50);
   
        strcpy(buf,"NAN");
        

		i=0;
		stat=0;
		
		*offset=-9999999.99;
		while ( (fabs(*offset+9999999.99)<1) && (i<=3 ))     //weidg
		{
		  GpibWrt("READ:SCALAR:MOD:RES?");
		  Sleep(500);   //was 500
		  GpibRd(buf);  // frequency error in 8th value (in Hz)

		  *offset=C_parse(buf,7);
		  i++;
		}
	 				  
		if( fabs(*offset+9999999.99)<1)
		{
		   stat=FALSE;
		}
		else
		{
		  stat=1;
		}
    }
  return stat;
  }

//***************
//------------- GetPhaseError
// note that channel and band aren't used - this routine assumes that the channel and band
// have been initialized elsewhere for the instrument.
// returns FALSE on error
//***************
BOOL measure::GetPhaseError(float *phase_error)
  {
  Int8 buf[256];
  float dummy1,dummy2,dummy3,dummy5,dummy6,dummy7,dummy8,dummy9,dummy10,dummy11;
  char dummy4[20];
  unsigned stat,Auto;
  char log_msg[256];
  unsigned i,j;   //weidg
  double measured_cmu;  //weidg cmu
  double diff;          //weidg cmu 
  double diff1;         //weidg cmu
  double expected_power; //weidg cmu

  if(tester_type==AGT8960)
    {
	  ViInt32		Integrity;
	  ViReal64	RMSError, PeakError, FreqError;
		
    age1960_readPFER_Q(vi_instr, &Integrity, &RMSError, &PeakError, &FreqError);
		sprintf(log_msg,"Querying phase offset: integrity=%d, rms_phase_error=%f, peak_phase_error=%f, freq_error=%f",
            Integrity,RMSError,PeakError,FreqError);
    LogGPIB(log_msg);
	  *phase_error = (float)RMSError;
	  if(Integrity==2)
      {
      stat=1;
      }
	  else
      {
      stat=0;
      }
    }

  else if(tester_type==HP8922)
    {
//Initialize the Freqency measurement
    GpibWrt("DISPLAY:DSPANALYZER:VIEW 'PHASEMAIN'");
	  Sleep(100);
// Read the phase error from IdHP8922	.
    GpibWrt("MEASURE:DSP:PHASE:ERROR:RMS?");
	  Sleep(500);
    GpibRd(buf);
    *phase_error = (float)atof(buf);
    if(strlen(buf)==0)
      {
      stat=0;
      }
    else
      {
      stat=1;
      }
    GpibWrt("DISPLAY:SCREEN CELL1");
    }

//--------------------- CMU200
  else if(tester_type==CM200)
    {

  //   ibloc(IdCM200_BASE);
  //   Sleep(500);  //was 500
        expected_power=20;
        measured_cmu=999;
        diff=expected_power-measured_cmu;
		stat=TRUE;
		i=0;
	    strcpy(buf,"NAN");
        diff1=0;
		stat=0;
		Auto=1;
	    while ( ((stat==0) && ( i<=1 )) || (((diff>=5.5) || (diff<=1)) && ((expected_power+12)>=0)&&(i<=1)) || ((Auto==1) && (i<=1)))
		{
            expected_power=expected_power-diff1+5;
			if (expected_power<=-12 )
			{  
				expected_power=-12;
			} 
			if (expected_power>=39 )
			{   
				expected_power=39;
			} 
			
			sprintf(buf,"SENSE:LEVEL:MAX %f",expected_power);
			GpibWrt(buf);
			GpibWrt("*OPC?");
            GpibRd(buf);
			GpibWrt("READ:POW?");  
			GpibRd(buf);

			measured_cmu=C_parse(buf,1);
			if( fabs(measured_cmu+9999999.99)<1)
			{ 
		        stat=0;
			} 
		    else
			{ 
		        stat=1;

⌨️ 快捷键说明

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