46 static void printHelp(std::ostream &os,
const std::string &command)
49 os << command <<
" [<args>] <IP address> <subnet mask> <default gateway>\n";
51 os <<
"-h, --help Show this help and exit\n";
52 os <<
"-f name=<name> Filter by name\n";
53 os <<
"-f serial=<serial> Filter by serial number\n";
54 os <<
"-f mac=<mac> Filter by MAC address\n";
55 os <<
"-f iface=<mac> Filter by interface name\n";
56 os <<
"-f model=<model> Filter by model name\n";
57 os <<
"-y Assume 'yes' for all queries\n";
60 int runForceIP(
const std::string &command,
int argc,
char **argv)
68 std::string p = argv[i++];
80 catch (
const std::invalid_argument &ex)
82 std::cerr << ex.what() << std::endl;
87 else if (p ==
"-h" || p ==
"--help")
92 else if (!p.empty() && p[0] ==
'-')
94 std::cerr <<
"Invalid argument: " << p <<
'\n';
105 if (device_filter.mac.empty() &&
106 device_filter.name.empty() &&
107 device_filter.serial.empty())
109 std::cerr <<
"No filter set" << std::endl;
116 std::cerr <<
"IP address, subnet mask and default gateway must be set" << std::endl;
121 std::array<uint8_t, 4> ip;
122 std::array<uint8_t, 4> mask;
123 std::array<uint8_t, 4> gateway;
129 catch (
const std::exception &ex)
131 std::cerr <<
"Cannot parse IP address" << std::endl;
140 catch (
const std::exception &ex)
142 std::cerr <<
"Cannot parse subnet mask" << std::endl;
151 catch (
const std::exception &ex)
153 std::cerr <<
"Cannot parse default gateway" << std::endl;
162 std::cout <<
"No device found" << std::endl;
166 if (devices.size() > 1)
168 std::cout <<
"Found more than one device matching the filter criteria." << std::endl;
173 std::cout <<
"Setting the IP address of the following device:\n";
178 std::cout <<
"Are you sure? [y/N] ";
180 std::getline(std::cin, answer);
181 if (answer !=
"y" && answer !=
"Y")
183 std::cout <<
"Cancel" << std::endl;
188 for (
const auto &device : devices)
197 std::cout <<
"Done" << std::endl;
void sendCommand(std::uint64_t mac, std::uint32_t ip, std::uint32_t subnet, std::uint32_t gateway)
Send FORCEIP_CMD.
Class for sending GigE Vision FORCEIP_CMD to camera.
std::vector< rcdiscover::DeviceInfo > discoverWithFilter(const DeviceFilter &filter)
void printDeviceTable(std::ostream &oss, const std::vector< rcdiscover::DeviceInfo > &devices, bool print_header, bool iponly, bool serialonly)
MinFittingType< N >::type byteArrayToInt(const std::array< std::uint8_t, N > &a)
int runForceIP(const std::string &command, int argc, char **argv)
int parseFilterArguments(int argc, char **argv, DeviceFilter &filter)
std::array< uint8_t, 4 > string2ip(const std::string &ip)
static void printHelp(std::ostream &os, const std::string &command)