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