reconnect_window.cc
Go to the documentation of this file.
1 /*
2  * Roboception GmbH
3  * Munich, Germany
4  * www.roboception.com
5  *
6  * Copyright (c) 2024 Roboception GmbH
7  * All rights reserved
8  *
9  * Author: Heiko Hirschmueller
10  */
11 
12 #include "reconnect_window.h"
13 #include "help_window.h"
14 
15 #include "layout.h"
16 #include "label.h"
17 
18 #include "rcdiscover/force_ip.h"
19 
20 #include <FL/fl_ask.H>
21 
22 #include <stdexcept>
23 
24 namespace
25 {
26 
27 void changingDeviceCb(Fl_Widget *, void *user_data)
28 {
29  ReconnectWindow *win=reinterpret_cast<ReconnectWindow *>(user_data);
30  win->isChangingDevice();
31 }
32 
33 void macCb(Fl_Widget *, void *user_data)
34 {
35  ReconnectWindow *win=reinterpret_cast<ReconnectWindow *>(user_data);
36  win->update();
37 }
38 
39 void reconnectCb(Fl_Widget *, void *user_data)
40 {
41  ReconnectWindow *win=reinterpret_cast<ReconnectWindow *>(user_data);
42  win->isReconnect();
43 }
44 
45 void helpCb(Fl_Widget *, void *)
46 {
47  HelpWindow::showWindow("reconnect");
48 }
49 
50 }
51 
52 namespace
53 {
54 
55 static ReconnectWindow *win=0;
56 
57 }
58 
60 {
61  if (!win)
62  {
63  win=new ReconnectWindow();
64  }
65 
66  win->show();
67 
68  return win;
69 }
70 
72 {
73  if (win)
74  {
75  win->hide();
76  }
77 }
78 
79 void ReconnectWindow::updateDevices(const std::vector<std::pair<std::string, std::string> > &list,
80  const std::string &sel_mac)
81 {
82  device->update(list, sel_mac);
84  update();
85 }
86 
88 {
89  std::string v=device->getMAC();
90 
91  if (v.size() == 0)
92  {
93  mac->activate();
94  }
95  else
96  {
97  mac->deactivate();
98  }
99 
100  if (mac->isValid())
101  {
102  reconnect->activate();
103  }
104  else
105  {
106  reconnect->deactivate();
107  }
108 }
109 
111 {
112  mac->value(device->getMAC().c_str());
113  update();
114 }
115 
117 {
118  if (mac->isValid())
119  {
120  try
121  {
122  rcdiscover::ForceIP force_ip;
123 
124  if (fl_choice("Are you sure to reconnect device with MAC-address %s?",
125  "No", "Yes", 0, mac->value()) == 1)
126  {
127  force_ip.sendCommand(mac->getMAC(), 0, 0, 0);
128  }
129 
130  hide();
131  }
132  catch(const std::runtime_error &ex)
133  {
134  fl_alert("%s", ex.what());
135  }
136  }
137 }
138 
139 ReconnectWindow::ReconnectWindow() : Fl_Double_Window(400, 124, "Reconnect device")
140 {
141  int width=400-2*GAP_SIZE;
142  int row_height=28;
143 
144  new Label(ADD_BELOW_XY, 120, row_height, "rc_visard");
145  device=new DeviceChoice(ADD_RIGHT_XY, width-GAP_SIZE-120, row_height, 0);
146  device->add("<Custom>");
147  device->callback(changingDeviceCb, this);
148 
149  new Label(ADD_BELOW_XY, 120, row_height, "MAC address");
150  mac=new InputMAC(ADD_RIGHT_XY, width-GAP_SIZE-120, row_height, 0);
151  mac->setChangeCallback(macCb, this);
152 
153  reconnect=new Button(ADD_BELOW_XY, 160, row_height, "Reconnect");
154  reconnect->callback(reconnectCb, this);
155 
156  help=new Button(width+GAP_SIZE-row_height, addRightY(), row_height, row_height, "?");
157  help->callback(helpCb, this);
158 
159  checkGroupSize(__func__);
160  end();
161 
162  size_range(w(), h(), w(), h());
163 
164  update();
165 }
ReconnectWindow::update
void update()
Definition: reconnect_window.cc:87
ADD_BELOW_XY
#define ADD_BELOW_XY
Definition: layout.h:121
rcdiscover::ForceIP
Class for sending GigE Vision FORCEIP_CMD to camera.
Definition: force_ip.h:26
ReconnectWindow
Definition: reconnect_window.h:25
Button
Definition: button.h:18
ReconnectWindow::updateDevices
void updateDevices(const std::vector< std::pair< std::string, std::string > > &list, const std::string &sel_mac)
Definition: reconnect_window.cc:79
InputMAC::getMAC
uint64_t getMAC()
Definition: input_mac.cc:24
ReconnectWindow::hideWindow
static void hideWindow()
Definition: reconnect_window.cc:71
ReconnectWindow::showWindow
static ReconnectWindow * showWindow()
Definition: reconnect_window.cc:59
reconnect_window.h
ReconnectWindow::isChangingDevice
void isChangingDevice()
Definition: reconnect_window.cc:110
ADD_RIGHT_XY
#define ADD_RIGHT_XY
Definition: layout.h:120
ReconnectWindow::help
Button * help
Definition: reconnect_window.h:47
GAP_SIZE
#define GAP_SIZE
Definition: layout.h:21
ReconnectWindow::reconnect
Button * reconnect
Definition: reconnect_window.h:46
InputMAC::isValid
bool isValid()
Definition: input_mac.h:30
addRightY
int addRightY(int gap=GAP_SIZE)
Computes the y coordinate of a widget to the right of the last added widget.
Definition: layout.h:43
InputMAC
Definition: input_mac.h:20
label.h
checkGroupSize
void checkGroupSize(const char *group_name)
The size of the current group must be set before adding all children, especially resizable ones.
Definition: layout.h:88
ReconnectWindow::device
DeviceChoice * device
Definition: reconnect_window.h:44
rcdiscover::ForceIP::sendCommand
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
ReconnectWindow::isReconnect
void isReconnect()
Definition: reconnect_window.cc:116
help_window.h
layout.h
Label
Definition: label.h:18
DeviceChoice::update
void update(const std::vector< std::pair< std::string, std::string > > &list, const std::string &sel_mac)
Definition: device_choice.cc:41
force_ip.h
DeviceChoice
Definition: device_choice.h:22
InputMAC::setChangeCallback
void setChangeCallback(Fl_Callback *_cb, void *p)
Definition: input_mac.h:26
DeviceChoice::getMAC
std::string getMAC()
Definition: device_choice.cc:20
ReconnectWindow::ReconnectWindow
ReconnectWindow()
Definition: reconnect_window.cc:139
ReconnectWindow::mac
InputMAC * mac
Definition: reconnect_window.h:45
HelpWindow::showWindow
static void showWindow(const char *target=0)
Definition: help_window.cc:28


rcdiscover
Author(s): Heiko Hirschmueller , Raphael Schaller
autogenerated on Thu Aug 1 2024 02:55:56