Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef SICK_TIM3XX_COMMON_TCP_H
00036 #define SICK_TIM3XX_COMMON_TCP_H
00037
00038 #include <stdio.h>
00039 #include <stdlib.h>
00040 #include <string.h>
00041 #include <boost/asio.hpp>
00042
00043 #undef NOMINMAX // to get rid off warning C4005: "NOMINMAX": Makro-Neudefinition
00044
00045 #include "sick_scan_common.h"
00046 #include "sick_generic_parser.h"
00047 #include "template_queue.h"
00048 namespace sick_scan
00049 {
00050
00051
00052 class DatagramWithTimeStamp
00053 {
00054 public:
00055 DatagramWithTimeStamp(ros::Time timeStamp_, std::vector<unsigned char> datagram_)
00056 {
00057 timeStamp = timeStamp_;
00058 datagram = datagram_;
00059 }
00060
00061 ros::Time timeStamp;
00062 std::vector<unsigned char> datagram;
00063 };
00064
00065
00066 class SickScanCommonTcp : public SickScanCommon
00067 {
00068 public:
00069 static void disconnectFunctionS(void *obj);
00070
00071 SickScanCommonTcp(const std::string &hostname, const std::string &port, int &timelimit, SickGenericParser *parser, char cola_dialect_id);
00072
00073 virtual ~SickScanCommonTcp();
00074
00075 static void readCallbackFunctionS(void *obj, UINT8 *buffer, UINT32 &numOfBytes);
00076
00077 void readCallbackFunction(UINT8 *buffer, UINT32 &numOfBytes);
00078
00079 void setReplyMode(int _mode);
00080
00081 int getReplyMode();
00082
00083 void setEmulSensor(bool _emulFlag);
00084
00085 bool getEmulSensor();
00086
00087 bool stopScanData();
00088
00089 int numberOfDatagramInInputFifo();
00090 SopasEventMessage findFrameInReceiveBuffer();
00091 void processFrame(ros::Time timeStamp, SopasEventMessage& frame);
00092
00093 Queue<DatagramWithTimeStamp> recvQueue;
00094 UINT32 m_alreadyReceivedBytes;
00095 UINT32 m_lastPacketSize;
00096 UINT8 m_packetBuffer[480000];
00102 protected:
00103 void disconnectFunction();
00104
00105 void readCallbackFunctionOld(UINT8* buffer, UINT32& numOfBytes);
00106 virtual int init_device();
00107
00108 virtual int close_device();
00109
00111 virtual int sendSOPASCommand(const char *request, std::vector<unsigned char> *reply, int cmdLen);
00112
00114
00121 virtual int
00122 get_datagram(ros::Time &recvTimeStamp, unsigned char *receiveBuffer, int bufferSize, int *actual_length,
00123 bool isBinaryProtocol, int *numberOfRemainingFifoEntries);
00124
00125
00126 int readWithTimeout(size_t timeout_ms, char *buffer, int buffer_size, int *bytes_read = 0,
00127 bool *exception_occured = 0, bool isBinary = false);
00128
00129 void handleRead(boost::system::error_code error, size_t bytes_transfered);
00130
00131 void checkDeadline();
00132
00133 private:
00134
00135
00136
00137
00138 UINT32 m_numberOfBytesInResponseBuffer;
00139 UINT8 m_responseBuffer[1024];
00140 Mutex m_receiveDataMutex;
00141
00142
00143 UINT32 m_numberOfBytesInReceiveBuffer;
00144 UINT8 m_receiveBuffer[480000];
00145
00146 bool m_beVerbose;
00147 bool m_emulSensor;
00148
00149 boost::asio::io_service io_service_;
00150 boost::asio::ip::tcp::socket socket_;
00151 boost::asio::deadline_timer deadline_;
00152 boost::asio::streambuf input_buffer_;
00153 boost::system::error_code ec_;
00154 size_t bytes_transfered_;
00155
00156 std::string hostname_;
00157 std::string port_;
00158 int timelimit_;
00159 int m_replyMode;
00160 };
00161
00162
00163 }
00164 #endif
00165