RF24Ethernet - TCP/IP over RF24Network v1.6.17
TMRh20 - Pushing the practical limits of RF24 modules
Loading...
Searching...
No Matches
RF24Server.cpp
Go to the documentation of this file.
1/*
2 RF24Server.cpp - Arduino implementation of a uIP wrapper class.
3 Copyright (c) 2014 tmrh20@gmail.com, github.com/TMRh20
4 Copyright (c) 2013 Norbert Truchsess <norbert.truchsess@t-online.de>
5 All rights reserved.
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20#include "RF24Ethernet.h"
21#include "RF24Server.h"
22
23extern "C" {
24//#include "uip-conf.h"
25}
26
27/*************************************************************/
28
29RF24Server::RF24Server(uint16_t port) : _port(htons(port))
30{
31}
32
33/*************************************************************/
34
36{
37 Ethernet.tick();
38 for (uip_userdata_t* data = &RF24Client::all_data[0]; data < &RF24Client::all_data[UIP_CONNS]; data++)
39 {
40 if (data->packets_in != 0 && (((data->state & UIP_CLIENT_CONNECTED) && uip_conns[data->state & UIP_CLIENT_SOCKETS].lport == _port) || ((data->state & UIP_CLIENT_REMOTECLOSED) && ((uip_userdata_closed_t*)data)->lport == _port)))
41 {
42 return RF24Client(data);
43 }
44 }
45 return RF24Client();
46}
47
48/*************************************************************/
49
51{
52 uip_listen(_port);
53 RF24Ethernet.tick();
54}
55
56/*************************************************************/
57#if defined(ESP32)
58void RF24Server::begin(uint16_t port)
59{
60 _port = port;
61 begin();
62}
63#endif
64
65/*************************************************************/
66
67size_t RF24Server::write(uint8_t c)
68{
69 return write(&c, 1);
70}
71
72/*************************************************************/
73
74size_t RF24Server::write(const uint8_t* buf, size_t size)
75{
76 size_t ret = 0;
77 for (uip_userdata_t* data = &RF24Client::all_data[0]; data < &RF24Client::all_data[UIP_CONNS]; data++)
78 {
79 if ((data->state & UIP_CLIENT_CONNECTED) && uip_conns[data->state & UIP_CLIENT_SOCKETS].lport == _port)
80 ret += RF24Client::_write(data, buf, size);
81 }
82 return ret;
83}
84
85/*************************************************************/
86
87void RF24Server::setTimeout(uint32_t timeout)
88{
89#if UIP_CONNECTION_TIMEOUT > 0
90 for (uint8_t i = 0; i < UIP_CONNS; i++) {
91 uip_userdata_t* data = &RF24Client::all_data[i];
92 if (data) {
93 data->connectTimeout = timeout;
94 }
95 }
96#endif
97}
#define UIP_CLIENT_SOCKETS
Definition RF24Client.h:36
#define UIP_CLIENT_REMOTECLOSED
Definition RF24Client.h:33
#define UIP_CLIENT_CONNECTED
Definition RF24Client.h:31
RF24EthernetClass RF24Ethernet
static uip_userdata_t all_data[UIP_CONNS]
Definition RF24Client.h:162
size_t write(uint8_t)
void begin()
RF24Server(uint16_t)
RF24Client available()
void setTimeout(uint32_t timeout)
#define Ethernet