[PC-BSD Commits] r9503 - pcbsd/current/src-qt4/libpcbsd

svn at pcbsd.org svn at pcbsd.org
Sat Mar 5 15:07:02 PST 2011


Author: kenmoore
Date: 2011-03-05 15:07:02 -0800 (Sat, 05 Mar 2011)
New Revision: 9503

Modified:
   pcbsd/current/src-qt4/libpcbsd/netif.cpp
   pcbsd/current/src-qt4/libpcbsd/pcbsd-netif.h
Log:
Added a new function to parse the output of "ifconfig (wifi device) list scan"


Modified: pcbsd/current/src-qt4/libpcbsd/netif.cpp
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/netif.cpp	2011-03-05 14:51:11 UTC (rev 9502)
+++ pcbsd/current/src-qt4/libpcbsd/netif.cpp	2011-03-05 23:07:02 UTC (rev 9503)
@@ -295,3 +295,43 @@
    uint pos = name.indexOf(QRegExp("[0-9]+$"));
    return name.mid(pos).toInt();
 }
+
+QStringList NetworkInterface::parseWifiScanLine( QString linein, bool isverbose){
+  /*
+    This function works given a single line of the command:
+      "ifconfig (wifi device) list scan" (verbose or not)
+    Output: QStringList[ssid,bssid,channel,rate,signal%,INT,CAPS,etc]
+  */
+  int n; //index for end of the SSID section
+  if(isverbose){n=33;} //verbose can display full ssid names between 16-33 characters long
+  else{n=16;}
+  QString line = linein; //make sure we do not change the line outside the function
+  //Parse the line into its components
+  QString ssid = line.left(n); //Entire SSID/MESH ID column
+    ssid = ssid.trimmed(); //remove excess whitespace at the ends
+    line.remove(0,n); //remove the ssid from the line (multiple words mess up later parts otherwise)
+  QString bssid = line.section(" ",0,0,QString::SectionSkipEmpty); //BSSID column
+  QString chan = line.section(" ",1,1,QString::SectionSkipEmpty); //CHAN column
+  QString rate = line.section(" ",2,2,QString::SectionSkipEmpty); //RATE column
+  QString signoise = line.section(" ",3,3,QString::SectionSkipEmpty); //S:G column
+  QString inte = line.section(" ",4,4,QString::SectionSkipEmpty); //INT column
+  QString caps = line.section(" ",5,5,QString::SectionSkipEmpty); //CAPS column
+  QString etc = line.section(" ",6,50,QString::SectionSkipEmpty); //Everything at the end  
+
+    //change signoise into signal strength(%)
+    QString sig = signoise.section(":",0,0); //determine signal
+    QString noise = signoise.section(":",1,1); //determine noise
+    //determine the signal strength
+    int signal = ( sig.toInt()-noise.toInt() )*4;
+    if(signal<0){signal=0;}
+    if(signal>100){signal=100;}
+    //output result as a QString percentage
+    QString strength = QString::number(signal);
+    strength.append("%");
+
+  //put into QStringList for output
+  QStringList out;
+  out << ssid << bssid << chan << rate << strength << inte << caps << etc;
+  return out;
+}
+

Modified: pcbsd/current/src-qt4/libpcbsd/pcbsd-netif.h
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/pcbsd-netif.h	2011-03-05 14:51:11 UTC (rev 9502)
+++ pcbsd/current/src-qt4/libpcbsd/pcbsd-netif.h	2011-03-05 23:07:02 UTC (rev 9503)
@@ -50,6 +50,7 @@
    uint devNum();
    
    static QStringList getInterfaces();
+   static QStringList parseWifiScanLine(QString linein, bool isverbose);
 
 private:
    QString name;



More information about the Commits mailing list