FakeAnalogDevice.hpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Thu Apr 22 20:40:59 CEST 2004  FakeAnalogDevice.hpp
00003 
00004                         FakeAnalogDevice.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 FAKEANALOGDEVICE_HPP
00029 #define FAKEANALOGDEVICE_HPP
00030 
00031 #include <extras/dev/AnalogInInterface.hpp>
00032 #include <extras/dev/AnalogOutInterface.hpp>
00033 
00034 namespace RTT
00035 {
00036     using namespace dev;
00041     struct FakeAnalogDevice :
00042         public AnalogInInterface,
00043         public AnalogOutInterface
00044     {
00045         unsigned int nbofchans;
00046         int* mchannels;
00047         unsigned int mbin_range;
00048         double mlowest, mhighest;
00049 
00050         FakeAnalogDevice(unsigned int channels=32, unsigned int bin_range=4096, double lowest = -5.0, double highest = +5.0)
00051             : AnalogInInterface("FakeAnalogDevice"),
00052               AnalogOutInterface("FakeAnalogDevice"),
00053               nbofchans(channels),
00054               mchannels( new int[channels] ),
00055               mbin_range( bin_range),
00056               mlowest( lowest),
00057               mhighest( highest)
00058         {}
00059 
00060         ~FakeAnalogDevice() {
00061             delete[] mchannels;
00062         }
00063 
00064         virtual void rangeSet(unsigned int /*chan*/,
00065                               unsigned int /*range*/) {}
00066 
00067         virtual void arefSet(unsigned int /*chan*/,
00068                              unsigned int /*aref*/) {}
00069 
00070         virtual unsigned int nbOfChannels() const {
00071             return nbofchans;
00072         }
00073 
00074         virtual int read( unsigned int chan, double& value )
00075         {
00076             if (chan < nbofchans) {
00077                 value = mchannels[chan] / resolution(chan) + mlowest;
00078                 return 0;
00079             }
00080             return -1;
00081         }
00082 
00083         virtual int write( unsigned int chan, double value ) {
00084             if (chan < nbofchans) {
00085                 mchannels[chan] = (unsigned int)((value - mlowest) * resolution(chan));
00086                 return 0;
00087             }
00088             return -1;
00089         }
00090 
00091         virtual int rawRead( unsigned int chan,  int & value )
00092         {
00093             if (chan < nbofchans) {
00094                  value = mchannels[chan];
00095                  return 0;
00096             }
00097             return -1;
00098         }
00099 
00100         virtual int rawWrite( unsigned int chan,  int value ) {
00101             if (chan < nbofchans)
00102                 mchannels[chan] = value;
00103             return 0;
00104         }
00105 
00106 
00107         virtual unsigned int rawRange() const
00108         {
00109             return mbin_range;
00110         }
00111 
00112         virtual double lowest(unsigned int /*chan*/) const
00113         {
00114             return mlowest;
00115         }
00116 
00117         virtual double highest(unsigned int /*chan*/) const
00118         {
00119             return mhighest;
00120         }
00121 
00122         virtual double resolution(unsigned int /*chan*/) const
00123         {
00124             return mbin_range/(mhighest-mlowest);
00125         }
00126 
00127     };
00128 
00129 }
00130 
00131 #endif


rtt
Author(s): RTT Developers
autogenerated on Sat Jun 8 2019 18:46:11