Skip to content

Commit c67b6c7

Browse files
Adding ping as api of connection handler
1 parent f338e51 commit c67b6c7

15 files changed

+128
-5
lines changed

src/CatM1ConnectionHandler.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting()
9595
}
9696

9797
DEBUG_INFO(F("Sending PING to outer space..."));
98-
int const ping_result = GSM.ping("time.arduino.cc");
98+
int const ping_result = ping("time.arduino.cc");
9999
DEBUG_INFO(F("GSM.ping(): %d"), ping_result);
100100
if (ping_result < 0)
101101
{
@@ -140,4 +140,16 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleDisconnected()
140140
}
141141
}
142142

143+
int CatM1ConnectionHandler::ping(IPAddress ip, uint8_t ttl, uint8_t count) {
144+
return GSM.ping(ip, ttl, count);
145+
}
146+
147+
int CatM1ConnectionHandler::ping(const String &hostname, uint8_t ttl, uint8_t count) {
148+
return GSM.ping(hostname, ttl, count);
149+
}
150+
151+
int CatM1ConnectionHandler::ping(const char* host, uint8_t ttl, uint8_t count) {
152+
return GSM.ping(host, ttl, count);
153+
}
154+
143155
#endif /* #ifdef BOARD_HAS_CATM1_NBIOT */

src/CatM1ConnectionHandler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class CatM1ConnectionHandler : public ConnectionHandler
4141
virtual Client & getClient() override { return _gsm_client; };
4242
virtual UDP & getUDP() override { return _gsm_udp; };
4343

44+
int ping(IPAddress ip, uint8_t ttl = 128, uint8_t count = 1) override;
45+
int ping(const String &hostname, uint8_t ttl = 128, uint8_t count = 1) override;
46+
int ping(const char* host, uint8_t ttl = 128, uint8_t count = 1) override;
4447

4548
protected:
4649

src/CellularConnectionHandler.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,16 @@ NetworkConnectionState CellularConnectionHandler::update_handleDisconnected()
111111
return NetworkConnectionState::CLOSED;
112112
}
113113

114+
int CatM1ConnectionHandler::ping(IPAddress ip, uint8_t ttl, uint8_t count) {
115+
return 0;
116+
}
117+
118+
int CatM1ConnectionHandler::ping(const String &hostname, uint8_t ttl, uint8_t count) {
119+
return 0;
120+
}
121+
122+
int CatM1ConnectionHandler::ping(const char* host, uint8_t ttl, uint8_t count) {
123+
return 0;
124+
}
125+
114126
#endif /* #ifdef BOARD_HAS_CELLULAR */

src/CellularConnectionHandler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class CellularConnectionHandler : public ConnectionHandler
4141
virtual Client & getClient() override { return _gsm_client; };
4242
virtual UDP & getUDP() override;
4343

44+
int ping(IPAddress ip, uint8_t ttl = 128, uint8_t count = 1) override;
45+
int ping(const String &hostname, uint8_t ttl = 128, uint8_t count = 1) override;
46+
int ping(const char* host, uint8_t ttl = 128, uint8_t count = 1) override;
4447

4548
protected:
4649

src/ConnectionHandlerInterface.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class ConnectionHandler {
5959
#else
6060
virtual Client &getClient() = 0;
6161
virtual UDP &getUDP() = 0;
62+
63+
virtual int ping(IPAddress ip, uint8_t ttl = 128, uint8_t count = 1) = 0;
64+
virtual int ping(const String &hostname, uint8_t ttl = 128, uint8_t count = 1) = 0;
65+
virtual int ping(const char* host, uint8_t ttl = 128, uint8_t count = 1) = 0;
6266
#endif
6367

6468
NetworkConnectionState getStatus() __attribute__((deprecated)) {

src/EthernetConnectionHandler.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ NetworkConnectionState EthernetConnectionHandler::update_handleConnecting()
110110
return NetworkConnectionState::CONNECTED;
111111
}
112112

113-
int ping_result = Ethernet.ping("time.arduino.cc");
113+
int ping_result = ping("time.arduino.cc");
114114
DEBUG_INFO(F("Ethernet.ping(): %d"), ping_result);
115115
if (ping_result < 0)
116116
{
@@ -157,4 +157,16 @@ NetworkConnectionState EthernetConnectionHandler::update_handleDisconnected()
157157
}
158158
}
159159

160+
int EthernetConnectionHandler::ping(IPAddress ip, uint8_t ttl, uint8_t count) {
161+
return Ethernet.ping(ip, ttl, count);
162+
}
163+
164+
int EthernetConnectionHandler::ping(const String &hostname, uint8_t ttl, uint8_t count) {
165+
return Ethernet.ping(hostname, ttl, count);
166+
}
167+
168+
int EthernetConnectionHandler::ping(const char* host, uint8_t ttl, uint8_t count) {
169+
return Ethernet.ping(host, ttl, count);
170+
}
171+
160172
#endif /* #ifdef BOARD_HAS_ETHERNET */

src/EthernetConnectionHandler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ class EthernetConnectionHandler : public ConnectionHandler
5858
virtual Client & getClient() override{ return _eth_client; }
5959
virtual UDP & getUDP() override { return _eth_udp; }
6060

61+
int ping(IPAddress ip, uint8_t ttl = 128, uint8_t count = 1) override;
62+
int ping(const String &hostname, uint8_t ttl = 128, uint8_t count = 1) override;
63+
int ping(const char* host, uint8_t ttl = 128, uint8_t count = 1) override;
64+
6165
protected:
6266

6367
virtual NetworkConnectionState update_handleInit () override;

src/GSMConnectionHandler.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ NetworkConnectionState GSMConnectionHandler::update_handleConnecting()
105105
}
106106

107107
DEBUG_INFO(F("Sending PING to outer space..."));
108-
int const ping_result = _gprs.ping("time.arduino.cc");
108+
int const ping_result = ping("time.arduino.cc");
109109
DEBUG_INFO(F("GPRS.ping(): %d"), ping_result);
110110
if (ping_result < 0)
111111
{
@@ -144,8 +144,20 @@ NetworkConnectionState GSMConnectionHandler::update_handleDisconnected()
144144
}
145145
else
146146
{
147-
return NetworkConnectionState::CLOSED;
147+
return NetworkConnectionState::CLOSED;
148148
}
149149
}
150150

151+
int GSMConnectionHandler::ping(IPAddress ip, uint8_t ttl, uint8_t count) {
152+
return _gprs.ping(ip, ttl, count);
153+
}
154+
155+
int GSMConnectionHandler::ping(const String &hostname, uint8_t ttl, uint8_t count) {
156+
return _gprs.ping(hostname, ttl, count);
157+
}
158+
159+
int GSMConnectionHandler::ping(const char* host, uint8_t ttl, uint8_t count) {
160+
return _gprs.ping(host, ttl, count);
161+
}
162+
151163
#endif /* #ifdef BOARD_HAS_GSM */

src/GSMConnectionHandler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class GSMConnectionHandler : public ConnectionHandler
4040
virtual Client & getClient() override { return _gsm_client; };
4141
virtual UDP & getUDP() override { return _gsm_udp; };
4242

43+
int ping(IPAddress ip, uint8_t ttl = 128, uint8_t count = 1) override;
44+
int ping(const String &hostname, uint8_t ttl = 128, uint8_t count = 1) override;
45+
int ping(const char* host, uint8_t ttl = 128, uint8_t count = 1) override;
4346

4447
protected:
4548

src/GenericConnectionHandler.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ void GenericConnectionHandler::setKeepAlive(bool keep_alive) {
115115
}
116116
}
117117

118+
int GenericConnectionHandler::ping(IPAddress ip, uint8_t ttl, uint8_t count) {
119+
return _ch != nullptr ? _ch->ping(ip, ttl, count) : 0;
120+
}
121+
122+
int GenericConnectionHandler::ping(const String &hostname, uint8_t ttl, uint8_t count) {
123+
return _ch != nullptr ? _ch->ping(hostname, ttl, count) : 0;
124+
}
125+
126+
int GenericConnectionHandler::ping(const char* host, uint8_t ttl, uint8_t count) {
127+
return _ch != nullptr ? _ch->ping(host, ttl, count) : 0;
128+
}
129+
118130
static inline ConnectionHandler* instantiate_handler(NetworkAdapter adapter) {
119131
switch(adapter) {
120132
#if defined(BOARD_HAS_WIFI)

0 commit comments

Comments
 (0)