19 #include <wx/stattext.h> 22 #include <wx/textctrl.h> 23 #include <wx/button.h> 24 #include <wx/cshelp.h> 25 #include <wx/msgdlg.h> 28 wxWindow *parent, wxWindowID
id,
31 const wxString &name) :
39 auto *ip_text =
new wxStaticText(panel, wxID_ANY,
"IP address");
41 auto *ip_box =
new wxBoxSizer(wxHORIZONTAL);
45 auto *subnet_text =
new wxStaticText(panel, wxID_ANY,
"Subnet mask");
46 grid->Add(subnet_text);
47 auto *subnet_box =
new wxBoxSizer(wxHORIZONTAL);
49 grid->Add(subnet_box);
51 auto *gateway_text =
new wxStaticText(panel, wxID_ANY,
"Default gateway");
52 grid->Add(gateway_text);
53 auto *gateway_box =
new wxBoxSizer(wxHORIZONTAL);
55 grid->Add(gateway_box);
57 auto *button_box =
new wxBoxSizer(wxHORIZONTAL);
58 auto *set_ip_button =
new wxButton(panel,
ID_Force_IP,
59 "Set temporary IP address");
60 button_box->Add(set_ip_button, 1);
63 button_box->Add(clear_button, 0);
65 button_box->AddSpacer(20);
68 set_ip_button->GetSize(&w, &h);
70 wxDefaultPosition, wxSize(h,h));
71 button_box->Add(help_button, 0);
73 vbox->Add(button_box, 0, wxLEFT | wxRIGHT | wxBOTTOM, 15);
111 std::array<wxTextCtrl *, 4> &ip,
121 i =
new wxTextCtrl(
getPanel(),
id, wxEmptyString, wxDefaultPosition,
132 std::uint32_t result{};
134 for (std::uint8_t i = 0; i < 4; ++i)
136 const auto s = ip[i]->GetValue().ToStdString();
140 const auto v = std::stoul(s,
nullptr, 10);
143 throw std::invalid_argument(
"");
145 result |= (
static_cast<std::uint32_t
>(v) << ((4 - 1 - i) * 8));
147 catch(
const std::invalid_argument &)
149 throw std::runtime_error(
150 std::string(
"Each ip address, subnet and gateway segment must ") +
151 "contain a decimal value ranging from 0 to 255.");
159 const std::string &v)
161 if (ctrl->HasFocus())
166 if (ctrl->GetValue().empty())
173 ctrl->ChangeValue(v);
174 ctrl->SetBackgroundColour(wxColour(240, 240, 240));
180 auto *
const text_ctrl =
181 dynamic_cast<wxTextCtrl *
>(
event.GetEventObject());
182 if (text_ctrl !=
nullptr)
184 if (!text_ctrl->GetValue().empty())
187 text_ctrl->SetBackgroundColour(wxColor(255, 255, 255));
199 if (static_cast<std::uint8_t>(ip >> 24) == 10)
208 if (static_cast<std::uint8_t>(ip >> 24) == 172 &&
209 (static_cast<std::uint8_t>(ip >> 16) & 16) != 0)
218 if (static_cast<std::uint8_t>(ip >> 24) == 192
219 && static_cast<std::uint8_t>(ip >> 16) == 168)
228 if (static_cast<std::uint8_t>(ip >> 24) == 169
229 && static_cast<std::uint8_t>(ip >> 16) == 254)
239 const auto predicted_gateway = (ip & subnet) | 0x1;
242 std::to_string(static_cast<std::uint8_t>(predicted_gateway >> 24)));
244 std::to_string(static_cast<std::uint8_t>(predicted_gateway >> 16)));
246 std::to_string(static_cast<std::uint8_t>(predicted_gateway >> 8)));
248 std::to_string(static_cast<std::uint8_t>(predicted_gateway >> 0)));
250 catch(
const std::runtime_error &)
259 std::array<uint8_t, 6> mac =
getMac();
266 if ((ip & subnet) != (gateway & subnet))
268 std::ostringstream oss;
269 oss <<
"IP address and gateway appear to be in different subnets. " <<
270 "Are you sure to proceed?";
271 const int answer = wxMessageBox(oss.str(),
"", wxYES_NO);
280 std::ostringstream oss;
281 oss <<
"Are you sure to set the IP address of the device with MAC-address " 282 << mac_string <<
"?";
283 const int answer = wxMessageBox(oss.str(),
"", wxYES_NO);
288 m |=
static_cast<std::uint64_t
>(mac[0]) << 40;
289 m |=
static_cast<std::uint64_t
>(mac[1]) << 32;
290 m |=
static_cast<std::uint64_t
>(mac[2]) << 24;
291 m |=
static_cast<std::uint64_t
>(mac[3]) << 16;
292 m |=
static_cast<std::uint64_t
>(mac[4]) << 8;
293 m |=
static_cast<std::uint64_t
>(mac[5]) << 0;
299 catch(
const std::runtime_error &ex)
301 wxMessageBox(ex.what(),
"Error", wxOK | wxICON_ERROR);
void sendCommand(std::uint64_t mac, std::uint32_t ip, std::uint32_t subnet, std::uint32_t gateway)
Send FORCEIP_CMD.
std::string getMacString() const
wxBoxSizer * getVerticalBox()
void onIpChanged(wxCommandEvent &event)
std::array< wxTextCtrl *, 4 > ip_
Class for sending GigE Vision FORCEIP_CMD to camera.
Dialog for sending FORCEIP_CMD to camera.
std::array< wxTextCtrl *, 4 > gateway_
std::map< const wxTextCtrl *, bool > changed_by_user_
wxFlexGridSizer * getGrid()
void onClearButton(wxCommandEvent &event)
Base class for dialogs for sending commands to a camera.
std::array< wxTextCtrl *, 4 > subnet_
void displayHelp(const std::string §ion)
static std::uint32_t parseIp(const std::array< wxTextCtrl *, 4 > &ip)
void onForceIpButton(wxCommandEvent &event)
void onHelpButton(wxCommandEvent &event)
std::array< uint8_t, 6 > getMac() const
void addIpToBoxSizer(wxBoxSizer *sizer, std::array< wxTextCtrl *, 4 > &ip, int id)
void changeTextCtrlIfNotChangedByUser(wxTextCtrl *ctrl, const std::string &v)