50 static void printHelp(std::ostream &os,
const std::string &command)
52 os << command <<
" [<args>]\n";
54 os <<
"-h, --help Show this help and exit\n";
55 os <<
"-f name=<name> Filter by name\n";
56 os <<
"-f serial=<serial> Filter by serial number\n";
57 os <<
"-f mac=<mac> Filter by MAC address\n";
58 os <<
"-f iface=<mac> Filter by interface name\n";
59 os <<
"-f model=<model> Filter by model name\n";
60 os <<
"--iponly Show only the IP addresses of discovered sensors\n";
61 os <<
"--serialonly Show only the serial number of discovered sensors\n";
64 int runDiscover(
const std::string &command,
int argc,
char **argv)
68 bool printheader =
true;
70 bool serialonly =
false;
76 std::string p = argv[i++];
78 if (p ==
"-iponly" || p ==
"--iponly")
83 else if (p ==
"-serialonly" || p ==
"--serialonly")
94 catch (
const std::invalid_argument &ex)
96 std::cerr << ex.what() << std::endl;
102 else if (p ==
"-h" || p ==
"--help")
109 std::cerr <<
"Invalid argument: " << p <<
'\n';
120 std::vector<rcdiscover::DeviceInfo> infos;
127 std::sort(infos.begin(), infos.end());
128 const auto it = std::unique(infos.begin(), infos.end(),
132 return lhs.
getMAC() == rhs.getMAC() &&
135 infos.erase(it, infos.end());
139 std::vector<rcdiscover::DeviceInfo> filtered_infos;
150 filtered_infos.push_back(info);
153 printDeviceTable(std::cout, filtered_infos, printheader, iponly, serialonly);
void printDeviceTable(std::ostream &oss, const std::vector< rcdiscover::DeviceInfo > &devices, bool print_header, bool iponly, bool serialonly)
bool filterDevice(const rcdiscover::DeviceInfo &device_info, const DeviceFilter &filter)
static void printHelp(std::ostream &os, const std::string &command)
void broadcastRequest()
Broadcasts a discovery command request.
int parseFilterArguments(int argc, char **argv, DeviceFilter &filter)
bool getResponse(std::vector< DeviceInfo > &info, int timeout_per_socket=1000)
Returns a discovery response.
uint64_t getMAC() const
Returns 6 bytes with the MAC address of the device.
const std::string & getIfaceName() const
Returns the name of the interface on which this device was found.
int runDiscover(const std::string &command, int argc, char **argv)