reconnect-dialog.cc
Go to the documentation of this file.
1 /*
2 * Roboception GmbH
3 * Munich, Germany
4 * www.roboception.com
5 *
6 * Copyright (c) 2017 Roboception GmbH
7 * All rights reserved
8 *
9 * Author: Raphael Schaller
10 */
11 #include "rcdiscover/force_ip.h"
12 
13 #include "reconnect-dialog.h"
14 
15 #include "event-ids.h"
16 
17 #include <sstream>
18 
19 #include <wx/sizer.h>
20 #include <wx/panel.h>
21 #include <wx/button.h>
22 #include <wx/cshelp.h>
23 #include <wx/msgdlg.h>
24 
26  wxHtmlHelpController *help_ctrl,
27  wxWindow *parent, wxWindowID id,
28  const wxPoint &pos, long style,
29  const wxString &name) :
30  SensorCommandDialog(help_ctrl, parent, id, "Reconnect device", 0,
31  pos, style, name)
32 {
33  auto *const panel = getPanel();
34  auto *const vbox = getVerticalBox();
35 
36  auto *button_box = new wxBoxSizer(wxHORIZONTAL);
37  auto *reconnect_button = new wxButton(panel, ID_Reconnect, "Reconnect");
38  button_box->Add(reconnect_button, 1);
39 
40  button_box->AddSpacer(20);
41 
42  int w, h;
43  reconnect_button->GetSize(&w, &h);
44  auto *help_button = new wxContextHelpButton(panel, ID_Help_Reconnect,
45  wxDefaultPosition, wxSize(h,h));
46  button_box->Add(help_button, 0);
47 
48  vbox->Add(button_box, 0, wxLEFT | wxRIGHT | wxBOTTOM, 15);
49  vbox->Fit(this);
50 
51  Connect(ID_Reconnect,
52  wxEVT_BUTTON,
53  wxCommandEventHandler(ReconnectDialog::onReconnectButton));
54  Connect(ID_Help_Reconnect,
55  wxEVT_BUTTON,
56  wxCommandEventHandler(ReconnectDialog::onHelpButton));
57 
58  Centre();
59 }
60 
61 void ReconnectDialog::onReconnectButton(wxCommandEvent &)
62 {
63  try
64  {
65  std::array<uint8_t, 6> mac = getMac();
66  std::string mac_string = getMacString();
67 
68  rcdiscover::ForceIP force_ip;
69 
70  std::ostringstream oss;
71  oss << "Are you sure to reconnect device with MAC-address "
72  << mac_string << "?";
73  const int answer = wxMessageBox(oss.str(), "", wxYES_NO);
74 
75  if (answer == wxYES)
76  {
77  std::uint64_t m = 0;
78  m |= static_cast<std::uint64_t>(mac[0]) << 40;
79  m |= static_cast<std::uint64_t>(mac[1]) << 32;
80  m |= static_cast<std::uint64_t>(mac[2]) << 24;
81  m |= static_cast<std::uint64_t>(mac[3]) << 16;
82  m |= static_cast<std::uint64_t>(mac[4]) << 8;
83  m |= static_cast<std::uint64_t>(mac[5]) << 0;
84  force_ip.sendCommand(m, 0, 0, 0);
85  }
86 
87  Hide();
88  }
89  catch(const std::runtime_error &ex)
90  {
91  wxMessageBox(ex.what(), "Error", wxOK | wxICON_ERROR);
92  }
93 }
94 
95 void ReconnectDialog::onHelpButton(wxCommandEvent &)
96 {
97  displayHelp("reconnect");
98 }
99 
100 BEGIN_EVENT_TABLE(ReconnectDialog, SensorCommandDialog)
101 END_EVENT_TABLE()
void sendCommand(std::uint64_t mac, std::uint32_t ip, std::uint32_t subnet, std::uint32_t gateway)
Send FORCEIP_CMD.
Definition: force_ip.cc:29
std::string getMacString() const
Class for sending GigE Vision FORCEIP_CMD to camera.
Definition: force_ip.h:26
void onReconnectButton(wxCommandEvent &event)
ReconnectDialog()=default
Dialog for sending FORCEIP_CMD with IP set to 0 to camera.
Base class for dialogs for sending commands to a camera.
void displayHelp(const std::string &section)
void onHelpButton(wxCommandEvent &event)
std::array< uint8_t, 6 > getMac() const


rcdiscover
Author(s): Heiko Hirschmueller , Raphael Schaller
autogenerated on Sun Apr 18 2021 02:16:32