Skip to content

Commit

Permalink
ran clang-format on all relevant sources
Browse files Browse the repository at this point in the history
including all example sources
  • Loading branch information
2bndy5 committed Jul 8, 2022
1 parent 2c22d90 commit a4d4834
Show file tree
Hide file tree
Showing 32 changed files with 2,193 additions and 2,197 deletions.
63 changes: 32 additions & 31 deletions RF24Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RF24Client::RF24Client() : data(NULL) {}

/*************************************************************/

RF24Client::RF24Client(uip_userdata_t *conn_data) : data(conn_data) {}
RF24Client::RF24Client(uip_userdata_t* conn_data) : data(conn_data) {}

/*************************************************************/

Expand All @@ -47,7 +47,7 @@ int RF24Client::connect(IPAddress ip, uint16_t port)
uip_ipaddr_t ipaddr;
uip_ip_addr(ipaddr, ip);

struct uip_conn *conn = uip_connect(&ipaddr, htons(port));
struct uip_conn* conn = uip_connect(&ipaddr, htons(port));

if (conn)
{
Expand All @@ -61,7 +61,7 @@ int RF24Client::connect(IPAddress ip, uint16_t port)

if ((conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED)
{
data = (uip_userdata_t *)conn->appstate;
data = (uip_userdata_t*)conn->appstate;
IF_RF24ETHERNET_DEBUG_CLIENT(Serial.print(millis()); Serial.print(F(" connected, state: ")); Serial.print(data->state); Serial.print(F(", first packet in: ")); Serial.println(data->packets_in););
return 1;
}
Expand All @@ -73,7 +73,6 @@ int RF24Client::connect(IPAddress ip, uint16_t port)
break;
}
#endif

}
}
//delay(25);
Expand All @@ -86,7 +85,7 @@ int RF24Client::connect(IPAddress ip, uint16_t port)

/*************************************************************/

int RF24Client::connect(const char *host, uint16_t port)
int RF24Client::connect(const char* host, uint16_t port)
{
// Look up the host first
int ret = 0;
Expand All @@ -105,10 +104,12 @@ int RF24Client::connect(const char *host, uint16_t port)
#endif
return connect(remote_addr, port);
}
#else // ! UIP_UDP
//Do something with the input paramaters to prevent compile time warnings
if (host) {};
if (port) {};
#else // ! UIP_UDP
//Do something with the input parameters to prevent compile time warnings
if (host) {
};
if (port) {
};
#endif // ! UIP_UDP

#if defined(ETH_DEBUG_L1) || defined(RF24ETHERNET_DEBUG_DNS)
Expand Down Expand Up @@ -154,7 +155,7 @@ void RF24Client::stop()

// 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)
bool RF24Client::operator==(const RF24Client& rhs)
{
return data && rhs.data && (data == rhs.data);
}
Expand All @@ -176,14 +177,14 @@ size_t RF24Client::write(uint8_t c)

/*************************************************************/

size_t RF24Client::write(const uint8_t *buf, size_t size)
size_t RF24Client::write(const uint8_t* buf, size_t size)
{
return _write(data, buf, size);
}

/*************************************************************/

size_t RF24Client::_write(uip_userdata_t *u, const uint8_t *buf, size_t size)
size_t RF24Client::_write(uip_userdata_t* u, const uint8_t* buf, size_t size)
{

size_t total_written = 0;
Expand All @@ -200,7 +201,7 @@ size_t RF24Client::_write(uip_userdata_t *u, const uint8_t *buf, size_t size)
goto test2;
}

IF_RF24ETHERNET_DEBUG_CLIENT(Serial.println(); Serial.print(millis()); Serial.print(F(" UIPClient.write: writePacket(")); Serial.print(u->packets_out); Serial.print(F(") pos: ")); Serial.print(u->out_pos); Serial.print(F(", buf[")); Serial.print(size - total_written); Serial.print(F("]: '")); Serial.write((uint8_t *)buf + total_written, payloadSize); Serial.println(F("'")););
IF_RF24ETHERNET_DEBUG_CLIENT(Serial.println(); Serial.print(millis()); Serial.print(F(" UIPClient.write: writePacket(")); Serial.print(u->packets_out); Serial.print(F(") pos: ")); Serial.print(u->out_pos); Serial.print(F(", buf[")); Serial.print(size - total_written); Serial.print(F("]: '")); Serial.write((uint8_t*)buf + total_written, payloadSize); Serial.println(F("'")););

memcpy(u->myData + u->out_pos, buf + total_written, payloadSize);
u->packets_out = 1;
Expand All @@ -224,7 +225,7 @@ size_t RF24Client::_write(uip_userdata_t *u, const uint8_t *buf, size_t size)

/*************************************************************/

void uip_log(char *msg)
void uip_log(char* msg)
{
//Serial.println();
//Serial.println("** UIP LOG **");
Expand All @@ -238,21 +239,21 @@ void uip_log(char *msg)

void serialip_appcall(void)
{
uip_userdata_t *u = (uip_userdata_t *)uip_conn->appstate;
uip_userdata_t* u = (uip_userdata_t*)uip_conn->appstate;

if(u && u->connectTimeout > 0){
if(millis() - u->connectTimer > u->connectTimeout && u->initialData == false){
uip_close();
IF_RF24ETHERNET_DEBUG_CLIENT(Serial.println(); Serial.print(millis()); Serial.println("UIP Client close(timeout)"););
}
if (u && u->connectTimeout > 0) {
if (millis() - u->connectTimer > u->connectTimeout && u->initialData == false) {
uip_close();
IF_RF24ETHERNET_DEBUG_CLIENT(Serial.println(); Serial.print(millis()); Serial.println("UIP Client close(timeout)"););
}
}

/*******Connected**********/
if (!u && uip_connected())
{
IF_RF24ETHERNET_DEBUG_CLIENT(Serial.println(); Serial.print(millis()); Serial.println(F(" UIPClient uip_connected")););

u = (uip_userdata_t *)EthernetClient::_allocateData();
u = (uip_userdata_t*)EthernetClient::_allocateData();

if (u)
{
Expand All @@ -273,7 +274,7 @@ void serialip_appcall(void)
IF_RF24ETHERNET_DEBUG_CLIENT(Serial.println(); Serial.print(millis()); Serial.print(F(" UIPClient uip_newdata, uip_len:")); Serial.println(uip_len););

u->initialData = true;

if (u->sent)
{
u->hold = (u->out_pos = (u->windowOpened = (u->packets_out = false)));
Expand Down Expand Up @@ -302,7 +303,7 @@ void serialip_appcall(void)

if (u->packets_in)
{
((uip_userdata_closed_t *)u)->lport = uip_conn->lport;
((uip_userdata_closed_t*)u)->lport = uip_conn->lport;
u->state |= UIP_CLIENT_REMOTECLOSED;
IF_RF24ETHERNET_DEBUG_CLIENT(Serial.println(F("UIPClient close 1")););
}
Expand Down Expand Up @@ -401,18 +402,18 @@ void serialip_appcall(void)
IF_RF24ETHERNET_DEBUG_CLIENT(Serial.println(F("blocks outstanding transfer -> uip_stop()")););
}
}
finish:;
finish:;

if (u->state & UIP_CLIENT_RESTART && !u->windowOpened)
{
if (!(u->state & (UIP_CLIENT_CLOSE | UIP_CLIENT_REMOTECLOSED)))
{
uip_restart();
#if defined ETH_DEBUG_L1
#if defined ETH_DEBUG_L1
Serial.println();
Serial.print(millis());
Serial.println(F(" UIPClient Re-Open TCP Window"));
#endif
#endif
u->windowOpened = true;
u->restartInterval = UIP_WINDOW_REOPEN_DELAY; //.75 seconds
u->restartTime = u->connAbortTime = millis();
Expand All @@ -423,11 +424,11 @@ void serialip_appcall(void)

/*******************************************************/

uip_userdata_t *RF24Client::_allocateData()
uip_userdata_t* RF24Client::_allocateData()
{
for (uint8_t sock = 0; sock < UIP_CONNS; sock++)
{
uip_userdata_t *data = &RF24Client::all_data[sock];
uip_userdata_t* data = &RF24Client::all_data[sock];
if (!data->state)
{
data->state = sock | UIP_CLIENT_CONNECTED;
Expand Down Expand Up @@ -473,7 +474,7 @@ int RF24Client::available()

/*************************************************************/

int RF24Client::_available(uip_userdata_t *u)
int RF24Client::_available(uip_userdata_t* u)
{
if (u->packets_in)
{
Expand All @@ -482,7 +483,7 @@ int RF24Client::_available(uip_userdata_t *u)
return 0;
}

int RF24Client::read(uint8_t *buf, size_t size)
int RF24Client::read(uint8_t* buf, size_t size)
{
if (*this)
{
Expand Down
45 changes: 23 additions & 22 deletions RF24Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,30 @@
//#define UIP_SOCKET_NUMPACKETS 5
//#endif

#define UIP_CLIENT_CONNECTED 0x10
#define UIP_CLIENT_CLOSE 0x20
#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
#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

/**
* @warning <b> This is used internally and should not be accessed directly by users </b>
*/
typedef struct {
typedef struct
{
uint8_t state;
uint8_t packets_in[UIP_SOCKET_NUMPACKETS];
/** The local TCP port, in network byte order. */
uint16_t lport;
} uip_userdata_closed_t;


/**
* Data structure for holding per connection data
* @warning <b> This is used internally and should not be accessed directly by users </b>
*/
typedef struct {
typedef struct
{
bool hold;
bool sent;
bool packets_in;
Expand All @@ -61,7 +62,7 @@ typedef struct {
uint16_t dataPos;
uint16_t dataCnt;
#if UIP_CLIENT_TIMER >= 0
uint32_t timer;
uint32_t timer;
#endif
uint32_t restartTime;
uint32_t restartInterval;
Expand All @@ -72,11 +73,10 @@ typedef struct {
bool initialData;
} uip_userdata_t;


class RF24Client : public Client {
class RF24Client : public Client
{

public:

/** Basic constructor */
RF24Client();

Expand All @@ -91,7 +91,7 @@ class RF24Client : public Client {
* Lookups will generally return responses with a single A record if using hostnames like
* "www.google.com" instead of "google.com" which works well with the default buffer size
*/
int connect(const char *host, uint16_t port);
int connect(const char* host, uint16_t port);

/**
* Read available data into a buffer
Expand All @@ -100,7 +100,7 @@ class RF24Client : public Client {
* client.read(buf,size);
* @endcode
*/
int read(uint8_t *buf, size_t size);
int read(uint8_t* buf, size_t size);

/**
* Read data one byte at a time
Expand All @@ -123,7 +123,7 @@ class RF24Client : public Client {
size_t write(uint8_t);

/** Write a buffer of data, to be sent in a single TCP packet */
size_t write(const uint8_t *buf, size_t size);
size_t write(const uint8_t* buf, size_t size);

/**
* Indicates whether data is available to be read by the client.
Expand All @@ -143,7 +143,7 @@ class RF24Client : public Client {
* @note Calling client or server available() keeps the IP stack and RF24Network layer running, so needs to be called regularly,
* even when disconnected or delaying for extended periods.
*/
int waitAvailable(uint32_t timeout=750);
int waitAvailable(uint32_t timeout = 750);

/** Read a byte from the incoming buffer without advancing the point of reading */
int peek();
Expand All @@ -155,21 +155,23 @@ class RF24Client : public Client {

operator bool();
virtual bool operator==(const EthernetClient&);
virtual bool operator!=(const EthernetClient& rhs) { return !this->operator==(rhs); };
virtual bool operator!=(const EthernetClient& rhs)
{
return !this->operator==(rhs);
};

static uip_userdata_t all_data[UIP_CONNS];

private:

RF24Client(struct uip_conn *_conn);
RF24Client(struct uip_conn* _conn);
RF24Client(uip_userdata_t* conn_data);

uip_userdata_t* data;

static int _available(uip_userdata_t *);
static int _available(uip_userdata_t*);

static uip_userdata_t* _allocateData();
static size_t _write(uip_userdata_t *,const uint8_t *buf, size_t size);
static size_t _write(uip_userdata_t*, const uint8_t* buf, size_t size);

friend class RF24EthernetClass;
friend class RF24Server;
Expand All @@ -178,5 +180,4 @@ class RF24Client : public Client {
friend void uip_log(char* msg);
};


#endif // RF24CLIENT_H
Loading

0 comments on commit a4d4834

Please sign in to comment.