iCub-main
EthBoard.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 iCub Facility - Istituto Italiano di Tecnologia
3  * Author: Marco Accame, Alessandro Scalzo
4  * email: marco.accame@iit.it, alessandro.scalzo@iit.it
5  * website: www.robotcub.org
6  * Permission is granted to copy, distribute, and/or modify this program
7  * under the terms of the GNU General Public License, version 2 or any
8  * later version published by the Free Software Foundation.
9  *
10  * A copy of the license can be found at
11  * http://www.robotcub.org/icub/license/gpl.txt
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details
17 */
18 
19 
20 
21 #include "EthBoard.h"
22 
23 
24 // - class EthBoard
25 
26 EthBoard::EthBoard(boardInfo2_t &info2, eOipv4addr_t ipv4)
27 {
28  _info2 = info2;
29  _ipv4 = ipv4;
30  char tmp[20];
31  eo_common_ipv4addr_to_string(ipv4, tmp, sizeof(tmp));
32  _ipv4string = string(tmp);
33  _selected = false;
34 }
35 
36 
38 {
39 
40 }
41 
42 void EthBoard::setSelected(bool selected)
43 {
44  _selected = selected;
45 }
46 
48 {
49  return _selected;
50 }
51 
52 void EthBoard::setIPV4(eOipv4addr_t ipv4)
53 {
54  _ipv4 = ipv4;
55  char tmp[20];
56  eo_common_ipv4addr_to_string(ipv4, tmp, sizeof(tmp));
57  _ipv4string = string(tmp);
58 }
59 
60 eOipv4addr_t EthBoard::getIPV4()
61 {
62  return _ipv4;
63 }
64 
66 {
67  return _ipv4string;
68 }
69 
71 {
72  return _info2;
73 }
74 
76 {
77  _info2 = info2;
78 }
79 
81 {
83 }
84 
86 {
88 }
89 
90 void EthBoard::setMoreInfo(string &moreinfo)
91 {
92  _info2.moreinfostring = moreinfo;
93 }
94 
95 const string EthBoard::getMoreInfo(void)
96 {
97  return _info2.moreinfostring;
98 }
99 
101 {
102  string ret;
103  ret = (0xff == _info2.boardinfo32[0]) ? (string("N/A: PAGE32 IS UNFORMATTED")) : (string((const char*) &_info2.boardinfo32[1]));
104  return ret;
105 }
106 
108 {
109  string ret;
110  char tmp[32];
111  if(uprot_proc_None == _info2.processes.runningnow)
112  {
113  // see if
114  if((0 != _info2.versionOfRunning.major) || (0 != _info2.versionOfRunning.minor))
115  {
116  snprintf(tmp, sizeof(tmp), "%d.%d", _info2.versionOfRunning.major, _info2.versionOfRunning.minor);
117  ret = tmp;
118  }
119  else
120  {
121  ret = "N/A";
122  }
123  }
124  else
125  {
126  uint8_t index = eouprot_process2index((eOuprot_process_t)_info2.processes.runningnow);
127  snprintf(tmp, sizeof(tmp), "%d.%d", _info2.processes.info[index].version.major, _info2.processes.info[index].version.minor);
128  ret = tmp;
129  }
130  return ret;
131 }
132 
134 {
135  string ret;
136  if(uprot_proc_None == _info2.processes.runningnow)
137  {
138  ret = "N/A";
139  }
140  else
141  {
142  char tmp[32];
143  uint8_t index = eouprot_process2index((eOuprot_process_t)_info2.processes.runningnow);
144  eo_common_date_to_string(_info2.processes.info[index].date, tmp, sizeof(tmp));
145  ret = tmp;
146  }
147  return ret;
148 }
149 
151 {
152  string ret;
153  if(uprot_proc_None == _info2.processes.runningnow)
154  {
155  ret = "N/A";
156  }
157  else
158  {
159  char tmp[32];
160  uint8_t index = eouprot_process2index((eOuprot_process_t)_info2.processes.runningnow);
161  eo_common_date_to_string(_info2.processes.info[index].compilationdate, tmp, sizeof(tmp));
162  ret = tmp;
163  }
164  return ret;
165 }
166 
167 
168 // -- class EthBoardList
169 #if defined(WIN32)
170 #else
171 const eOipv4addr_t EthBoardList::ipv4all = EO_COMMON_IPV4ADDR(255, 255, 255, 255);
172 const eOipv4addr_t EthBoardList::ipv4selected = EO_COMMON_IPV4ADDR(0, 0, 0, 0);
173 #endif
174 
176 {
177  theboards.clear();
178 }
179 
181 {
182  theboards.clear();
183 }
184 
185 // it adds if the mac is not inside, else it refreshes the item
186 int EthBoardList::add(boardInfo2_t &info2, eOipv4addr_t ipv4, bool force)
187 {
188 
189  if(force)
190  {
191  EthBoard board(info2, ipv4);
192  theboards.push_back(board);
193  return theboards.size();
194  }
195 
196  bool addit = true;
197 
198  const bool check_MAC_IPV4 = true;
199 
200  if(check_MAC_IPV4)
201  {
202  uint64_t mac = info2.macaddress;
203 
204  // look for the same mac
205  for(int i=0; i<theboards.size(); i++)
206  {
207  if(mac == theboards[i].getInfo().macaddress)
208  {
209  addit = false;
210  theboards[i].setInfo(info2);
211  theboards[i].setIPV4(ipv4);
212  return theboards.size();
213  }
214  }
215 
216  // look for the same ipv4
217  for(int i=0; i<theboards.size(); i++)
218  {
219  if((0 == theboards[i].getInfo().macaddress) && (ipv4 == theboards[i].getIPV4()))
220  { // a board inside the list with a zero mac is a fake one
221  addit = false;
222  theboards[i].setInfo(info2);
223  return theboards.size();
224  }
225  }
226 
227  }
228 
229  if(addit)
230  {
231  EthBoard board(info2, ipv4);
232  theboards.push_back(board);
233  }
234 
235  return theboards.size();
236 }
237 
238 
239 int EthBoardList::rem(eOipv4addr_t ipv4)
240 {
241  if(ipv4all == ipv4)
242  {
243  return clear();
244  }
245 
246  // look for the same ipv4
247  for(int i=0; i<theboards.size(); i++)
248  {
249  if(ipv4selected == ipv4)
250  { // if selected
251  if(true == theboards[i].isSelected())
252  {
253  theboards.erase(theboards.begin()+i);
254  }
255  }
256  else if(ipv4 == theboards[i].getIPV4())
257  {
258  theboards.erase(theboards.begin()+i);
259  }
260  }
261 
262  return theboards.size();
263 }
264 
265 
267 {
268  theboards.clear();
269  return theboards.size();
270 }
271 
272 
274 {
275  return theboards.size();
276 }
277 
278 
279 int EthBoardList::numberof(eOipv4addr_t ipv4)
280 {
281  if(ipv4all == ipv4)
282  {
283  return theboards.size();
284  }
285 
286  int number = 0;
287  for(int i=0; i<theboards.size(); i++)
288  {
289  if(ipv4selected == ipv4)
290  { // all the selected
291  if(true == theboards[i].isSelected())
292  {
293  number++;
294  }
295  }
296  else
297  {
298  if(ipv4 == theboards[i].getIPV4())
299  {
300  number++;
301  }
302  }
303 
304  }
305 
306  return number;
307 }
308 
309 // vector of pointers so that we can modify them
310 vector<EthBoard *> EthBoardList::get(eOipv4addr_t ipv4)
311 {
312  vector<EthBoard *> tmp;
313  bool getit = false;
314 
315  for(int i=0; i<theboards.size(); i++)
316  {
317  getit = false;
318 
319  if(EthBoardList::ipv4all == ipv4)
320  { // all boards
321  getit = true;
322  }
323  else if(EthBoardList::ipv4selected == ipv4)
324  { // all the selected
325  if(true == theboards[i].isSelected())
326  {
327  getit = true;
328  }
329  }
330  else
331  { // equal ipv4
332  if(ipv4 == theboards[i].getIPV4())
333  {
334  getit = true;
335  }
336  }
337 
338  if(getit)
339  {
340  tmp.push_back(&theboards[i]);
341  }
342  }
343 
344  return tmp;
345 }
346 
347 void EthBoardList::select(bool on, eOipv4addr_t ipv4)
348 {
349  // look for the same ipv4
350  for(int i=0; i<theboards.size(); i++)
351  {
352  if(EthBoardList::ipv4all == ipv4)
353  {
354  theboards[i].setSelected(on);
355  }
356  else
357  {
358  if(ipv4 == theboards[i].getIPV4())
359  {
360  theboards[i].setSelected(on);
361  }
362  }
363  }
364 }
365 
367 {
368  return theboards[i];
369 }
370 
371 
372 
373 // eof
374 
375 
vector< EthBoard > theboards
Definition: EthBoard.h:132
static const eOipv4addr_t ipv4all
Definition: EthBoard.h:140
int numberof(eOipv4addr_t ipv4)
Definition: EthBoard.cpp:279
vector< EthBoard * > get(eOipv4addr_t ipv4)
Definition: EthBoard.cpp:310
int rem(eOipv4addr_t ipv4)
Definition: EthBoard.cpp:239
void select(bool on, eOipv4addr_t ipv4)
Definition: EthBoard.cpp:347
int add(boardInfo2_t &info2, eOipv4addr_t ipv4, bool force=false)
Definition: EthBoard.cpp:186
EthBoard & operator[](int i)
Definition: EthBoard.cpp:366
static const eOipv4addr_t ipv4selected
Definition: EthBoard.h:141
string _ipv4string
Definition: EthBoard.h:84
void setMoreInfo(string &moreinfo)
Definition: EthBoard.cpp:90
string getCompilationDateOfRunning(void)
Definition: EthBoard.cpp:150
string getVersionfRunning(void)
Definition: EthBoard.cpp:107
bool _selected
Definition: EthBoard.h:85
bool isInApplication()
Definition: EthBoard.cpp:85
EthBoard(boardInfo2_t &info2, eOipv4addr_t ipv4)
Definition: EthBoard.cpp:26
boardInfo2_t & getInfo()
Definition: EthBoard.cpp:70
void setIPV4(eOipv4addr_t ipv4)
Definition: EthBoard.cpp:52
eOipv4addr_t _ipv4
Definition: EthBoard.h:83
boardInfo2_t _info2
Definition: EthBoard.h:82
string getInfoOnEEPROM(void)
Definition: EthBoard.cpp:100
~EthBoard()
Definition: EthBoard.cpp:37
string getDatefRunning(void)
Definition: EthBoard.cpp:133
bool isSelected()
Definition: EthBoard.cpp:47
string getIPV4string()
Definition: EthBoard.cpp:65
const string getMoreInfo(void)
Definition: EthBoard.cpp:95
void setInfo(boardInfo2_t &info2)
Definition: EthBoard.cpp:75
void setSelected(bool selected)
Definition: EthBoard.cpp:42
eOipv4addr_t getIPV4()
Definition: EthBoard.cpp:60
bool isInMaintenance()
Definition: EthBoard.cpp:80
uint8_t board
grid on
Definition: show_eyes_axes.m:5
eOversion_t versionOfRunning
Definition: EthBoard.h:44
string moreinfostring
Definition: EthBoard.h:46
uint8_t boardinfo32[32]
Definition: EthBoard.h:41
uint64_t macaddress
Definition: EthBoard.h:37
bool maintenanceIsActive
Definition: EthBoard.h:42
eOuprot_proctable_t processes
Definition: EthBoard.h:40