mirror of
https://github.com/introlab/rtabmap_ros.git
synced 2026-10-03 16:27:46 +08:00
Implemented wifi_mapping example on Mac OS X
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
|
||||
SET(srcs
|
||||
main.cpp)
|
||||
|
||||
SET(INCLUDE_DIRS
|
||||
${PROJECT_SOURCE_DIR}/utilite/include
|
||||
${PROJECT_SOURCE_DIR}/corelib/include
|
||||
@@ -25,8 +28,20 @@ ELSE()
|
||||
QT5_WRAP_CPP(moc_srcs ../RGBDMapping/MapBuilder.h MapBuilderWifi.h)
|
||||
ENDIF()
|
||||
|
||||
ADD_EXECUTABLE(wifi_mapping main.cpp ${moc_srcs})
|
||||
|
||||
IF(APPLE)
|
||||
FIND_LIBRARY(CoreWLAN_LIBRARY CoreWLAN)
|
||||
MARK_AS_ADVANCED(CoreWLAN_LIBRARY)
|
||||
SET(LIBRARIES
|
||||
${LIBRARIES}
|
||||
${CoreWLAN_LIBRARY}
|
||||
)
|
||||
SET(srcs
|
||||
${srcs}
|
||||
WifiOSX.mm
|
||||
)
|
||||
ENDIF(APPLE)
|
||||
|
||||
ADD_EXECUTABLE(wifi_mapping ${srcs} ${moc_srcs})
|
||||
TARGET_LINK_LIBRARIES(wifi_mapping rtabmap_core rtabmap_gui rtabmap_utilite ${LIBRARIES})
|
||||
|
||||
SET_TARGET_PROPERTIES( wifi_mapping
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* WifiOSX.h
|
||||
*
|
||||
* Created on: Mar 26, 2015
|
||||
* Author: mathieu
|
||||
*/
|
||||
|
||||
#ifndef WIFIOSX_H_
|
||||
#define WIFIOSX_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct AccessPoint
|
||||
{
|
||||
std::string ssid;
|
||||
std::string bssid;
|
||||
int rssi;
|
||||
};
|
||||
|
||||
int getRssi(const std::string& interfaceName);
|
||||
std::vector<AccessPoint> scanAir(const std::string& interfaceName);
|
||||
|
||||
|
||||
#endif /* WIFIOSX_H_ */
|
||||
@@ -0,0 +1,34 @@
|
||||
#import <CoreWLAN/CoreWLAN.h>
|
||||
#include "WifiOSX.h"
|
||||
|
||||
int getRssi(const std::string& interfaceName)
|
||||
{
|
||||
NSString* ifName = [NSString stringWithUTF8String:interfaceName.c_str()];
|
||||
CWInterface* interface = [CWInterface interfaceWithName:ifName];
|
||||
return interface.rssiValue;
|
||||
}
|
||||
|
||||
std::vector<AccessPoint> scanAir(const std::string& interfaceName)
|
||||
{
|
||||
NSString* ifName = [NSString stringWithUTF8String:interfaceName.c_str()];
|
||||
CWInterface* interface = [CWInterface interfaceWithName:ifName];
|
||||
|
||||
NSError* error = nil;
|
||||
NSArray* scanResult = [[interface scanForNetworksWithSSID:nil error:&error] allObjects];
|
||||
if (error)
|
||||
{
|
||||
NSLog(@"%@ (%ld)", [error localizedDescription], [error code]);
|
||||
}
|
||||
|
||||
std::vector<AccessPoint> result;
|
||||
for (CWNetwork* network in scanResult)
|
||||
{
|
||||
AccessPoint ap;
|
||||
ap.ssid = std::string([[network ssid] UTF8String]);
|
||||
ap.bssid = std::string([[network bssid] UTF8String]);
|
||||
ap.rssi = [network rssiValue];
|
||||
result.push_back(ap);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -45,6 +45,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
// Need to link with Wlanapi.lib and Ole32.lib
|
||||
#pragma comment(lib, "wlanapi.lib")
|
||||
#pragma comment(lib, "ole32.lib")
|
||||
#elif __APPLE__
|
||||
#include "WifiOSX.h"
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <linux/wireless.h>
|
||||
@@ -159,6 +161,8 @@ private:
|
||||
WlanFreeMemory(pIfList);
|
||||
pIfList = NULL;
|
||||
}
|
||||
#elif __APPLE__
|
||||
dBm = getRssi(interfaceName_);
|
||||
#else
|
||||
// Code inspired from http://blog.ajhodges.com/2011/10/using-ioctl-to-gather-wifi-information.html
|
||||
|
||||
|
||||
Reference in New Issue
Block a user