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_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


schunk_svh_driver
Author(s): Georg Heppner
autogenerated on Thu Jun 6 2019 18:29:08