psen_scan_udp_interface.h
Go to the documentation of this file.
1 // Copyright (c) 2019-2020 Pilz GmbH & Co. KG
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU Lesser General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public License
14 // along with this program. If not, see <https://www.gnu.org/licenses/>.
15 
16 #ifndef PSEN_SCAN_UDP_INTERFACE_H
17 #define PSEN_SCAN_UDP_INTERFACE_H
18 
19 #include <chrono>
20 
21 #include <boost/asio.hpp>
22 #include <boost/bind.hpp>
23 
25 #include "psen_scan/scanner_data.h"
26 
27 namespace psen_scan
28 {
34 {
35 public:
36  PSENscanUDPInterface(const std::string& scanner_ip,
37  const uint32_t& host_udp_port,
38  const unsigned short scanner_port_write = PSEN_SCAN_PORT_WRITE,
39  const unsigned short scanner_port_read = PSEN_SCAN_PORT_READ);
40 
41  virtual ~PSENscanUDPInterface();
42 
43 public:
44  void open() override;
45  void close() override;
46 
47  void write(const boost::asio::mutable_buffers_1& buffer) override;
48  std::size_t read(boost::asio::mutable_buffers_1& buffer, const std::chrono::steady_clock::duration timeout) override;
49 
50 private:
51  bool isUdpMsgAvailable() const;
52 
53 private:
54  boost::asio::io_service io_service_;
55  boost::asio::ip::udp::socket socket_write_;
56  boost::asio::ip::udp::socket socket_read_;
57  boost::asio::ip::udp::endpoint udp_write_endpoint_;
58  boost::asio::ip::udp::endpoint udp_read_endpoint_;
59 };
60 
61 } // namespace psen_scan
62 
63 #endif // PSEN_SCAN_UDP_INTERFACE_H
PSENscanUDPInterface(const std::string &scanner_ip, const uint32_t &host_udp_port, const unsigned short scanner_port_write=PSEN_SCAN_PORT_WRITE, const unsigned short scanner_port_read=PSEN_SCAN_PORT_READ)
Abstract base class for the communication interface with the PSENscan scanner.
unsigned short const PSEN_SCAN_PORT_WRITE
Definition: scanner_data.h:52
std::size_t read(boost::asio::mutable_buffers_1 &buffer, const std::chrono::steady_clock::duration timeout) override
Receive data from the scanner.
boost::asio::ip::udp::socket socket_write_
boost::asio::ip::udp::endpoint udp_write_endpoint_
boost::asio::ip::udp::endpoint udp_read_endpoint_
void close() override
Closes the connection to the scanner device.
unsigned short const PSEN_SCAN_PORT_READ
Definition: scanner_data.h:53
boost::asio::ip::udp::socket socket_read_
Class for the UDP communication with the scanner.
void open() override
Opens the connection to the scanner device.
void write(const boost::asio::mutable_buffers_1 &buffer) override
Sends data to the scanner device.


psen_scan
Author(s):
autogenerated on Mon Feb 28 2022 23:16:20