1/* 2 Copyright (c) 2015 Arduino LLC. All right reserved. 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with this library; if not, write to the Free Software 16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17*/ 18 19#pragma once 20 21#include <Udp.h> 22#include"Bridge.h" 23 24class BridgeUDP :public UDP { 25 26public: 27BridgeUDP(BridgeClass &_b = Bridge); 28virtualuint8_tbegin(uint16_t); 29virtualvoidstop(); 30 31virtualintbeginPacket(IPAddress ip,uint16_t port); 32virtualintbeginPacket(const char*host,uint16_t port); 33virtualintbeginBroadcastPacket(uint16_t port); 34virtualintendPacket(); 35virtualsize_twrite(uint8_t d) {returnwrite(&d,1); } 36virtualsize_twrite(const uint8_t*buffer,size_t size); 37 38usingPrint::write; 39 40virtualintparsePacket(); 41/* return number of bytes available in the current packet, 42 will return zero if parsePacket hasn't been called yet */ 43virtualintavailable() {return avail; } 44virtualintread(); 45virtualintread(unsigned char* buffer,size_t len); 46virtualintread(char* buffer,size_t len) {returnread((unsigned char*)buffer, len); }; 47virtualintpeek(); 48virtualvoidflush() { avail =0; } 49 50virtual IPAddress remoteIP(); 51virtualuint16_tremotePort(); 52 53private: 54 BridgeClass &bridge; 55uint8_t handle; 56 boolean opened; 57 58private: 59voiddoBuffer(); 60uint16_t avail; 61uint8_t buffered; 62uint8_t readPos; 63static const int BUFFER_SIZE =64; 64uint8_t buffer[BUFFER_SIZE]; 65};