iCub-main
fakeEthResource.cpp
Go to the documentation of this file.
1 // -*- Mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4  * Copyright (C) 2012 iCub Facility, Istituto Italiano di Tecnologia
5  * Authors: Valentina Gaggero
6  * CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
7  *
8  */
9 
10 // api
11 
12 #include <fakeEthResource.h>
13 
14 // other includes
15 
16 #include "ethResource.h"
17 #include <ethManager.h>
18 #include <yarp/os/Time.h>
19 #include <yarp/os/Network.h>
20 #include <yarp/os/NetType.h>
21 
22 // embobj
23 #include "EOropframe_hid.h"
24 #include "EOarray.h"
25 #include "EoProtocol.h"
26 #include "EoManagement.h"
27 #include "EoProtocolMN.h"
28 #include "EoProtocolAS.h"
29 
30 #include "ethParser.h"
31 
32 using namespace yarp::os;
33 using namespace yarp::os::impl;
34 
35 using namespace eth;
36 
37 // implemention of the class
38 
39 FakeEthResource::FakeEthResource()
40 {
41  yTrace();
42 
43  ipv4addr = 0;
44  ipv4addressing.addr = 0;
45  ipv4addressing.port = 0;
46  ipv4addrstring = "0.0.0.0";
47  ethboardtype = eobrd_ethtype_unknown;
48  boardTypeString = "unknown";
49 
50  ethManager = NULL;
51  isInRunningMode = false;
52 
53  verifiedBoardPresence = false;
54  verifiedBoardTransceiver = false;
55 
56  memset(verifiedEPprotocol, 0, sizeof(verifiedEPprotocol));
57 
58  usedNumberOfRegularROPs = 0;
59  memset(&boardCommStatus, 0, sizeof(boardCommStatus));
60 
61 }
62 
63 
64 FakeEthResource::~FakeEthResource()
65 {
66  ethManager = NULL;
67 }
68 
69 bool FakeEthResource::lock(bool on)
70 {
71  if(true == on)
72  objLock.lock();
73  else
74  objLock.unlock();
75 
76  return true;
77 }
78 
79 
80 bool FakeEthResource::open2(eOipv4addr_t remIP, yarp::os::Searchable &cfgtotal)
81 {
82  ethManager = eth::TheEthManager::instance();
83 
84  eth::parser::pc104Data pc104data;
85  eth::parser::read(cfgtotal, pc104data);
86 // eth::parser::print(pc104data);
87 
88 
89  eth::parser::boardData brddata;
90  eth::parser::read(cfgtotal, brddata);
91 // eth::parser::print(brddata);
92 
93  properties.ipv4addr = remIP;
94  properties.ipv4addressing = brddata.properties.ipv4addressing;
95  properties.boardtype = brddata.properties.type;
96  properties.ipv4addrString = brddata.properties.ipv4string;
97  properties.ipv4addressingString = brddata.properties.ipv4addressingstring;
98  properties.boardtypeString = brddata.properties.typestring;
99  properties.boardnameString = brddata.settings.name;
100 
101  // i fill remote address
102  ipv4addr = remIP;
103  ipv4addrstring = brddata.properties.ipv4string;
104  ipv4addressing = brddata.properties.ipv4addressing;
105 
106  ethboardtype = brddata.properties.type;
107  boardTypeString = brddata.properties.typestring;
108 
109  boardName = brddata.settings.name;
110 
111 
113 
114  // default values ...
115  mpConfig.enabled = brddata.actions.monitorpresence_enabled;
116  mpConfig.timeout = brddata.actions.monitorpresence_timeout;
118  mpConfig.name = ipv4addrstring + " (" + boardName + ")";
119 
120 
121 
122  // now i init objects
123 
124  lock(true);
125 
126  // 1. init transceiver
127 
128  eOipv4addressing_t localIPv4 = ethManager->getLocalIPV4addressing();
129 
130 
131  if(false == transceiver.init2(this, cfgtotal, localIPv4, remIP))
132  {
133  yError() << "EthResource::open2() cannot init transceiver w/ HostTransceiver::init2() for BOARD" << boardName << "IP" << ipv4addrstring;
134  lock(false);
135  return false;
136  }
137 
138  // 2. init monitor presence
139 
140  //monitorpresence.config(mpConfig);
141  //monitorpresence.tick();
142 
143 
144  lock(false);
145 
146  return true;
147 }
148 
149 
150 
151 bool FakeEthResource::close()
152 {
153  yTrace();
154  return false;
155 }
156 
157 
158 const void * FakeEthResource::getUDPtransmit(eOipv4addressing_t &destination, size_t &sizeofpacket, uint16_t &numofrops)
159 {
160  return nullptr;
161 }
162 
163 
164 bool FakeEthResource::Tick()
165 {
166  return true;
167 }
168 
169 
170 bool FakeEthResource::Check()
171 {
172  return true;
173 }
174 
175 
176 
177 
178 bool FakeEthResource::processRXpacket(const void *data, const size_t size)
179 {
180  return true;
181 }
182 
183 
184 
185 const AbstractEthResource::Properties & FakeEthResource::getProperties()
186 {
187  return properties;
188 }
189 
190 
191 bool FakeEthResource::isRunning(void)
192 {
193  return(isInRunningMode);
194 }
195 
196 
197 
198 bool FakeEthResource::verifyEPprotocol(eOprot_endpoint_t ep)
199 {
200  if((uint8_t)ep >= eoprot_endpoints_numberof)
201  {
202  yError() << "EthResource::verifyEPprotocol() called with wrong ep = " << ep << ": cannot proceed any further";
203  return(false);
204  }
205 
206  if(true == verifiedEPprotocol[ep])
207  {
208  return(true);
209  }
210 
211  if(false == verifyBoard())
212  {
213  yError() << "FakeEthResource::verifyEPprotocol() cannot verify BOARD" << getProperties().boardnameString << "with IP" << getProperties().ipv4addrString << ": cannot proceed any further";
214  return(false);
215  }
216 
217  verifiedEPprotocol[ep] = true;
218 
219  return(true);
220 
221 }
222 
223 
224 
225 bool FakeEthResource::verifyBoard(void)
226 {
227  return(true);
228 }
229 
230 bool FakeEthResource::getRemoteValue(const eOprotID32_t id32, void *value, const double timeout, const unsigned int retries)
231 {
232  return true;
233 }
234 
235 bool FakeEthResource::getRemoteValues(const std::vector<eOprotID32_t> &id32s, const std::vector<void*> &values, const double timeout)
236 {
237  return true;
238 }
239 
240 
241 
242 bool FakeEthResource::setRemoteValue(const eOprotID32_t id32, void *value)
243 {
244  return true;
245 }
246 
247 bool FakeEthResource::setcheckRemoteValue(const eOprotID32_t id32, void *value, const unsigned int retries, const double waitbeforecheck, const double timeout)
248 {
249  return true;
250 }
251 
252 
253 
254 bool FakeEthResource::CANPrintHandler(eOmn_info_basic_t *infobasic)
255 {
256  yError() << "FakeEthResource " << boardName << ": should never be in CANPrintHandler";
257  return false;
258 }
259 
260 
261 bool FakeEthResource::serviceVerifyActivate(eOmn_serv_category_t category, const eOmn_serv_parameter_t* param, double timeout)
262 {
263  return true;
264 }
265 
266 
267 bool FakeEthResource::serviceSetRegulars(eOmn_serv_category_t category, vector<eOprotID32_t> &id32vector, double timeout)
268 {
269  return true;
270 }
271 
272 bool FakeEthResource::serviceStart(eOmn_serv_category_t category, double timeout)
273 {
274  isInRunningMode = true;
275  return true;
276 }
277 
278 
279 bool FakeEthResource::serviceStop(eOmn_serv_category_t category, double timeout)
280 {
281  return true;
282 }
283 
284 bool FakeEthResource::getLocalValue(const eOprotID32_t id32, void *data)
285 {
286  bool ret = transceiver.read(id32, data);
287  if(false == ret)
288  return ret;
289 
290  //manage special case:
291  if(id32 == eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_strain, 0, eoprot_tag_as_strain_status_fullscale))
292  {
293  //I need to set size to 6, else the device strain can't be opened
294  eOas_arrayofupto12bytes_t * fullscale = (eOas_arrayofupto12bytes_t *)data;
295  fullscale->head.size = 6;
296  }
297 
298  return ret;
299 }
300 
301 bool FakeEthResource::setLocalValue(eOprotID32_t id32, const void *value, bool overrideROprotection)
302 {
303  return transceiver.write(id32, value, overrideROprotection);
304  //return true;
305 }
306 
307 //bool FakeEthResource::addSetMessage(eOprotID32_t id32, uint8_t* data)
308 //{
309 // return true;
310 //}
311 
312 //bool FakeEthResource::addGetMessage(eOprotID32_t id32)
313 //{
314 // return true;
315 //}
316 
317 //bool FakeEthResource::addGetMessage(eOprotID32_t id32, std::uint32_t signature)
318 //{
319 // return true;
320 //}
321 
322 //bool FakeEthResource::addSetMessageAndCacheLocally(eOprotID32_t id32, uint8_t* data)
323 //{
324 // return true;
325 //}
326 
327 //bool FakeEthResource::readSentValue(eOprotID32_t id32, uint8_t *data, uint16_t* size)
328 //{
329 // *size=0;
330 // return true;
331 //}
332 
333 //EOnv* FakeEthResource::getNVhandler(eOprotID32_t id32, EOnv* nv)
334 //{
335 // return transceiver.getnvhandler(id32, nv);
336 //}
337 
338 bool FakeEthResource::isFake()
339 {
340  return true;
341 }
342 
343 HostTransceiver * FakeEthResource::getTransceiver()
344 {
345  return nullptr;
346 }
347 
348 //bool FakeEthResource::isID32supported(eOprotID32_t id32)
349 //{
350 // return true;
351 //}
352 
353 
354 
355 // eof
356 
@ data
static TheEthManager * instance()
Definition: ethManager.cpp:159
bool read(yarp::os::Searchable &cfgtotal, pc104Data &pc104data)
Definition: ethParser.cpp:92
grid on
Definition: show_eyes_axes.m:5
double monitorpresence_periodofmissingreport
Definition: ethParser.h:74
boardActions actions
Definition: ethParser.h:89
boardProperties properties
Definition: ethParser.h:87
boardSettings settings
Definition: ethParser.h:88
eObrd_ethtype_t type
Definition: ethParser.h:40
eOipv4addressing_t ipv4addressing
Definition: ethParser.h:39
std::string ipv4addressingstring
Definition: ethParser.h:43