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 FAKEANALOGDEVICE_HPP
00029 #define FAKEANALOGDEVICE_HPP
00030
00031 #include "rtt/dev/AnalogInInterface.hpp"
00032 #include "rtt/dev/AnalogOutInterface.hpp"
00033
00034 namespace RTT
00035 {
00040 struct FakeAnalogDevice :
00041 public AnalogInInterface,
00042 public AnalogOutInterface
00043 {
00044 unsigned int nbofchans;
00045 unsigned int* mchannels;
00046 unsigned int mbin_range;
00047 double mlowest, mhighest;
00048
00049 FakeAnalogDevice(unsigned int channels=32, unsigned int bin_range=4096, double lowest = -5.0, double highest = +5.0)
00050 : AnalogInInterface("FakeAnalogDevice"),
00051 AnalogOutInterface("FakeAnalogDevice"),
00052 nbofchans(channels),
00053 mchannels( new unsigned int[channels] ),
00054 mbin_range( bin_range),
00055 mlowest( lowest),
00056 mhighest( highest)
00057 {}
00058
00059 ~FakeAnalogDevice() {
00060 delete[] mchannels;
00061 }
00062
00063 virtual void rangeSet(unsigned int ,
00064 unsigned int ) {}
00065
00066 virtual void arefSet(unsigned int ,
00067 unsigned int ) {}
00068
00069 virtual unsigned int nbOfChannels() const {
00070 return nbofchans;
00071 }
00072
00073 virtual void read( unsigned int chan, int& value ) const
00074 {
00075 if (chan < nbofchans)
00076 value = mchannels[chan];
00077 }
00078
00079 virtual void write( unsigned int chan, int value ) {
00080 if (chan < nbofchans)
00081 mchannels[chan] = value;
00082 }
00083
00084 virtual unsigned int binaryRange() const
00085 {
00086 return mbin_range;
00087 }
00088
00089 virtual int binaryLowest() const
00090 {
00091 return 0;
00092 }
00093
00094 virtual int binaryHighest() const
00095 {
00096 return mbin_range;
00097 }
00098
00099 virtual double lowest(unsigned int ) const
00100 {
00101 return mlowest;
00102 }
00103
00104 virtual double highest(unsigned int ) const
00105 {
00106 return mhighest;
00107 }
00108
00109 virtual double resolution(unsigned int ) const
00110 {
00111 return mbin_range/(mhighest-mlowest);
00112 }
00113
00114 };
00115
00116 }
00117
00118 #endif