FakeAnalogDevice.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Apr 22 20:40:59 CEST 2004 FakeAnalogDevice.hpp
3 
4  FakeAnalogDevice.hpp - description
5  -------------------
6  begin : Thu April 22 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU Lesser General Public *
13  * License as published by the Free Software Foundation; either *
14  * version 2.1 of the License, or (at your option) any later version. *
15  * *
16  * This library is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
19  * Lesser General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU Lesser General Public *
22  * License along with this library; if not, write to the Free Software *
23  * Foundation, Inc., 59 Temple Place, *
24  * Suite 330, Boston, MA 02111-1307 USA *
25  * *
26  ***************************************************************************/
27 
28 #ifndef FAKEANALOGDEVICE_HPP
29 #define FAKEANALOGDEVICE_HPP
30 
33 
34 namespace RTT
35 {
36  using namespace dev;
42  public AnalogInInterface,
43  public AnalogOutInterface
44  {
45  unsigned int nbofchans;
46  int* mchannels;
47  unsigned int mbin_range;
48  double mlowest, mhighest;
49 
50  FakeAnalogDevice(unsigned int channels=32, unsigned int bin_range=4096, double lowest = -5.0, double highest = +5.0)
51  : AnalogInInterface("FakeAnalogDevice"),
52  AnalogOutInterface("FakeAnalogDevice"),
53  nbofchans(channels),
54  mchannels( new int[channels] ),
55  mbin_range( bin_range),
56  mlowest( lowest),
57  mhighest( highest)
58  {}
59 
61  delete[] mchannels;
62  }
63 
64  virtual void rangeSet(unsigned int /*chan*/,
65  unsigned int /*range*/) {}
66 
67  virtual void arefSet(unsigned int /*chan*/,
68  unsigned int /*aref*/) {}
69 
70  virtual unsigned int nbOfChannels() const {
71  return nbofchans;
72  }
73 
74  virtual int read( unsigned int chan, double& value )
75  {
76  if (chan < nbofchans) {
77  value = mchannels[chan] / resolution(chan) + mlowest;
78  return 0;
79  }
80  return -1;
81  }
82 
83  virtual int write( unsigned int chan, double value ) {
84  if (chan < nbofchans) {
85  mchannels[chan] = (unsigned int)((value - mlowest) * resolution(chan));
86  return 0;
87  }
88  return -1;
89  }
90 
91  virtual int rawRead( unsigned int chan, int & value )
92  {
93  if (chan < nbofchans) {
94  value = mchannels[chan];
95  return 0;
96  }
97  return -1;
98  }
99 
100  virtual int rawWrite( unsigned int chan, int value ) {
101  if (chan < nbofchans)
102  mchannels[chan] = value;
103  return 0;
104  }
105 
106 
107  virtual unsigned int rawRange() const
108  {
109  return mbin_range;
110  }
111 
112  virtual double lowest(unsigned int /*chan*/) const
113  {
114  return mlowest;
115  }
116 
117  virtual double highest(unsigned int /*chan*/) const
118  {
119  return mhighest;
120  }
121 
122  virtual double resolution(unsigned int /*chan*/) const
123  {
124  return mbin_range/(mhighest-mlowest);
125  }
126 
127  };
128 
129 }
130 
131 #endif
virtual double lowest(unsigned int) const
virtual int read(unsigned int chan, double &value)
virtual unsigned int nbOfChannels() const
virtual double resolution(unsigned int) const
virtual int rawRead(unsigned int chan, int &value)
FakeAnalogDevice(unsigned int channels=32, unsigned int bin_range=4096, double lowest=-5.0, double highest=+5.0)
virtual void rangeSet(unsigned int, unsigned int)
virtual double highest(unsigned int) const
virtual int write(unsigned int chan, double value)
virtual int rawWrite(unsigned int chan, int value)
virtual void arefSet(unsigned int, unsigned int)
virtual unsigned int rawRange() const
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:24