FakeDigitalDevice.hpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Thu Apr 22 20:40:58 CEST 2004  FakeDigitalDevice.hpp
00003 
00004                         FakeDigitalDevice.hpp -  description
00005                            -------------------
00006     begin                : Thu April 22 2004
00007     copyright            : (C) 2004 Peter Soetens
00008     email                : peter.soetens@mech.kuleuven.ac.be
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU Lesser General Public            *
00013  *   License as published by the Free Software Foundation; either          *
00014  *   version 2.1 of the License, or (at your option) any later version.    *
00015  *                                                                         *
00016  *   This library is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00019  *   Lesser General Public License for more details.                       *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU Lesser General Public      *
00022  *   License along with this library; if not, write to the Free Software   *
00023  *   Foundation, Inc., 59 Temple Place,                                    *
00024  *   Suite 330, Boston, MA  02111-1307  USA                                *
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


rtt
Author(s): RTT Developers
autogenerated on Wed Aug 26 2015 16:15:48