From 2b3f19274bb0aad8443bac7a7fc4a645ca5be3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Camelo=20Neves=20Pereira?= Date: Tue, 19 Feb 2019 22:27:58 +0000 Subject: [PATCH 1/7] Exposed DHCP timeout in begin function as an optional parameter --- src/EtherCard.h | 2 +- src/dhcp.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/EtherCard.h b/src/EtherCard.h index ff17ea5..2cab405 100644 --- a/src/EtherCard.h +++ b/src/EtherCard.h @@ -128,7 +128,7 @@ class EtherCard : public Ethernet { * @return uint8_t Firmware version or zero on failure. */ static uint8_t begin (const uint16_t size, const uint8_t* macaddr, - uint8_t csPin = SS); + uint8_t csPin = SS, uint16_t timeout = 60000); /** @brief Configure network interface with static IP * @param my_ip IP address (4 bytes). 0 for no change. diff --git a/src/dhcp.cpp b/src/dhcp.cpp index 960c366..f976dea 100644 --- a/src/dhcp.cpp +++ b/src/dhcp.cpp @@ -332,7 +332,7 @@ static char toAsciiHex(byte b) { return c; } -bool EtherCard::dhcpSetup (const char *hname, bool fromRam) { +bool EtherCard::dhcpSetup (const char *hname, bool fromRam, uint16_t timeout = 60000) { // Use during setup, as this discards all incoming requests until it returns. // That shouldn't be a problem, because we don't have an IPaddress yet. // Will try 60 secs to obtain DHCP-lease. @@ -356,7 +356,7 @@ bool EtherCard::dhcpSetup (const char *hname, bool fromRam) { dhcpState = DHCP_STATE_INIT; uint16_t start = millis(); - while (dhcpState != DHCP_STATE_BOUND && uint16_t(millis()) - start < 60000) { + while (dhcpState != DHCP_STATE_BOUND && uint16_t(millis()) - start < timeout) { if (isLinkUp()) DhcpStateMachine(packetReceive()); } updateBroadcastAddress(); From 26736b3dc844cb3d336d4164422bebef9f3b704c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Camelo=20Neves=20Pereira?= Date: Tue, 19 Feb 2019 23:03:38 +0000 Subject: [PATCH 2/7] Version Bump --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index ad4054e..df0358b 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "EtherCard", - "version": "1.1.0", + "version": "1.1.1", "keywords": "http, web, server, client, ethernet", "description": "EtherCard is an IPv4 driver for the ENC28J60 chip.", "homepage": "https://github.com/njh/EtherCard", diff --git a/library.properties b/library.properties index e7f9ed9..2227bbe 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=EtherCard -version=1.1.0 +version=1.1.1 author=Jean-Claude Wippler maintainer=Nicholas Humfrey sentence=EtherCard is an IPv4 driver for the ENC28J60 chip. From 9666a1377bf0ab0f4270a67f288ec20cec778a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Camelo=20Neves=20Pereira?= Date: Tue, 19 Feb 2019 23:12:23 +0000 Subject: [PATCH 3/7] Moved timeout to begin function --- src/EtherCard.cpp | 2 +- src/EtherCard.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EtherCard.cpp b/src/EtherCard.cpp index f752a9b..2b24753 100644 --- a/src/EtherCard.cpp +++ b/src/EtherCard.cpp @@ -30,7 +30,7 @@ uint16_t EtherCard::delaycnt = 0; //request gateway ARP lookup uint8_t EtherCard::begin (const uint16_t size, const uint8_t* macaddr, - uint8_t csPin) { + uint8_t csPin, uint16_t timeout = 60000) { using_dhcp = false; #if ETHERCARD_STASH Stash::initMap(); diff --git a/src/EtherCard.h b/src/EtherCard.h index 2cab405..ff8c66b 100644 --- a/src/EtherCard.h +++ b/src/EtherCard.h @@ -128,7 +128,7 @@ class EtherCard : public Ethernet { * @return uint8_t Firmware version or zero on failure. */ static uint8_t begin (const uint16_t size, const uint8_t* macaddr, - uint8_t csPin = SS, uint16_t timeout = 60000); + uint8_t csPin = SS, uint16_t timeout); /** @brief Configure network interface with static IP * @param my_ip IP address (4 bytes). 0 for no change. From ca1fe5d24f3a39d3d097941fe2d425a4f5f3458b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Camelo=20Neves=20Pereira?= Date: Tue, 19 Feb 2019 23:15:33 +0000 Subject: [PATCH 4/7] Fixed --- src/EtherCard.cpp | 2 +- src/EtherCard.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EtherCard.cpp b/src/EtherCard.cpp index 2b24753..3522875 100644 --- a/src/EtherCard.cpp +++ b/src/EtherCard.cpp @@ -30,7 +30,7 @@ uint16_t EtherCard::delaycnt = 0; //request gateway ARP lookup uint8_t EtherCard::begin (const uint16_t size, const uint8_t* macaddr, - uint8_t csPin, uint16_t timeout = 60000) { + uint8_t csPin, uint16_t timeout) { using_dhcp = false; #if ETHERCARD_STASH Stash::initMap(); diff --git a/src/EtherCard.h b/src/EtherCard.h index ff8c66b..2cab405 100644 --- a/src/EtherCard.h +++ b/src/EtherCard.h @@ -128,7 +128,7 @@ class EtherCard : public Ethernet { * @return uint8_t Firmware version or zero on failure. */ static uint8_t begin (const uint16_t size, const uint8_t* macaddr, - uint8_t csPin = SS, uint16_t timeout); + uint8_t csPin = SS, uint16_t timeout = 60000); /** @brief Configure network interface with static IP * @param my_ip IP address (4 bytes). 0 for no change. From 3f44854521f58afde464bd375c664ce9261148dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Camelo=20Neves=20Pereira?= Date: Tue, 19 Feb 2019 23:17:31 +0000 Subject: [PATCH 5/7] clear extra code --- src/dhcp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dhcp.cpp b/src/dhcp.cpp index f976dea..0bcca9d 100644 --- a/src/dhcp.cpp +++ b/src/dhcp.cpp @@ -332,7 +332,7 @@ static char toAsciiHex(byte b) { return c; } -bool EtherCard::dhcpSetup (const char *hname, bool fromRam, uint16_t timeout = 60000) { +bool EtherCard::dhcpSetup (const char *hname, bool fromRam, uint16_t timeout) { // Use during setup, as this discards all incoming requests until it returns. // That shouldn't be a problem, because we don't have an IPaddress yet. // Will try 60 secs to obtain DHCP-lease. From d73505169230433c4d0f901e4cd8087f77c4ff84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Camelo=20Neves=20Pereira?= Date: Tue, 19 Feb 2019 23:29:49 +0000 Subject: [PATCH 6/7] clear timeout from begin --- src/EtherCard.cpp | 2 +- src/EtherCard.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/EtherCard.cpp b/src/EtherCard.cpp index 3522875..f752a9b 100644 --- a/src/EtherCard.cpp +++ b/src/EtherCard.cpp @@ -30,7 +30,7 @@ uint16_t EtherCard::delaycnt = 0; //request gateway ARP lookup uint8_t EtherCard::begin (const uint16_t size, const uint8_t* macaddr, - uint8_t csPin, uint16_t timeout) { + uint8_t csPin) { using_dhcp = false; #if ETHERCARD_STASH Stash::initMap(); diff --git a/src/EtherCard.h b/src/EtherCard.h index 2cab405..97bf66a 100644 --- a/src/EtherCard.h +++ b/src/EtherCard.h @@ -128,7 +128,7 @@ class EtherCard : public Ethernet { * @return uint8_t Firmware version or zero on failure. */ static uint8_t begin (const uint16_t size, const uint8_t* macaddr, - uint8_t csPin = SS, uint16_t timeout = 60000); + uint8_t csPin = SS); /** @brief Configure network interface with static IP * @param my_ip IP address (4 bytes). 0 for no change. @@ -371,7 +371,7 @@ class EtherCard : public Ethernet { * @return bool True if DHCP successful * @note Blocks until DHCP complete or timeout after 60 seconds */ - static bool dhcpSetup (const char *hname = NULL, bool fromRam =false); + static bool dhcpSetup (const char *hname = NULL, bool fromRam = false, uint16_t timeout = 60000); /** @brief Register a callback for a specific DHCP option number * @param option The option number to request from the DHCP server From f85649570b64550ab6777b6f31b41c1d511fcdc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Camelo=20Neves=20Pereira?= Date: Tue, 19 Feb 2019 23:42:23 +0000 Subject: [PATCH 7/7] added documentation --- src/EtherCard.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EtherCard.h b/src/EtherCard.h index 97bf66a..f8ea407 100644 --- a/src/EtherCard.h +++ b/src/EtherCard.h @@ -368,8 +368,8 @@ class EtherCard : public Ethernet { /** @brief Configure network interface with DHCP * @param hname The hostname to pass to the DHCP server * @param fromRam Set true to indicate whether hname is in RAM or in program space. Default = false + * @param timeout Time to wait before failing (default is 60 seconds) * @return bool True if DHCP successful - * @note Blocks until DHCP complete or timeout after 60 seconds */ static bool dhcpSetup (const char *hname = NULL, bool fromRam = false, uint16_t timeout = 60000);