void parseIniFile(char *fileName,struct NodeInfo *ndInfo)
{
	FILE *iniFptr = NULL;
	struct stat fileData;
	char line[100];
	char *str = NULL, * strkey = NULL;
	char *section = (char *)malloc(10);
	if(stat(fileName,&fileData) < 0)
	{
		printf("\nThe specified ini file %s does not exist\n",fileName);
		exit(0);
	}
	if((iniFptr = fopen(fileName,"r")) == NULL)
	{
		printf("\nError opening ini file: %s\n",fileName);
		exit(0);
	}
	while(fgets(line,sizeof(line),iniFptr) != NULL)
	{
		if((str = strchr(line,'[')) != NULL)
		{
			//This is a section, so find the ']' bracket
			int i = 0;
			str++;
			while(*str != ']')
			{
				section[i] = *str;
				str++;
				i++;
			}
			section[i] = '\0';
		}
		else if(strcmp(line,"\n") != 0)
		{
			//This is not a section, these are key value pairs
			if(strcmp(section,"init") == 0)
			{
				strkey = getKey(line);
				if(strkey != NULL)
					getValue(strkey);
				initializeNodeInfo(key,value,ndInfo);
			}
			else if(strcmp(section,"beacons") == 0)
			{
				strkey = getKey(line);
				if(strcmp(key,"Retry") == 0)
				{
					if(strkey != NULL)
						getValue(strkey);
					initializeNodeInfo(key,value,ndInfo);
				}
				else
				{
					getBeaconInfo(key,ndInfo);
				}
			}
		}
	}
	free(section);
}
Exemple #2
0
int main(int argc, char *argv[]){
	//Check option values from command line.
	//checkOption(argc, argv);
	//Apply option values to simulation settings.
	simSetting(argc,argv);

	if((gFileSta=fopen("sta's buffer.txt", "w"))==NULL){
		printf("File cannot open! 3");
		exit(33);
	}

	staInfo *sta;
	sta = (staInfo*)malloc(sizeof(staInfo)*gSpec.numSta);
	apInfo ap;
	resultInfo result;
	//Intialize result information.
	initializeResult(&result);

	if(gSpec.fDebug==true){
		debug();
		//printf("End debug.\n");
		//exit(99);
	}

	int numTx = 0;
	int trialID;
	bool fEmpty = false;

	for (trialID=0; trialID<gSpec.numTrial; trialID++){
		srand(trialID);
		numTx = 0;
		fEmpty = false;
		initializeNodeInfo(sta, &ap);

		gElapsedTime = (double)gStd.difs;
		idle(sta, &ap, &numTx, &fEmpty);
		//Wrong? fEmpty=true?

		for(; gElapsedTime<gSpec.simTime*1000000;){
			if(numTx==1){
				//debugSta(&sta[7],7);
				txSuccess(sta, &ap, &numTx);
				fEmpty = true;
				for(int i=0; i<gSpec.numSta; i++){
					if(sta[i].buffer[0].lengthMsdu!=0){
						fEmpty = false;
						break;
					}
				}
				if(ap.buffer[0].lengthMsdu!=0){
					fEmpty = false;
				}
				if(fEmpty==true){
					idle(sta, &ap, &numTx, &fEmpty);
				}else{
					afterSuccess(sta, &ap, &numTx);
				}
			}else{
				txCollision(sta, &ap);
				afterCollision(sta, &ap, &numTx);
			}
		}
		simulationResult(sta, &ap, &result, trialID);
	}

	if(gSpec.fOutput==true){
		fclose(gSpec.output);
	}
	fclose(gFileSta);
	free(sta);
	return 0;
}