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 
30 
31 using namespace eth;
32 
33 
34 
35 // --------------------------------------------------------------------------------------------------------------------
36 // - declaration of extern public interface
37 // --------------------------------------------------------------------------------------------------------------------
38 
39 #include "FeatureInterface.h"
40 
41 
42 // --------------------------------------------------------------------------------------------------------------------
43 // - declaration of extern hidden interface
44 // --------------------------------------------------------------------------------------------------------------------
45 
46 #include "FeatureInterface_hid.h"
47 
48 
49 // --------------------------------------------------------------------------------------------------------------------
50 // - definition (and initialisation) of extern variables. deprecated: better using _get(), _set() on static variables
51 // --------------------------------------------------------------------------------------------------------------------
52 // empty-section
53 
54 // --------------------------------------------------------------------------------------------------------------------
55 // - typedef with internal scope
56 // --------------------------------------------------------------------------------------------------------------------
57 // empty-section
58 
59 // --------------------------------------------------------------------------------------------------------------------
60 // - declaration of static functions
61 // --------------------------------------------------------------------------------------------------------------------
62 // empty-secction
63 
64 // --------------------------------------------------------------------------------------------------------------------
65 // - #define with internal scope
66 // --------------------------------------------------------------------------------------------------------------------
67 // empty-secction
68 
69 
70 // --------------------------------------------------------------------------------------------------------------------
71 // - definition (and initialisation) of static variables
72 // --------------------------------------------------------------------------------------------------------------------
73 
75 
76 static const eOysystem_cfg_t eosys_config_ace =
77 {
79  {
81  }
82 };
83 
84 // --------------------------------------------------------------------------------------------------------------------
85 // - definition of extern public functions
86 // --------------------------------------------------------------------------------------------------------------------
87 
88 
89 void feat_Initialise(void *handleOfTheEthManager)
90 {
91  if(NULL == _interface2ethManager)
92  {
93  _interface2ethManager = reinterpret_cast<eth::TheEthManager*>(handleOfTheEthManager);
94  }
95 }
96 
97 
99 {
100  _interface2ethManager = NULL;
101 }
102 
103 const eOysystem_cfg_t * feat_getSYSconfig()
104 {
105  return &eosys_config_ace;
106 }
107 
108 eObool_t feat_manage_motioncontrol_data(eOipv4addr_t ipv4, eOprotID32_t id32, void* rxdata)
109 {
110  IethResource* mc = NULL;
111 
112  if(NULL == _interface2ethManager)
113  {
114  return eobool_false;
115  }
116 
117  mc = _interface2ethManager->getInterface(ipv4, id32);
118 
119  if(NULL == mc)
120  {
121  char ipinfo[20];
122  char nvinfo[128];
123  eo_common_ipv4addr_to_string(ipv4, ipinfo, sizeof(ipinfo));
124  eoprot_ID2information(id32, nvinfo, sizeof(nvinfo));
125  yDebug("feat_manage_motioncontrol_data() fails to get a handle of embObjMotionControl for IP = %s and NV = %s", ipinfo, nvinfo);
126  return eobool_false;
127  }
128 
129  if(false == mc->initialised())
130  {
131  return eobool_false;
132  }
133  else
134  {
135  mc->update(id32, yarp::os::Time::now(), rxdata);
136  }
137 
138  return eobool_true;
139 }
140 
141 
142 eObool_t feat_manage_motioncontrol_addinfo_multienc(eOipv4addr_t ipv4, eOprotID32_t id32, void* rxdata)
143 {
144  IethResource* multienc = NULL;
145 
146  if(NULL == _interface2ethManager)
147  {
148  return eobool_false;
149  }
150 
152 
153  if(NULL == multienc)
154  {
155  char ipinfo[20];
156  char nvinfo[128];
157  eo_common_ipv4addr_to_string(ipv4, ipinfo, sizeof(ipinfo));
158  eoprot_ID2information(id32, nvinfo, sizeof(nvinfo));
159  yDebug("feat_manage_motioncontrol_addinfo_multienc() fails to get a handle of embObjMotionControl for IP = %s and NV = %s", ipinfo, nvinfo);
160  return eobool_false;
161  }
162 
163  if(false == multienc->initialised())
164  {
165  return eobool_false;
166  }
167  else
168  {
169  multienc->update(id32, yarp::os::Time::now(), rxdata);
170  }
171 
172  return eobool_true;
173 }
174 
175 
176 eObool_t feat_manage_skin_data(eOipv4addr_t ipv4, eOprotID32_t id32, void *arrayofcandata)
177 {
178  IethResource* skin;
179 
180  if(NULL == _interface2ethManager)
181  {
182  return eobool_false;
183  }
184 
185  skin = _interface2ethManager->getInterface(ipv4, id32);
186 
187  if(NULL == skin)
188  {
189  char ipinfo[20];
190  char nvinfo[128];
191  eo_common_ipv4addr_to_string(ipv4, ipinfo, sizeof(ipinfo));
192  eoprot_ID2information(id32, nvinfo, sizeof(nvinfo));
193  yDebug("feat_manage_skin_data() fails to get a handle of embObjSkin for IP = %s and NV = %s", ipinfo, nvinfo);
194  return eobool_false;
195  }
196 
197  if(false == skin->initialised())
198  {
199  return eobool_false;
200  }
201  else
202  {
203  skin->update(id32, yarp::os::Time::now(), (void *)arrayofcandata);
204  }
205 
206  return eobool_true;
207 }
208 
209 
210 eObool_t feat_manage_analogsensors_data(eOipv4addr_t ipv4, eOprotID32_t id32, void *data)
211 {
212  IethResource* sensor;
213 
214  if(NULL == _interface2ethManager)
215  {
216  return eobool_false;
217  }
218 
219  sensor = _interface2ethManager->getInterface(ipv4, id32);
220 
221  if(NULL == sensor)
222  {
223  char ipinfo[20];
224  char nvinfo[128];
225  eo_common_ipv4addr_to_string(ipv4, ipinfo, sizeof(ipinfo));
226  eoprot_ID2information(id32, nvinfo, sizeof(nvinfo));
227  yDebug("feat_manage_analogsensors_data() fails to get a handle of embObjAnalogSensor for IP = %s and NV = %s", ipinfo, nvinfo);
228  return eobool_false;
229  }
230 
231  if(false == sensor->initialised())
232  {
233  return eobool_false;
234  }
235  else
236  { // data is a EOarray* in case of mais or strain but it is a eOas_inertial_status_t* in case of inertial sensor
237  sensor->update(id32, yarp::os::Time::now(), data);
238  }
239 
240  return eobool_true;
241 }
242 
243 
244 void* feat_MC_handler_get(eOipv4addr_t ipv4, eOprotID32_t id32)
245 {
246  IethResource* h = NULL;
247 
248  if(NULL == _interface2ethManager)
249  {
250  return NULL;
251  }
252 
253  h = _interface2ethManager->getInterface(ipv4, id32);
254 
255  return (void*) h;
256 }
257 
258 
259 double feat_yarp_time_now(void)
260 {
261  return(yarp::os::Time::now());
262 }
263 
264 eObool_t feat_signal_network_onsay(eOipv4addr_t ipv4, eOprotID32_t id32, uint32_t signature)
265 {
267  nvman.onarrival(theNVmanager::ropCode::say, ipv4, id32, signature);
268  return eobool_true;
269 }
270 
271 eObool_t feat_signal_network_onsig(eOipv4addr_t ipv4, eOprotID32_t id32, uint32_t signature)
272 {
274  nvman.onarrival(theNVmanager::ropCode::sig, ipv4, id32, signature);
275  return eobool_true;
276 }
277 
278 
279 eObool_t feat_CANprint(eOipv4addr_t ipv4, eOmn_info_basic_t* infobasic)
280 {
281  if(NULL == _interface2ethManager)
282  {
283  return(eobool_false);
284  }
285 
287 
288  bool res = ethres->CANPrintHandler(infobasic);
289  return res;
290 }
291 
292 
293 const char * feat_GetBoardName(eOipv4addr_t ipv4)
294 {
295  static const char * errorstr = "error";
296 
297  if(NULL == _interface2ethManager)
298  {
299  return errorstr;
300  }
301 
302  return(_interface2ethManager->getName(ipv4).c_str());
303 }
304 
305 
306 void feat_PrintTrace(char *string)
307 {
308  yTrace("%s", string);
309 }
310 
311 
312 void feat_PrintDebug(char *string)
313 {
314  yDebug("%s", string);
315 }
316 
317 
318 void feat_PrintInfo(char *string)
319 {
320  yInfo("%s", string);
321 }
322 
323 
324 void feat_PrintWarning(char *string)
325 {
326  yWarning("%s", string);
327 }
328 
329 
330 void feat_PrintError(char *string)
331 {
332  yError("%s", string);
333 }
334 
335 
336 void feat_PrintFatal(char *string)
337 {
338  yError("EMS received the following FATAL error: %s", string);
339 }
340 
341 
342 // returns a void pointer to the allocated ACE_Recursive_Thread_Mutex
343 void* ace_mutex_new(void)
344 {
345  ACE_Recursive_Thread_Mutex* mtx = new ACE_Recursive_Thread_Mutex();
346  return(mtx);
347 }
348 
349 
350 // 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).
351 int8_t ace_mutex_take(void* m, uint32_t tout_usec)
352 {
353  ACE_Recursive_Thread_Mutex* acemtx = reinterpret_cast<ACE_Recursive_Thread_Mutex*>(m);
354  if(NULL == acemtx)
355  {
356  return(-2);
357  }
358 
359  acemtx->acquire();
360 
361  return(0);
362 }
363 
364 
365 // 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(),
366 int8_t ace_mutex_release(void* m)
367 {
368  ACE_Recursive_Thread_Mutex* acemtx = reinterpret_cast<ACE_Recursive_Thread_Mutex*>(m);
369  if(NULL == acemtx)
370  {
371  return(-2);
372  }
373 
374  acemtx->release();
375 
376  return(0);
377 }
378 
379 
380 void ace_mutex_delete(void* m)
381 {
382  ACE_Recursive_Thread_Mutex* acemtx = reinterpret_cast<ACE_Recursive_Thread_Mutex*>(m);
383  if(NULL != acemtx)
384  {
385  delete acemtx;
386  }
387 }
388 
389 
390 // --------------------------------------------------------------------------------------------------------------------
391 // - definition of extern hidden functions
392 // --------------------------------------------------------------------------------------------------------------------
393 // empty-section
394 
395 
396 // --------------------------------------------------------------------------------------------------------------------
397 // - definition of static functions
398 // --------------------------------------------------------------------------------------------------------------------
399 // empty-section
400 
401 
402 // --------------------------------------------------------------------------------------------------------------------
403 // - end-of-file (leave a blank line after)
404 // --------------------------------------------------------------------------------------------------------------------
405 
406 
407 
408 
409 
410 
@ data
virtual bool CANPrintHandler(eOmn_info_basic_t *infobasic)=0
eth::IethResource * get_interface(eOipv4addr_t ipv4, eOprotID32_t id32)
Definition: ethBoards.cpp:325
virtual bool update(eOprotID32_t id32, double timestamp, void *rxdata)=0
virtual bool initialised()=0
eth::AbstractEthResource * getEthResource(eOipv4addr_t ipv4)
Definition: ethManager.cpp:706
IethResource * getInterface(eOipv4addr_t ipv4, eOprotID32_t id32)
Definition: ethManager.cpp:519
eth::EthBoards * ethBoards
Definition: ethManager.h:93
const string & getName(eOipv4addr_t ipv4)
Definition: ethManager.cpp:700
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_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