Skip to content

Commit

Permalink
Merge pull request #40 from nRF24/ConnectionTimeouts
Browse files Browse the repository at this point in the history
Simplify connection timeouts more
  • Loading branch information
TMRh20 authored Oct 23, 2023
2 parents 792b0be + 2e2b700 commit 32e3133
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
28 changes: 10 additions & 18 deletions RF24Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,6 @@ void serialip_appcall(void)
{
uip_userdata_t* u = (uip_userdata_t*)uip_conn->appstate;

#if UIP_CONNECTION_TIMEOUT > 0
if (u && u->connectTimeout > 0) {
if (!u->initialData) {
u->connectTimer = millis();
u->initialData = true;
}
else if (millis() - u->connectTimer > u->connectTimeout) {
u->state |= UIP_CLIENT_CLOSE;
u->connectTimer = millis();
IF_RF24ETHERNET_DEBUG_CLIENT(Serial.println(); Serial.print(millis()); Serial.println("UIP Client close(timeout)"););
}
}
#endif

/*******Connected**********/
if (!u && uip_connected())
{
Expand All @@ -264,9 +250,6 @@ void serialip_appcall(void)

if (u)
{
#if UIP_CONNECTION_TIMEOUT > 0
u->connectTimer = millis();
#endif
uip_conn->appstate = u;
IF_RF24ETHERNET_DEBUG_CLIENT(Serial.print(F("UIPClient allocated state: ")); Serial.println(u->state, BIN););
}
Expand All @@ -276,6 +259,16 @@ void serialip_appcall(void)
}
}

#if UIP_CONNECTION_TIMEOUT > 0
if (u && u->connectTimeout > 0) {
if (millis() - u->connectTimer > u->connectTimeout) {
u->state |= UIP_CLIENT_CLOSE;
u->connectTimer = millis();
IF_RF24ETHERNET_DEBUG_CLIENT(Serial.println(); Serial.print(millis()); Serial.println("UIP Client close(timeout)"););
}
}
#endif

/*******User Data RX**********/
if (u)
{
Expand Down Expand Up @@ -433,7 +426,6 @@ uip_userdata_t* RF24Client::_allocateData()
data->dataPos = 0;
data->out_pos = 0;
data->hold = 0;
data->initialData = false;
#if (UIP_CONNECTION_TIMEOUT > 0)
data->connectTimer = millis();
data->connectTimeout = UIP_CONNECTION_TIMEOUT;
Expand Down
1 change: 0 additions & 1 deletion RF24Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ typedef struct
uint32_t connectTimer;
#endif
uint8_t myData[OUTPUT_BUFFER_SIZE];
bool initialData;
} uip_userdata_t;

class RF24Client : public Client
Expand Down

0 comments on commit 32e3133

Please sign in to comment.