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 <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 ,
00065 unsigned int ) {}
00066
00067 virtual void arefSet(unsigned int ,
00068 unsigned int ) {}
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 ) const
00113 {
00114 return mlowest;
00115 }
00116
00117 virtual double highest(unsigned int ) const
00118 {
00119 return mhighest;
00120 }
00121
00122 virtual double resolution(unsigned int ) const
00123 {
00124 return mbin_range/(mhighest-mlowest);
00125 }
00126
00127 };
00128
00129 }
00130
00131 #endif