iCub-main
EthBoard.h
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 #ifndef __ETHBOARD_H__
21 #define __ETHBOARD_H__
22 
23 
24 #include <string>
25 #include <vector>
26 
27 using namespace std;
28 
29 #include "EoCommon.h"
30 #include "EoUpdaterProtocol.h"
31 #include "EoBoards.h"
32 
33 // this struct contains the ultimate source of information for a given board
35 {
36  uint8_t protversion; // the updater protocol used by the running process which is specified by:
37  uint64_t macaddress; // the mac address (only 6 bytes out of 8)
38  eObrd_ethtype_t boardtype; // the type of eth board
39  uint32_t capabilities; // it contains a mask of eOuprot_proc_capabilities_t which tells what the remote board can do
40  eOuprot_proctable_t processes; // it contains the properties of the processes in the remote board
41  uint8_t boardinfo32[32]; // if boardinfo32[0] is not 0xff then boardinfo32[1] contains a descriptive string of the remote board (30 characters max).
42  bool maintenanceIsActive;// tells if the maintenance is active (hence if the processes.runningnow is the eUpdater).
44  eOversion_t versionOfRunning; // we keep this info (which for protversion is also inside processes.info[processes.runningnow].version) because ...
45  // in the case of protversion 0 we dont have any info about which process is running now.
47  eOuprot_procinfo_t extraprocesses[2]; // this buffer is used to to transport the information related to the extraprocesses running multi-core processors
48 
50  {
51  reset();
52  }
53 
54  void reset(void)
55  {
56  protversion = 0;
57  macaddress = 0;
58  boardtype = eobrd_ethtype_unknown;
59  capabilities = 0;
60  applicationdetails = 0xff;
61  memset(&processes, 0, sizeof(processes));
62  processes.numberofthem = 0;
63  processes.def2run = uprot_proc_None;
64  processes.runningnow = uprot_proc_None;
65  processes.startup = uprot_proc_None;
66  processes.info[0].type = processes.info[1].type = processes.info[2].type = uprot_proc_None;
67  memset(boardinfo32, 0, sizeof(boardinfo32));
68  boardinfo32[0] = 0xff;
69  maintenanceIsActive = false;
70  versionOfRunning.major = versionOfRunning.minor = 0;
71  moreinfostring.clear();
72  extraprocesses[0].type = extraprocesses[1].type = uprot_proc_None;
73  }
74 };
75 
76 
77 class EthBoard
78 {
79 
80 public:
81 
83  eOipv4addr_t _ipv4;
84  string _ipv4string;
85  bool _selected;
86 
87 public:
88 
89  EthBoard(boardInfo2_t &info2, eOipv4addr_t ipv4);
90 
91  ~EthBoard();
92 
93  void setSelected(bool selected);
94 
95  bool isSelected();
96 
97  void setIPV4(eOipv4addr_t ipv4);
98 
99  eOipv4addr_t getIPV4();
100 
101  string getIPV4string();
102 
103  boardInfo2_t& getInfo();
104 
105  void setInfo(boardInfo2_t &info2);
106 
107  bool isInMaintenance();
108 
109  bool isInApplication();
110 
111  void setMoreInfo(string &moreinfo);
112 
113  const string getMoreInfo(void);
114 
115  string getInfoOnEEPROM(void);
116 
117  string getVersionfRunning(void);
118 
119  string getDatefRunning(void);
120 
121  string getCompilationDateOfRunning(void);
122 
123  // we dont publish any other methods for what is inside _info2 .... use getInfo().
124 
125 };
126 
127 
128 
130 {
131 public:
132  vector<EthBoard> theboards;
133 
134 #if defined(WIN32)
135  enum {
136  ipv4selected = EO_COMMON_IPV4ADDR(0, 0, 0, 0),
137  ipv4all = EO_COMMON_IPV4ADDR(255, 255, 255, 255)
138  };
139 #else
140  static const eOipv4addr_t ipv4all;
141  static const eOipv4addr_t ipv4selected;
142 #endif
143 
144 public:
145  EthBoardList();
146 
147  ~EthBoardList();
148 
149  // if force is true: it does not check if the mac or the ipv4 is already inside and just adds a new entry
150  // if force is false: it does a number of checks... in order of priority:
151  // 1. if it finds the same info2.macaddress inside an item list: it does not add a new item and refreshes the item matching the mac with info2
152  // 2. the mac is surely not in the list. if it finds the same ipv4 inside an item list: it adds a new entry (but if the item list has mac = 0,
153  // it refreshes the item).
154  int add(boardInfo2_t &info2, eOipv4addr_t ipv4, bool force = false);
155 
156  int rem(eOipv4addr_t ipv4);
157 
158  int clear();
159 
160  int size();
161 
162  // it selects on/off the board w/ a given ip address. if ipv4 is 0 the rule applies to all
163  void select(bool on, eOipv4addr_t ipv4);
164 
165  // tells how many have that ip address. if 0, it tells how many are selected
166  int numberof(eOipv4addr_t ipv4);
167 
168  // retrieve a vector of pointers with a given ip address. if ipv4 is 0, then it retrieves all the selected
169  // if 0xffffffff we retrieve them all
170  // we have a vector of pointer so that we can modify the boards (but dont delete them, use rem() or clear() instead).
171  vector<EthBoard *> get(eOipv4addr_t ipv4);
172 
173  EthBoard& operator[](int i);
174 };
175 
176 #endif
177 
178 
vector< EthBoard > theboards
Definition: EthBoard.h:132
static const eOipv4addr_t ipv4all
Definition: EthBoard.h:140
static const eOipv4addr_t ipv4selected
Definition: EthBoard.h:141
string _ipv4string
Definition: EthBoard.h:84
bool _selected
Definition: EthBoard.h:85
eOipv4addr_t _ipv4
Definition: EthBoard.h:83
boardInfo2_t _info2
Definition: EthBoard.h:82
Q15 add(const Q15 a, const Q15 b)
Definition: strain.cpp:1209
grid on
Definition: show_eyes_axes.m:5
eOversion_t versionOfRunning
Definition: EthBoard.h:44
void reset(void)
Definition: EthBoard.h:54
eObrd_ethtype_t boardtype
Definition: EthBoard.h:38
uint8_t applicationdetails
Definition: EthBoard.h:43
boardInfo2_t()
Definition: EthBoard.h:49
uint8_t protversion
Definition: EthBoard.h:36
string moreinfostring
Definition: EthBoard.h:46
uint32_t capabilities
Definition: EthBoard.h:39
uint64_t macaddress
Definition: EthBoard.h:37
bool maintenanceIsActive
Definition: EthBoard.h:42
eOuprot_proctable_t processes
Definition: EthBoard.h:40