sick_scan_common_tcp.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013, Freiburg University
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Osnabrück University nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Created on: 15.11.2013
30  *
31  * Authors:
32  * Christian Dornhege <c.dornhege@googlemail.com>
33  */
34 
35 #ifndef SICK_TIM3XX_COMMON_TCP_H
36 #define SICK_TIM3XX_COMMON_TCP_H
37 
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <boost/asio.hpp>
42 
43 #undef NOMINMAX // to get rid off warning C4005: "NOMINMAX": Makro-Neudefinition
44 
45 #include "sick_scan_common.h"
46 #include "sick_generic_parser.h"
47 #include "template_queue.h"
48 namespace sick_scan
49 {
50 /* class prepared for optimized time stamping */
51 
53 {
54 public:
55  DatagramWithTimeStamp(ros::Time timeStamp_, std::vector<unsigned char> datagram_)
56  {
57  timeStamp = timeStamp_;
58  datagram = datagram_;
59  }
60 // private:
62  std::vector<unsigned char> datagram;
63 };
64 
65 
67  {
68 public:
69  static void disconnectFunctionS(void *obj);
70 
71  SickScanCommonTcp(const std::string &hostname, const std::string &port, int &timelimit, SickGenericParser *parser, char cola_dialect_id);
72 
73  virtual ~SickScanCommonTcp();
74 
75  static void readCallbackFunctionS(void *obj, UINT8 *buffer, UINT32 &numOfBytes);
76 
77  void readCallbackFunction(UINT8 *buffer, UINT32 &numOfBytes);
78 
79  void setReplyMode(int _mode);
80 
81  int getReplyMode();
82 
83  void setEmulSensor(bool _emulFlag);
84 
85  bool getEmulSensor();
86 
87  bool stopScanData();
88 
89  int numberOfDatagramInInputFifo();
90  SopasEventMessage findFrameInReceiveBuffer();
91  void processFrame(ros::Time timeStamp, SopasEventMessage& frame);
92  // Queue<std::vector<unsigned char> > recvQueue;
96  UINT8 m_packetBuffer[480000];
102  protected:
103  void disconnectFunction();
104 
105  void readCallbackFunctionOld(UINT8* buffer, UINT32& numOfBytes);
106  virtual int init_device();
107 
108  virtual int close_device();
109 
111  virtual int sendSOPASCommand(const char *request, std::vector<unsigned char> *reply, int cmdLen);
112 
114 
121  virtual int
122  get_datagram(ros::Time &recvTimeStamp, unsigned char *receiveBuffer, int bufferSize, int *actual_length,
123  bool isBinaryProtocol, int *numberOfRemainingFifoEntries);
124 
125  // Helpers for boost asio
126  int readWithTimeout(size_t timeout_ms, char *buffer, int buffer_size, int *bytes_read = 0,
127  bool *exception_occured = 0, bool isBinary = false);
128 
129  void handleRead(boost::system::error_code error, size_t bytes_transfered);
130 
131  void checkDeadline();
132 
133  private:
134 
135 
136 
137  // Response buffer
139  UINT8 m_responseBuffer[1024];
141 
142  // Receive buffer
144  UINT8 m_receiveBuffer[480000];
145 
148 
149  boost::asio::io_service io_service_;
150  boost::asio::ip::tcp::socket socket_;
151  boost::asio::deadline_timer deadline_;
152  boost::asio::streambuf input_buffer_;
153  boost::system::error_code ec_;
155 
156  std::string hostname_;
157  std::string port_;
160 };
161 
162 
163 } /* namespace sick_scan */
164 #endif /* SICK_TIM3XX_COMMON_TCP_H */
165 
boost::asio::io_service io_service_
boost::asio::ip::tcp::socket socket_
DatagramWithTimeStamp(ros::Time timeStamp_, std::vector< unsigned char > datagram_)
uint32_t UINT32
Definition: Mutex.hpp:15
Queue< DatagramWithTimeStamp > recvQueue
std::vector< unsigned char > datagram
boost::asio::streambuf input_buffer_
boost::asio::deadline_timer deadline_
UINT32 m_numberOfBytesInReceiveBuffer
Number of bytes in buffer.
boost::system::error_code ec_
UINT32 m_numberOfBytesInResponseBuffer
Number of bytes in buffer.
Class that represents a message that was sent by a sensor. (Event message)
parser
Mutex m_receiveDataMutex
Access mutex for buffer.
uint8_t UINT8


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Tue Jul 9 2019 04:55:32