configurable interfaces over ros params
This commit is contained in:
parent
a22bb36ab1
commit
2f28e926c3
1 changed files with 61 additions and 35 deletions
|
@ -31,13 +31,39 @@ string GetStdoutFromCommand(const string &cmd)
|
|||
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)
|
||||
{
|
||||
// TODO: make interface configurable
|
||||
string singalLevelCmd("iwconfig wlp3s0 | grep Signal | cut -d \"=\" -f3 | cut -d \" \" -f1");
|
||||
|
||||
init(argc, argv, "wlanSignal");
|
||||
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
|
||||
Publisher publisher = node.advertise<WlanSignalMsg>("wlan_signal", 1000);
|
||||
|
@ -48,8 +74,8 @@ int main(int argc, char **argv)
|
|||
{
|
||||
WlanSignalMsg msg;
|
||||
msg.timestamp = ros::Time::now();
|
||||
msg.level_24G = stol(GetStdoutFromCommand(singalLevelCmd));
|
||||
msg.level_5G = 0;
|
||||
msg.level_24G = getWlanSignalStrength(wlanInterface24G);
|
||||
msg.level_5G = getWlanSignalStrength(wlanInterface5G);
|
||||
|
||||
ROS_INFO("Signal strength 2.4G: %li Signal strength 5G: %li", msg.level_24G, msg.level_5G);
|
||||
|
||||
|
|
Loading…
Reference in a new issue