iCub-main
embObjMais.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 
4 #ifndef __embObjMais_h__
5 #define __embObjMais_h__
6 
7 #include <yarp/dev/DeviceDriver.h>
8 #include <yarp/dev/IAnalogSensor.h>
9 #include <yarp/os/PeriodicThread.h>
10 #include <string>
11 #include <list>
12 #include <mutex>
13 
14 #include <iCub/FactoryInterface.h>
15 #include <iCub/LoggerInterfaces.h>
16 
17 
18 #include "IethResource.h"
19 #include <ethManager.h>
20 #include <abstractEthResource.h>
21 
22 
23 #include <yarp/os/LogStream.h>
24 
25 #include "serviceParser.h"
26 
27 namespace yarp {
28  namespace dev {
29  class embObjMais;
30  }
31 }
32 
33 
34 #define EMBOBJMAIS_USESERVICEPARSER
35 
36 
37 // -- class embObjMais
38 
39 class yarp::dev::embObjMais: public yarp::dev::IAnalogSensor,
40  public yarp::dev::DeviceDriver,
41  public eth::IethResource
42 {
43 
44 public:
45 
46  enum { mais_Channels = 15, mais_FormatData = 8 };
47 
48 public:
49 
50  embObjMais();
51  ~embObjMais();
52 
53  // An open function yarp factory compatible
54  bool open(yarp::os::Searchable &config);
55  bool close();
56 
57  // IAnalogSensor interface
58  virtual int read(yarp::sig::Vector &out);
59  virtual int getState(int ch);
60  virtual int getChannels();
61  virtual int calibrateChannel(int ch, double v);
62  virtual int calibrateSensor();
63  virtual int calibrateSensor(const yarp::sig::Vector& value);
64  virtual int calibrateChannel(int ch);
65 
66  // IethResource interface
67  virtual bool initialised();
68  virtual eth::iethresType_t type();
69  virtual bool update(eOprotID32_t id32, double timestamp, void* rxdata);
70 
71 private:
72 
73  string boardIPstring;
74  string boardName;
75  eOipv4addr_t ipv4addr;
76 
77  eth::TheEthManager* ethManager;
79  ServiceParser* parser;
80 
81  bool opened;
82  bool verbosewhenok;
83 
84  unsigned int counterSat;
85  unsigned int counterError;
86  unsigned int counterTimeout;
87 
89  // parameters
90  servConfigMais_t serviceConfig;
91 
92  std::mutex mtx;
93 
94  vector<double> analogdata;
95 
96  short status;
97  double timeStamp;
98 
99 private:
100 
101  // for all
102  bool extractGroup(Bottle &input, Bottle &out, const std::string &key1, const std::string &txt, int size);
103  bool fromConfig(yarp::os::Searchable &config);
104  bool initRegulars();
105  void cleanup(void);
106  void printServiceConfig(void);
107 
108  // for mais
109  bool sendConfig2Mais(void);
110 
111 
112  // for ??
113  void resetCounters();
114  void getCounters(unsigned int &saturations, unsigned int &errors, unsigned int &timeouts);
115 };
116 
117 
118 #endif
119 
Interface for a factory device; a device that can create objects.
virtual bool initialised()
Definition: embObjMais.cpp:168
virtual int read(yarp::sig::Vector &out)
Read a vector from the sensor.
Definition: embObjMais.cpp:434
virtual int getChannels()
Definition: embObjMais.cpp:503
virtual int getState(int ch)
Definition: embObjMais.cpp:496
virtual bool update(eOprotID32_t id32, double timestamp, void *rxdata)
Definition: embObjMais.cpp:539
virtual int calibrateSensor()
Definition: embObjMais.cpp:509
bool open(yarp::os::Searchable &config)
Definition: embObjMais.cpp:176
virtual int calibrateChannel(int ch, double v)
Definition: embObjMais.cpp:527
virtual eth::iethresType_t type()
Definition: embObjMais.cpp:533
static int v
Definition: iCub_Sim.cpp:42
iethresType_t
Definition: IethResource.h:61
Copyright (C) 2008 RobotCub Consortium.
out
Definition: sine.m:8