#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
system("iwlist ath0 peers > foo.txt"); // get all the peers and their corresponding strength and put them in a file
FILE *file;
file = fopen("foo.txt", "r");
int i, p_index, str_index, index, check;
char p[50]; // contains parsed string
int sig_strength[3]; // store the strength of the 3 peers,
// this is what needs to be put in packet and sent to server
check = fscanf(file, "%s", &p);
while(p != NULL && check != EOF)
{
if (strcmp(p, "00:18:39:05:20:26") == 0) // Robot 192.168.1.4's mac addr
{
char str1[3] = {' ',' ',' '};
char str2[3] = {' ',' ',' '};
for(index = 0; index < 8; index++) // get the 8 strings on this line associated with this mac addr
{
fscanf(file, "%s",&p);
if (index == 1) // The second string represents Signal Strength data, obtain strength value from it
{
str_index = 0;
p_index = 8;
str1[str_index++] = p[p_index++];
while(p[p_index] != '/')
{
str1[str_index++] = p[p_index++];
}
p_index++;
str_index = 0;
while(p_index < strlen(p))
{
str2[str_index++] = p[p_index++];
}
sig_strength[2] = (int) ((atof(str1)/atof(str2)) * 100); // Convert signal strength to reflect value out of 100
}
}
}
else if (strcmp(p, "00:18:39:05:1B:37") == 0) // Robot 192.168.1.3's mac addr
{
char str1[3] = {' ',' ',' '};
char str2[3] = {' ',' ',' '};
for(index = 0; index < 8; index++) // get the 8 strings on this line associated with this mac addr
{
fscanf(file, "%s",&p);
if (index == 1) // The second string represents Signal Strength data, obtain strength value from it
{
str_index = 0;
p_index = 8;
str1[str_index++] = p[p_index++];
while(p[p_index] != '/')
{
str1[str_index++] = p[p_index++];
}
p_index++;
str_index = 0;
while(p_index < strlen(p))
{
str2[str_index++] = p[p_index++];
}
sig_strength[1] = (int) ((atof(str1)/atof(str2)) * 100); // Convert signal strength to reflect value out of 100
}
}
}
else if (strcmp(p, "00:18:39:05:1E:DE") == 0) // Robot 192.168.1.2's mac addr
{
char str1[3] = {' ',' ',' '};
char str2[3] = {' ',' ',' '};
for(index = 0; index < 8; index++) // get the 8 strings on this line associated with this mac addr
{
fscanf(file, "%s",&p);
if (index == 1) // The second string represents Signal Strength data, obtain strength value from it
{
str_index = 0;
p_index = 8;
str1[str_index++] = p[p_index++];
while(p[p_index] != '/')
{
str1[str_index++] = p[p_index++];
}
p_index++;
str_index = 0;
while(p_index < strlen(p))
{
str2[str_index++] = p[p_index++];
}
sig_strength[0] = (int) ((atof(str1)/atof(str2)) * 100); // Convert signal strength to reflect value out of 100
}
}
}
check = fscanf(file,"%s\n", &p);
}
// These print statements are just for testing to see if right values were obtained
// They will not be needed once this code is integrated
printf("Robot 1 Strength: %d/100\n", sig_strength[0]);
printf("Robot 2 Strength: %d/100\n", sig_strength[1]);
printf("Robot 3 Strength: %d/100\n", sig_strength[2]);
return 0;
}