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 "rtt/dev/DigitalInInterface.hpp"
00032 #include "rtt/dev/DigitalOutInterface.hpp"
00033 #include <vector>
00034
00035 namespace RTT
00036 {
00041 class FakeDigitalDevice
00042 : public DigitalInInterface,
00043 public DigitalOutInterface
00044 {
00045 public:
00046 std::vector<bool> mchannels;
00047
00048 FakeDigitalDevice(unsigned int channels=32)
00049 : DigitalInInterface("FakeDigitalDevice"),
00050 DigitalOutInterface("FakeDigitalDevice"),
00051 mchannels(channels, false)
00052 {}
00053
00054 virtual void switchOn( unsigned int n )
00055 {
00056 if ( n < mchannels.size() )
00057 mchannels[n] = true;
00058 }
00059
00060 virtual void switchOff( unsigned int n )
00061 {
00062 if ( n < mchannels.size() )
00063 mchannels[n] = false;
00064 }
00065
00066 virtual void setBit( unsigned int bit, bool value )
00067 {
00068 if ( bit < mchannels.size() )
00069 mchannels[bit] = value;
00070 }
00071
00072 virtual void setSequence(unsigned int start_bit, unsigned int stop_bit, unsigned int value)
00073 {
00074 if ( start_bit < mchannels.size() && stop_bit < mchannels.size() )
00075 for (unsigned int i = start_bit; i <= stop_bit; ++i)
00076 mchannels[i] = value & ( 1<<( i - start_bit ) );
00077 }
00078
00079 virtual bool checkBit(unsigned int n) const
00080 {
00081 if ( n < mchannels.size() )
00082 return mchannels[n];
00083 return false;
00084 }
00085
00086
00087 virtual unsigned int checkSequence( unsigned int start_bit, unsigned int stop_bit ) const
00088 {
00089 unsigned int result = 0;
00090 if ( start_bit < mchannels.size() && stop_bit < mchannels.size() )
00091 for (unsigned int i = start_bit; i <= stop_bit; ++i)
00092 result += (mchannels[i] & 1)<<i;
00093 return result;
00094 }
00095
00096 virtual unsigned int nbOfOutputs() const
00097 {
00098 return mchannels.size();
00099 }
00100
00101 virtual unsigned int nbOfInputs() const
00102 {
00103 return mchannels.size();
00104 }
00105
00106 virtual bool isOn( unsigned int bit = 0) const
00107 {
00108 if ( bit < mchannels.size() )
00109 return mchannels[bit];
00110 return false;
00111 }
00112
00113 virtual bool isOff( unsigned int bit = 0) const
00114 {
00115 if ( bit < mchannels.size() )
00116 return !mchannels[bit];
00117 return true;
00118 }
00119
00120 virtual bool readBit( unsigned int bit = 0) const
00121 {
00122 if ( bit < mchannels.size() )
00123 return mchannels[bit];
00124 return false;
00125 }
00126
00127 virtual unsigned int readSequence(unsigned int start_bit, unsigned int stop_bit) const
00128 {
00129 if ( start_bit < mchannels.size() && stop_bit < mchannels.size() )
00130 return checkSequence(start_bit, stop_bit);
00131 return 0;
00132 }
00133
00134 };
00135
00136
00137 }
00138
00139
00140 #endif