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

📄 rssi_power.c

📁 Atheros AP Test with Agilent N4010A source code
💻 C
📖 第 1 页 / 共 3 页
字号:

void sendCalDataFromGU(A_UINT32 devNum, A_UINT32 mode, A_UINT32 opcode, A_UINT32 debug)
{
	A_UINT16 ch ;
	A_INT16 ii;
	double pwrList[64];
	A_UCHAR  devlibMode ; // use setResetParams to communicate appropriate mode to devlib
	dPCDACS_EEPROM *pRawDatasetLocal;
	char cmd[1024];

	switch (mode) {
	case MODE_11a:
		devlibMode = MODE_11A;
		break;
	case MODE_11g :
		devlibMode = MODE_11G;
		break;
	case MODE_11b :
		devlibMode = MODE_11B;
		break;
	default:
		uiPrintf("Unknown mode : %d \n", mode);
		exit(0);
		break;
	}

	configSetup.eepromLoad = 0;
	art_setResetParams(devNum, configSetup.pCfgFile, (A_BOOL)configSetup.eepromLoad,
					(A_BOOL)configSetup.eepromHeaderLoad, (A_UCHAR)devlibMode, configSetup.use_init);

	if (mode != MODE_11a)
	{
		pRawDatasetLocal = pRawDataset_2p4[mode] ;
	} else
	{
		pRawDatasetLocal = pRawDataset ;
	}

	uiPrintf("\nAssisting with raw data collection for mode %s\n", modeName[mode]);
	setupGUForPwrMeas(devNum, opcode, mode, debug);
	fprintf(logGU, "%d\n", pRawDatasetLocal->numChannels);
	writeIntListToStr(cmd, sizeOfRawPcdacs, &(RAW_PCDACS[0]), sizeOfRawPcdacs);
	fprintf(logGU, cmd);

	if (debug)
		uiPrintf("numChannels=%d for mode %s\n", pRawDatasetLocal->numChannels, modeName[mode]);

	for (ii=0; ii<pRawDatasetLocal->numChannels; ii++)
	{
		ch = pRawDatasetLocal->pDataPerChannel[ii].channelValue;
		if (debug)
			uiPrintf("starting channel %d\n", ch);
		art_changeChannel(devNum, ch);
		sendPwrData(devNum, opcode, ch, mode, RAW_PCDACS, sizeOfRawPcdacs, &(pwrList[0]), debug);
	}

	fclose(logGU);
	attSet(guDevAtt, MAX_ATTENUATOR_RANGE);

} // sendCalDataFromGU



void setupGUForPwrMeas(A_UINT32 devNum, A_UINT32 opcode, A_UINT32 mode, A_UINT32 debug)
{

	double		minAtten, maxCcaPower, pmAtten, fixedAtten;
	char		filename[64], parseFilename[64];
	A_UINT32	filetype;
	A_UINT32	atten;
	A_UINT32	ch, rddata, wrdata, kk=0;
	A_INT32		minccapwr;

	ch = ((mode == MODE_11a) ? 5170 : 2412) ;
	sprintf(filename, "%s_", modeName[mode]);
	sprintf(parseFilename, "%s_", modeName[mode]);

	minAtten = MAX_TRANSMIT_POWER - MAX_RECEIVE_POWER;
	maxCcaPower = MIN_TRANSMIT_POWER - MAX_RECEIVE_ROLLOFF - minAtten ;
	// maxccapwr_int = (A_INT32) maxCcaPower;

	if (mode == MODE_11a)
	{
		pmAtten = CalSetup.attenDutPM ;
		fixedAtten = CalSetup.attenDutGolden;
	} else
	{
		pmAtten = CalSetup.attenDutPM_2p4[mode] ;
		fixedAtten = CalSetup.attenDutGolden_2p4[mode] ;
	}

	switch (opcode) {
	case GET_GU_PWR :
		strcat(parseFilename, COEFF_GU_FILENAME);
		parseCoeffTable(parseFilename, debug);
		strcat(filename, LOG_GU_FILENAME);
		logGU = fopen(filename, "w");
		if (logGU == NULL)
			uiPrintf("Unable to open file for logging : %s\n", filename);
		filetype = LOG_FILETYPE;
		break ;
	case CAL_PM_PWR :
		strcat(filename, CAL_PM_FILENAME);
		logGU = fopen(filename, "w");
		if (logGU == NULL)
			uiPrintf("Unable to open file for logging : %s\n", filename);
		filetype = REF_FILETYPE;

		if (CalSetup.pmModel != PM_E4416A)
		{
			uiPrintf("fast cal is only supported with Agilent E4416A model power meters at this point.\n");
			exit(0);
		}

		gpibClear(guDevPM);
		gpibWrite(guDevPM, "*rcl 7\n");
		Sleep(3000);
		gpibWrite(guDevPM, "*cls;:sens:mrat doub\n");
		break ;
	case CAL_GU_PWR :
		strcat(filename, CAL_GU_FILENAME);
		logGU = fopen(filename, "w");
		if (logGU == NULL)
			uiPrintf("Unable to open file for logging : %s\n", filename);
		filetype = RAW_FILETYPE;
		break;
	default :
		uiPrintf("Illegal opcode in setupGUForPwrMeas : %d\n", opcode);
		exit(0);
		break;
	}

	fprintf(logGU, "%f\n", FAST_CAL_FILES_VERSION);
	fprintf(logGU, "%d\n", filetype);

	uiPrintf("Verify the Following Constraints ...\n");
	uiPrintf("\tReceive input ( gu ) < %3.1f dBm\n", MAX_RECEIVE_POWER);
	uiPrintf("\tTransmit power (dut) < %3.1f dBm\n", MAX_TRANSMIT_POWER);
	uiPrintf("\tTransmit power (dut) > %3.1f dBm\n", MIN_TRANSMIT_POWER);
	atten = (A_UINT32) floor( minAtten - fixedAtten );

	if (atten > MAX_ATTENUATOR_RANGE)
	{
		uiPrintf("required attenuation (%d) > max attenutor range (%d)\n", atten, MAX_ATTENUATOR_RANGE);
		exit(0);
	} else
	{
		attSet(guDevAtt, atten);
		uiPrintf("\tMinimum Attenuation Needed: %3.1f, Prog Attenuator Set to : %d\n", minAtten, atten);
	}


	uiPrintf("\tReceive rolloff < %3.1f dBm\n", MAX_RECEIVE_ROLLOFF);
	uiPrintf("\tMin cca power   > %3.1f dBm\n", maxCcaPower);
	uiPrintf("\tDut to PM atten = %3.1f dBm\n", pmAtten);
	uiPrintf("\tPeak TX power   > %3.1f dBm\n", MIN_TRANSMIT_POWER + MAX_PEAK_TO_AVERAGE);
	uiPrintf("\tPM trig level   < %3.1f dBm\n\n", MIN_TRANSMIT_POWER + MAX_PEAK_TO_AVERAGE - pmAtten);
// SNOOP: eventually set this trig level automatically.

	// disable noise cal
	art_resetDevice(devNum, rxStation, bssID, ch, 0);

	// select rssi output format
	rddata = art_regRead(devNum, (0x9800 + (23<<2)));
	wrdata = ( rddata & ~(3<<30) )| (RSSI_OUT_SELECT<<30) ;
	art_regWrite(devNum, (0x9800 + (23<<2)), wrdata);
	uiPrintf("setting rssi format to %3.2f dB resolution\n", 1.0/pow(2,RSSI_OUT_SELECT) );


//	Sleep(50);


	Sleep(50);
	rddata = art_regRead(devNum, (0x9800 + (24<<2)));
	wrdata = rddata & ~0x8002;
	art_regWrite(devNum, (0x9800 + (24<<2)), wrdata);

	// force noise floor

	rddata = art_regRead(devNum, 0x9800+(25<<2));
// for read-modify-write
//	wrdata = (rddata & ~(0x1ff)) | (( (maxCcaPower<0) ? (abs((A_UINT32)(maxCcaPower*2)) ^ 0x1ff)+1 : (A_UINT32)(maxCcaPower*2)));
	wrdata =  (( (maxCcaPower<0) ? (abs((A_UINT32)(maxCcaPower*2)) ^ 0x1ff)+1 : (A_UINT32)(maxCcaPower*2)));
	art_regWrite(devNum, 0x9800+(25<<2), wrdata);

//	uiPrintf("rddata = %x, wrdata = %x\n", rddata, wrdata);

	rddata = art_regRead(devNum, (0x9800 + (24<<2)));
	wrdata = rddata | 0x0002;
	art_regWrite(devNum, (0x9800 + (24<<2)), wrdata);

	//	uiPrintf("forceval=%x\n", wrdata);

	rddata = 1;
	while ( rddata != 0)
	{
		rddata = ( art_regRead(devNum, (0x9800 + (24<<2))) & 0x2);
		Sleep(10);
		uiPrintf("SNOOP: (%d) rddata = %x\n", kk++, rddata);
	}

	rddata = art_regRead(devNum, (0x9800+(25<<2)));
	minccapwr = (rddata >> 19) & 0x1ff;
	if (minccapwr & 0x100) {
		minccapwr = -((minccapwr ^ 0x1ff) + 1);
	}
	uiPrintf( "Minimum CCA power was forced to %d dBm\n\n", minccapwr);

	if (debug)
		uiPrintf("finished setupGUForPwrMeas with opcode %d\n", opcode);
} // setupGUForPwrMeas

void sendPwrData(A_UINT32 devNum, A_UINT32 opcode, A_UINT32 channel, A_UINT32 mode,
						A_UINT16 *pcdacs, A_UINT32 numPcd, double *retVals,
						A_UINT32 debug)
{
	A_UINT32 ii, pcdIter, numAvg;
	A_UCHAR  datapattern[1] = {0x00};
	A_UINT32 broadcast = 1;
	A_UINT32 start_timeout = 1000; //1000;
//	A_UINT32 complete_timeout_short = (mode == MODE_11b) ? 50: 20; // for one pcdac
	A_UINT32 complete_timeout_short = 500; // for one pcdac
	A_UINT32 complete_timeout_long = 3000; // for all pcdacs
	A_UINT32 statsMode = SKIP_SOME_STATS | (NUM_INITIAL_PKTS_TO_SKIP << NUM_TO_SKIP_S);
	//A_UINT32 statsMode = NO_REMOTE_STATS;
	A_UINT32 enablePPM = 0;
	double   sum[64], avg[64];
	double	 pwr, corr;
	A_UINT32 cnt[64];
	RX_STATS_STRUCT rStats;
	A_INT32 rssi;
	char cmd[1024];
	A_UCHAR		spr; // serial poll register


	double   pmAtten, fixedAtten;

	if (mode == MODE_11a)
	{
		pmAtten = CalSetup.attenDutPM ;
		fixedAtten = CalSetup.attenDutGolden;
	} else
	{
		pmAtten = CalSetup.attenDutPM_2p4[mode] ;
		fixedAtten = CalSetup.attenDutGolden_2p4[mode] ;
	}

	numAvg = (opcode == CAL_PM_PWR) ? 1 : NUM_POWER_AVERAGES ;

	for (ii=0; ii<64; ii++)
	{
		sum[ii] = 0.0;
		avg[ii] = 0.0;
		cnt[ii]=0;
	}

	if (opcode == CAL_PM_PWR)
	{
		Sleep(1000);
		sprintf(cmd, "freq %dmhz\n", channel);
		gpibWrite(guDevPM, cmd);
		Sleep(1000);
	}

	for (ii=0; ii<numAvg; ii++)
	{
		if (opcode != CAL_PM_PWR)
		{
			// wait for transmitter
			waitForAck(debug);
			if (!verifyAckStr("Prepare to begin receive for power meas at "))
			{
				uiPrintf("acks out of sync: should sync for fastcal at ch: %d, avg_iter: %d, opcode: %d\n", channel, ii, opcode);
				uiPrintf("ack parameters found to be - par1: %d, par2: %d, par3: %d\n", ackRecvPar1, ackRecvPar2, ackRecvPar3);
				exit(0);
			}

			sendAck(devNum, "Ready to begin receive for power meas at ",  channel, ii, opcode, debug);
		}

		for (pcdIter=0; pcdIter < numPcd; pcdIter++)
		{
			if (opcode == CAL_PM_PWR)
			{
				// arm power meter
				Sleep(E4416_SLEEP_INTERVAL);
				gpibWrite(guDevPM, "init\n");
				Sleep(E4416_SLEEP_INTERVAL);

				// wait for transmitter
				waitForAck(debug);
				if (!verifyAckStr("Prepare for RX at pcdac = ") || (RAW_PCDACS[pcdIter] != ackRecvPar2))
				{
					uiPrintf("acks got out of sync in sendPwrData\n");
					exit(0);
				}

				art_rxDataSetup(devNum, NUM_POWER_PACKETS + 40, LEN_POWER_PACKETS, enablePPM);
				sendAck(devNum, "Ready for RX at pcdac = ", channel, RAW_PCDACS[pcdIter], opcode, debug);
				art_rxDataBegin(devNum, start_timeout, complete_timeout_short, statsMode, 0, datapattern, 1);

				// measure power
				gpibWrite(guDevPM, "fetch?\n");
				while(!(gpibRSP(guDevPM, (A_CHAR *)&(spr)) & 16))
				{
					Sleep(E4416_SLEEP_INTERVAL);
					break;
				}

				Sleep(E4416_SLEEP_INTERVAL);
				sum[pcdIter] += atof(gpibRead(guDevPM, 17)) + pmAtten ;
				uiPrintf("Pcdac %d: %f dBm (ch: %d)\n", RAW_PCDACS[pcdIter], sum[pcdIter], channel);
				(cnt[pcdIter])++ ;
			} else
			{

				// wait for transmitter
				waitForAck(debug);
				if (!verifyAckStr("Prepare for RX at pcdac = ") || (RAW_PCDACS[pcdIter] != ackRecvPar2))
				{
					uiPrintf("acks got out of sync in sendPwrData\n");
					exit(0);
				}

				art_rxDataSetup(devNum, NUM_POWER_PACKETS + 40, LEN_POWER_PACKETS, enablePPM);
				sendAck(devNum, "Ready for RX at pcdac = ", channel, RAW_PCDACS[pcdIter], opcode, debug);
				art_rxDataBegin(devNum, start_timeout, complete_timeout_short, statsMode, 0, datapattern, 1);

				// stats
				art_rxGetStats(devNum, 6, 0, &rStats);
				rssi = rStats.DataSigStrengthAvg ;
				if (rssi != 0)
				{
					cnt[pcdIter]++ ;
				} else
				{
					uiPrintf("SNOOP: rssi=%d, not incrementing count\n", rssi);
				}
				if (rssi & 0x80)
					rssi = -((rssi^0xff) + 1);
				sum[pcdIter] += rssi/pow(2, RSSI_OUT_SELECT) ;
			}

		} // for (0..numPcd)

	} // for (0..numAvg)


	if (opcode == GET_GU_PWR)
	{
		for (pcdIter=0; pcdIter<numPcd; pcdIter++)
		{
			pwr = sum[pcdIter]/cnt[pcdIter];
			corr = getCorrVal(channel, rssi, debug);
			avg[pcdIter] = pwr - corr;
		}
		writeDoubleListToStr(cmd, channel, &(avg[0]), numPcd);
		fprintf(logGU, cmd);
		fflush(logGU);
		waitForAck(debug);
		if (!verifyAckStr("Send Power List"))
		{
			uiPrintf("acks out of sync. expected req: %s\n", "Send Power List");
			exit(0);
		}
		sendAck(devNum, cmd, numPcd, channel, numAvg, debug);
	} else
	{
		for (pcdIter=0; pcdIter<numPcd; pcdIter++)
		{
			avg[pcdIter] = sum[pcdIter]/cnt[pcdIter];
		}
		writeDoubleListToStr(cmd, channel, &(avg[0]), numPcd);
		fprintf(logGU, cmd);
	}

	uiPrintf("done with channel: %d\n", channel);

} // sendPwrData

void parseCoeffTable(char *filename, A_UINT32 debug)
{
	FILE		*fp;
	char		linebuf[1024];
	A_BOOL		line1 = FALSE; // version #
	A_BOOL		line2 = FALSE; // fileType: 0->coeffs, 1->ref, 2->raw
	A_BOOL		line3 = FALSE; // numChannels
	A_BOOL		line4 = FALSE; // numCoeffs
	A_UINT32	dummy[NUM_COEFFS];
	A_UINT32	filetype;
	double		version;
	A_UINT16	numCh, ii, jj;
	A_UINT32	numCoeffs, channel;



	uiPrintf("\nReading from file %s\n", filename);
	if( (fp = fopen( filename, "r")) == NULL ) {
		uiPrintf("Failed to open %s to read golden coeffs\n", filename);
		exit(0);
	}

	ii=0;

	while(fgets(linebuf, 1020, fp) != NULL)
	{
		if (!line1)
		{
			if (!sscanf(linebuf, "%lf", &(version)))
			{
				uiPrintf("Could not read version from file %s, line: %s\n", filename, linebuf);
				exit(0);
			} else
			{
				line1 = TRUE;
				if (debug)
					uiPrintf("Coeff file version: %f\n", version);
				continue;
			}
		}

		if (!line2)
		{
			if (!sscanf(linebuf, "%d", &(filetype)))
			{
				uiPrintf("Could not read the file type from file %s, line: %s\n", filename, linebuf);
				exit(0);
			} else
			{
				line2 = TRUE;
				if (filetype != COEFF_FILETYPE)
				{
					uiPrintf("File %s is not a valid golden coeff file.\n", filename);
					exit(0);
				}
				if (debug)
					uiPrintf("Filetype is : %d\n", filetype);
				continue;
			}
		}

		if (!line3)
		{
			if (!sscanf(linebuf, "%d", &(numCh)))
			{
				uiPrintf("Could not read number of channels from file %s, line: %s\n", filename, linebuf);
				exit(0);
			} else
			{
				line3 = TRUE;
				if (debug)
					uiPrintf("Number of channels : %d\n", numCh);
				continue;
			}
		}

		if (!line4)
		{
			extractIntsFromStr(linebuf, dummy, NUM_COEFFS, &(numCoeffs), debug);
			line4 = TRUE;
			if (numCoeffs != NUM_COEFFS)
			{
				uiPrintf("Number of coeffs read (%d) form file (%s) is different from expected (%d)\n", numCoeffs, filename, NUM_COEFFS);
				exit(0);
			}

			if (debug)
				uiPrintf("Number of coeffs : %d\n", numCoeffs);
			break;
		}
	} // done reading first 4 lines

	pGoldenCoeffs->numChannels = numCh;
	pGoldenCoeffs->numCoeffs = (A_UINT16) numCoeffs;

	pGoldenCoeffs->pChannels = (A_UINT16 *)malloc(sizeof(A_UINT16) * numCh);
	if (NULL == pGoldenCoeffs->pChannels) {
		uiPrintf("unable to allocate golden coeffs channels\n");
		exit(0);
	}

⌨️ 快捷键说明

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