iCub-main
FeatureInterface.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 iCub Facility, Istituto Italiano di Tecnologia
3  * Author: Alberto Cardellino, Marco Accame
4  * email: alberto.cardellino@iit.it, marco.accame@iit.it
5  * CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
6  *
7  */
8 
9 
10 // --------------------------------------------------------------------------------------------------------------------
11 // - external dependencies
12 // --------------------------------------------------------------------------------------------------------------------
13 
14 #include <ethManager.h>
15 #include <IethResource.h>
16 #include <abstractEthResource.h>
17 #include <theNVmanager.h>
18 
19 
20 #include <yarp/os/Time.h>
21 #include <yarp/os/LogStream.h>
22 
23 
24 #include <ace/ACE.h>
25 #include <ace/config.h>
26 #include <ace/Recursive_Thread_Mutex.h>
27 #include "EOYtheSystem.h"
28 #include "EOYmutex.h"
29 
31 
32 
33 using namespace eth;
34 
35 
36 
37 // --------------------------------------------------------------------------------------------------------------------
38 // - declaration of extern public interface
39 // --------------------------------------------------------------------------------------------------------------------
40 
41 #include "FeatureInterface.h"
42 
43 
44 // --------------------------------------------------------------------------------------------------------------------
45 // - declaration of extern hidden interface
46 // --------------------------------------------------------------------------------------------------------------------
47 
48 #include "FeatureInterface_hid.h"
49 
50 
51 // --------------------------------------------------------------------------------------------------------------------
52 // - definition (and initialisation) of extern variables. deprecated: better using _get(), _set() on static variables
53 // --------------------------------------------------------------------------------------------------------------------
54 // empty-section
55 
56 // --------------------------------------------------------------------------------------------------------------------
57 // - typedef with internal scope
58 // --------------------------------------------------------------------------------------------------------------------
59 // empty-section
60 
61 // --------------------------------------------------------------------------------------------------------------------
62 // - declaration of static functions
63 // --------------------------------------------------------------------------------------------------------------------
64 // empty-secction
65 
66 // --------------------------------------------------------------------------------------------------------------------
67 // - #define with internal scope
68 // --------------------------------------------------------------------------------------------------------------------
69 // empty-secction
70 
71 
72 // --------------------------------------------------------------------------------------------------------------------
73 // - definition (and initialisation) of static variables
74 // --------------------------------------------------------------------------------------------------------------------
75 
77 
78 static const eOysystem_cfg_t eosys_config_ace =
79 {
81  {
83  }
84 };
85 
86 // --------------------------------------------------------------------------------------------------------------------
87 // - definition of extern public functions
88 // --------------------------------------------------------------------------------------------------------------------
89 
90 
91 void feat_Initialise(void *handleOfTheEthManager)
92 {
93  if(NULL == _interface2ethManager)
94  {
95  _interface2ethManager = reinterpret_cast<eth::TheEthManager*>(handleOfTheEthManager);
96  }
97 }
98 
99 
101 {
102  _interface2ethManager = NULL;
103 }
104 
105 const eOysystem_cfg_t * feat_getSYSconfig()
106 {
107  return &eosys_config_ace;
108 }
109 
110 eObool_t feat_manage_motioncontrol_data(eOipv4addr_t ipv4, eOprotID32_t id32, void* rxdata)
111 {
112  IethResource* mc = NULL;
113 
114  if(NULL == _interface2ethManager)
115  {
116  return eobool_false;
117  }
118 
119  mc = _interface2ethManager->getInterface(ipv4, id32);
120 
121  if(NULL == mc)
122  {
123  char ipinfo[20];
124  char nvinfo[128];
125  eo_common_ipv4addr_to_string(ipv4, ipinfo, sizeof(ipinfo));
126  eoprot_ID2information(id32, nvinfo, sizeof(nvinfo));
127  yDebug("feat_manage_motioncontrol_data() fails to get a handle of embObjMotionControl for IP = %s and NV = %s", ipinfo, nvinfo);
128  return eobool_false;
129  }
130 
131  if(false == mc->initialised())
132  {
133  return eobool_false;
134  }
135  else
136  {
137  mc->update(id32, yarp::os::Time::now(), rxdata);
138  }
139 
140  return eobool_true;
141 }
142 
143 
144 eObool_t feat_manage_motioncontrol_addinfo_multienc(eOipv4addr_t ipv4, eOprotID32_t id32, void* rxdata)
145 {
146  IethResource* multienc = NULL;
147 
148  if(NULL == _interface2ethManager)
149  {
150  return eobool_false;
151  }
152 
154 
155  if(NULL == multienc)
156  {
157  char ipinfo[20];
158  char nvinfo[128];
159  eo_common_ipv4addr_to_string(ipv4, ipinfo, sizeof(ipinfo));
160  eoprot_ID2information(id32, nvinfo, sizeof(nvinfo));
161  yDebug("feat_manage_motioncontrol_addinfo_multienc() fails to get a handle of embObjMotionControl for IP = %s and NV = %s", ipinfo, nvinfo);
162  return eobool_false;
163  }
164 
165  if(false == multienc->initialised())
166  {
167  return eobool_false;
168  }
169  else
170  {
171  multienc->update(id32, yarp::os::Time::now(), rxdata);
172  }
173 
174  return eobool_true;
175 }
176 
177 
178 eObool_t feat_manage_skin_data(eOipv4addr_t ipv4, eOprotID32_t id32, void *arrayofcandata)
179 {
180  IethResource* skin;
181 
182  if(NULL == _interface2ethManager)
183  {
184  return eobool_false;
185  }
186 
187  skin = _interface2ethManager->getInterface(ipv4, id32);
188 
189  if(NULL == skin)
190  {
191  char ipinfo[20];
192  char nvinfo[128];
193  eo_common_ipv4addr_to_string(ipv4, ipinfo, sizeof(ipinfo));
194  eoprot_ID2information(id32, nvinfo, sizeof(nvinfo));
195  yDebug("feat_manage_skin_data() fails to get a handle of embObjSkin for IP = %s and NV = %s", ipinfo, nvinfo);
196  return eobool_false;
197  }
198 
199  if(false == skin->initialised())
200  {
201  return eobool_false;
202  }
203  else
204  {
205  skin->update(id32, yarp::os::Time::now(), (void *)arrayofcandata);
206  }
207 
208  return eobool_true;
209 }
210 
211 
212 eObool_t feat_manage_analogsensors_data(eOipv4addr_t ipv4, eOprotID32_t id32, void *data)
213 {
214  IethResource* sensor;
215 
216  if(NULL == _interface2ethManager)
217  {
218  return eobool_false;
219  }
220 
221  sensor = _interface2ethManager->getInterface(ipv4, id32);
222 
223  if(NULL == sensor)
224  {
225  char ipinfo[20];
226  char nvinfo[128];
227  eo_common_ipv4addr_to_string(ipv4, ipinfo, sizeof(ipinfo));
228  eoprot_ID2information(id32, nvinfo, sizeof(nvinfo));
229  yDebug("feat_manage_analogsensors_data() fails to get a handle of embObjAnalogSensor for IP = %s and NV = %s", ipinfo, nvinfo);
230  return eobool_false;
231  }
232 
233  if(false == sensor->initialised())
234  {
235  return eobool_false;
236  }
237  else
238  { // data is a EOarray* in case of mais or strain but it is a eOas_inertial_status_t* in case of inertial sensor
239  sensor->update(id32, yarp::os::Time::now(), data);
240  }
241 
242  return eobool_true;
243 }
244 
245 void* feat_MC_handler_get(eOipv4addr_t ipv4, eOprotID32_t id32)
246 {
247  IethResource* h = NULL;
248 
249  if(NULL == _interface2ethManager)
250  {
251  return NULL;
252  }
253 
254  h = _interface2ethManager->getInterface(ipv4, id32);
255 
256  return (void*) h;
257 }
258 
259 
260 double feat_yarp_time_now(void)
261 {
262  return(yarp::os::Time::now());
263 }
264 
265 eObool_t feat_signal_network_onsay(eOipv4addr_t ipv4, eOprotID32_t id32, uint32_t signature)
266 {
268  nvman.onarrival(theNVmanager::ropCode::say, ipv4, id32, signature);
269  return eobool_true;
270 }
271 
272 eObool_t feat_signal_network_onsig(eOipv4addr_t ipv4, eOprotID32_t id32, uint32_t signature)
273 {
275  nvman.onarrival(theNVmanager::ropCode::sig, ipv4, id32, signature);
276  return eobool_true;
277 }
278 
279 
280 eObool_t feat_CANprint(eOipv4addr_t ipv4, eOmn_info_basic_t* infobasic)
281 {
282  if(NULL == _interface2ethManager)
283  {
284  return(eobool_false);
285  }
286 
288 
289  bool res = ethres->CANPrintHandler(infobasic);
290  return res;
291 }
292 
293 
294 const char * feat_GetBoardName(eOipv4addr_t ipv4)
295 {
296  static const char * errorstr = "error";
297 
298  if(NULL == _interface2ethManager)
299  {
300  return errorstr;
301  }
302 
303  return(_interface2ethManager->getName(ipv4).c_str());
304 }
305 
306 
307 void feat_PrintTrace(char *string)
308 {
309  yTrace("%s", string);
310 }
311 
312 
313 void feat_PrintDebug(char *string)
314 {
315  yDebug("%s", string);
316 }
317 
318 
319 void feat_PrintInfo(char *string)
320 {
321  yInfo("%s", string);
322 }
323 
324 
325 void feat_PrintWarning(char *string)
326 {
327  yWarning("%s", string);
328 }
329 
330 
331 void feat_PrintError(char *string)
332 {
333  yError("%s", string);
334 }
335 
336 
337 void feat_PrintFatal(char *string)
338 {
339  yError("EMS received the following FATAL error: %s", string);
340 }
341 
342 
343 void feat_manage_diagnostic(eOmn_info_basic_t* infobasic, uint8_t * extra, const EOnv* nv, const eOropdescriptor_t* rd)
344 {
345  if(NULL == _interface2ethManager)
346  {
347  yError("the diagnostic service can not start. The interface to the eth manager is not working.");
348  return;
349  }
350  Diagnostic::LowLevel::InfoFormatter dngFormatter(_interface2ethManager, infobasic, extra, nv, rd);
351 
353  dngFormatter.getDiagnosticInfo(info);
354  info.printMessage();
355 }
356 
357 
358 // returns a void pointer to the allocated ACE_Recursive_Thread_Mutex
359 void* ace_mutex_new(void)
360 {
361  ACE_Recursive_Thread_Mutex* mtx = new ACE_Recursive_Thread_Mutex();
362  return(mtx);
363 }
364 
365 
366 // returns 0 on success to take mutex, -3 on failure upon timeout, -2 on failure upon null pointer. m is pointer obtained w/ ace_mutex_new(), tout_usec is in microsec (no timeout is 0xffffffff).
367 int8_t ace_mutex_take(void* m, uint32_t tout_usec)
368 {
369  ACE_Recursive_Thread_Mutex* acemtx = reinterpret_cast<ACE_Recursive_Thread_Mutex*>(m);
370  if(NULL == acemtx)
371  {
372  return(-2);
373  }
374 
375  acemtx->acquire();
376 
377  return(0);
378 }
379 
380 
381 // returns 0 on success to take mutex, -1 on genric failure of releasing mutex, -2 on failure upon null pointer. m is pointer obtained w/ ace_mutex_new(),
382 int8_t ace_mutex_release(void* m)
383 {
384  ACE_Recursive_Thread_Mutex* acemtx = reinterpret_cast<ACE_Recursive_Thread_Mutex*>(m);
385  if(NULL == acemtx)
386  {
387  return(-2);
388  }
389 
390  acemtx->release();
391 
392  return(0);
393 }
394 
395 
396 void ace_mutex_delete(void* m)
397 {
398  ACE_Recursive_Thread_Mutex* acemtx = reinterpret_cast<ACE_Recursive_Thread_Mutex*>(m);
399  if(NULL != acemtx)
400  {
401  delete acemtx;
402  }
403 }
404 
405 
406 // --------------------------------------------------------------------------------------------------------------------
407 // - definition of extern hidden functions
408 // --------------------------------------------------------------------------------------------------------------------
409 // empty-section
410 
411 
412 // --------------------------------------------------------------------------------------------------------------------
413 // - definition of static functions
414 // --------------------------------------------------------------------------------------------------------------------
415 // empty-section
416 
417 
418 // --------------------------------------------------------------------------------------------------------------------
419 // - end-of-file (leave a blank line after)
420 // --------------------------------------------------------------------------------------------------------------------
421 
422 
423 
424 
425 
426 
@ data
virtual bool getDiagnosticInfo(Diagnostic::EmbeddedInfo &info)
virtual bool CANPrintHandler(eOmn_info_basic_t *infobasic)=0
eth::IethResource * get_interface(eOipv4addr_t ipv4, eOprotID32_t id32)
Definition: ethBoards.cpp:320
virtual bool update(eOprotID32_t id32, double timestamp, void *rxdata)=0
virtual bool initialised()=0
eth::AbstractEthResource * getEthResource(eOipv4addr_t ipv4)
Definition: ethManager.cpp:708
IethResource * getInterface(eOipv4addr_t ipv4, eOprotID32_t id32)
Definition: ethManager.cpp:514
eth::EthBoards * ethBoards
Definition: ethManager.h:93
const string & getName(eOipv4addr_t ipv4)
Definition: ethManager.cpp:702
bool onarrival(const ropCode ropcode, const eOprotIP_t ipv4, const eOprotID32_t id32, const std::uint32_t signature)
static theNVmanager & getInstance()
double feat_yarp_time_now(void)
eObool_t feat_signal_network_onsay(eOipv4addr_t ipv4, eOprotID32_t id32, uint32_t signature)
void feat_PrintFatal(char *string)
eObool_t feat_manage_motioncontrol_addinfo_multienc(eOipv4addr_t ipv4, eOprotID32_t id32, void *rxdata)
const eOysystem_cfg_t * feat_getSYSconfig()
void * ace_mutex_new(void)
int8_t ace_mutex_take(void *m, uint32_t tout_usec)
int8_t ace_mutex_release(void *m)
eObool_t feat_manage_skin_data(eOipv4addr_t ipv4, eOprotID32_t id32, void *arrayofcandata)
void feat_PrintTrace(char *string)
void feat_DeInitialise()
static const eOysystem_cfg_t eosys_config_ace
eObool_t feat_manage_analogsensors_data(eOipv4addr_t ipv4, eOprotID32_t id32, void *data)
eObool_t feat_CANprint(eOipv4addr_t ipv4, eOmn_info_basic_t *infobasic)
eObool_t feat_manage_motioncontrol_data(eOipv4addr_t ipv4, eOprotID32_t id32, void *rxdata)
void feat_manage_diagnostic(eOmn_info_basic_t *infobasic, uint8_t *extra, const EOnv *nv, const eOropdescriptor_t *rd)
void * feat_MC_handler_get(eOipv4addr_t ipv4, eOprotID32_t id32)
void feat_PrintDebug(char *string)
const char * feat_GetBoardName(eOipv4addr_t ipv4)
void feat_PrintInfo(char *string)
static eth::TheEthManager * _interface2ethManager
void feat_PrintError(char *string)
eObool_t feat_signal_network_onsig(eOipv4addr_t ipv4, eOprotID32_t id32, uint32_t signature)
void feat_Initialise(void *handleOfTheEthManager)
void ace_mutex_delete(void *m)
void feat_PrintWarning(char *string)
@ iethres_analogmultienc
Definition: IethResource.h:70