From 692d1e83f9088c3b417299f0bb6b6f3304bd05e8 Mon Sep 17 00:00:00 2001 From: Florian Zirker Date: Sat, 15 Dec 2018 16:44:19 +0100 Subject: [PATCH] added cell count --- msg/WlanSignalMsg.msg | 2 ++ src/wlanSignal.cpp | 35 +++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/msg/WlanSignalMsg.msg b/msg/WlanSignalMsg.msg index 149a056..0bd0640 100644 --- a/msg/WlanSignalMsg.msg +++ b/msg/WlanSignalMsg.msg @@ -2,3 +2,5 @@ time timestamp string ssid int8 level_2G4 int8 level_5G +int8 cellCount_2G4 +int8 cellCount_5G diff --git a/src/wlanSignal.cpp b/src/wlanSignal.cpp index aa1c32f..2a1cff8 100644 --- a/src/wlanSignal.cpp +++ b/src/wlanSignal.cpp @@ -11,22 +11,25 @@ using namespace std; using namespace ros; using namespace wlan_pioneer; +// Global variables for wifi scanning const int MAX_APS = 64; // the maximum amounts of APs (Access Points) we want to store struct wifi_scan* wifi = nullptr; // this stores all the library information struct bss_info bss[MAX_APS]; // this is where we are going to keep informatoin about APs (Access Points) -int status; -int8_t signalLevel2G4 = numeric_limits::min(); -int8_t signalLevel5G = numeric_limits::min(); + +WlanSignalMsg msg; void scanInterface( const string& interface, const string& monitoringSsid ) { - signalLevel2G4 = numeric_limits::min(); - signalLevel5G = numeric_limits::min(); + + msg.level_2G4 = numeric_limits::min(); + msg.level_5G = numeric_limits::min(); + msg.cellCount_2G4 = 0; + msg.cellCount_5G = 0; if ( wifi == nullptr ) { wifi = wifi_scan_init( interface.c_str() ); } - status = wifi_scan_all( wifi, bss, MAX_APS ); + int status = wifi_scan_all( wifi, bss, MAX_APS ); if ( status < 0 ) { ROS_ERROR( "Unable to get WLAN scan data: %s", std::strerror( errno ) ); @@ -47,11 +50,13 @@ void scanInterface( const string& interface, const string& monitoringSsid ) { int8_t level = bss[i].signal_mbm / 100; if ( bss[i].frequency >= 2400 && bss[i].frequency <= 2499 ) { // this AP is sending on 2.4 GHz band - signalLevel2G4 = std::max( signalLevel2G4, level ); + msg.level_2G4 = std::max( msg.level_2G4, level ); + msg.cellCount_2G4++; } else if ( bss[i].frequency >= 5000 && bss[i].frequency <= 5999 ) { // this AP is sending on 5 GHz band - signalLevel5G = std::max( signalLevel5G, level ); + msg.level_5G = std::max( msg.level_5G, level ); + msg.cellCount_5G++; } } } @@ -82,16 +87,18 @@ int main( int argc, char** argv ) { Publisher publisher = node.advertise( "wlan_signal", 1000 ); Rate loopRate( 1 ); // every second + msg.ssid = monitoringSsid; + while ( ok() ) { + scanInterface( wlanInterface, monitoringSsid ); - - WlanSignalMsg msg; msg.timestamp = Time::now(); - msg.level_2G4 = signalLevel2G4; - msg.level_5G = signalLevel5G; - msg.ssid = monitoringSsid; - ROS_INFO( "Signal strength 2.4G: %i Signal strength 5G: %i", msg.level_2G4, msg.level_5G ); + ROS_INFO( "Signal strength 2.4G: %i (%d Cells) Signal strength 5G: %i (%d Cells)", + msg.level_2G4, + msg.cellCount_2G4, + msg.level_5G, + msg.cellCount_5G); publisher.publish( msg ); spinOnce();