iCub-main
IethResource.h
Go to the documentation of this file.
1 
2 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
3 
4 /* Copyright (C) 2014 iCub Facility, Istituto Italiano di Tecnologia
5  * Author: Marco Accame
6  * email: marco.accame@iit.it
7  * Permission is granted to copy, distribute, and/or modify this program
8  * under the terms of the GNU General Public License, version 2 or any
9  * later version published by the Free Software Foundation.
10  *
11  * A copy of the license can be found at
12  * http://www.robotcub.org/icub/license/gpl.txt
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17  * Public License for more details
18  */
19 
20 //
21 // $Id: TheEthManager.h,v 1.5 2008/06/25 22:33:53 nat Exp $
22 //
23 //
24 
25 #ifndef __IethResource__
26 #define __IethResource__
27 
28 
29 #include "EoProtocol.h"
30 #include <string>
31 
32 
33 // marco.accame on 20 oct 2014.
34 // the objects which use ethResource to communicate with the ethernet boards inside the robot
35 // must be derived from this class IethResource.
36 // these objects are: embObjMotionControl, embObjSkin, embObjAnalogSensor, and future ones.
37 // these object must implement the virtual functions initialised() and update() so that:
38 // - initialised() must return true only if the object is opened (its method open() has returned).
39 // - update() takes care of filling private data structures with bytes contained in the relevant ROPs coming from remote boards.
40 // as an example, see how the skin data is moved from ems board to embObjSkin.
41 // when a ROP containing a EOarray of skin data arrives, the callback eoprot_fun_UPDT_sk_skin_status_arrayof10canframes() is called.
42 // this function calls feat_manage_skin_data() and passes the boardnumber, the id32, and the pointer to the received EOarray.
43 // this function uses TheEthManager::getHandle() to retrieve a pointer to the relevant IethResource which matches (boardnumber, id32)
44 // the pointer is used directly or transformed with dynamic_cast to a pointer to embObjSkin and the function update() is called.
45 // needless to say, the update(0 function whcich is called is always the embObjSkin::update() which gets the EOarray and copies its
46 // items inside embObjSkin::data.
47 //
48 // warning: the caller of function embObjSkin::update() is the ethReceiver thread. if it writes something into embObjSkin::data,
49 // and the same embObjSkin::data is read by other threads via EmbObjSkin::read(), then ..... the two concurrent operations
50 // must be protected with a mutex.
51 // the rxdata passed from eoprot_fun_UPDT_sk_skin_status_arrayof10canframes() upto embObjSkin::update() does not need to be
52 // protected vs concurrent use because ... the only thread which writes into it is the caller of teh function: the ethReceiver thread
53 //
54 // the name of the class is IethResource because this class acts as an interface from ethResource which is the one which
55 // manages decoding of received UDP packets and calls the callbacks of the EOnv which in turn call IethResource::update().
56 //
57 
58 
59 namespace eth {
60 
61  typedef enum
62  {
63  iethres_none = 255,
78 
79  enum { iethresType_numberof = 14 };
80 
81 
83  {
84 
85  public:
86  virtual ~IethResource() {}
87 
88  virtual bool initialised() = 0;
89  virtual bool update(eOprotID32_t id32, double timestamp, void *rxdata) = 0;
90  virtual iethresType_t type() = 0;
91 
92  public:
93  const char * stringOfType();
94  /* the entityName there will be the name of the entity, or it can be an empty string if the enity han't name
95  The entity could be:
96  - axis in case the ethResource type is iethres_motioncontrol
97  - sensor id in case of, skin, mais and strain
98  The defiult value is an empty string
99  return false in case of error, like entityId is not present. Aniway the entity name is initialize to empty string.*/
100  virtual bool getEntityName(uint32_t entityId, std::string &entityName);
101 
102  private:
103  static const char * names[iethresType_numberof+1];
104  };
105 
106 } // namespace eth
107 
108 #endif
109 
110 // eof
111 
virtual bool getEntityName(uint32_t entityId, std::string &entityName)
virtual iethresType_t type()=0
virtual ~IethResource()
Definition: IethResource.h:86
virtual bool update(eOprotID32_t id32, double timestamp, void *rxdata)=0
virtual bool initialised()=0
const char * stringOfType()
iethresType_t
Definition: IethResource.h:62
@ iethres_motioncontrol
Definition: IethResource.h:67
@ iethres_analogmais
Definition: IethResource.h:65
@ iethres_analoginertial3
Definition: IethResource.h:71
@ iethres_analogpsc
Definition: IethResource.h:73
@ iethres_analogft
Definition: IethResource.h:75
@ iethres_management
Definition: IethResource.h:64
@ iethres_analogmultienc
Definition: IethResource.h:70
@ iethres_skin
Definition: IethResource.h:68
@ iethres_analogbattery
Definition: IethResource.h:76
@ iethres_none
Definition: IethResource.h:63
@ iethres_analogpos
Definition: IethResource.h:74
@ iethres_analogstrain
Definition: IethResource.h:66
@ iethres_temperature
Definition: IethResource.h:72
@ iethres_analogvirtual
Definition: IethResource.h:69
@ iethresType_numberof
Definition: IethResource.h:79