FakeDigitalDevice.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Apr 22 20:40:58 CEST 2004 FakeDigitalDevice.hpp
3 
4  FakeDigitalDevice.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 FAKEDIGITALDEVICE_HPP
29 #define FAKEDIGITALDEVICE_HPP
30 
33 #include <vector>
34 
35 namespace RTT
36 {
37  using namespace dev;
43  : public DigitalInInterface,
44  public DigitalOutInterface
45  {
46  public:
47  std::vector<bool> mchannels;
48 
49  FakeDigitalDevice(unsigned int channels=32)
50  : DigitalInInterface("FakeDigitalDevice"),
51  DigitalOutInterface("FakeDigitalDevice"),
52  mchannels(channels, false)
53  {}
54 
55  virtual void switchOn( unsigned int n )
56  {
57  if ( n < mchannels.size() )
58  mchannels[n] = true;
59  }
60 
61  virtual void switchOff( unsigned int n )
62  {
63  if ( n < mchannels.size() )
64  mchannels[n] = false;
65  }
66 
67  virtual void setBit( unsigned int bit, bool value )
68  {
69  if ( bit < mchannels.size() )
70  mchannels[bit] = value;
71  }
72 
73  virtual void setSequence(unsigned int start_bit, unsigned int stop_bit, unsigned int value)
74  {
75  if ( start_bit < mchannels.size() && stop_bit < mchannels.size() )
76  for (unsigned int i = start_bit; i <= stop_bit; ++i)
77  mchannels[i] = (value & ( 1<<( i - start_bit ) )) != 0 ;
78  }
79 
80  virtual bool checkBit(unsigned int n) const
81  {
82  if ( n < mchannels.size() )
83  return mchannels[n];
84  return false;
85  }
86 
87 
88  virtual unsigned int checkSequence( unsigned int start_bit, unsigned int stop_bit ) const
89  {
90  unsigned int result = 0;
91  if ( start_bit < mchannels.size() && stop_bit < mchannels.size() )
92  for (unsigned int i = start_bit; i <= stop_bit; ++i)
93  result += (mchannels[i] & 1)<<i;
94  return result;
95  }
96 
97  virtual unsigned int nbOfOutputs() const
98  {
99  return mchannels.size();
100  }
101 
102  virtual unsigned int nbOfInputs() const
103  {
104  return mchannels.size();
105  }
106 
107  virtual bool isOn( unsigned int bit = 0) const
108  {
109  if ( bit < mchannels.size() )
110  return mchannels[bit];
111  return false;
112  }
113 
114  virtual bool isOff( unsigned int bit = 0) const
115  {
116  if ( bit < mchannels.size() )
117  return !mchannels[bit];
118  return true;
119  }
120 
121  virtual bool readBit( unsigned int bit = 0) const
122  {
123  if ( bit < mchannels.size() )
124  return mchannels[bit];
125  return false;
126  }
127 
128  virtual unsigned int readSequence(unsigned int start_bit, unsigned int stop_bit) const
129  {
130  if ( start_bit < mchannels.size() && stop_bit < mchannels.size() )
131  return checkSequence(start_bit, stop_bit);
132  return 0;
133  }
134 
135  };
136 
137 
138 }
139 
140 
141 #endif
virtual unsigned int checkSequence(unsigned int start_bit, unsigned int stop_bit) const
virtual bool isOff(unsigned int bit=0) const
virtual void setBit(unsigned int bit, bool value)
virtual bool isOn(unsigned int bit=0) const
std::vector< bool > mchannels
virtual unsigned int readSequence(unsigned int start_bit, unsigned int stop_bit) const
virtual void setSequence(unsigned int start_bit, unsigned int stop_bit, unsigned int value)
virtual void switchOn(unsigned int n)
virtual void switchOff(unsigned int n)
virtual bool readBit(unsigned int bit=0) const
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
virtual bool checkBit(unsigned int n) const
FakeDigitalDevice(unsigned int channels=32)
virtual unsigned int nbOfOutputs() const
virtual unsigned int nbOfInputs() const


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:33