packet_finder.hpp
Go to the documentation of this file.
00001 
00014 /*****************************************************************************
00015  ** Ifdefs
00016  *****************************************************************************/
00017 
00018 #ifndef PACKET_FINDER_HPP_
00019 #define PACKET_FINDER_HPP_
00020 
00021 /*****************************************************************************
00022  ** Includes
00023  *****************************************************************************/
00024 
00025 #include <iomanip>
00026 #include <ecl/containers.hpp>
00027 #include <ecl/sigslots.hpp>
00028 #include "../macros.hpp"
00029 
00030 /*****************************************************************************
00031  ** Namespaces
00032  *****************************************************************************/
00033 
00034 namespace kobuki
00035 {
00036 
00037 /*****************************************************************************
00038  ** Using
00039  *****************************************************************************/
00040 
00041 /*****************************************************************************
00042  ** Interface
00043  *****************************************************************************/
00072 class kobuki_PUBLIC PacketFinderBase
00073 {
00074 public:
00075   typedef ecl::PushAndPop<unsigned char> BufferType;
00076 
00077   enum packetFinderState
00078   {
00079     clearBuffer = 0,
00080     waitingForStx,
00081     waitingForPayloadSize,
00082     waitingForPayloadToEtx,
00083     waitingForEtx,
00084   };
00085   enum packetFinderState state;
00086 protected:
00087 
00088   unsigned int size_stx;
00089   unsigned int size_etx;
00090   unsigned int size_length_field;
00091   bool variable_size_payload;
00092   unsigned int size_max_payload;
00093   unsigned int size_payload;
00094   unsigned int size_checksum_field;
00095 
00096   BufferType STX;
00097   BufferType ETX;
00098   BufferType buffer;
00099 
00100   bool verbose;
00101 
00102   ecl::Signal<const std::string&> sig_warn, sig_error;
00103 
00104 public:
00105   PacketFinderBase(); 
00107   virtual ~PacketFinderBase() {};
00108 
00109   void configure(const std::string &sigslots_namespace,
00110                  const BufferType & putStx, const BufferType & putEtx, unsigned int sizeLengthField,
00111                  unsigned int sizeMaxPayload, unsigned int sizeChecksumField, bool variableSizePayload);
00112   void clear();
00113   void enableVerbose();
00114   virtual bool update(const unsigned char * incoming, unsigned int numberOfIncoming);
00115   virtual bool checkSum();
00116   unsigned int numberOfDataToRead();
00117   void getBuffer(BufferType & bufferRef);
00118   void getPayload(BufferType & bufferRef);
00119 
00120 protected:
00121   bool WaitForStx(const unsigned char datum);
00122   bool waitForPayloadSize(const unsigned char * incoming, unsigned int numberOfIncoming);
00123   bool waitForEtx(const unsigned char incoming, bool & foundPacket);
00124   bool waitForPayloadAndEtx(const unsigned char * incoming, unsigned int numberOfIncoming, bool & foundPacket);
00125 };
00126 
00127 }
00128 ;
00129 // namespace kobuki
00130 
00131 #endif /* PACKET_FINDER_HPP_ */


kobuki_driver
Author(s): Daniel Stonier , Younghun Ju , Jorge Santos Simon
autogenerated on Thu Aug 27 2015 13:43:58