Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef FAKEDIGITALDEVICE_HPP
00029 #define FAKEDIGITALDEVICE_HPP
00030
00031 #include <extras/dev/DigitalInInterface.hpp>
00032 #include <extras/dev/DigitalOutInterface.hpp>
00033 #include <vector>
00034
00035 namespace RTT
00036 {
00037 using namespace dev;
00042 class FakeDigitalDevice
00043 : public DigitalInInterface,
00044 public DigitalOutInterface
00045 {
00046 public:
00047 std::vector<bool> mchannels;
00048
00049 FakeDigitalDevice(unsigned int channels=32)
00050 : DigitalInInterface("FakeDigitalDevice"),
00051 DigitalOutInterface("FakeDigitalDevice"),
00052 mchannels(channels, false)
00053 {}
00054
00055 virtual void switchOn( unsigned int n )
00056 {
00057 if ( n < mchannels.size() )
00058 mchannels[n] = true;
00059 }
00060
00061 virtual void switchOff( unsigned int n )
00062 {
00063 if ( n < mchannels.size() )
00064 mchannels[n] = false;
00065 }
00066
00067 virtual void setBit( unsigned int bit, bool value )
00068 {
00069 if ( bit < mchannels.size() )
00070 mchannels[bit] = value;
00071 }
00072
00073 virtual void setSequence(unsigned int start_bit, unsigned int stop_bit, unsigned int value)
00074 {
00075 if ( start_bit < mchannels.size() && stop_bit < mchannels.size() )
00076 for (unsigned int i = start_bit; i <= stop_bit; ++i)
00077 mchannels[i] = (value & ( 1<<( i - start_bit ) )) != 0 ;
00078 }
00079
00080 virtual bool checkBit(unsigned int n) const
00081 {
00082 if ( n < mchannels.size() )
00083 return mchannels[n];
00084 return false;
00085 }
00086
00087
00088 virtual unsigned int checkSequence( unsigned int start_bit, unsigned int stop_bit ) const
00089 {
00090 unsigned int result = 0;
00091 if ( start_bit < mchannels.size() && stop_bit < mchannels.size() )
00092 for (unsigned int i = start_bit; i <= stop_bit; ++i)
00093 result += (mchannels[i] & 1)<<i;
00094 return result;
00095 }
00096
00097 virtual unsigned int nbOfOutputs() const
00098 {
00099 return mchannels.size();
00100 }
00101
00102 virtual unsigned int nbOfInputs() const
00103 {
00104 return mchannels.size();
00105 }
00106
00107 virtual bool isOn( unsigned int bit = 0) const
00108 {
00109 if ( bit < mchannels.size() )
00110 return mchannels[bit];
00111 return false;
00112 }
00113
00114 virtual bool isOff( unsigned int bit = 0) const
00115 {
00116 if ( bit < mchannels.size() )
00117 return !mchannels[bit];
00118 return true;
00119 }
00120
00121 virtual bool readBit( unsigned int bit = 0) const
00122 {
00123 if ( bit < mchannels.size() )
00124 return mchannels[bit];
00125 return false;
00126 }
00127
00128 virtual unsigned int readSequence(unsigned int start_bit, unsigned int stop_bit) const
00129 {
00130 if ( start_bit < mchannels.size() && stop_bit < mchannels.size() )
00131 return checkSequence(start_bit, stop_bit);
00132 return 0;
00133 }
00134
00135 };
00136
00137
00138 }
00139
00140
00141 #endif