configurable interfaces over ros params

This commit is contained in:
Florian Zirker 2018-11-26 19:50:11 +01:00
parent a22bb36ab1
commit 2f28e926c3

View file

@ -31,13 +31,39 @@ string GetStdoutFromCommand(const string &cmd)
return data; return data;
} }
int64_t getWlanSignalStrength(const string &interface)
{
stringstream command;
command << "iwconfig " << interface << " | grep Signal "
<< "| cut -d \"=\" -f3 "
<< "| cut -d \" \" -f1";
return stol(GetStdoutFromCommand(command.str()));
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
// TODO: make interface configurable
string singalLevelCmd("iwconfig wlp3s0 | grep Signal | cut -d \"=\" -f3 | cut -d \" \" -f1");
init(argc, argv, "wlanSignal"); init(argc, argv, "wlanSignal");
NodeHandle node; NodeHandle node;
string wlanInterface24G;
string wlanInterface5G;
if (node.param<string>("wlan_interface_24G", wlanInterface24G, "wlan0"))
{
ROS_INFO("Param wlan_interface_24: %s", wlanInterface24G.c_str());
}
else
{
ROS_INFO("Param 'wlan_interface_24' not set. Using 'wlan0'");
}
if (node.param<string>("wlan_interface_5G", wlanInterface5G, "wlan0"))
{
ROS_INFO("Param wlan_interface_5G: %s", wlanInterface5G.c_str());
}
else
{
ROS_INFO("Param 'wlan_interface_5G' not set. Using 'wlan0'");
}
// topic: wlan_signal // topic: wlan_signal
Publisher publisher = node.advertise<WlanSignalMsg>("wlan_signal", 1000); Publisher publisher = node.advertise<WlanSignalMsg>("wlan_signal", 1000);
@ -48,8 +74,8 @@ int main(int argc, char **argv)
{ {
WlanSignalMsg msg; WlanSignalMsg msg;
msg.timestamp = ros::Time::now(); msg.timestamp = ros::Time::now();
msg.level_24G = stol(GetStdoutFromCommand(singalLevelCmd)); msg.level_24G = getWlanSignalStrength(wlanInterface24G);
msg.level_5G = 0; msg.level_5G = getWlanSignalStrength(wlanInterface5G);
ROS_INFO("Signal strength 2.4G: %li Signal strength 5G: %li", msg.level_24G, msg.level_5G); ROS_INFO("Signal strength 2.4G: %li Signal strength 5G: %li", msg.level_24G, msg.level_5G);