49 std::string
getHost(
const std::string& device_name,
const std::string& interface)
55 std::vector<rcdiscover::DeviceInfo> infos;
62 std::vector<std::vector<std::string>> devices;
63 std::vector<std::string> filtered_info = {
"",
"" };
64 for (
const auto& info : infos)
66 if (!interface.empty() &&
interface != info.getIfaceName())
72 std::string user_defined_name = info.getUserName();
73 if (user_defined_name.empty())
75 user_defined_name = info.getModelName();
79 if (device_name.empty())
81 if (info.getModelName().find(
"rc_visard") != std::string::npos)
83 filtered_info[0] = user_defined_name;
84 filtered_info[1] =
ip2string(info.getIP());
85 devices.push_back(filtered_info);
88 else if ((device_name == info.getSerialNumber()) || (device_name == user_defined_name))
90 filtered_info[0] = user_defined_name;
91 filtered_info[1] =
ip2string(info.getIP());
92 devices.push_back(filtered_info);
95 std::sort(devices.begin(), devices.end());
96 auto unique_devices_it = std::unique(devices.begin(), devices.end());
97 devices.erase(unique_devices_it, devices.end());
104 else if (devices.size() > 1)
106 ROS_FATAL_STREAM(
"Found " << devices.size() <<
" devices with the name '" << device_name
107 <<
"'. Please specify a unique device name.");
111 ROS_INFO_STREAM(
"Using device '" << device_name <<
"' with name '" << devices[0][0] <<
"' and IP address " 113 return devices[0][1];
116 int main(
int argc,
char** argv)
118 std::string pick_type = PICK_TYPE;
121 if (pick_type !=
"rc_boxpick" && pick_type !=
"rc_itempick")
134 if (!host.empty() && !device.empty())
136 ROS_WARN(
"Both parameters: 'device' and 'host' are set. Using 'device' to start the client.");
139 if (!device.empty() || host.empty())
141 std::size_t delim_pos = 0;
142 delim_pos = device.find(
':');
143 std::string interface;
144 if (delim_pos != std::string::npos)
146 interface = device.substr(0, delim_pos);
147 device = device.substr(delim_pos + 1);
150 host =
getHost(device, interface);
161 if (pick_type ==
"rc_boxpick")
171 catch (
const std::exception& ex)
173 ROS_FATAL(
"Client could not be created due to an error: %s", ex.what());
std::string ip2string(const uint32_t ip)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL void spin(Spinner &spinner)
#define ROS_FATAL_STREAM(args)
bool getResponse(std::vector< DeviceInfo > &info, int timeout_per_socket=1000)
#define ROS_INFO_STREAM(args)
std::string getHost(const std::string &device_name, const std::string &interface)
bool getParam(const std::string &key, std::string &s) const
ROSCPP_DECL void shutdown()
std::unique_ptr< ros_pick_client::PickClient > pick_client
int main(int argc, char **argv)