gadget::Command Class Reference

Command is the abstract base class for devices that translate spoken commends into integer-identified commands. More...

#include <gadget/Type/Command.h>

Collaboration diagram for gadget::Command:

Collaboration graph
[legend]
List of all members.

Public Types

typedef gadget::SampleBuffer<
CommandData
SampleBuffer_t

Public Member Functions

 Command ()
virtual ~Command ()
virtual bool config (jccl::ConfigElementPtr e)
const CommandData getCommandData (int devNum=0)
 Gets the command data for the given devNum.
void addCommandSample (const std::vector< CommandData > &digSample)
 Helper method to add a collection of command samples to the sample buffers.
void swapCommandBuffers ()
 Swaps the command data buffers.
const SampleBuffer_t::buffer_tgetCommandDataBuffer ()
 Returns the current stable sample buffers for this device.
virtual std::string getInputTypeName ()
virtual vpr::ReturnStatus writeObject (vpr::ObjectWriter *writer)
 Serializes this object.
virtual vpr::ReturnStatus readObject (vpr::ObjectReader *reader)
 De-serializes this object.

Protected Member Functions

 Command (const gadget::Command &)
void operator= (const gadget::Command &)

Detailed Description

Command is the abstract base class for devices that translate spoken commends into integer-identified commands.

Drivers for all such devices must derive from this class (through gadget::InputMixer). This is in addition to gadget::Input. gadget::Input provides pure virtual function constraints in the following functions: startSampling(), stopSampling(), sample(), and updateData().

gadget::Command adds the function getCommandData() for retreiving the received commands. This is similar to the additions made by gadget::Position and gadget::Analog.

See also:
Input, InputMixer

Definition at line 68 of file Command.h.


Member Typedef Documentation

typedef gadget::SampleBuffer<CommandData> gadget::Command::SampleBuffer_t

Definition at line 71 of file Command.h.


Constructor & Destructor Documentation

gadget::Command::Command (  )  [inline]

Definition at line 75 of file Command.h.

00076       {
00077          ;
00078       }

virtual gadget::Command::~Command (  )  [inline, virtual]

Definition at line 80 of file Command.h.

00081       {
00082          ;
00083       }

gadget::Command::Command ( const gadget::Command  )  [inline, protected]

Definition at line 152 of file Command.h.

00153          : vpr::SerializableObject()
00154       {;}


Member Function Documentation

virtual bool gadget::Command::config ( jccl::ConfigElementPtr  e  )  [inline, virtual]

Definition at line 85 of file Command.h.

00086       {
00087          boost::ignore_unused_variable_warning(e);
00088          return true;
00089       }

const CommandData gadget::Command::getCommandData ( int  devNum = 0  ) 

Gets the command data for the given devNum.

Returns:
Command 0 or 1, if devNum makes sense. -1 is returned if function fails or if devNum is out of range.
Note:
If devNum is out of range, function will fail, possibly issuing an error to a log or console - but will not ASSERT.

Definition at line 43 of file Command.cpp.

References gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::stableBuffer().

00044 {
00045    SampleBuffer_t::buffer_t& stable_buffer = mCommandSamples.stableBuffer();
00046 
00047    if ( (!stable_buffer.empty()) &&
00048         (stable_buffer.back().size() > (unsigned)devNum) )  // If Have entry && devNum in range
00049    {
00050       return stable_buffer.back()[devNum];
00051    }
00052    else        // No data or request out of range, return default value
00053    {
00054       if ( stable_buffer.empty() )
00055       {
00056          vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
00057             << "WARNING: [gadget::Command::getCommandData()] "
00058             << "Stable buffer is empty.  If this is not the first "
00059             << "read, then this is a problem.\n" << vprDEBUG_FLUSH;
00060       }
00061       else
00062       {
00063          vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00064             << "WARNING: [gadget::Command::getCommandData()] "
00065             << "Requested devNum (" << devNum
00066             << ") is not in the range available.  "
00067             << "This is probably a configuration error.\n" << vprDEBUG_FLUSH;
00068       }
00069       return mDefaultValue;
00070    }
00071 }

void gadget::Command::addCommandSample ( const std::vector< CommandData > &  digSample  )  [inline]

Helper method to add a collection of command samples to the sample buffers.

This MUST be called by all command devices to add new samples.

Postcondition:
The given command samples are added to the buffers.
Parameters:
digSample A vector of CommandData objects that represent the newest samples taken.

Definition at line 111 of file Command.h.

00112       {
00113          // Locks and then swaps the indices.
00114          mCommandSamples.lock();
00115          mCommandSamples.addSample(digSample);
00116          mCommandSamples.unlock();
00117       }

void gadget::Command::swapCommandBuffers (  )  [inline]

Swaps the command data buffers.

Postcondition:
If the ready queue has values, then those values are copied from the ready queue to the stable queue. If not, then stable queue is not changed.

Definition at line 126 of file Command.h.

00127       {
00128          mCommandSamples.swapBuffers();
00129       }

const SampleBuffer_t::buffer_t& gadget::Command::getCommandDataBuffer (  )  [inline]

Returns the current stable sample buffers for this device.

Definition at line 134 of file Command.h.

00135       {
00136          return mCommandSamples.stableBuffer();
00137       }

virtual std::string gadget::Command::getInputTypeName (  )  [inline, virtual]

Definition at line 139 of file Command.h.

Referenced by readObject(), and writeObject().

00140       {
00141          return std::string("Command");
00142       }

vpr::ReturnStatus gadget::Command::writeObject ( vpr::ObjectWriter *  writer  )  [virtual]

Serializes this object.

Definition at line 73 of file Command.cpp.

References gadget::tokens::BufferSampleLenAttrib(), gadget::tokens::BufferSampleTag(), gadget::tokens::DataTypeAttrib(), gadget::tokens::DigitalValue(), getInputTypeName(), gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::lock(), gadget::MSG_DATA_COMMAND, gadget::tokens::SampleBufferLenAttrib(), gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::stableBuffer(), gadget::tokens::TimeStamp(), and gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::unlock().

00074 {
00075    writer->beginTag(Command::getInputTypeName());
00076    SampleBuffer_t::buffer_t& stable_buffer = mCommandSamples.stableBuffer();
00077    writer->beginAttribute(gadget::tokens::DataTypeAttrib);
00078       // Write out the data type so that we can assert if reading in wrong
00079       // place.
00080       writer->writeUint16(MSG_DATA_COMMAND);
00081    writer->endAttribute();
00082 
00083    writer->beginAttribute(gadget::tokens::SampleBufferLenAttrib);
00084       // Write the # of vectors in the stable buffer.
00085       writer->writeUint16(stable_buffer.size());
00086    writer->endAttribute();
00087 
00088    if ( !stable_buffer.empty() )
00089    {
00090       mCommandSamples.lock();
00091       for ( unsigned j = 0; j < stable_buffer.size(); ++j )                               // For each vector in the stable buffer
00092       {
00093          writer->beginTag(gadget::tokens::BufferSampleTag);
00094          writer->beginAttribute(gadget::tokens::BufferSampleLenAttrib);
00095             writer->writeUint16(stable_buffer[j].size());                           // Write the # of CommandDatas in the vector
00096          writer->endAttribute();
00097          for ( unsigned i = 0; i < stable_buffer[j].size(); ++i )                         // For each CommandData in the vector
00098          {
00099             writer->beginTag(gadget::tokens::DigitalValue);
00100             writer->beginAttribute(gadget::tokens::TimeStamp);
00101                writer->writeUint64(stable_buffer[j][i].getTime().usec());           // Write Time Stamp vpr::Uint64
00102             writer->endAttribute();
00103             writer->writeUint32((vpr::Uint32)stable_buffer[j][i].getDigital());  // Write Command Data(int)
00104             writer->endTag();
00105          }
00106          writer->endTag();
00107       }
00108       mCommandSamples.unlock();
00109    }
00110    writer->endTag();
00111 
00112    return vpr::ReturnStatus::Succeed;
00113 }

vpr::ReturnStatus gadget::Command::readObject ( vpr::ObjectReader *  reader  )  [virtual]

De-serializes this object.

Definition at line 115 of file Command.cpp.

References gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::addSample(), gadget::tokens::BufferSampleLenAttrib(), gadget::tokens::BufferSampleTag(), gadget::tokens::DataTypeAttrib(), gadget::tokens::DigitalValue(), getInputTypeName(), gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::lock(), gadget::MSG_DATA_COMMAND, gadget::tokens::SampleBufferLenAttrib(), gadget::DigitalData::setDigital(), gadget::InputData::setTime(), gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::swapBuffers(), gadget::tokens::TimeStamp(), and gadget::SampleBuffer< DATA_TYPE, MAX_BUFFER_SIZE >::unlock().

00116 {
00117    vprASSERT(reader->attribExists("rim.timestamp.delta"));
00118    vpr::Uint64 delta = reader->getAttrib<vpr::Uint64>("rim.timestamp.delta");
00119 
00120       // ASSERT if this data is really not Command Data
00121    reader->beginTag(Command::getInputTypeName());
00122    reader->beginAttribute(gadget::tokens::DataTypeAttrib);
00123       vpr::Uint16 temp = reader->readUint16();
00124    reader->endAttribute();
00125 
00126    // XXX: Should there be error checking for the case when vprASSERT()
00127    // is compiled out?  -PH 8/21/2003
00128    vprASSERT(temp==MSG_DATA_COMMAND && "[Remote Input Manager]Not Command Data");
00129    boost::ignore_unused_variable_warning(temp);
00130 
00131    std::vector<CommandData> dataSample;
00132 
00133    unsigned numCommandDatas;
00134    vpr::Uint32 value;
00135    vpr::Uint64 timeStamp;
00136    CommandData temp_command_data;
00137 
00138    reader->beginAttribute(gadget::tokens::SampleBufferLenAttrib);
00139       unsigned numVectors = reader->readUint16();
00140    reader->endAttribute();
00141 
00142    mCommandSamples.lock();
00143    for ( unsigned i = 0; i < numVectors; ++i )
00144    {
00145       reader->beginTag(gadget::tokens::BufferSampleTag);
00146       reader->beginAttribute(gadget::tokens::BufferSampleLenAttrib);
00147          numCommandDatas = reader->readUint16();
00148       reader->endAttribute();
00149 
00150       dataSample.clear();
00151       for ( unsigned j = 0; j < numCommandDatas; ++j )
00152       {
00153          reader->beginTag(gadget::tokens::DigitalValue);
00154          reader->beginAttribute(gadget::tokens::TimeStamp);
00155             timeStamp = reader->readUint64();    // read Time Stamp vpr::Uint64
00156          reader->endAttribute();
00157          value = reader->readUint32();           // read Command Data(int)
00158          reader->endTag();
00159 
00160          temp_command_data.setDigital(value);
00161          temp_command_data.setTime(vpr::Interval(timeStamp + delta,vpr::Interval::Usec));
00162          dataSample.push_back(temp_command_data);
00163       }
00164       mCommandSamples.addSample(dataSample);
00165       reader->endTag();
00166    }
00167    mCommandSamples.unlock();
00168    mCommandSamples.swapBuffers();
00169 
00170    reader->endTag();
00171 
00172    return vpr::ReturnStatus::Succeed;
00173 }

void gadget::Command::operator= ( const gadget::Command  )  [inline, protected]

Definition at line 156 of file Command.h.

00156 {;}


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:44:51 2007 for Gadgeteer by  doxygen 1.5.1