packet_finder.hpp
Go to the documentation of this file.
1 
14 /*****************************************************************************
15  ** Ifdefs
16  *****************************************************************************/
17 
18 #ifndef PACKET_FINDER_HPP_
19 #define PACKET_FINDER_HPP_
20 
21 /*****************************************************************************
22  ** Includes
23  *****************************************************************************/
24 
25 #include <iomanip>
26 #include <ecl/containers.hpp>
27 #include <ecl/sigslots.hpp>
28 #include "../macros.hpp"
29 
30 /*****************************************************************************
31  ** Namespaces
32  *****************************************************************************/
33 
34 namespace kobuki
35 {
36 
37 /*****************************************************************************
38  ** Using
39  *****************************************************************************/
40 
41 /*****************************************************************************
42  ** Interface
43  *****************************************************************************/
72 class kobuki_PUBLIC PacketFinderBase
73 {
74 public:
75  typedef ecl::PushAndPop<unsigned char> BufferType;
76 
77  enum packetFinderState
78  {
79  clearBuffer = 0,
80  waitingForStx,
81  waitingForPayloadSize,
82  waitingForPayloadToEtx,
83  waitingForEtx,
84  };
85  enum packetFinderState state;
86 protected:
87 
88  unsigned int size_stx;
89  unsigned int size_etx;
90  unsigned int size_length_field;
91  bool variable_size_payload;
92  unsigned int size_max_payload;
93  unsigned int size_payload;
94  unsigned int size_checksum_field;
95 
98  BufferType buffer;
99 
100  bool verbose;
101 
102  ecl::Signal<const std::string&> sig_warn, sig_error;
103 
104 public:
107  virtual ~PacketFinderBase() {};
108 
109  void configure(const std::string &sigslots_namespace,
110  const BufferType & putStx, const BufferType & putEtx, unsigned int sizeLengthField,
111  unsigned int sizeMaxPayload, unsigned int sizeChecksumField, bool variableSizePayload);
112  void clear();
113  void enableVerbose();
114  virtual bool update(const unsigned char * incoming, unsigned int numberOfIncoming);
115  virtual bool checkSum();
116  unsigned int numberOfDataToRead();
117  void getBuffer(BufferType & bufferRef);
118  void getPayload(BufferType & bufferRef);
119 
120 protected:
121  bool WaitForStx(const unsigned char datum);
122  bool waitForPayloadSize(const unsigned char * incoming, unsigned int numberOfIncoming);
123  bool waitForEtx(const unsigned char incoming, bool & foundPacket);
124  bool waitForPayloadAndEtx(const unsigned char * incoming, unsigned int numberOfIncoming, bool & foundPacket);
125 };
126 
127 }
128 ;
129 // namespace kobuki
130 
131 #endif /* PACKET_FINDER_HPP_ */
kobuki
Definition: command.hpp:31
sigslots.hpp
kobuki::PacketFinderBase
Provides simple packet finder which may be consist of stx, etx, payload, ...
Definition: packet_finder.hpp:78
ecl::Signal< const std::string & >
kobuki_PUBLIC
#define kobuki_PUBLIC
Definition: macros.hpp:39
ecl::PushAndPop< unsigned char >
containers.hpp


kobuki_driver
Author(s): Daniel Stonier , Younghun Ju , Jorge Santos Simon
autogenerated on Wed Mar 2 2022 00:26:14