iCub-main
Loading...
Searching...
No Matches
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
32using namespace yarp::os;
33using namespace yarp::os::impl;
34
35using namespace eth;
36
37// implemention of the class
38
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
65{
66 ethManager = NULL;
67}
68
69bool FakeEthResource::lock(bool on)
70{
71 if(true == on)
72 objLock.lock();
73 else
74 objLock.unlock();
75
76 return true;
77}
78
79
80bool 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
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;
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
152{
153 yTrace();
154 return false;
155}
156
157
158const void * FakeEthResource::getUDPtransmit(eOipv4addressing_t &destination, size_t &sizeofpacket, uint16_t &numofrops)
159{
160 return nullptr;
161}
162
163
165{
166 return true;
167}
168
169
171{
172 return true;
173}
174
175
176
177
178bool FakeEthResource::processRXpacket(const void *data, const size_t size)
179{
180 return true;
181}
182
183
184
186{
187 return properties;
188}
189
190
191bool FakeEthResource::isRunning(void)
192{
193 return(isInRunningMode);
194}
195
196
197
198bool 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
225bool FakeEthResource::verifyBoard(void)
226{
227 return(true);
228}
229
230bool FakeEthResource::getRemoteValue(const eOprotID32_t id32, void *value, const double timeout, const unsigned int retries)
231{
232 return true;
233}
234
235bool FakeEthResource::getRemoteValues(const std::vector<eOprotID32_t> &id32s, const std::vector<void*> &values, const double timeout)
236{
237 return true;
238}
239
240
241
242bool FakeEthResource::setRemoteValue(const eOprotID32_t id32, void *value)
243{
244 return true;
245}
246
247bool 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
254bool FakeEthResource::CANPrintHandler(eOmn_info_basic_t *infobasic)
255{
256 yError() << "FakeEthResource " << boardName << ": should never be in CANPrintHandler";
257 return false;
258}
259
260
261bool FakeEthResource::serviceVerifyActivate(eOmn_serv_category_t category, const eOmn_serv_parameter_t* param, double timeout)
262{
263 return true;
264}
265
266
267bool FakeEthResource::serviceSetRegulars(eOmn_serv_category_t category, vector<eOprotID32_t> &id32vector, double timeout)
268{
269 return true;
270}
271
272bool FakeEthResource::serviceStart(eOmn_serv_category_t category, double timeout)
273{
274 isInRunningMode = true;
275 return true;
276}
277
278
279bool FakeEthResource::serviceStop(eOmn_serv_category_t category, double timeout)
280{
281 return true;
282}
283
284bool 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
301bool 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
339{
340 return true;
341}
342
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
bool processRXpacket(const void *data, const size_t size)
bool serviceStart(eOmn_serv_category_t category, double timeout=0.500)
bool getRemoteValues(const std::vector< eOprotID32_t > &id32s, const std::vector< void * > &values, const double timeout=0.500)
bool getRemoteValue(const eOprotID32_t id32, void *value, const double timeout=0.100, const unsigned int retries=0)
const void * getUDPtransmit(eOipv4addressing_t &destination, size_t &sizeofpacket, uint16_t &numofrops)
HostTransceiver * getTransceiver()
bool serviceSetRegulars(eOmn_serv_category_t category, vector< eOprotID32_t > &id32vector, double timeout=0.500)
bool setRemoteValue(const eOprotID32_t id32, void *value)
bool serviceStop(eOmn_serv_category_t category, double timeout=0.500)
const Properties & getProperties()
bool setcheckRemoteValue(const eOprotID32_t id32, void *value, const unsigned int retries=10, const double waitbeforecheck=0.001, const double timeout=0.050)
bool open2(eOipv4addr_t remIP, yarp::os::Searchable &cfgtotal) override
bool verifyEPprotocol(eOprot_endpoint_t ep)
bool CANPrintHandler(eOmn_info_basic_t *infobasic)
bool setLocalValue(const eOprotID32_t id32, const void *value, bool overrideROprotection=false)
bool getLocalValue(const eOprotID32_t id32, void *value)
bool serviceVerifyActivate(eOmn_serv_category_t category, const eOmn_serv_parameter_t *param, double timeout=0.500)
static TheEthManager * instance()
const eOipv4addressing_t & getLocalIPV4addressing(void)
bool write(const eOprotID32_t id32, const void *data, bool forcewriteOfReadOnly)
bool init2(AbstractEthResource *owner, yarp::os::Searchable &cfgtotal, eOipv4addressing_t &localIPaddressing, eOipv4addr_t remoteIP, uint16_t rxpktsize=maxSizeOfRXpacket)
bool read(const eOprotID32_t id32, void *data)
bool read(yarp::os::Searchable &cfgtotal, pc104Data &pc104data)
Definition ethParser.cpp:92
grid on
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
eOipv4addressing_t ipv4addressing
Definition ethParser.h:39
std::string ipv4addressingstring
Definition ethParser.h:43