[pisa-src] r1218 - trunk/tools/iwlist_parser.c

  • From: Hanno Wirtz <hanno.wirtz@xxxxxxxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Fri, 16 Oct 2009 14:48:47 +0200

Author: wirtz
Date: Fri Oct 16 14:48:46 2009
New Revision: 1218

Log:
added signal strength

NOTE : Decision on best AP is still done based on Quality

Modified:
   trunk/tools/iwlist_parser.c

Modified: trunk/tools/iwlist_parser.c
==============================================================================
--- trunk/tools/iwlist_parser.c Fri Oct 16 14:15:38 2009        (r1217)
+++ trunk/tools/iwlist_parser.c Fri Oct 16 14:48:46 2009        (r1218)
@@ -25,6 +25,7 @@
 #define LINE_BUFFER_LENGTH     999
 
 //#define USESTEP 0
+//#define DEBUG 1
 
 bool essidflag;                                //Look for one SSID only
 bool fileflag;                         //Use a file rather than stdin?
@@ -32,7 +33,7 @@
 char strEssid[MAX_CELLS][ESSID_LENGTH];
 char strMAC[MAX_CELLS][MAC_LENGTH];
 char strSelectedESSID[ESSID_LENGTH];
-
+int iQuality[MAX_CELLS];
 int iSignalStrength[MAX_CELLS];
 int iCellNumber;
 int step;
@@ -134,6 +135,9 @@
 //
 void parseString(char * strBuffer)
 {
+       // this is so ugly, but the quickest way in this %^*&% pToken-format
+       bool bTokenWasSignal = false;
+
        char * pTokens = strtok(strBuffer, " ");
        while (pTokens != 0) {
 #ifdef DEBUG
@@ -203,15 +207,47 @@
                                tmp[1] = strQPos[9];
                        }
 
-                       iSignalStrength[iCellNumber - 1] = atoi(tmp);
+                       //iSignalStrength[iCellNumber - 1] = atoi(tmp);
+                       iQuality[iCellNumber-1] = atoi(tmp);
 #ifdef DEBUG
-                       printf("Signal Strength: %i \n", 
iSignalStrength[iCellNumber-1]);
+                       printf("Quality: %i \n", iQuality[iCellNumber-1]);
 #endif
                        step    = 1;
                        pTokens = strtok(NULL, " ");
                        continue;
 
                }
+       
+               strTmp = strstr(pTokens, "Signal");
+               if ( strTmp != 0 ) { // remember we read "Signal", next 
"level"-token is important
+                       bTokenWasSignal = true;
+                       pTokens = strtok(NULL, " ");
+                       continue;
+               }
+
+               strTmp = strstr(pTokens, "level");
+               if ( strTmp != 0 && bTokenWasSignal ) {
+
+                       bTokenWasSignal = false;
+       
+                       strcpy(strQPos, strTmp);
+                        char tmp[3];
+
+                       tmp[0] = strQPos[6];
+                       tmp[1] = strQPos[7];
+                       tmp[2] = strQPos[8];
+
+                        iSignalStrength[iCellNumber - 1] = atoi(tmp);
+                        //iQuality[iCellNumber-1] = atoi(tmp);
+#ifdef DEBUG
+                        printf("Signal Strength: %i \n", 
iSignalStrength[iCellNumber-1]);
+#endif
+                        step    = 1;
+                        pTokens = strtok(NULL, " ");
+                        continue;
+               
+               }
+                       
 
                //Parse AP Essid
                strTmp = strstr(pTokens, "ESSID:");
@@ -250,6 +286,7 @@
        //Select best SignalStrength for given AP (or all AP's)
        int iIndexCell    = 0;
        int iBestStrength = 0;
+       int iBestQuality = 0;
        int i;
        int foundBest = false;
        for (i = 0; i < MAX_CELLS; i++) {
@@ -258,8 +295,13 @@
 
                if (strncmp(strEssid[i], strSelectedESSID, 
strlen(strSelectedESSID)) == 0 || !essidflag) {
 
-                       if (iSignalStrength[i] > iBestStrength) {
-                               iBestStrength = iSignalStrength[i];
+                       //debug
+                       //printf("MAC: %s\nESSID: %s\nQuality: 
%d\nSignalStrength: %d\n", strMAC[i], strEssid[i], iQuality[i], 
iSignalStrength[i]);
+
+                       //if (iSignalStrength[i] > iBestStrength) {
+                               //i BestStrength = iSignalStrength[i];
+                       if ( iQuality[i] > iBestQuality) {
+                               iBestQuality = iQuality[i];
                                iIndexCell    = i;
 #ifdef DEBUG
                                printf("Set index for best Cell to:  %i\n", i);
@@ -269,9 +311,9 @@
                }
        }
 
-//Output
+       //Output
        if (foundBest == true) {
-               printf("%s %s %d", strMAC[iIndexCell], strEssid[iIndexCell], 
iSignalStrength[iIndexCell]);
+               printf("MAC: %s\nESSID: %s\nQuality: %d\nSignalStrength: %d\n", 
strMAC[iIndexCell], strEssid[iIndexCell], iQuality[iIndexCell], 
iSignalStrength[iIndexCell]);
        } else {
                printf("NONE");
        }

Other related posts: