SVHReceiveThread.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of the SCHUNK SVH Driver suite.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2014 SCHUNK Mobile Greifsysteme GmbH, Lauffen/Neckar Germany
00012 // © Copyright 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00013 //
00014 // -- END LICENSE BLOCK ------------------------------------------------
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_LENGTH,
00096     eRS_DATA,
00097     eRS_CHECKSUM,
00098     eRS_COMPLETE
00099   } typedef tState;
00100 
00102   tState m_received_state;
00103 
00105   uint16_t m_length;
00106 
00108   std::vector<uint8_t> m_data;
00109 
00111   icl_comm::ArrayBuilder m_ab;
00112 
00114   unsigned int m_packets_received;
00115 
00117   bool receiveData();
00118 
00120   ReceivedPacketCallback m_received_callback;
00121 
00122 };
00123 
00124 }
00125 
00126 #endif


schunk_svh_driver
Author(s): Georg Heppner
autogenerated on Fri Aug 28 2015 12:59:19