Exemple #1
0
static double
get_txpower_mw(void *arg)
{
	double mw = dbm2mw(get_txpower_dbm(arg));
	xsg_debug("get_txpower_mw: %f", mw);
	return mw;
}
Exemple #2
0
double sellectPhyRate(double snr){
	double phyRate;

	if(gSpec.rateMode==0){
		phyRate = shannon(dbm2mw(snr));
	}else{
		if(snr<9.63){
			phyRate = 0;
			printf("Phy rate is 0 Mbit/s\n");
			//exit(17);
		}else if(snr<10.63){
			phyRate = 6;
		}else if(snr<12.63){
			phyRate = 9;
		}else if(snr<14.63){
			phyRate = 12;
		}else if(snr<17.63){
			phyRate = 18;
		}else if(snr<21.63){
			phyRate = 24;
		}else if(snr<25.63){
			phyRate = 36;
		}else if(snr<26.63){
			phyRate = 48;
		}else{
			phyRate = 54;
		}
	}

	return phyRate;
}
Exemple #3
0
void calculateRSSI(apInfo *ap, staInfo sta[], double delay[]){
	double rssi = 1;
	//double distance = sqrt(pow(sta->x, 2) + pow(sta->y, 2));
	int i, j;
	double uplink, downlink;
	//double noise = -91.63;
	double ICI;   //Inter-client interference
	double snr;
	double sinr;
	double r_mat[NUM_STA+1][NUM_STA+1] = {};
	double txPower;
	/*
	if(isTxSta==false){
		RSSI = ap->txPower + ap->antennaGain + sta->antennaGain - (30*log10(distance) + gSpec.loss);
	}else{
		RSSI = sta->txPower + ap->antennaGain + sta->antennaGain - (30*log10(distance) + gSpec.loss);
	}*/
	for(i=0; i<NUM_STA+1; i++){
		for(j=0; j<NUM_STA+1; j++){
			if(i==j){
				r_mat[i][j] = 0;
			}else if(j==0 && i!=0){   //下りのみ
				rssi = ap->txPower + ap->antennaGain + sta[i-1].antennaGain - (30*log10(distance[i][0]) + gSpec.loss);
				snr = rssi - gSpec.noise;// pow(10,(rssi)/10)/(pow(10,(gSpec.noise)/10)+pow(10,(gSpec.ICI)/10));
				if(snr<9.63){
					r_mat[i][j] = 0;
				}else if(gSpec.proMode==0||gSpec.proMode==2||gSpec.proMode==3||gSpec.proMode==5||gSpec.proMode==6){
					r_mat[i][j] = shannon(dbm2mw(snr));//downlink = 20*log2(1+snr);
				}else if(gSpec.proMode==1||gSpec.proMode==4){
					r_mat[i][j] = shannon(dbm2mw(snr)) * pow(delay[j], gSpec.delayPower);
				}
				//printf("%f\n", ap->dataRate);
			}else if(j!=0 && i==0){   //上りのみ
				rssi = sta[j-1].txPower + sta[j-1].antennaGain + ap->antennaGain - (30*log10(distance[0][j]) + gSpec.loss);
				snr = rssi - gSpec.noise;
				if(snr<9.63){
					r_mat[i][j] = 0;
				}else if(gSpec.proMode==0||gSpec.proMode==2||gSpec.proMode==3||gSpec.proMode==5||gSpec.proMode==6){
					r_mat[i][j] = shannon(dbm2mw(snr));
				}else if(gSpec.proMode==1||gSpec.proMode==4){
					r_mat[i][j] = shannon(dbm2mw(snr)) * pow(delay[j], gSpec.delayPower);
					//printf("%f = %f * %f / 10000\n", r_mat[i][j], shannon(dbm2mw(snr)), delay[j]);
				}
				//printf("%f\n", sta[*upNode-1].dataRate);
			}else{
				rssi = ap->txPower + ap->antennaGain + sta[i-1].antennaGain - (30*log10(distance[i][0]) + gSpec.loss);
				snr = rssi - gSpec.noise - gSpec.ICIth;
				if(snr<9.63){
					downlink = 0;
				}else if(gSpec.proMode==0||gSpec.proMode==2||gSpec.proMode==3||gSpec.proMode==5||gSpec.proMode==6){
					downlink = shannon(dbm2mw(snr));
				}else if(gSpec.proMode==1||gSpec.proMode==4){
					downlink = shannon(dbm2mw(snr));// * delay[0] / 10000;
				}
				ICI = sta[j-1].txPower + sta[j-1].antennaGain + sta[i-1].antennaGain - (30*log10(distance[i][j]) + gSpec.loss);
				sinr = mw2dbm(dbm2mw(rssi)/(dbm2mw(gSpec.noise)+dbm2mw(ICI)));
				//printf("%f, %f, %f, %f\n", rssi, ICI, snr, sinr);
				if(sinr>=snr){
					rssi = sta[j-1].txPower + sta[j-1].antennaGain + ap->antennaGain - (30*log10(distance[0][j]) + gSpec.loss);
					sinr = mw2dbm(dbm2mw(rssi)/(dbm2mw(gSpec.noise)+dbm2mw(ap->txPower-gSpec.SIC)));
					if(sinr<9.63){
						uplink = 0;
					}else if(gSpec.proMode==0||gSpec.proMode==2||gSpec.proMode==3||gSpec.proMode==5||gSpec.proMode==6){
						uplink = shannon(dbm2mw(rssi)/(dbm2mw(gSpec.noise)+dbm2mw(ap->txPower-gSpec.SIC)));
					}else if(gSpec.proMode==1||gSpec.proMode==4){
						uplink = shannon(dbm2mw(rssi)/(dbm2mw(gSpec.noise)+dbm2mw(ap->txPower-gSpec.SIC)));// * delay[j] / 10000;
					}
				}else{
					ICI =mw2dbm((dbm2mw(gSpec.ICIth)-1)*dbm2mw(gSpec.noise));
					//printf("%f\n", ICI);
					txPower = ICI - sta[j-1].antennaGain - sta[i-1].antennaGain + 30*log10(distance[i][j]) + gSpec.loss;
					if(txPower>=sta[j-1].txPower){
						printf("ICI Error\n");
					}
					rssi = txPower + sta[j-1].antennaGain + ap->antennaGain - 30*log10(distance[0][j]) - gSpec.loss;
					sinr = mw2dbm(dbm2mw(rssi)/(dbm2mw(gSpec.noise)+dbm2mw(ap->txPower-gSpec.SIC)));
					if(sinr<9.63){
						uplink = 0;
					}else if(gSpec.proMode==0||gSpec.proMode==2||gSpec.proMode==3||gSpec.proMode==5||gSpec.proMode==6){
						uplink = shannon(dbm2mw(rssi)/(dbm2mw(gSpec.noise)+dbm2mw(ap->txPower-gSpec.SIC)));
					}else if(gSpec.proMode==1||gSpec.proMode==4){
						uplink = shannon(dbm2mw(rssi)/(dbm2mw(gSpec.noise)+dbm2mw(ap->txPower-gSpec.SIC)));// * delay[j] / 10000;
					}
					//printf("%f\n", txPower);
				}
				if(downlink==0||uplink==0){
					r_mat[i][j] = 0;
				}else if(gSpec.proMode==1||gSpec.proMode==4){
					r_mat[i][j] = (downlink + uplink) * pow(delay[j], gSpec.delayPower);
				}else{
					r_mat[i][j] = downlink + uplink;
				}

				//printf("%f\n", ap->dataRate);
				//printf("%f\n", sta[*upNode-1].dataRate);
			}

			/*if(i==j){
				r_mat[i][j] = 0;
			}else if(i==0){
				RSSI = sta[j-1].txPower + sta[j-1].antennaGain + ap->antennaGain - (30*log10(distance(ap, sta, 0, j)) + gSpec.loss);
				uplink = 20*log2(1+pow(10,(RSSI-noise)/10));
				r_mat[i][j] = uplink;
			}else if(j==0){
				RSSI = ap->txPower + ap->antennaGain + sta[i-1].antennaGain - (30*log10(distance(ap, sta, i, 0)) + gSpec.loss);
				downlink = 20*log2(1+pow(10,(RSSI-noise)/10));
				r_mat[i][j] = downlink;
			}else if(i!=j){
				RSSI = sta[j-1].txPower + ap->antennaGain + sta[j-1].antennaGain - (30*log10(distance(ap, sta, 0, j)) + gSpec.loss);
				snr = pow(10,RSSI/10) / (pow(10,noise/10) + pow(10,(sta->txPower-gSpec.SIC)/10));
				uplink = 20*log2(1+snr);
				RSSI = ap->txPower + ap->antennaGain + sta[i].antennaGain - (30*log10(distance(ap, sta, i, 0)) + gSpec.loss);
				ICInterference = sta[j-1].txPower + sta[j-1].antennaGain + sta[i-1].antennaGain - (30*log10(distance(ap, sta, i, j)) + gSpec.loss);
				snr = pow(10,(RSSI)/10)/(pow(10,(noise)/10)+pow(10,(ICInterference)/10));
				downlink = 20*log2(1+snr);
				r_mat[i][j] = uplink+downlink;
			}else{
				printf("RSSI error!\n");
			}*/
		}
	}

	ratePrintf("\n***** Rate Matrix *****\n");
	for(i=0;i<NUM_STA+1;i++){
		for(j=0;j<NUM_STA+1;j++){
			if(r_mat[i][j]!=0){
				r[i*(NUM_STA+1)+j] = -r_mat[i][j];
				ratePrintf("%f, ", r[i*(NUM_STA+1)+j]);
				ub[i*(NUM_STA+1)+j] = 100;
			}else{
				r[i*(NUM_STA+1)+j] = -r_mat[i][j];
				ub[i*(NUM_STA+1)+j] = 0;
				ratePrintf("%f, ", r[i*(NUM_STA+1)+j]);
			}
		}
		ratePrintf("\n");
	}
	ratePrintf("***** Rate Matrix *****\n\n");
}
Exemple #4
0
void calculatePhyRate(apInfo *ap, staInfo sta[], int *upNode, int *downNode){
	double rssi;   //dBm
	double snr;   //dBm
	double sinr;   //dBm
	double txPower;   //dBm
	double ICI;   //dBm

	//printf("calculatePhyRate %d %d\n", *downNode, *upNode);

	if(*upNode==0 && *downNode!=0){
		//printf("down half\n");
		rssi = ap->txPower + ap->antennaGain + sta[*downNode-1].antennaGain - (30*log10(distance[*downNode][0]) + gSpec.loss);
		snr = rssi - gSpec.noise;// pow(10,(rssi)/10)/(pow(10,(gSpec.noise)/10)+pow(10,(gSpec.ICI)/10));
		ap->dataRate = sellectPhyRate(snr);//shannon(dbm2mw(snr));//downlink = 20*log2(1+snr);
		//printf("%f\n", ap->dataRate);
	}else if(*upNode!=0 && *downNode==0){
		//printf("up half\n");
		rssi = sta[*upNode-1].txPower + sta[*upNode-1].antennaGain + ap->antennaGain - (30*log10(distance[0][*upNode]) + gSpec.loss);
		snr = rssi - gSpec.noise;
		sta[*upNode-1].dataRate = sellectPhyRate(snr);//shannon(dbm2mw(snr));
		//printf("%f\n", sta[*upNode-1].dataRate);
	}else if(*upNode==0 && *downNode==0){
		printf("Error 876\n");
	}else{
		//printf("full duplex\n");
		rssi = ap->txPower + ap->antennaGain + sta[*downNode-1].antennaGain - (30*log10(distance[*downNode][0]) + gSpec.loss);
		snr = rssi - gSpec.noise;
		ICI = sta[*upNode-1].txPower + sta[*upNode-1].antennaGain + sta[*downNode-1].antennaGain - (30*log10(distance[*downNode][ *upNode]) + gSpec.loss);
		sinr = mw2dbm(dbm2mw(rssi)/(dbm2mw(gSpec.noise)+dbm2mw(ICI)));
		//printf("%f, %f, %f, %f\n", rssi, ICI, snr, sinr);
		if(sinr>=snr-5){
			ap->dataRate = sellectPhyRate(sinr);//shannon(dbm2mw(sinr));
			rssi = sta[*upNode-1].txPower + sta[*upNode-1].antennaGain + ap->antennaGain - (30*log10(distance[0][*upNode]) + gSpec.loss);
			sta[*upNode-1].dataRate = sellectPhyRate(mw2dbm(dbm2mw(rssi)/(dbm2mw(gSpec.noise)+dbm2mw(ap->txPower-gSpec.SIC))));
			/*if(sta[*upNode].dataRate<6){
				sta[*upNode].dataRate = 6;
			}*/
		}else{
			ICI =mw2dbm((dbm2mw(gSpec.ICIth)-1)*dbm2mw(gSpec.noise));
			//printf("%f\n", ICI);
			txPower = ICI - sta[*upNode-1].antennaGain - sta[*downNode-1].antennaGain + 30*log10(distance[*downNode][*upNode]) + gSpec.loss;
			if(txPower>=sta[*upNode-1].txPower){
				printf("ICI Error\n");
			}
			rssi = txPower + sta[*upNode-1].antennaGain + ap->antennaGain - 30*log10(distance[0][*upNode]) - gSpec.loss;
			sinr = mw2dbm(dbm2mw(rssi)/(dbm2mw(gSpec.noise)+dbm2mw(ap->txPower-gSpec.SIC)));
			if(sinr<9.63){
				//printf("%f\n", r[(*downNode)*(NUM_STA+1)+*upNode]);
				//printf("sinr=%f\n", sinr);
			}
			sta[*upNode-1].dataRate = sellectPhyRate(mw2dbm(dbm2mw(rssi)/(dbm2mw(gSpec.noise)+dbm2mw(ap->txPower-gSpec.SIC))));
			/*if(sta[*upNode].dataRate<6){
				sta[*upNode].dataRate = 6;
			}*/
			rssi = ap->txPower + ap->antennaGain + sta[*downNode-1].antennaGain - (30*log10(distance[*downNode][0]) + gSpec.loss);
			sinr = mw2dbm(dbm2mw(rssi)/(dbm2mw(gSpec.noise)+dbm2mw(ICI)));
			ap->dataRate = sellectPhyRate(sinr);//shannon(dbm2mw(sinr));
		}
	}
	/*if(*downNode!=0){
		printf("AP's data rate: %f\n", ap->dataRate);
	}
	if(*upNode!=0){
		printf("sta %d's data rate: %f\n", *upNode-1, sta[*upNode-1].dataRate);
	}*/
}