rplidar_driver_TCP.h
Go to the documentation of this file.
1 /*
2  * RPLIDAR SDK
3  *
4  * Copyright (c) 2009 - 2014 RoboPeak Team
5  * http://www.robopeak.com
6  * Copyright (c) 2014 - 2019 Shanghai Slamtec Co., Ltd.
7  * http://www.slamtec.com
8  *
9  */
10 /*
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright notice,
15  * this list of conditions and the following disclaimer.
16  *
17  * 2. Redistributions in binary form must reproduce the above copyright notice,
18  * this list of conditions and the following disclaimer in the documentation
19  * and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34 
35 #pragma once
36 
37 namespace rp { namespace standalone{ namespace rplidar {
38 
40 {
41 public:
43  TCPChannelDevice():_binded_socket(rp::net::StreamSocket::CreateSocket()){}
44 
45  bool bind(const char * ipStr, uint32_t port)
46  {
47  rp::net::SocketAddress socket(ipStr, port);
48  return IS_OK(_binded_socket->connect(socket));
49  }
50  void close()
51  {
52  _binded_socket->dispose();
53  _binded_socket = NULL;
54  }
55  bool waitfordata(size_t data_count,_u32 timeout = -1, size_t * returned_size = NULL)
56  {
57  if(returned_size)
58  *returned_size = data_count;
59  return (_binded_socket->waitforData(timeout) == RESULT_OK);
60  }
61  int senddata(const _u8 * data, size_t size)
62  {
63  return _binded_socket->send(data, size) ;
64  }
65  int recvdata(unsigned char * data, size_t size)
66  {
67  size_t lenRec = 0;
68  _binded_socket->recv(data, size, lenRec);
69  return lenRec;
70  }
71 };
72 
73 
75 {
76 public:
77 
79  virtual ~RPlidarDriverTCP();
80  virtual u_result connect(const char * ipStr, _u32 port, _u32 flag = 0);
81  virtual void disconnect();
82 };
83 
84 
85 }}}
#define IS_OK(x)
Definition: rptypes.h:113
_u8 flag
Definition: rplidar_cmd.h:2
#define RESULT_OK
Definition: rptypes.h:102
virtual void dispose()=0
_u8 size
bool bind(const char *ipStr, uint32_t port)
int recvdata(unsigned char *data, size_t size)
uint8_t _u8
Definition: rptypes.h:63
bool waitfordata(size_t data_count, _u32 timeout=-1, size_t *returned_size=NULL)
int senddata(const _u8 *data, size_t size)
virtual u_result send(const void *buffer, size_t len)=0
virtual u_result waitforData(_u32 timeout=DEFAULT_SOCKET_TIMEOUT)=0
virtual u_result recv(void *buf, size_t len, size_t &recv_len)=0
uint32_t _u32
Definition: rptypes.h:69
virtual u_result connect(const SocketAddress &pairAddress)=0
_u8 data[0]
uint32_t u_result
Definition: rptypes.h:100


rplidar_ros
Author(s):
autogenerated on Wed Jan 1 2020 04:01:40