#include <Analog.h>
Inheritance diagram for gadget::Analog:


Public Types | |
| typedef gadget::SampleBuffer< AnalogData > | SampleBuffer_t |
Public Methods | |
| Analog () | |
| Constructor. More... | |
| virtual | ~Analog () |
| virtual vpr::ReturnStatus | writeObject (vpr::ObjectWriter *writer) |
| virtual vpr::ReturnStatus | readObject (vpr::ObjectReader *reader) |
| virtual bool | config (jccl::ConfigElementPtr e) |
| Just call base class config. More... | |
| AnalogData | getAnalogData (int devNum=0) |
| Returns "analog data". More... | |
| void | addAnalogSample (const std::vector< AnalogData > &anaSample) |
| Helper method to add a sample to the sample buffers. More... | |
| void | swapAnalogBuffers () |
| Swaps the analog data buffers. More... | |
| const SampleBuffer_t::buffer_t & | getAnalogDataBuffer () |
| virtual std::string | getBaseType () |
Protected Methods | |
| void | normalizeMinToMax (const float &plainJaneValue, float &normedFromMinToMax) |
| Given a value that will range from [min() <= n <= max()]. More... | |
| float | getMin () const |
| Gets the minimum "real" data value (real == from hardware). More... | |
| float | getMax () const |
| void | setMin (float mIn) |
| void | setMax (float mAx) |
| Analog (const gadget::Analog &d) | |
| void | operator= (const gadget::Analog &d) |
Analog is the base class that analog devices must derive from. Analog inherits from Input, so it has pure virtual function constraints from Input in the following functions: StartSampling, StopSampling, Sample, and UpdateData.
Analog adds one new pure virtual function, getAnalogData() for retreiving the analog data, similar to the type specific get data methods in gadget::Position and gadget::Digital.
Definition at line 64 of file Analog.h.
|
|
|
|
|
Constructor.
Definition at line 46 of file Analog.cpp.
00047 : mMin(0.0f), mMax(0.0f)
00048 {}
|
|
|
Definition at line 50 of file Analog.cpp.
00051 {}
|
|
|
Definition at line 154 of file Analog.h.
00154 : vpr::SerializableObject() {;}
|
|
|
Reimplemented in gadget::InputMixer< InputMixer< SimInput, Input >, Analog >. Definition at line 53 of file Analog.cpp. References gadget::SampleBuffer< AnalogData >::lock, gadget::MSG_DATA_ANALOG, gadget::SampleBuffer< AnalogData >::stableBuffer, and gadget::SampleBuffer< AnalogData >::unlock.
00054 {
00055 //std::cout << "[Remote Input Manager] In Analog write" << std::endl;
00056
00058 SampleBuffer_t::buffer_t& stable_buffer = mAnalogSamples.stableBuffer();
00059 writer->beginTag(Analog::getBaseType());
00060 writer->beginAttribute(gadget::tokens::DataTypeAttrib);
00061 writer->writeUint16(MSG_DATA_ANALOG); // Write out the data type so that we can assert if reading in wrong place
00062 writer->endAttribute();
00063
00064 if ( !stable_buffer.empty() )
00065 {
00066 mAnalogSamples.lock();
00067 writer->beginAttribute(gadget::tokens::SampleBufferLenAttrib);
00068 writer->writeUint16(stable_buffer.size()); // Write the # of vectors in the stable buffer
00069 writer->endAttribute();
00070 for ( unsigned j=0;j<stable_buffer.size();j++ ) // For each vector in the stable buffer
00071 {
00072 writer->beginTag(gadget::tokens::BufferSampleTag);
00073 writer->beginAttribute(gadget::tokens::BufferSampleLenAttrib);
00074 writer->writeUint16(stable_buffer[j].size()); // Write the # of AnalogDatas in the vector
00075 writer->endAttribute();
00076 for ( unsigned i=0;i<stable_buffer[j].size();i++ ) // For each AnalogData in the vector
00077 {
00078 writer->beginTag(gadget::tokens::AnalogValue);
00079 writer->beginAttribute(gadget::tokens::TimeStamp);
00080 writer->writeUint64(stable_buffer[j][i].getTime().usec()); // Write Time Stamp vpr::Uint64
00081 writer->endAttribute();
00082 writer->writeFloat(stable_buffer[j][i].getAnalog()); // Write Analog Data(int)
00083 writer->endTag();
00084 }
00085 writer->endTag();
00086 }
00087 mAnalogSamples.unlock();
00088 }
00089 else // No data or request out of range, return default value
00090 {
00091 writer->beginTag(gadget::tokens::BufferSampleTag);
00092 writer->beginAttribute(gadget::tokens::BufferSampleLenAttrib);
00093 writer->writeUint16(0);
00094 writer->endAttribute();
00095 writer->endTag();
00096 vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
00097 << "Warning: Analog::writeObject: Stable buffer is empty. If this is not the first write, then this is a problem.\n"
00098 << vprDEBUG_FLUSH;
00099 }
00100 writer->endTag();
00101
00102 return vpr::ReturnStatus::Succeed;
00104 }
|
|
|
Reimplemented in gadget::InputMixer< InputMixer< SimInput, Input >, Analog >. Definition at line 106 of file Analog.cpp. References gadget::SampleBuffer< AnalogData >::addSample, gadget::SampleBuffer< AnalogData >::lock, gadget::MSG_DATA_ANALOG, swapAnalogBuffers, and gadget::SampleBuffer< AnalogData >::unlock.
00107 {
00108 vprASSERT(reader->attribExists("rim.timestamp.delta"));
00109 vpr::Uint64 delta = reader->getAttrib<vpr::Uint64>("rim.timestamp.delta");
00110
00111 reader->beginTag(Analog::getBaseType());
00112 reader->beginAttribute(gadget::tokens::DataTypeAttrib);
00113 vpr::Uint16 temp = reader->readUint16();
00114 reader->endAttribute();
00115
00116 // ASSERT if this data is really not Analog Data
00117 // XXX: Should there be error checking for the case when vprASSERT is
00118 // compied out? -PH 8/21/2003
00119 vprASSERT(temp==MSG_DATA_ANALOG && "[Remote Input Manager] Not Analog Data");
00120 boost::ignore_unused_variable_warning(temp);
00121
00122 std::vector<AnalogData> dataSample;
00123
00124 unsigned numAnalogDatas;
00125 float value;
00126 vpr::Uint64 timeStamp;
00127 AnalogData temp_analog_data;
00128 reader->beginAttribute(gadget::tokens::SampleBufferLenAttrib);
00129 unsigned numVectors = reader->readUint16();
00130 reader->endAttribute();
00131
00132 mAnalogSamples.lock();
00133 for ( unsigned i=0;i<numVectors;i++ )
00134 {
00135 reader->beginTag(gadget::tokens::BufferSampleTag);
00136 reader->beginAttribute(gadget::tokens::BufferSampleLenAttrib);
00137 numAnalogDatas = reader->readUint16();
00138 reader->endAttribute();
00139 //std::cout << "Analog Data Size: " << numAnalogDatas << std::endl;
00140 dataSample.clear();
00141 //std::cout << "ME: ";
00142 for ( unsigned j=0;j<numAnalogDatas;j++ )
00143 {
00144 reader->beginTag(gadget::tokens::AnalogValue);
00145 reader->beginAttribute(gadget::tokens::TimeStamp);
00146 timeStamp = reader->readUint64(); // Write Time Stamp vpr::Uint64
00147 reader->endAttribute();
00148 value = reader->readFloat(); // Write Analog Data(int)
00149 reader->endTag();
00150
00151 temp_analog_data.setAnalog(value);
00152 temp_analog_data.setTime(vpr::Interval(timeStamp + delta,vpr::Interval::Usec));
00153 dataSample.push_back(temp_analog_data);
00154 }
00155 //std::cout << std::endl;
00156 mAnalogSamples.addSample(dataSample);
00157 reader->endTag();
00158 }
00159 mAnalogSamples.unlock();
00160 swapAnalogBuffers();
00161
00162 reader->endTag();
00163
00164 return vpr::ReturnStatus::Succeed;
00165 }
|
|
|
Just call base class config.
Reimplemented in gadget::SimAnalog. Definition at line 167 of file Analog.cpp.
00168 {
00169 mMin = e->getProperty<float>("min");
00170 mMax = e->getProperty<float>("max");
00171
00172 vprDEBUG(vprDBG_ALL, vprDBG_VERB_LVL)
00173 << " Analog::config() min:" << mMin
00174 << " max:" << mMax << "\n" << vprDEBUG_FLUSH;
00175
00176 return true;
00177 }
|
|
|
Returns "analog data".
Definition at line 181 of file Analog.cpp. References gadget::SampleBuffer< AnalogData >::stableBuffer.
00182 {
00183 SampleBuffer_t::buffer_t& stable_buffer = mAnalogSamples.stableBuffer();
00184
00185 if ( (!stable_buffer.empty()) &&
00186 (stable_buffer.back().size() > (unsigned)devNum) ) // If Have entry && devNum in range
00187 {
00188 return stable_buffer.back()[devNum];
00189 }
00190 else // No data or request out of range, return default value
00191 {
00192 if ( stable_buffer.empty() )
00193 {
00194 vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
00195 << "Warning: Analog::getAnalogData: Stable buffer is empty. If this is not the first read, then this is a problem.\n"
00196 << vprDEBUG_FLUSH;
00197 }
00198 else
00199 {
00200 vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00201 << "Warning: Analog::getAnalogData: Requested devNum is not in the range available. May have configuration error\n"
00202 << vprDEBUG_FLUSH;
00203 }
00204 return mDefaultValue;
00205 }
00206 }
|
|
|
Helper method to add a sample to the sample buffers. This MUST be called by all analog devices to add a new sample. The data samples passed in will then be modified by any local filters.
Definition at line 208 of file Analog.cpp. References gadget::SampleBuffer< AnalogData >::addSample, gadget::SampleBuffer< AnalogData >::lock, and gadget::SampleBuffer< AnalogData >::unlock. Referenced by gadget::SimAnalog::updateData.
00209 {
00210 // Locks and then swaps the indices.
00211 mAnalogSamples.lock();
00212 mAnalogSamples.addSample(anaSample);
00213 mAnalogSamples.unlock();
00214 }
|
|
|
Swaps the analog data buffers.
Definition at line 216 of file Analog.cpp. References gadget::SampleBuffer< AnalogData >::swapBuffers. Referenced by readObject, and gadget::SimAnalog::updateData.
00217 {
00218 mAnalogSamples.swapBuffers();
00219 }
|
|
|
Definition at line 222 of file Analog.cpp. References gadget::SampleBuffer< AnalogData >::stableBuffer.
00223 {
00224 return mAnalogSamples.stableBuffer();
00225 }
|
|
|
Reimplemented in gadget::InputMixer< InputMixer< SimInput, Input >, Analog >. Definition at line 227 of file Analog.cpp.
00228 {
00229 return std::string("Analog");
00230 }
|
|
||||||||||||
|
Given a value that will range from [min() <= n <= max()]. This returns a value that is normalized to [0,1] Definition at line 235 of file Analog.cpp. Referenced by gadget::SimAnalog::updateData.
00237 {
00238 float value = plainJaneValue;
00239
00240 // first clamp the value so that min<=value<=max
00241 if ( value < mMin ) value = mMin;
00242 if ( value > mMax ) value = mMax;
00243
00244 // slide everything to 0.0 (subtract all by mMin)
00245 // Then divide by max to get normalized value
00246 float tmax( mMax - mMin),
00247 tvalue(value - mMin);
00248
00249 // since [tmin/tmax...tmax/tmax] == [0.0f...1.0f], the normalized value will be value/tmax
00250 normedFromMinToMax = tvalue / tmax;
00251 }
|
|
|
Gets the minimum "real" data value (real == from hardware). This value is used to normalize the return value of getAnalogData.
Definition at line 253 of file Analog.cpp. Referenced by gadget::SimAnalog::updateData.
00254 {
00255 return mMin;
00256 }
|
|
|
Definition at line 258 of file Analog.cpp. Referenced by gadget::SimAnalog::updateData.
00259 {
00260 return mMax;
00261 }
|
|
|
Definition at line 263 of file Analog.cpp.
00264 {
00265 mMin = mIn;
00266 }
|
|
|
Definition at line 268 of file Analog.cpp.
00269 {
00270 mMax = mAx;
00271 }
|
|
|
Definition at line 155 of file Analog.h.
00155 {;}
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002