-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Unit tests - Roaming functionality independent of navigation Missing: - Deployment
- Loading branch information
1 parent
cfc62cd
commit 10e5b95
Showing
20 changed files
with
907 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
project(roaming) | ||
set(ROAMING_SERVER roaming_server) | ||
set(ROAMING_CLIENT roaming_client) | ||
|
||
## Roaming server configuration | ||
add_executable(${ROAMING_SERVER}) | ||
target_include_directories(${ROAMING_SERVER} PUBLIC include) | ||
target_sources(${ROAMING_SERVER} PRIVATE | ||
src/mainServer.cpp | ||
src/RoamingServer.cpp | ||
src/LinuxNetworkInteraction.cpp | ||
include/LinuxNetworkInteraction.h | ||
include/RoamingServer.h) | ||
target_link_libraries(${ROAMING_SERVER} PRIVATE ${YARP_LIBRARIES}) | ||
if(${ENABLE_TESTS}) | ||
add_subdirectory(test) | ||
endif() | ||
|
||
|
||
## Roaming client configuration | ||
find_library(wpa libwpa_client.so HINTS /opt/wpa_supplicant-2.10/wpa_supplicant) | ||
if(${wpa} MATCHES wpa-NOTFOUND) | ||
message("-- Cannot build roaming client") | ||
else() | ||
add_executable(${ROAMING_CLIENT}) | ||
cmake_path(GET wpa PARENT_PATH WPA_PATH) | ||
cmake_path(GET WPA_PATH PARENT_PATH WPA_PARENT_PATH) | ||
target_include_directories(${ROAMING_CLIENT} PUBLIC | ||
include | ||
${WPA_PARENT_PATH}/src/common | ||
${WPA_PARENT_PATH}/src/utils | ||
) | ||
target_sources(${ROAMING_CLIENT} PRIVATE | ||
src/mainClient.cpp | ||
src/RoamingClient.cpp | ||
src/WpaSupplicantRoaming.cpp | ||
include/RoamingClient.h | ||
) | ||
target_link_libraries(${ROAMING_CLIENT} PUBLIC | ||
${YARP_LIBRARIES} | ||
${wpa} | ||
) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef INETWORKINTERACTION_H_ | ||
#define INETWORKINTERACTION_H_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
class INetworkInteraction | ||
{ | ||
public: | ||
virtual ~INetworkInteraction() {}; | ||
virtual std::vector<std::string> getCurrentApName() = 0; | ||
virtual bool roam(const std::string& ap_name) = 0; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef LINUXNETWORKINTERACTION_H_ | ||
#define LINUXNETWORKINTERACTION_H_ | ||
|
||
#include <INetworkInteraction.h> | ||
|
||
class LinuxNetworkInteraction : public INetworkInteraction | ||
{ | ||
|
||
public: | ||
LinuxNetworkInteraction() {}; | ||
std::vector<std::string> getCurrentApName() override; | ||
bool roam(const std::string& ap_name) override; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <yarp/os/RFModule.h> | ||
#include <yarp/os/Port.h> | ||
#include <WpaSupplicantRoaming.h> | ||
|
||
class RoamingClient: public yarp::os::RFModule | ||
{ | ||
public: | ||
RoamingClient(); | ||
bool configure(yarp::os::ResourceFinder& rf) override; | ||
bool updateModule() override; | ||
bool interruptModule() override; | ||
double getPeriod() override; | ||
bool close() override; | ||
|
||
private: | ||
std::string m_name; | ||
std::string m_port_ap_name; | ||
std::string m_interface_name; | ||
std::string m_ssid; | ||
|
||
yarp::os::Port m_port_ap; | ||
|
||
WpaSupplicantRoaming roaming; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <yarp/os/RFModule.h> | ||
#include <yarp/dev/INavigation2D.h> | ||
#include <yarp/dev/PolyDriver.h> | ||
#include <yarp/os/Port.h> | ||
|
||
#include <optional> | ||
|
||
#include <INetworkInteraction.h> | ||
|
||
class RoamingServer : public yarp::os::RFModule | ||
{ | ||
public: | ||
RoamingServer(std::string name); | ||
RoamingServer(std::string name, INetworkInteraction& inet); | ||
virtual bool configure(yarp::os::ResourceFinder &rf); | ||
virtual double getPeriod(); | ||
virtual bool updateModule(); | ||
virtual bool close(); | ||
virtual bool interruptModule(); | ||
|
||
bool roam(const std::string &ap_name); | ||
|
||
// APs | ||
const std::vector<std::string> getAPList() const; | ||
const std::optional<yarp::dev::Nav2D::Map2DLocation> getApPosition(const std::string &ap_name) const; | ||
const std::optional<std::string> getCurrentApName() const; | ||
const bool isAP(const std::string &location_name) const; | ||
const double distanceToAP(const std::string& ap_name) const; | ||
const std::string getBestAP() const; | ||
|
||
private: | ||
std::string m_name; | ||
std::string m_roaming_port_name; | ||
yarp::os::Port m_roaming_port; | ||
|
||
yarp::dev::Nav2D::INavigation2D *m_navigation; | ||
yarp::dev::Nav2D::ILocalization2D *m_localization; | ||
yarp::dev::Nav2D::IMap2D *m_map; | ||
yarp::dev::PolyDriver m_ddNav; | ||
|
||
INetworkInteraction& m_net; | ||
|
||
std::vector<std::string> m_ap_list; | ||
std::string m_map_name; | ||
|
||
|
||
// Configuration | ||
bool configureInterfaces(); | ||
|
||
// Roaming | ||
yarp::dev::Nav2D::Map2DLocation m_robot_position; | ||
bool checkRoamingCondition(const double threshold = 5.0); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <string> | ||
#include <wpa_ctrl.h> | ||
|
||
class WpaSupplicantRoaming | ||
{ | ||
public: | ||
bool roam(const std::string& if_name, const std::string& ssid, const std::string& ap_name); | ||
private: | ||
std::string wpa_request(wpa_ctrl* ctrl, const std::string& cmd); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <LinuxNetworkInteraction.h> | ||
#include <yarp/os/LogStream.h> | ||
|
||
std::vector<std::string> LinuxNetworkInteraction::getCurrentApName() | ||
{ | ||
// Get current connected AP name | ||
std::vector<std::string> iw_config_out; | ||
|
||
// Get iwconfig output | ||
FILE* pipe = popen("iwconfig 2>&1", "r"); | ||
if(!pipe) { | ||
yError() << "Failed to execute iwconfig. Is iwconfig installed? Please run sudo apt update; sudo apt install wireless-tools"; | ||
return iw_config_out; | ||
} | ||
|
||
// Parse iwconfig output to get Access Point name | ||
char buffer[128]; | ||
while(fgets(buffer, 128, pipe) != NULL) { | ||
std::string line(buffer); | ||
iw_config_out.push_back(line); | ||
} | ||
|
||
return iw_config_out; | ||
} | ||
|
||
bool LinuxNetworkInteraction::roam(const std::string& ap_name) | ||
{ | ||
yWarning() << "Roaming capability is not implemented in LinuxNetworkInteraction"; | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include <RoamingClient.h> | ||
#include <yarp/os/Bottle.h> | ||
#include <yarp/os/LogStream.h> | ||
#include <algorithm> | ||
|
||
RoamingClient::RoamingClient(): | ||
roaming{WpaSupplicantRoaming()} | ||
{} | ||
|
||
bool RoamingClient::configure(yarp::os::ResourceFinder& rf) | ||
{ | ||
m_name = rf.check("name",yarp::os::Value("RoamingClient")).asString(); | ||
m_interface_name = rf.check("interface",yarp::os::Value("wlp0s20f3")).asString(); | ||
m_ssid = rf.check("ssid",yarp::os::Value("r1_wifi")).asString(); | ||
|
||
yDebug() << "Parameter name set to:" << m_name; | ||
yDebug() << "Parameter interface set to:" << m_interface_name; | ||
yDebug() << "Parameter ssid set to:" << m_ssid; | ||
|
||
m_port_ap_name = "/" + m_name + "/ap:i"; | ||
m_port_ap.open(m_port_ap_name); | ||
|
||
return true; | ||
} | ||
|
||
bool RoamingClient::updateModule() | ||
{ | ||
yarp::os::Bottle ap_name_bot; | ||
if(m_port_ap.read(ap_name_bot)) | ||
{ | ||
std::string ap_name = ap_name_bot.toString(); | ||
|
||
// Trimming the \" at the start and end of string introduced by the bottle | ||
ap_name.erase(std::remove(ap_name.begin(),ap_name.end(),'\"'),ap_name.end()); | ||
if(!roaming.roam(m_interface_name,m_ssid,ap_name)) | ||
{ | ||
yError() << "Roaming to ap: " << ap_name << " has failed"; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool RoamingClient::interruptModule() | ||
{ | ||
m_port_ap.interrupt(); | ||
return true; | ||
} | ||
|
||
bool RoamingClient::close() | ||
{ | ||
m_port_ap.close(); | ||
return true; | ||
} | ||
|
||
double RoamingClient::getPeriod() | ||
{ | ||
return 1; | ||
} |
Oops, something went wrong.