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

📄 minst.c

📁 Atheros AP Test with Agilent N4010A source code
💻 C
📖 第 1 页 / 共 5 页
字号:
#endif
		return 0;
	} else {
		pm = ibdev (0, ud, 0, T30s, 1, 0);
		pm_model = model;
		return pm;
	}
}

MANLIB_API int pmPreset(const int ud,
                        const double trigger_level,
                        const double trigger_delay,
                        const double gate_start,
                        const double gate_length,
                        const double trace_display_length) {

    switch (pm_model) {
        case PM_E4416A :
            gpibWrite( ud, qq(":disp:wind1:form dnum;num1:res 2;:disp:wind1:num2:res 2;:disp:wind2:form trac;num1:res 1;:calc1:feed \x22pow:aver\x22;:calc3:feed \x22pow:peak\x22;:aver:stat 1;coun 1;coun:auto 0;:aver2:stat 0;:pow:ac:rang:auto 0;:swe:time %f;offs:time %f;:sens:trac:time %f;:init:cont:seq 0;:trig:sour int;del %f;lev %f;lev:auto 0",
                             gate_length, gate_start, trace_display_length, trigger_delay, trigger_level) );
            return 1;

        default:

            return 0;

    }
                    
}

MANLIB_API double pmMeasAvgPower(const int ud, const int reset) {

//	printf("?????????????????pmMeasAvgPowr\n");

    char power[10];                 // 436A
    int i = 0, err = 0x0;
    char *buf, *channel, *reading;  // E4416A
	double retval = -120.;	

    switch (pm_model) {
        case PM_436A :
			buf = gpibQuery(ud, "9D-V", 14L);
			if (strlen(buf)==14) {
				strncpy(power, buf + 3, 9L);
					// 9        range             = auto
					// D        units             = dBm
					// -        disable calfactor = false
					// V        rate              = delayed freerun
        
				// check for garbage
				for (i = 1; i <=4 ; i++) { err = err | ( isdigit(power[i]) ? 0x0 : 0x1); }
				// return average power
				retval = atof(power);
				return (err ? -120 : retval);

			} else {
				printf("SNOOP: buf = --|%s|--\n", buf);
				return -120;
			}
        case PM_E4416A :

            if (reset) gpibWrite(ud, "*RCL 5;\n");

            // take a reading
			buf = gpibQuery(ud, "MEAS1:POW?\n", 20L);
			
            // parse output
            reading = strtok(buf,",");

            return (reading == NULL ? -120. : atof(reading));

        case PM_4531 :

            if (reset) {
                gpibWrite(ud, "MEM:SYS1:LOAD;\n");
                gpibWrite(ud, "SENS1:AVER4096;\n");
            }

            // take a reading
            buf = gpibQuery(ud, "MEAS1:POW?\n", 20L);

            // parse output
            channel = strtok(buf,",");
            reading = strtok(NULL, ",");

            return (reading == NULL ? -120. : atof(reading));

		case NRP_Z11 :

#ifndef LINUX
			retval = aquire_data();
#endif
			return retval;

        default:
			//printf("IT IS RETUNRED -Ve Value \n");
            return -120.;

    }

}

int spa_sweep_points() {
    switch(spa_model) {
        case SPA_E4404B :
            return SPA_E4404B_MAX_SWEEP_POINTS;
        case SPA_R3162 :
            return SPA_R3162_MAX_SWEEP_POINTS;
        case SPA_8595E :
            return SPA_8595E_MAX_SWEEP_POINTS;
        default:
            return SPA_E4404B_MAX_SWEEP_POINTS;

    }

}

MANLIB_API int spaInit(const int adr, const int model) {

    spa = ibdev (0, adr, 0, T30s, 1, 0);
    spa_model = model;
    return spa;

}

MANLIB_API char *spaMeasPhaseNoise(const int ud, 
                                   const double center, 
                                   const double ref_level,
                                   const int reset) {

    int n, rsp = 0;
    double ns0, ns1, ns2, ns3, ns4, ns5, ns6, ns7, ns8, ns9, ns10, ns11;
    static char ph_noise[107] =
                         "+999.99, +999.99, +999.99, +999.99, +999.99, +999.99, +999.99, +999.99, +999.99, +999.99, +999.99, +999.99";

    // reset prior to setting the center frequency
    if (reset) rsp = atoi(gpibQuery(ud, "*RST;*OPC?", 5L));

    // change to channel frequency
    gpibWrite(ud, qq(":FREQ:CENT %f;", center));      // center freq
    gpibWrite(ud, ":FREQ:SPAN 3E5;");                 // set span
    gpibWrite(ud, ":BAND:RES 1E3;VID 1E3;");          // resolution / video bandwidth
    gpibWrite(ud, qq(":DISP:WIND:TRAC:Y:RLEV %f;", ref_level)); // reference level
    gpibWrite(ud, ":DISP:WIND:TRAC:Y:PDIV 10;");      // scale
    gpibWrite(ud, ":INIT:CONT 0;");                   // single sweep
    gpibWrite(ud, ":AVER 0;");                        // averaging off
    gpibWrite(ud, ":DET SAMP;");                      // detector mode (sample)
    gpibWrite(ud, ":CALC:MARK:MODE POS;");            // marker mode (position)
    gpibWrite(ud, ":CALC:MARK:FUNC OFF;");            // marker function (off)
    gpibWrite(ud, ":FREQ:CENT:STEP:AUTO 0;");         // center freq step size manual
    gpibWrite(ud, ":TRAC:MODE WRIT;");                // max hold off
    gpibWrite(ud, ":INIT:IMM;*WAI;");                 // trigger sweep
    gpibWrite(ud, ":CALC:MARK:MAX;");                 // find max peak
    gpibWrite(ud, ":CALC:MARK:CENT;");                // center marker
    gpibWrite(ud, ":FREQ:SPAN 1E5;");                 // change span
    gpibWrite(ud, ":AVER:COUN 10;STATE 1;");          // take 10 averages
    gpibWrite(ud, ":INIT:IMM;*WAI;");                 // trigger sweep
    gpibWrite(ud, ":CALC:MARK:MAX;");                 // find max peak
    gpibWrite(ud, ":CALC:MARK:CENT;");                // recenter marker
    gpibWrite(ud, ":CALC:MARK:MODE DELT;");           // marker mode (delta)
    gpibWrite(ud, ":CALC:MARK:FUNC NOIS;");           // marker function (noise measurement)
    gpibWrite(ud, ":CALC:MARK:X 1E4;");               // move marker to 10 kHz
    ns0 = atof(gpibQuery(ud, ":CALC:MARK:Y?", 55L));  // measure amplitude delta
    gpibWrite(ud, ":CALC:MARK:X 3E4;");               // move marker to 30 kHz
    ns1 = atof(gpibQuery(ud, ":CALC:MARK:Y?", 55L));  // measure amplitude delta
    gpibWrite(ud, ":FREQ:CENT:STEP 6E4;");            // center freq step size 60 kHz
    gpibWrite(ud, ":FREQ:CENT UP;");                  // increment center freq
    gpibWrite(ud, ":INIT:IMM;*WAI;");                 // trigger sweep
    gpibWrite(ud, ":CALC:MARK:X 6E4;");               // move marker to 60 kHz
    ns2 = atof(gpibQuery(ud, ":CALC:MARK:Y?", 55L));  // measure amplitude delta
    gpibWrite(ud, ":FREQ:CENT:STEP 4E4;");            // center freq step size 40 kHz
    gpibWrite(ud, ":FREQ:CENT UP;");                  // increment center freq
    gpibWrite(ud, ":INIT:IMM;*WAI;");                 // trigger sweep
    gpibWrite(ud, ":CALC:MARK:X 1E5;");               // move marker to 100 kHz
    ns3 = atof(gpibQuery(ud, ":CALC:MARK:Y?", 55L));  // measure amplitude delta
    gpibWrite(ud, ":FREQ:CENT:STEP 2E5;");            // center freq step size 200 kHz
    gpibWrite(ud, ":FREQ:CENT UP;");                  // increment center freq
    gpibWrite(ud, ":INIT:IMM;*WAI;");                 // trigger sweep
    gpibWrite(ud, ":CALC:MARK:X 3E5;");               // move marker to 300 kHz
    ns4 = atof(gpibQuery(ud, ":CALC:MARK:Y?", 55L));  // measure amplitude delta
    gpibWrite(ud, ":FREQ:CENT:STEP 3E5;");            // center freq step size 300 kHz
    gpibWrite(ud, ":FREQ:CENT UP;");                  // increment center freq
    gpibWrite(ud, ":INIT:IMM;*WAI;");                 // trigger sweep
    gpibWrite(ud, ":CALC:MARK:X 6E5;");               // move marker to 600 kHz
    ns5 = atof(gpibQuery(ud, ":CALC:MARK:Y?", 55L));  // measure amplitude delta
    gpibWrite(ud, ":FREQ:CENT:STEP 4E5;");            // center freq step size 400 kHz
    gpibWrite(ud, ":FREQ:CENT UP;");                  // increment center freq
    gpibWrite(ud, ":INIT:IMM;*WAI;");                 // trigger sweep
    gpibWrite(ud, ":CALC:MARK:X 1E6;");               // move marker to 1 MHz
    ns6 = atof(gpibQuery(ud, ":CALC:MARK:Y?", 55L));  // measure amplitude delta
    gpibWrite(ud, ":FREQ:CENT:STEP 2E6;");            // center freq step size 2 MHz
    gpibWrite(ud, ":FREQ:CENT UP;");                  // increment center freq
    gpibWrite(ud, ":INIT:IMM;*WAI;");                 // trigger sweep
    gpibWrite(ud, ":CALC:MARK:X 3E6;");               // move marker to 3 MHz
    ns7 = atof(gpibQuery(ud, ":CALC:MARK:Y?", 55L));  // measure amplitude delta
    gpibWrite(ud, ":FREQ:CENT:STEP 3E6;");            // center freq step size 3 MHz
    gpibWrite(ud, ":FREQ:CENT UP;");                  // increment center freq
    gpibWrite(ud, ":INIT:IMM;*WAI;");                 // trigger sweep
    gpibWrite(ud, ":CALC:MARK:X 6E6;");               // move marker to 6 MHz
    ns8 = atof(gpibQuery(ud, ":CALC:MARK:Y?", 55L));  // measure amplitude delta
    gpibWrite(ud, ":FREQ:CENT:STEP 4E6;");            // center freq step size 4 MHz
    gpibWrite(ud, ":FREQ:CENT UP;");                  // increment center freq
    gpibWrite(ud, ":INIT:IMM;*WAI;");                 // trigger sweep
    gpibWrite(ud, ":CALC:MARK:X 1E7;");               // move marker to 10 MHz
    ns9 = atof(gpibQuery(ud, ":CALC:MARK:Y?", 55L));  // measure amplitude delta
    gpibWrite(ud, ":FREQ:CENT:STEP 2E7;");            // center freq step size 20 MHz
    gpibWrite(ud, ":FREQ:CENT UP;");                  // increment center freq
    gpibWrite(ud, ":INIT:IMM;*WAI;");                 // trigger sweep
    gpibWrite(ud, ":CALC:MARK:X 3E7;");               // move marker to 30 MHz
    ns10 = atof(gpibQuery(ud, ":CALC:MARK:Y?", 55L)); // measure amplitude delta
    gpibWrite(ud, ":FREQ:CENT:STEP 3E7;");            // center freq step size 30 MHz
    gpibWrite(ud, ":FREQ:CENT UP;");                  // increment center freq
    gpibWrite(ud, ":INIT:IMM;*WAI;");                 // trigger sweep
    gpibWrite(ud, ":CALC:MARK:X 6E7;");               // move marker to 60 MHz
    ns11 = atof(gpibQuery(ud, ":CALC:MARK:Y?", 55L)); // measure amplitude delta


    n = sprintf(ph_noise, "%06.2f, %06.2f, %06.2f, %06.2f, %06.2f, %06.2f, %06.2f, %06.2f, %06.2f, %06.2f, %06.2f, %06.2f",
                          ns0, ns1, ns2, ns3, ns4, ns5, ns6, ns7, ns8, ns9, ns10, ns11);
    ph_noise[n] = '\0';

    return ph_noise;
}

MANLIB_API char *spaMeasSpectralFlatness(const int ud, 
                                         const double center, 
                                         const double ref_level,
                                         const int reset) {

    int n, sc, worst_car_low = 0, worst_car_high = 0, rsp = 0;
    double max_peak, thresh, sub_car, total_amp, avg_amp, max_dev, deviation_low = 0, deviation_high = 0;
    double sc_amp[52];
    static char flat_data[25] = "-99.99, -99, -99.99, -99";

    // reset prior to setting the center frequency
    if (reset) rsp = atoi(gpibQuery(ud, "*RST;*OPC?", 5L));

    // change to channel frequency
    gpibWrite(ud, qq(":FREQ:CENT %f;", center));

    if (reset) {
       gpibWrite(ud, ":FREQ:SPAN 17E6;");                          // span
       gpibWrite(ud, ":BAND:RES 1E5;VID 1E3;");                    // resolution / video bandwidth
       gpibWrite(ud, qq(":DISP:WIND:TRAC:Y:RLEV %f;", ref_level)); // reference level
       gpibWrite(ud, ":DISP:WIND:TRAC:Y:PDIV 5;");                 // scale
       gpibWrite(ud, ":INIT:CONT 0;");                             // single sweep
       gpibWrite(ud, ":DET SAMP;");                                // detector mode (sample)
       gpibWrite(ud, ":TRAC:MODE WRIT;");                          // max hold off
    }

    // Make Spectral Flatness Measurement
    gpibWrite(ud, ":AVER:COUN 10;STATE 1;");                   // take 10 averages
    gpibWrite(ud, ":INIT:IMM;*WAI;");                          // trigger sweep

    gpibWrite(ud, ":CALC:MARK:MAX;");                          // find max peak
    max_peak = atof(gpibQuery(ud, ":CALC:MARK:Y?", 55L));      // measure peak amplitude
    thresh = max_peak - 3;                                     // calculate peak threshold
    gpibWrite(ud, qq(":CALC:MARK:PEAK:THR %f;", thresh));      // define peak threshold
    gpibWrite(ud, ":CALC:MARK:PEAK:EXC 1;");                   // define peak excursion
    gpibWrite(ud, ":CALC:MARK:MODE POS;");                     // marker mode (position)

    gpibWrite(ud, qq(":CALC:MARK:X %f;", center));             // marker to center frequency
    gpibWrite(ud, ":CALC:MARK:MAX:RIGH;");                     // find subcarrier +1
    sub_car = atof(gpibQuery(ud, ":CALC:MARK:X?", 55L));       // measure frequency of subcarrier +1
    sc_amp[0] = atof(gpibQuery(ud, ":CALC:MARK:Y?", 55L));     // measure amplitude of subcarrier +1
    for (sc=1; sc<26; sc++) {
       sub_car = sub_car + 312500;                             // calculate frequency of next subcarrier
       gpibWrite(ud, qq(":CALC:MARK:X %f;", sub_car));         // marker to next subcarrier
       sc_amp[sc] = atof(gpibQuery(ud, ":CALC:MARK:Y?", 55L)); // measure amplitude of next subcarrier
    }
    gpibWrite(ud, qq(":CALC:MARK:X %f;", center));             // marker to center frequency
    gpibWrite(ud, ":CALC:MARK:MAX:LEFT;");                     // find subcarrier -1
    sub_car = atof(gpibQuery(ud, ":CALC:MARK:X?", 55L));       // measure frequency of subcarrier -1
    sc_amp[26] = atof(gpibQuery(ud, ":CALC:MARK:Y?", 55L));    // measure amplitude of subcarrier -1
    for (sc=27; sc<52; sc++) {
       sub_car = sub_car - 312500;                             // calculate frequency of next subcarrier
       gpibWrite(ud, qq(":CALC:MARK:X %f;", sub_car));         // marker to next subcarrier
       sc_amp[sc] = atof(gpibQuery(ud, ":CALC:MARK:Y?", 55L)); // measure amplitude of next subcarrier
    }
    total_amp = 0;
    for (sc=0; sc<16; sc++) {
       total_amp = total_amp + sc_amp[sc];
    }
    for (sc=26; sc<42; sc++) {
       total_amp = total_amp + sc_amp[sc];
    }
    avg_amp = total_amp/32;
    max_dev = 0;
    for (sc=0; sc<16; sc++) {
       if (fabs(sc_amp[sc] - avg_amp) > max_dev) {
          max_dev = fabs(sc_amp[sc] - avg_amp);
          deviation_low = sc_amp[sc] - avg_amp;
          worst_car_low = sc + 1;
       }
    }
    for (sc=26; sc<42; sc++) {
       if (fabs(sc_amp[sc] - avg_amp) > max_dev) {
          max_dev = fabs(sc_amp[sc] - avg_amp);
          deviation_low = sc_amp[sc] - avg_amp;
          worst_car_low = sc + 1;
       }
    }
    if (worst_car_low > 26)
       worst_car_low = 26 - worst_car_low;
    max_dev = 0;
    for (sc=16; sc<26; sc++) {
       if (fabs(sc_amp[sc] - avg_amp) > max_dev) {
          max_dev = fabs(sc_amp[sc] - avg_amp);
          deviation_high = sc_amp[sc] - avg_amp;
          worst_car_high = sc + 1;
       }
    }
    for (sc=42; sc<52; sc++) {
       if (fabs(sc_amp[sc] - avg_amp) > max_dev) {
          max_dev = fabs(sc_amp[sc] - avg_amp);
          deviation_high = sc_amp[sc] - avg_amp;
          worst_car_high = sc + 1;
       }
    }
    if (worst_car_high > 26)
       worst_car_high = 26 - worst_car_high;

    n = sprintf(flat_data, "%06.2f, %03d, %06.2f, %03d", deviation_low, worst_car_low, deviation_high, worst_car_high);
    flat_data[n] = '\0';

    return flat_data;
}

/* Should only be used if tx is in continuous mode */
MANLIB_API double spaMeasChannelPower(const int ud, 
                                      const double center, 
                                      const double span, 
                                      const double ref_level,
                                      const double rbw,
                                      const double vbw,
                                      const double int_bw,
                                      const int det_mode,
                                      const int averages, 
                                      const int max_hold, 
                                      const int reset) {

⌨️ 快捷键说明

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