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

📄 forms.c

📁 802.11仿真源码 对分析RSSI很有用的
💻 C
📖 第 1 页 / 共 2 页
字号:
/*forms.cWritten by: Peter TzannesINPUT          ->    OUTPUTstrength'i'.txt     &            ->    analysed'i'.txtform'i'.csvwhere:  forms'i'.txt is the output of the strength.c file  form'i'.csv is the csv form fileand 'i' is an integer which represents different sample of data  The first few lines identify  - the confidence level  - the number of operating WLANs  - if the sample had ducted air-conditioning  - the number of people present while doing the experiment  This program calculates and writes to the output file for each MP:  - the distance from the router to all MP  - the room type   - the angle of incident between the router and MP  - the information form the strength.c programOUTPUT The output is in the format: Room> <MP> <Distance> <RSSI> < Number of excess packets >  <Number of total received packets> <Room number>  <Angle of Incident> and the <PER>   where "<>" identifies the use of a column. */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <math.h>#define MAXLINE 40#define KISLINE 350 //max line in Kismet form#define MAX_FIELD_SIZE 8#define pi 3.14159int router_found = 0; //variable used to determine if the experimental router was foundint low, high;        //the lowest and highest levels used in experimentint z = 0;            //global analyses counterint once = 0;         //ensure himidity is only run once float routerroomx, routerroomy, routerroomz; //router position coordinates of the roomdouble routerposx, routerposy, routerposz;   //router position cordinates relative to the origin//empty the contents of array tmpint empty(char *tmp){  int j;  for(j = 0 ; j<= MAX_FIELD_SIZE; j++)     tmp[j] = 0;    return(0);}//delete all commas in student numberint studnum(char *x) // the inital contents are x = #,1234567...{  int i,j;  char temp[BUFSIZ];    if (x[2] != 'z')    {      for(i = 0, j = 2; i <= strlen(x); i++, j++)	  temp[i] = x[j];            temp[7] = '\0';      strcpy(x, temp);    }  else // if students put the z in their student number    {      for(i = 0, j = 3; i <= strlen(x); i++, j++)	{	  temp[i] = x[j];      	}      temp[7] = '\0';      strcpy(x, temp);    }  return(0);}//delete commas in post codeint postcode(char *x) // initial contents are x = ,1234...{  int i,j;  char temp[BUFSIZ];  for(i = 0, j = 5; i <= strlen(x); i++, j++)    {      temp[i] = x[j];          }  temp[4] = '\0';  strcpy(x, temp);  return(0);}//Determines the number of floors used in the expeirment, using the data in the buildings form.//The highest floor is written to the variable floor, while the lowest floor is written to a variable low.int levelhouse(FILE *in){  char room[BUFSIZ], line[BUFSIZ];  int inc;  rewind(in);  for(inc = 0; inc < 6; inc++) //skip over first 6 lines      fgets(line, 150, in);  sscanf(line, "%s", room);  low = room[1];  fgets(line, 150, in);  sscanf(line, "%s", room);  high = room[1];  return(0);}//This function needs the relevent form'i'.txt file created by the program strength.c, //where the 'i' is the unique attribute number for that form. //The program then creates//Also calculates the angle of incidence, from router to MP and writes it to the file,//where 0 degrees means the router was directly op top of the MP. int form(int arg, int ROOM, int MP, FILE *out, int TMP, float distance, int rm_type, float displacementz){  FILE *fw;  char temp[BUFSIZ];    //a temp string  char line[MAXLINE];  const char *final = "strength";  int room, mp, pkt_over, pkt_total;  //int pkt_lost, pkt_recv;  float rssi;   float oldrssi = -1.0, angle = 0;   float per = 0;  float humidity = 0;  sprintf(temp,"%s%d.txt",final,arg); //form'i'.txt  fw = fopen(temp, "r");    if ((fw) == NULL)      exit(1);  if(once == 0) // global once counter  {    fgets(line, MAXLINE, fw);    sscanf(line,"%f\n", &humidity);    fprintf(out,"%f\n",humidity);    once++;  }  while(!feof(out))    {      fgets(line, MAXLINE, fw);      char *tmp;      tmp = (char *)malloc(60);       if(strcmp(line, "END") == 0)	return(0);      if(strcmp(line, "EMPTY") == 0)	return(0);      sscanf(line,"%g,%d,%d,%d,%d,%f\n", &per, &room, &mp, &pkt_over, &pkt_total, &rssi);      if(ROOM == 0)        //ROOM will be 0 if a line is not of the form ROOM MP RSSI        return(0);      if((ROOM == room) && (MP == mp))      {		if(displacementz >= 0)	  angle = (acos(displacementz/distance))*(180/pi); 	else	  angle = (asin(displacementz/distance))*(180/pi)+ 90;        fprintf(out, "%d %d %f %f %d %d %d %f %g\n", room, mp, distance, rssi, pkt_over, pkt_total, rm_type, angle, per);//printf output to file	       }      oldrssi = rssi;     //backup the rssi value.       }  fclose(fw);  return(0);}//This function determines the number of WLANs detected by Kismet, and then subtracts this from the //number of WLANs disabled during the experiment as recorded in the csv file. //It then writes number of operating WLANs to the output fileint kismet(int arg, FILE *out, FILE *in){  FILE *read;  char line[KISLINE];   char temp[10];    //a temp string  const char *kis = "Kismet";  int i = 0, j = 0, counter = 0;  sprintf(temp,"%s%d.csv",kis,arg); //form'i'.txt  read = fopen(temp, "r");    if ((read) == NULL)      exit(1);  fgets(line, KISLINE, read); //skip over first line  while(!feof(read))    {      fgets(line, KISLINE, read);      if(strlen(line) > 2) //skip counter over blank line	i++;    }  //find '802.11 disabled' in form  rewind(in);  while(j<18)  {    fgets(line, 100, in);       j++;  }  //deals with the first line of the 802.11 disabled section  fgets(line, KISLINE, in);      if(line[16] == '0')    counter++;  else    i--;    j = 0;  //deals with the rest  while(counter != 1)  {    fgets(line,KISLINE, in);        if(j == 4) //have recorded all fields in 802.11 disabled section    {      fprintf(out,"WLAN: 0%d \n",i);      return(0);    }    if(line[1] == '0')      counter++;    else      {	j++;	i--;      }  }  if((i >= 0) && (i <= 9)) //make number into 2 digits    fprintf(out,"WLAN: 0%d \n",i);  else    fprintf(out,"WLAN: %d \n",i);  return(0);}//Determines if the dwelling has airconditioning and the number of people//that were recorded in the spreadsheet, writes the result to the output fileint aircon_people(int arg, FILE *out, FILE *in){  char line[KISLINE];  int j = 0;  int yes = 1, no = 0;  rewind(in);  while(j < 15)  {    fgets(line,KISLINE, in);         j++;  }  fgets(line, KISLINE, in);    if(line[7] == '2')    fprintf(out,"AIR: %d \n",yes);  else    fprintf(out,"AIR: %d \n",no);    fgets(line, KISLINE, in);   if(line[9] == 0)   //if didn't fill in then assume only 1 person in dwelling    fprintf(out,"PEOPLE: %d \n",yes);   else    fprintf(out,"PEOPLE: %c \n",(line[9] - 1)); //greater than 9 people in dwelling are both set to 0,rest correspond to output number   return(0);}//This function is used to start from the beginning of the file, and find the beginning of the rooms. //Once found, all variables in that line are assigned a unique variable, so can be manipulated.//Depending on the fields set in the function call, either the coordinates or height of the router will be determined.int scan(int level, float xpos, float ypos, FILE *in, FILE *out, int coord, int height, int roomcoord, int confidence){  char room[BUFSIZ], line[BUFSIZ], temp[BUFSIZ];  int count = 0;  int inc; // major loop counter  int a,b,c,d,e,f,g,h,i,j,k, single,length,templ, test; //variables  float l,m,n,o,p; //variables  int roomcoordtemp = 1; //temp integer  float x,y,z; //coordinates  int perheight = 1.0; //height of the user when holding laptop  float displacementx, displacementy, displacementz; //displacement from MP to router at coordinates x,y,z   float dismag; //magnitude from the router  int one = 1;  rewind(in);  for(inc = 0; inc < 140; inc++)    {      a=b=c=d=e=f=g=h=i=j=k=-1;      l=m=n=o=p=-1.0;      fgets(line, BUFSIZ, in);      count =(sscanf(line, "%s", room));      if (strcmp(room,",,,Width") == 0)	{	  for(inc = 0; inc<150;inc++)	    {	      fgets(line, BUFSIZ, in);	      count =(sscanf(line, "%d,%d", &a,&b)); // read in first 2 numbers	      for(single = 0, count = 0, test = 0; single <= strlen(line); single++) //skip over works		{		  if (line[single] == ',')		      count++;		  if((count == 3) && (test == 0))		    {		      test = 1;		      for(length = single, templ = 0; length <= strlen(line); length++, templ++)			{			  temp[templ] = line[length];			}		    }  		}	      //read in all other variables	      count =(sscanf(temp, ",%f,%f,%f,%f,%d,%d,%d,%d,%d,%f,%d,%d,%d,%d", &l,&m,&n,&o,&c,&d,&e,&f,&g,&p,&h,&i,&j,&k)); //elements from a line	      if(coord == 1)       //coordinates of router need to be determined		{	  	    	  		  if(a == level)		    {		      routerroomx = n; //x coord of router		      routerroomy = o; //y coord of router		      if((xpos > l) || (ypos > o)) //students that meausred the router from the origin of the house			{			  routerroomx = xpos - n ; //position from origin minus coordinates of foom			  routerroomy = ypos - o;  //same method			  if ((routerroomx < 0) || (routerroomy < 0)) //if less than 0, then made a mistake			    {			      routerroomx = n;			      routerroomy = o;			    }			  return(0);			}		      return(0);		    }		}	      else if(height == 1) //height needs to be determined		{

⌨️ 快捷键说明

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