51 static void printHelp(std::ostream &os,
const std::string &command)
53 os << command <<
" [<args>]\n";
55 os <<
"-h, --help Show this help and exit\n";
56 os <<
"-f name=<name> Filter by name\n";
57 os <<
"-f serial=<serial> Filter by serial number\n";
58 os <<
"-f mac=<mac> Filter by MAC address\n";
59 os <<
"-f iface=<mac> Filter by interface name\n";
60 os <<
"-f model=<model> Filter by model name\n";
61 os <<
"--iponly Show only the IP addresses of discovered sensors\n";
62 os <<
"--serialonly Show only the serial number of discovered sensors\n";
65 int runDiscover(
const std::string &command,
int argc,
char **argv)
69 bool printheader =
true;
71 bool serialonly =
false;
77 std::string p = argv[i++];
79 if (p ==
"-iponly" || p ==
"--iponly")
84 else if (p ==
"-serialonly" || p ==
"--serialonly")
95 catch (
const std::invalid_argument &ex)
97 std::cerr << ex.what() << std::endl;
103 else if (p ==
"-h" || p ==
"--help")
110 std::cerr <<
"Invalid argument: " << p <<
'\n';
121 std::vector<rcdiscover::DeviceInfo> infos;
125 std::chrono::steady_clock::time_point tstart=std::chrono::steady_clock::now();
126 std::chrono::steady_clock::time_point tend=tstart;
129 std::chrono::duration<double, std::milli>(tend-tstart).count() < 1000)
131 tend=std::chrono::steady_clock::now();
134 std::sort(infos.begin(), infos.end());
135 const auto it = std::unique(infos.begin(), infos.end(),
139 return lhs.getMAC() == rhs.getMAC() &&
140 lhs.getIfaceName() == rhs.getIfaceName();
142 infos.erase(it, infos.end());
146 std::vector<rcdiscover::DeviceInfo> filtered_infos;
157 filtered_infos.push_back(info);
160 printDeviceTable(std::cout, filtered_infos, printheader, iponly, serialonly);