-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check in current code of RF24Ethernet
- Moving to new structure similar to the standard Arduino Ethernet library (Also using UIPEthernet as a reference) - Currently the library only directly supports incoming connections as a server, with little to no control beyond receiving data from the connection - Can now be used on multiple nodes, but the network address is hard-coded - RF24Network support for Arduino receiving fragmented multicast payloads allows actual ARP protocol handling, and integration with RF24Network (Using RF24 radio mac addresses at the routing/IP layer) - Need to add configuration for the MAC address as the radio address, etc, but wanted to check-in the code
- Loading branch information
Showing
38 changed files
with
9,540 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
|
||
extern "C" | ||
{ | ||
//#import "utility/uip-conf.h" | ||
#import "utility/uip.h" | ||
#import "utility/uip_arp.h" | ||
//#import "string.h" | ||
} | ||
|
||
#include "RF24Ethernet.h" | ||
#include "RF24Client.h" | ||
|
||
#define UIP_TCP_PHYH_LEN UIP_LLH_LEN+UIP_IPTCPH_LEN | ||
|
||
uip_userdata_t RF24Client::all_data[UIP_CONNS]; | ||
|
||
|
||
RF24Client::RF24Client(){} | ||
|
||
RF24Client::RF24Client(uint16_t dataSize): _dataLen(dataSize){} | ||
|
||
EthernetClient::EthernetClient(uint8_t sock) : _sock(sock) { | ||
} | ||
|
||
//RF24Client::RF24Client(uip_userdata_t* conn_data) : | ||
// data(conn_data) | ||
//{ | ||
//} | ||
|
||
uint8_t RF24Client::connected(){ | ||
return 1;//(uip_connected()); | ||
} | ||
|
||
int RF24Client::available(){ | ||
return RF24Ethernet.dataCnt; | ||
} | ||
|
||
|
||
|
||
int RF24Client::connect(IPAddress ip, uint16_t port) | ||
{ | ||
//stop(); | ||
/*uip_ipaddr_t ipaddr; | ||
uip_ip_addr(ipaddr, ip); | ||
struct uip_conn* conn = uip_connect(&ipaddr, htons(port)); | ||
if (conn) | ||
{ | ||
#if UIP_CONNECT_TIMEOUT > 0 | ||
int32_t timeout = millis() + 1000 * UIP_CONNECT_TIMEOUT; | ||
#endif | ||
while((conn->tcpstateflags & UIP_TS_MASK) != UIP_CLOSED) | ||
{ | ||
RF24EthernetClass::tick(); | ||
if ((conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) | ||
{ | ||
data = (uip_userdata_t*) conn->appstate; | ||
#ifdef UIPETHERNET_DEBUG_CLIENT | ||
Serial.print(F("connected, state: ")); | ||
Serial.print(data->state); | ||
Serial.print(F(", first packet in: ")); | ||
Serial.println(data->packets_in[0]); | ||
#endif | ||
return 1; | ||
} | ||
#if UIP_CONNECT_TIMEOUT > 0 | ||
if (((int32_t)(millis() - timeout)) > 0) | ||
{ | ||
conn->tcpstateflags = UIP_CLOSED; | ||
break; | ||
} | ||
#endif | ||
} | ||
}*/ | ||
return 1; | ||
} | ||
|
||
int | ||
RF24Client::connect(const char *host, uint16_t port) | ||
{ | ||
// Look up the host first | ||
int ret = 1; | ||
/*#if UIP_UDP | ||
DNSClient dns; | ||
IPAddress remote_addr; | ||
dns.begin(UIPEthernetClass::_dnsServerAddress); | ||
ret = dns.getHostByName(host, remote_addr); | ||
if (ret == 1) { | ||
return connect(remote_addr, port); | ||
} | ||
#endif*/ | ||
return ret; | ||
} | ||
|
||
void | ||
RF24Client::stop() | ||
{ | ||
/*if (data && data->state) | ||
{ | ||
#ifdef UIPETHERNET_DEBUG_CLIENT | ||
Serial.println(F("before stop(), with data")); | ||
_dumpAllData(); | ||
#endif | ||
//_flushBlocks(&data->packets_in[0]); | ||
if (data->state & UIP_CLIENT_REMOTECLOSED) | ||
{ | ||
data->state = 0; | ||
} | ||
else | ||
{ | ||
data->state |= UIP_CLIENT_CLOSE; | ||
} | ||
#ifdef UIPETHERNET_DEBUG_CLIENT | ||
Serial.println(F("after stop()")); | ||
_dumpAllData(); | ||
#endif | ||
} | ||
#ifdef UIPETHERNET_DEBUG_CLIENT | ||
else | ||
{ | ||
Serial.println(F("stop(), data: NULL")); | ||
} | ||
#endif | ||
data = NULL;*/ | ||
//RF24EthernetClass::tick(); | ||
} | ||
/* | ||
uint8_t RF24Client::connected() | ||
{ | ||
//return (data && (data->packets_in[0] != NOBLOCK || (data->state & UIP_CLIENT_CONNECTED))) ? 1 : 0; | ||
return 0; | ||
}*/ | ||
|
||
// the next function allows us to use the client returned by | ||
// EthernetServer::available() as the condition in an if-statement. | ||
bool RF24Client::operator==(const RF24Client& rhs) | ||
{ | ||
return RF24Ethernet.dataCnt;//uip_connected();//data && rhs.data && (data == rhs.data); | ||
//return 0; | ||
} | ||
|
||
RF24Client::operator bool() | ||
{ | ||
//RF24EthernetClass::tick(); | ||
return RF24Ethernet.dataCnt;//uip_connected();//data && (!(data->state & UIP_CLIENT_REMOTECLOSED) || data->packets_in[0] != NOBLOCK); | ||
} | ||
|
||
size_t RF24Client::write(uint8_t c) | ||
{ | ||
//return _write(data, &c, 1); | ||
return 0; | ||
} | ||
|
||
size_t RF24Client::write(const uint8_t *buf, size_t size) | ||
{ | ||
return 0;//_write(data, buf, size); | ||
} | ||
/* | ||
size_t RF24Client::_write(uip_userdata_t* u, const uint8_t *buf, size_t size) | ||
{ | ||
return 0; | ||
}*/ | ||
|
||
/* | ||
int RF24Client::available() | ||
{ | ||
if (*this) | ||
return _available(data); | ||
return 0; | ||
}*/ | ||
/* | ||
int RF24Client::_available(uip_userdata_t *u) | ||
{ | ||
int len = 0; | ||
// for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++) | ||
// { | ||
// len += Enc28J60Network::blockSize(u->packets_in[i]); | ||
// } | ||
// if(UIPEthernet.network.update() == EXTERNAL_DATA_TYPE){ | ||
// RF24NetworkFrame *frame = UIPEthernet.network.frag_ptr; | ||
// len = frame->message_size; | ||
// } | ||
// if(UIPEthernet.inPos > 0){ | ||
// len=UIPEthernet.inPos; | ||
// } | ||
//len=UIPEthernet.dataSize; | ||
//Serial.print("av len"); | ||
//Serial.println(len); | ||
return len; | ||
} | ||
*/ | ||
int RF24Client::read(uint8_t *buf, size_t size) | ||
{ | ||
} | ||
|
||
int | ||
RF24Client::read() | ||
{/* | ||
uint8_t c; | ||
if (read(&c,1) < 0) | ||
return -1; | ||
return c;*/ | ||
} | ||
|
||
int | ||
RF24Client::peek() | ||
{ | ||
if (*this) | ||
{ | ||
/*if (data->packets_in[0] != NOBLOCK) | ||
{ | ||
uint8_t c; | ||
Enc28J60Network::readPacket(data->packets_in[0],0,&c,1); | ||
return c; | ||
}*/ | ||
} | ||
return -1; | ||
} | ||
|
||
void RF24Client::flush() | ||
{ | ||
if (*this) | ||
{ | ||
//_flushBlocks(&data->packets_in[0]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
|
||
|
||
#ifndef RF24CLIENT_H | ||
#define RF24CLIENT_H | ||
|
||
|
||
#include "Print.h" | ||
#import "Client.h" | ||
|
||
#include "ethernet_comp.h" | ||
#include "Print.h" | ||
#import "Client.h" | ||
|
||
extern "C" { | ||
#import "utility/uip.h" | ||
} | ||
|
||
|
||
#define UIP_SOCKET_DATALEN UIP_TCP_MSS | ||
//#define UIP_SOCKET_NUMPACKETS UIP_RECEIVE_WINDOW/UIP_TCP_MSS+1 | ||
#ifndef UIP_SOCKET_NUMPACKETS | ||
#define UIP_SOCKET_NUMPACKETS 5 | ||
#endif | ||
|
||
#define UIP_CLIENT_CONNECTED 0x10 | ||
#define UIP_CLIENT_CLOSE 0x20 | ||
#define UIP_CLIENT_REMOTECLOSED 0x40 | ||
#define UIP_CLIENT_RESTART 0x80 | ||
#define UIP_CLIENT_STATEFLAGS (UIP_CLIENT_CONNECTED | UIP_CLIENT_CLOSE | UIP_CLIENT_REMOTECLOSED | UIP_CLIENT_RESTART) | ||
#define UIP_CLIENT_SOCKETS ~UIP_CLIENT_STATEFLAGS | ||
|
||
/* | ||
typedef struct { | ||
uint8_t state; | ||
memhandle packets_in[UIP_SOCKET_NUMPACKETS]; | ||
memhandle packets_out[UIP_SOCKET_NUMPACKETS]; | ||
memaddress out_pos; | ||
#if UIP_CLIENT_TIMER >= 0 | ||
unsigned long timer; | ||
#endif | ||
} uip_userdata_t; | ||
*/ | ||
typedef struct { | ||
uint8_t state; | ||
uint8_t packets_in[UIP_SOCKET_NUMPACKETS]; | ||
uint8_t packets_out[UIP_SOCKET_NUMPACKETS]; | ||
uint8_t out_pos; | ||
#if UIP_CLIENT_TIMER >= 0 | ||
unsigned long timer; | ||
#endif | ||
} uip_userdata_t; | ||
|
||
|
||
|
||
|
||
class RF24Client : public Client { | ||
|
||
public: | ||
RF24Client(); | ||
//RF24Client(int len); | ||
RF24Client(uint8_t sock); | ||
int connect(IPAddress ip, uint16_t port); | ||
int connect(const char *host, uint16_t port); | ||
int read(uint8_t *buf, size_t size); | ||
void stop(); | ||
|
||
|
||
uint8_t connected(); | ||
//int available(); | ||
|
||
size_t write(uint8_t); | ||
size_t write(const uint8_t *buf, size_t size); | ||
int available(); | ||
int read(); | ||
int peek(); | ||
void flush(); | ||
|
||
using Print::write; | ||
|
||
operator bool(); | ||
virtual bool operator==(const EthernetClient&); | ||
virtual bool operator!=(const EthernetClient& rhs) { return !this->operator==(rhs); }; | ||
|
||
|
||
private: | ||
uint8_t _sock; | ||
uint16_t _dataLen; | ||
|
||
//This is referenced by UIPServer.cpp in available() | ||
//RF24Client(serialip_state* conn_data); | ||
//RF24Client(uint8_t sock); | ||
RF24Client(size_t tmp); | ||
/*RF24Client(struct uip_conn *_conn); | ||
RF24Client(uip_userdata_t* conn_data);*/ | ||
|
||
uip_userdata_t* data; | ||
static uip_userdata_t all_data[UIP_CONNS]; | ||
|
||
friend class RF24EthernetClass; | ||
friend class RF24Server; | ||
|
||
friend void uipclient_appcall(void); | ||
|
||
}; | ||
|
||
|
||
#endif |
Oops, something went wrong.