configurable interfaces over ros params
This commit is contained in:
parent
a22bb36ab1
commit
2f28e926c3
1 changed files with 61 additions and 35 deletions
|
@ -10,52 +10,78 @@ using namespace wlan_pioneer;
|
||||||
|
|
||||||
string GetStdoutFromCommand(const string &cmd)
|
string GetStdoutFromCommand(const string &cmd)
|
||||||
{
|
{
|
||||||
string data;
|
string data;
|
||||||
FILE *stream;
|
FILE *stream;
|
||||||
const int max_buffer = 256;
|
const int max_buffer = 256;
|
||||||
char buffer[max_buffer];
|
char buffer[max_buffer];
|
||||||
//cmd.append(" 2>&1");
|
//cmd.append(" 2>&1");
|
||||||
|
|
||||||
stream = popen(cmd.c_str(), "r");
|
stream = popen(cmd.c_str(), "r");
|
||||||
if (stream)
|
if (stream)
|
||||||
{
|
{
|
||||||
while (!feof(stream))
|
while (!feof(stream))
|
||||||
{
|
|
||||||
if (fgets(buffer, max_buffer, stream) != NULL)
|
|
||||||
{
|
{
|
||||||
data.append(buffer);
|
if (fgets(buffer, max_buffer, stream) != NULL)
|
||||||
|
{
|
||||||
|
data.append(buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
pclose(stream);
|
||||||
pclose(stream);
|
}
|
||||||
}
|
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
|
init(argc, argv, "wlanSignal");
|
||||||
string singalLevelCmd("iwconfig wlp3s0 | grep Signal | cut -d \"=\" -f3 | cut -d \" \" -f1");
|
NodeHandle node;
|
||||||
|
string wlanInterface24G;
|
||||||
|
string wlanInterface5G;
|
||||||
|
|
||||||
init(argc, argv, "wlanSignal");
|
if (node.param<string>("wlan_interface_24G", wlanInterface24G, "wlan0"))
|
||||||
NodeHandle node;
|
{
|
||||||
|
ROS_INFO("Param wlan_interface_24: %s", wlanInterface24G.c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ROS_INFO("Param 'wlan_interface_24' not set. Using 'wlan0'");
|
||||||
|
}
|
||||||
|
|
||||||
// topic: wlan_signal
|
if (node.param<string>("wlan_interface_5G", wlanInterface5G, "wlan0"))
|
||||||
Publisher publisher = node.advertise<WlanSignalMsg>("wlan_signal", 1000);
|
{
|
||||||
|
ROS_INFO("Param wlan_interface_5G: %s", wlanInterface5G.c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ROS_INFO("Param 'wlan_interface_5G' not set. Using 'wlan0'");
|
||||||
|
}
|
||||||
|
|
||||||
Rate loopRate(1); // every second
|
// topic: wlan_signal
|
||||||
|
Publisher publisher = node.advertise<WlanSignalMsg>("wlan_signal", 1000);
|
||||||
|
|
||||||
while (ros::ok())
|
Rate loopRate(1); // every second
|
||||||
{
|
|
||||||
WlanSignalMsg msg;
|
|
||||||
msg.timestamp = ros::Time::now();
|
|
||||||
msg.level_24G = stol(GetStdoutFromCommand(singalLevelCmd));
|
|
||||||
msg.level_5G = 0;
|
|
||||||
|
|
||||||
ROS_INFO("Signal strength 2.4G: %li Signal strength 5G: %li", msg.level_24G, msg.level_5G);
|
while (ros::ok())
|
||||||
|
{
|
||||||
|
WlanSignalMsg msg;
|
||||||
|
msg.timestamp = ros::Time::now();
|
||||||
|
msg.level_24G = getWlanSignalStrength(wlanInterface24G);
|
||||||
|
msg.level_5G = getWlanSignalStrength(wlanInterface5G);
|
||||||
|
|
||||||
publisher.publish(msg);
|
ROS_INFO("Signal strength 2.4G: %li Signal strength 5G: %li", msg.level_24G, msg.level_5G);
|
||||||
spinOnce();
|
|
||||||
loopRate.sleep();
|
publisher.publish(msg);
|
||||||
}
|
spinOnce();
|
||||||
return 0;
|
loopRate.sleep();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue