9 std::vector<int>
split(std::string s, std::string delimiter) {
10 size_t pos_start = 0, pos_end, delim_len = delimiter.length();
14 while((pos_end = s.find(delimiter, pos_start)) != std::string::npos) {
15 token = s.substr(pos_start, pos_end - pos_start);
16 pos_start = pos_end + delim_len;
17 res.push_back(stoi(token));
19 res.push_back(stoi(s.substr(pos_start)));
24 std::vector<int> v =
split(str,
".");
26 std::cout <<
"Entered value " << str <<
" doesn't contain 3 dots. Value has to be in the following format: '255.255.255.255'" << std::endl;
30 if(i < 0 || 255 < i) {
31 std::cout <<
"Entered values can't be above 255!" << std::endl;
38 int main(
int argc,
char** argv) {
43 std::cout <<
"No device found to flash. Exiting." << std::endl;
47 std::cout <<
"Found device with name: " <<
info.getMxId() << std::endl;
48 std::cout <<
"-------------------------------------" << std::endl;
49 std::cout <<
"\"1\" to set a static IPv4 address" << std::endl;
50 std::cout <<
"\"2\" to set a dynamic IPv4 address" << std::endl;
51 std::cout <<
"\"3\" to clear the config" << std::endl;
52 auto key = std::cin.get();
53 std::cout <<
"-------------------------------------" << std::endl;
58 if(key ==
'1' || key ==
'2') {
59 std::string ip, mask, gateway, in;
61 std::cout <<
"Enter IPv4: ";
65 std::cout <<
"Enter IPv4 Mask: ";
69 std::cout <<
"Enter IPv4 Gateway: ";
73 std::string mode =
"static";
74 if(key ==
'2') mode =
"dynamic";
75 std::cout <<
"Flashing " << mode <<
" IPv4 " << ip <<
", mask " << mask <<
", gateway " << gateway <<
" to the POE device. Enter 'y' to confirm. ";
78 std::cout <<
"Flashing aborted.";
83 conf.setStaticIPv4(ip, mask, gateway);
85 conf.setDynamicIPv4(ip, mask, gateway);
89 }
else if(key ==
'3') {
92 std::cout <<
"Entered value should either be '1', '2' or '3'!";
97 std::cout <<
"Flashing successful." << std::endl;
99 std::cout <<
"Flashing failed: " <<
error << std::endl;