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 
31 
32 // marco.accame on 20 oct 2014.
33 // the objects which use ethResource to communicate with the ethernet boards inside the robot
34 // must be derived from this class IethResource.
35 // these objects are: embObjMotionControl, embObjSkin, embObjAnalogSensor, and future ones.
36 // these object must implement the virtual functions initialised() and update() so that:
37 // - initialised() must return true only if the object is opened (its method open() has returned).
38 // - update() takes care of filling private data structures with bytes contained in the relevant ROPs coming from remote boards.
39 // as an example, see how the skin data is moved from ems board to embObjSkin.
40 // when a ROP containing a EOarray of skin data arrives, the callback eoprot_fun_UPDT_sk_skin_status_arrayof10canframes() is called.
41 // this function calls feat_manage_skin_data() and passes the boardnumber, the id32, and the pointer to the received EOarray.
42 // this function uses TheEthManager::getHandle() to retrieve a pointer to the relevant IethResource which matches (boardnumber, id32)
43 // the pointer is used directly or transformed with dynamic_cast to a pointer to embObjSkin and the function update() is called.
44 // needless to say, the update(0 function whcich is called is always the embObjSkin::update() which gets the EOarray and copies its
45 // items inside embObjSkin::data.
46 //
47 // warning: the caller of function embObjSkin::update() is the ethReceiver thread. if it writes something into embObjSkin::data,
48 // and the same embObjSkin::data is read by other threads via EmbObjSkin::read(), then ..... the two concurrent operations
49 // must be protected with a mutex.
50 // the rxdata passed from eoprot_fun_UPDT_sk_skin_status_arrayof10canframes() upto embObjSkin::update() does not need to be
51 // protected vs concurrent use because ... the only thread which writes into it is the caller of teh function: the ethReceiver thread
52 //
53 // the name of the class is IethResource because this class acts as an interface from ethResource which is the one which
54 // manages decoding of received UDP packets and calls the callbacks of the EOnv which in turn call IethResource::update().
55 //
56 
57 
58 namespace eth {
59 
60  typedef enum
61  {
62  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 
95  private:
96  static const char * names[iethresType_numberof+1];
97  };
98 
99 } // namespace eth
100 
101 #endif
102 
103 // eof
104 
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:61
@ iethres_motioncontrol
Definition: IethResource.h:66
@ iethres_analogmais
Definition: IethResource.h:64
@ iethres_analoginertial3
Definition: IethResource.h:71
@ iethres_analogpsc
Definition: IethResource.h:73
@ iethres_analoginertial
Definition: IethResource.h:69
@ iethres_analogft
Definition: IethResource.h:75
@ iethres_management
Definition: IethResource.h:63
@ iethres_analogmultienc
Definition: IethResource.h:70
@ iethres_skin
Definition: IethResource.h:67
@ iethres_analogbattery
Definition: IethResource.h:76
@ iethres_none
Definition: IethResource.h:62
@ iethres_analogpos
Definition: IethResource.h:74
@ iethres_analogstrain
Definition: IethResource.h:65
@ iethres_temperature
Definition: IethResource.h:72
@ iethres_analogvirtual
Definition: IethResource.h:68
@ iethresType_numberof
Definition: IethResource.h:79