Branch data Line data Source code
1 : : // Copyright 2020 Silexica GmbH, Lichtstr. 25, Cologne, Germany. All rights reserved. 2 : : // 3 : : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : : // you may not use this file except in compliance with the License. 5 : : // You may obtain a copy of the License at 6 : : // 7 : : // http://www.apache.org/licenses/LICENSE-2.0 8 : : // 9 : : // Unless required by applicable law or agreed to in writing, software 10 : : // distributed under the License is distributed on an "AS IS" BASIS, 11 : : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : : // See the License for the specific language governing permissions and 13 : : // limitations under the License. 14 : : // 15 : : // Co-developed by Tier IV, Inc. and Apex.AI, Inc. 16 : : 17 : : 18 : : #ifndef LIDAR_INTEGRATION__UDP_SENDER_HPP_ 19 : : #define LIDAR_INTEGRATION__UDP_SENDER_HPP_ 20 : : 21 : : #include <lidar_integration/visibility_control.hpp> 22 : : #include <common/types.hpp> 23 : : 24 : : #include <stdint.h> 25 : : #include <netinet/in.h> 26 : : 27 : : using autoware::common::types::bool8_t; 28 : : using autoware::common::types::char8_t; 29 : : 30 : : class LIDAR_INTEGRATION_PUBLIC UdpSenderBase 31 : : { 32 : : public: 33 : : UdpSenderBase( 34 : : const char8_t * const ip, const uint16_t port, 35 : : const bool8_t ipv6 = false); 36 : : 37 : : protected: 38 : : void send(const void * const data, const size_t length) const; 39 : : 40 : : private: 41 : : int m_socket; 42 : : struct sockaddr_in6 m_addr; 43 : : }; 44 : : 45 : : template<typename Packet> 46 : : class UdpSender : public UdpSenderBase 47 : : { 48 : : public: 49 : 19 : using UdpSenderBase::UdpSenderBase; 50 : : 51 : : public: 52 : : void send(Packet const & pkt) const 53 : : { 54 : 53082 : UdpSenderBase::send(static_cast<const void * const>(&pkt), sizeof(pkt)); 55 : 53082 : } 56 : : }; 57 : : 58 : : #endif // LIDAR_INTEGRATION__UDP_SENDER_HPP_