Developer World
Spresense Arduino Library v3.3.0-b2e6327
LTEUDP.h
Go to the documentation of this file.
1/*
2 * LTEUDP.h - LTEUDP include file for Spresense Arduino
3 * Copyright 2019 Sony Semiconductor Solutions Corporation
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
32#ifndef _LTE_UDP_H_
33#define _LTE_UDP_H_
34
35#ifdef SUBCORE
36#error "LTEUDP library is NOT supported by SubCore."
37#endif
38
46/****************************************************************************
47 * Included Files
48 ****************************************************************************/
49
50#include <Udp.h>
51
52class IPAddress;
53
54/****************************************************************************
55 * class declaration
56 ****************************************************************************/
57
66{
67public:
69 LTEUDPBuffer(size_t size);
71
72 size_t write(uint8_t val);
73 size_t write(const uint8_t *buffer, size_t size);
74 int available();
75 int read();
76 int read(char* buffer, size_t size);
77 int peek();
78
79private:
80 size_t _maxSize;
81 char *_buf;
82 int _begin;
83 int _end;
84};
85
92class LTEUDP : public UDP
93{
94public:
99
104
119 uint8_t begin(uint16_t port);
120
128 void stop();
129
146 int beginPacket(IPAddress ip, uint16_t port);
147
163 int beginPacket(const char *host, uint16_t port);
164
177
192 size_t write(uint8_t val);
193
210 size_t write(const uint8_t *buffer, size_t size);
211
224
237
249 int read();
250
267 int read(unsigned char* buffer, size_t len);
268
285 int read(char* buffer, size_t len);
286
298 int peek();
299
307 void flush();
308
320 IPAddress remoteIP();
321
333 uint16_t remotePort();
334
346 int setTimeout(uint32_t milliseconds);
347
348private:
349 int _fd;
350 uint8_t *_wbuf;
351 size_t _wbufSize;
352 LTEUDPBuffer *_rbuf;
353 IPAddress _remoteIp;
354 uint16_t _remotePort;
355};
356
360#endif
[en] UDP packet memory management class. This is internal use class. [ja] UDPパケットメモリ管理用クラス。内部利用Clas...
Definition: LTEUDP.h:66
[en] This class can send and receive UDP packets to a specific Internet IP address and port....
Definition: LTEUDP.h:93
void stop()
Finish with the UDP socket.
int beginPacket(IPAddress ip, uint16_t port)
Start building up a packet to send to the remote host specific in ip and port.
int endPacket()
Finish off this packet and send it.
LTEUDP()
Construct LTEUDP instance.
int beginPacket(const char *host, uint16_t port)
Start building up a packet to send to the remote host specific in host and port.
int read(unsigned char *buffer, size_t len)
Read up to len bytes from the current packet and place them into buffer.
void flush()
Discards any bytes that have been written to the packet.
size_t write(uint8_t val)
Write a single byte into the packet.
uint16_t remotePort()
Return the port of the host who sent the current incoming packet.
int available()
Returns number of bytes remaining in the current packet.
size_t write(const uint8_t *buffer, size_t size)
Write series of bytes from buffer into the packet.
int peek()
Return the next byte from the current packet without removing it.
~LTEUDP()
Destruct LTEUDP instance.
int parsePacket()
Start processing the next available incoming packet.
IPAddress remoteIP()
Return the IP address of the host who sent the current incoming packet.
int read()
Read a single byte from the current packet.
int setTimeout(uint32_t milliseconds)
Set the timeout when send or receive.
uint8_t begin(uint16_t port)
Initialize, start listening on specified port.
int read(char *buffer, size_t len)
Read up to len characters from the current packet and place them into buffer.