Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00029
00030 #ifndef DRIVER_SVH_SVH_RECEIVE_THREAD_H_INCLUDED
00031 #define DRIVER_SVH_SVH_RECEIVE_THREAD_H_INCLUDED
00032
00033 #include <icl_core/TimeSpan.h>
00034 #include <icl_core_thread/PeriodicThread.h>
00035 #include <icl_comm_serial/Serial.h>
00036 #include <icl_comm/ByteOrderConversion.h>
00037
00038 #include <driver_svh/Logging.h>
00039 #include <driver_svh/SVHSerialPacket.h>
00040
00041 #include <boost/function.hpp>
00042 #include <boost/shared_ptr.hpp>
00043
00044 using icl_core::TimeSpan;
00045 using icl_core::thread::PeriodicThread;
00046 using icl_comm::serial::Serial;
00047
00048 namespace driver_svh {
00049
00051 typedef boost::function<void (const SVHSerialPacket& packet, unsigned int packet_count)> ReceivedPacketCallback;
00052
00056 class SVHReceiveThread : public PeriodicThread
00057 {
00058 public:
00066 SVHReceiveThread(const TimeSpan& period, boost::shared_ptr<Serial> device,
00067 ReceivedPacketCallback const & received_callback);
00068
00070 virtual ~SVHReceiveThread() {}
00071
00073 virtual void run();
00074
00076 unsigned int receivedPacketCount() { return m_packets_received; }
00077
00081 void resetReceivedPackageCount() { m_packets_received = 0; }
00082
00083 private:
00084
00086 boost::shared_ptr<Serial> m_serial_device;
00087
00089 enum
00090 {
00091 eRS_HEADER1,
00092 eRS_HEADER2,
00093 eRS_INDEX,
00094 eRS_ADDRESS,
00095 eRS_LENGTH1,
00096 eRS_LENGTH2,
00097 eRS_DATA,
00098 eRS_CHECKSUM1,
00099 eRS_CHECKSUM2
00100 } typedef tState;
00101
00103 tState m_received_state;
00104
00106 uint16_t m_length;
00108 uint8_t m_checksum1;
00109 uint8_t m_checksum2;
00110
00112 std::vector<uint8_t> m_data;
00113
00115 icl_comm::ArrayBuilder m_ab;
00116
00118 unsigned int m_packets_received;
00120 unsigned int m_skipped_bytes;
00121
00123 bool receiveData();
00124
00126 ReceivedPacketCallback m_received_callback;
00127
00128 };
00129
00130 }
00131
00132 #endif