S Morita / mbed-mros2

Dependents:   mbed-os-example-mros2 example-mbed-mros2-sub-pose example-mbed-mros2-pub-twist example-mbed-mros2-mturtle-teleop

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers UdpDriver.h Source File

UdpDriver.h

00001 /*
00002 The MIT License
00003 Copyright (c) 2019 Lehrstuhl Informatik 11 - RWTH Aachen University
00004 Permission is hereby granted, free of charge, to any person obtaining a copy
00005 of this software and associated documentation files (the "Software"), to deal
00006 in the Software without restriction, including without limitation the rights
00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008 copies of the Software, and to permit persons to whom the Software is
00009 furnished to do so, subject to the following conditions:
00010 The above copyright notice and this permission notice shall be included in
00011 all copies or substantial portions of the Software.
00012 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00013 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00014 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00015 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00016 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00017 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00018 THE SOFTWARE
00019 
00020 This file is part of embeddedRTPS.
00021 
00022 Author: i11 - Embedded Software, RWTH Aachen University
00023 */
00024 
00025 #ifndef RTPS_UDPDRIVER_H
00026 #define RTPS_UDPDRIVER_H
00027 
00028 #include "UdpConnection.h"
00029 #include "lwip/udp.h"
00030 #include "rtps/common/types.h"
00031 #include "rtps/communication/PacketInfo.h"
00032 #include "rtps/config.h"
00033 #include "rtps/storages/PBufWrapper.h"
00034 
00035 #include <array>
00036 
00037 namespace rtps {
00038 
00039 class UdpDriver {
00040 
00041 public:
00042   typedef void (*udpRxFunc_fp)(void *arg, udp_pcb *pcb, pbuf *p,
00043                                const ip_addr_t *addr, Ip4Port_t port);
00044 
00045   UdpDriver(udpRxFunc_fp callback, void *args);
00046 
00047   const rtps::UdpConnection *createUdpConnection(Ip4Port_t receivePort);
00048   bool joinMultiCastGroup(ip4_addr_t addr) const;
00049   void sendPacket(PacketInfo &info);
00050 
00051   static bool isSameSubnet(ip4_addr_t addr);
00052 
00053 private:
00054   std::array<UdpConnection, Config::MAX_NUM_UDP_CONNECTIONS> m_conns;
00055   std::size_t m_numConns = 0;
00056   udpRxFunc_fp m_rxCallback = nullptr;
00057   void *m_callbackArgs = nullptr;
00058 
00059   bool sendPacket(const UdpConnection &conn, ip4_addr_t &destAddr,
00060                   Ip4Port_t destPort, pbuf &buffer);
00061 };
00062 } // namespace rtps
00063 
00064 #endif // RTPS_UDPDRIVER_H