iCub-main
Loading...
Searching...
No Matches
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
59namespace eth {
60
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 hasn'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 /* the encoderTypeName will be the name of the type of the encoder mounted at the joint or at the motor,
103 or it can be the string "ERROR" is a corresponding name is not found
104 The entity, i.e. the jomo, can be:
105 - motor
106 - joint
107 The default value is the empty string
108 It returns false in case of error and the encoderTypeName string is filled with "ERROR"
109 */
110 virtual bool getEncoderTypeName(uint32_t jomoId, eOmc_position_t pos, std::string &encoderTypeName);
111
112 private:
113 static const char * names[iethresType_numberof+1];
114 };
115
116} // namespace eth
117
118#endif
119
120// eof
121
virtual bool getEncoderTypeName(uint32_t jomoId, eOmc_position_t pos, std::string &encoderTypeName)
virtual bool getEntityName(uint32_t entityId, std::string &entityName)
virtual iethresType_t type()=0
virtual ~IethResource()
virtual bool update(eOprotID32_t id32, double timestamp, void *rxdata)=0
virtual bool initialised()=0
const char * stringOfType()
iethresType_t
@ iethres_motioncontrol
@ iethres_analogmais
@ iethres_analoginertial3
@ iethres_analogpsc
@ iethres_analogft
@ iethres_management
@ iethres_analogmultienc
@ iethres_skin
@ iethres_analogbattery
@ iethres_none
@ iethres_analogpos
@ iethres_analogstrain
@ iethres_temperature
@ iethres_analogvirtual
@ iethresType_numberof