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 {
175  return eobool_true;
176 }
177 
178 
179 eObool_t feat_manage_skin_data(eOipv4addr_t ipv4, eOprotID32_t id32, void *arrayofcandata)
180 {
181  IethResource* skin;
182 
183  if(NULL == _interface2ethManager)
184  {
185  return eobool_false;
186  }
187 
188  skin = _interface2ethManager->getInterface(ipv4, id32);
189 
190  if(NULL == skin)
191  {
192  char ipinfo[20];
193  char nvinfo[128];
194  eo_common_ipv4addr_to_string(ipv4, ipinfo, sizeof(ipinfo));
195  eoprot_ID2information(id32, nvinfo, sizeof(nvinfo));
196  yDebug("feat_manage_skin_data() fails to get a handle of embObjSkin for IP = %s and NV = %s", ipinfo, nvinfo);
197  return eobool_false;
198  }
199 
200  if(false == skin->initialised())
201  {
202  return eobool_false;
203  }
204  else
205  {
206  skin->update(id32, yarp::os::Time::now(), (void *)arrayofcandata);
207  }
208 
209  return eobool_true;
210 }
211 
212 
213 eObool_t feat_manage_analogsensors_data(eOipv4addr_t ipv4, eOprotID32_t id32, void *data)
214 {
215  IethResource* sensor;
216 
217  if(NULL == _interface2ethManager)
218  {
219  return eobool_false;
220  }
221 
222  sensor = _interface2ethManager->getInterface(ipv4, id32);
223 
224  if(NULL == sensor)
225  {
226  char ipinfo[20];
227  char nvinfo[128];
228  eo_common_ipv4addr_to_string(ipv4, ipinfo, sizeof(ipinfo));
229  eoprot_ID2information(id32, nvinfo, sizeof(nvinfo));
230  yDebug("feat_manage_analogsensors_data() fails to get a handle of embObjAnalogSensor for IP = %s and NV = %s", ipinfo, nvinfo);
231  return eobool_false;
232  }
233 
234  if(false == sensor->initialised())
235  {
236  return eobool_false;
237  }
238  else
239  { // data is a EOarray* in case of mais or strain but it is a eOas_inertial_status_t* in case of inertial sensor
240  sensor->update(id32, yarp::os::Time::now(), data);
241  }
242 
243  return eobool_true;
244 }
245 
246 void* feat_MC_handler_get(eOipv4addr_t ipv4, eOprotID32_t id32)
247 {
248  IethResource* h = NULL;
249 
250  if(NULL == _interface2ethManager)
251  {
252  return NULL;
253  }
254 
255  h = _interface2ethManager->getInterface(ipv4, id32);
256 
257  return (void*) h;
258 }
259 
260 
261 double feat_yarp_time_now(void)
262 {
263  return(yarp::os::Time::now());
264 }
265 
266 eObool_t feat_signal_network_onsay(eOipv4addr_t ipv4, eOprotID32_t id32, uint32_t signature)
267 {
269  nvman.onarrival(theNVmanager::ropCode::say, ipv4, id32, signature);
270  return eobool_true;
271 }
272 
273 eObool_t feat_signal_network_onsig(eOipv4addr_t ipv4, eOprotID32_t id32, uint32_t signature)
274 {
276  nvman.onarrival(theNVmanager::ropCode::sig, ipv4, id32, signature);
277  return eobool_true;
278 }
279 
280 
281 eObool_t feat_CANprint(eOipv4addr_t ipv4, eOmn_info_basic_t* infobasic)
282 {
283  if(NULL == _interface2ethManager)
284  {
285  return(eobool_false);
286  }
287 
289 
290  bool res = ethres->CANPrintHandler(infobasic);
291  return res;
292 }
293 
294 
295 const char * feat_GetBoardName(eOipv4addr_t ipv4)
296 {
297  static const char * errorstr = "error";
298 
299  if(NULL == _interface2ethManager)
300  {
301  return errorstr;
302  }
303 
304  return(_interface2ethManager->getName(ipv4).c_str());
305 }
306 
307 
308 void feat_PrintTrace(char *string)
309 {
310  yTrace("%s", string);
311 }
312 
313 
314 void feat_PrintDebug(char *string)
315 {
316  yDebug("%s", string);
317 }
318 
319 
320 void feat_PrintInfo(char *string)
321 {
322  yInfo("%s", string);
323 }
324 
325 
326 void feat_PrintWarning(char *string)
327 {
328  yWarning("%s", string);
329 }
330 
331 
332 void feat_PrintError(char *string)
333 {
334  yError("%s", string);
335 }
336 
337 
338 void feat_PrintFatal(char *string)
339 {
340  yError("EMS received the following FATAL error: %s", string);
341 }
342 
343 
344 void feat_manage_diagnostic(eOmn_info_basic_t* infobasic, uint8_t * extra, const EOnv* nv, const eOropdescriptor_t* rd)
345 {
346  if(NULL == _interface2ethManager)
347  {
348  yError("the diagnostic service can not start. The interface to the eth manager is not working.");
349  return;
350  }
351  Diagnostic::LowLevel::InfoFormatter dngFormatter(_interface2ethManager, infobasic, extra, nv, rd);
352 
354  dngFormatter.getDiagnosticInfo(info);
355  info.printMessage();
356 }
357 
358 
359 // returns a void pointer to the allocated ACE_Recursive_Thread_Mutex
360 void* ace_mutex_new(void)
361 {
362  ACE_Recursive_Thread_Mutex* mtx = new ACE_Recursive_Thread_Mutex();
363  return(mtx);
364 }
365 
366 
367 // 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).
368 int8_t ace_mutex_take(void* m, uint32_t tout_usec)
369 {
370  ACE_Recursive_Thread_Mutex* acemtx = reinterpret_cast<ACE_Recursive_Thread_Mutex*>(m);
371  if(NULL == acemtx)
372  {
373  return(-2);
374  }
375 
376  acemtx->acquire();
377 
378  return(0);
379 }
380 
381 
382 // 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(),
383 int8_t ace_mutex_release(void* m)
384 {
385  ACE_Recursive_Thread_Mutex* acemtx = reinterpret_cast<ACE_Recursive_Thread_Mutex*>(m);
386  if(NULL == acemtx)
387  {
388  return(-2);
389  }
390 
391  acemtx->release();
392 
393  return(0);
394 }
395 
396 
397 void ace_mutex_delete(void* m)
398 {
399  ACE_Recursive_Thread_Mutex* acemtx = reinterpret_cast<ACE_Recursive_Thread_Mutex*>(m);
400  if(NULL != acemtx)
401  {
402  delete acemtx;
403  }
404 }
405 
406 
407 // --------------------------------------------------------------------------------------------------------------------
408 // - definition of extern hidden functions
409 // --------------------------------------------------------------------------------------------------------------------
410 // empty-section
411 
412 
413 // --------------------------------------------------------------------------------------------------------------------
414 // - definition of static functions
415 // --------------------------------------------------------------------------------------------------------------------
416 // empty-section
417 
418 
419 // --------------------------------------------------------------------------------------------------------------------
420 // - end-of-file (leave a blank line after)
421 // --------------------------------------------------------------------------------------------------------------------
422 
423 
424 
425 
426 
427 
@ data
virtual bool getDiagnosticInfo(Diagnostic::EmbeddedInfo &info)
virtual bool CANPrintHandler(eOmn_info_basic_t *infobasic)=0
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
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)