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;
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
152{
153 yTrace();
154 posServiceConfiguration.clearOnStop(eomn_serv_category_all);
155 return false;
156}
157
158
159const void * FakeEthResource::getUDPtransmit(eOipv4addressing_t &destination, size_t &sizeofpacket, uint16_t &numofrops)
160{
161 return nullptr;
162}
163
164
166{
167 return true;
168}
169
170
172{
173 return true;
174}
175
176
177
178
179bool FakeEthResource::processRXpacket(const void *data, const size_t size)
180{
181 return true;
182}
183
184
185
187{
188 return properties;
189}
190
191
192bool FakeEthResource::isRunning(void)
193{
194 return(isInRunningMode);
195}
196
197
198
199bool FakeEthResource::verifyEPprotocol(eOprot_endpoint_t ep)
200{
201 if((uint8_t)ep >= eoprot_endpoints_numberof)
202 {
203 yError() << "EthResource::verifyEPprotocol() called with wrong ep = " << ep << ": cannot proceed any further";
204 return(false);
205 }
206
207 if(true == verifiedEPprotocol[ep])
208 {
209 return(true);
210 }
211
212 if(false == verifyBoard())
213 {
214 yError() << "FakeEthResource::verifyEPprotocol() cannot verify BOARD" << getProperties().boardnameString << "with IP" << getProperties().ipv4addrString << ": cannot proceed any further";
215 return(false);
216 }
217
218 verifiedEPprotocol[ep] = true;
219
220 return(true);
221
222}
223
224
225
226bool FakeEthResource::verifyBoard(void)
227{
228 return(true);
229}
230
231bool FakeEthResource::getRemoteValue(const eOprotID32_t id32, void *value, const double timeout, const unsigned int retries)
232{
233 return true;
234}
235
236bool FakeEthResource::getRemoteValues(const std::vector<eOprotID32_t> &id32s, const std::vector<void*> &values, const double timeout)
237{
238 return true;
239}
240
241
242
243bool FakeEthResource::setRemoteValue(const eOprotID32_t id32, void *value)
244{
245 return true;
246}
247
248bool FakeEthResource::setcheckRemoteValue(const eOprotID32_t id32, void *value, const unsigned int retries, const double waitbeforecheck, const double timeout)
249{
250 return true;
251}
252
253
254
255bool FakeEthResource::CANPrintHandler(eOmn_info_basic_t *infobasic)
256{
257 yError() << "FakeEthResource " << boardName << ": should never be in CANPrintHandler";
258 return false;
259}
260
261
262bool FakeEthResource::serviceVerifyActivate(eOmn_serv_category_t category, const eOmn_serv_parameter_t* param, double timeout)
263{
264 eOmn_serv_parameter_t prepared {};
265 if(!posServiceConfiguration.prepare(category, param, prepared))
266 {
267 yError() << "FakeEthResource::serviceVerifyActivate(): MC requires"
268 << "standalone POS to be activated first on BOARD" << getProperties().boardnameString;
269 return false;
270 }
271 posServiceConfiguration.rememberActivated(category, param ? &prepared : nullptr);
272 return true;
273}
274
275
276bool FakeEthResource::serviceSetRegulars(eOmn_serv_category_t category, vector<eOprotID32_t> &id32vector, double timeout)
277{
278 return true;
279}
280
281bool FakeEthResource::serviceStart(eOmn_serv_category_t category, double timeout)
282{
283 isInRunningMode = true;
284 return true;
285}
286
287
288bool FakeEthResource::serviceStop(eOmn_serv_category_t category, double timeout)
289{
290 posServiceConfiguration.clearOnStop(category);
291 return true;
292}
293
294bool FakeEthResource::getLocalValue(const eOprotID32_t id32, void *data)
295{
296 bool ret = transceiver.read(id32, data);
297 if(false == ret)
298 return ret;
299
300 //manage special case:
301 if(id32 == eoprot_ID_get(eoprot_endpoint_analogsensors, eoprot_entity_as_strain, 0, eoprot_tag_as_strain_status_fullscale))
302 {
303 //I need to set size to 6, else the device strain can't be opened
304 eOas_arrayofupto12bytes_t * fullscale = (eOas_arrayofupto12bytes_t *)data;
305 fullscale->head.size = 6;
306 }
307
308 return ret;
309}
310
311bool FakeEthResource::setLocalValue(eOprotID32_t id32, const void *value, bool overrideROprotection)
312{
313 return transceiver.write(id32, value, overrideROprotection);
314 //return true;
315}
316
317//bool FakeEthResource::addSetMessage(eOprotID32_t id32, uint8_t* data)
318//{
319// return true;
320//}
321
322//bool FakeEthResource::addGetMessage(eOprotID32_t id32)
323//{
324// return true;
325//}
326
327//bool FakeEthResource::addGetMessage(eOprotID32_t id32, std::uint32_t signature)
328//{
329// return true;
330//}
331
332//bool FakeEthResource::addSetMessageAndCacheLocally(eOprotID32_t id32, uint8_t* data)
333//{
334// return true;
335//}
336
337//bool FakeEthResource::readSentValue(eOprotID32_t id32, uint8_t *data, uint16_t* size)
338//{
339// *size=0;
340// return true;
341//}
342
343//EOnv* FakeEthResource::getNVhandler(eOprotID32_t id32, EOnv* nv)
344//{
345// return transceiver.getnvhandler(id32, nv);
346//}
347
349{
350 return true;
351}
352
354{
355 return nullptr;
356}
357
358//bool FakeEthResource::isID32supported(eOprotID32_t id32)
359//{
360// return true;
361//}
362
363
364
365// eof
366
@ data
POSServiceConfiguration posServiceConfiguration
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()
bool read(yarp::os::Searchable &cfgtotal, pc104Data &pc104data)
Definition ethParser.cpp:92
grid on
double monitorpresence_periodofmissingreport
Definition ethParser.h:111
boardActions actions
Definition ethParser.h:126
boardProperties properties
Definition ethParser.h:124
boardSettings settings
Definition ethParser.h:125
eOipv4addressing_t ipv4addressing
Definition ethParser.h:39
std::string ipv4addressingstring
Definition ethParser.h:43