Skip to content

Commit b969055

Browse files
Adding ping as api of connection handler
1 parent 43cc82c commit b969055

15 files changed

Lines changed: 144 additions & 11 deletions

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);
145+
}
146+
147+
int CatM1ConnectionHandler::ping(const String &hostname, uint8_t ttl, uint8_t count) {
148+
return GSM.ping(hostname);
149+
}
150+
151+
int CatM1ConnectionHandler::ping(const char* host, uint8_t ttl, uint8_t count) {
152+
return GSM.ping(host);
153+
}
154+
143155
#endif /* #ifdef BOARD_HAS_CATM1_NBIOT */

src/CatM1ConnectionHandler.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ class CatM1ConnectionHandler : public ConnectionHandler
3636
CatM1ConnectionHandler();
3737
CatM1ConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, RadioAccessTechnologyType rat = CATM1, uint32_t band = BAND_3 | BAND_20 | BAND_19, bool const keep_alive = true);
3838

39+
int ping(IPAddress ip, uint8_t ttl = 128, uint8_t count = 1) override;
40+
int ping(const String &hostname, uint8_t ttl = 128, uint8_t count = 1) override;
41+
int ping(const char* host, uint8_t ttl = 128, uint8_t count = 1) override;
3942

4043
virtual unsigned long getTime() override;
4144
virtual Client & getClient() override { return _gsm_client; };
4245
virtual UDP & getUDP() override { return _gsm_udp; };
4346

44-
4547
protected:
4648

4749
virtual NetworkConnectionState update_handleInit () override;

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 CellularConnectionHandler::ping(IPAddress ip, uint8_t ttl, uint8_t count) {
115+
return 0;
116+
}
117+
118+
int CellularConnectionHandler::ping(const String &hostname, uint8_t ttl, uint8_t count) {
119+
return 0;
120+
}
121+
122+
int CellularConnectionHandler::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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ class CellularConnectionHandler : public ConnectionHandler
3636
CellularConnectionHandler();
3737
CellularConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, bool const keep_alive = true);
3838

39+
int ping(IPAddress ip, uint8_t ttl = 128, uint8_t count = 1) override;
40+
int ping(const String &hostname, uint8_t ttl = 128, uint8_t count = 1) override;
41+
int ping(const char* host, uint8_t ttl = 128, uint8_t count = 1) override;
3942

4043
virtual unsigned long getTime() override;
4144
virtual Client & getClient() override { return _gsm_client; };
4245
virtual UDP & getUDP() override;
4346

44-
4547
protected:
4648

4749
virtual NetworkConnectionState update_handleInit () override;

src/ConnectionHandlerInterface.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class ConnectionHandler {
5757
virtual UDP &getUDP() = 0;
5858

5959
virtual unsigned long getTime() = 0;
60+
61+
virtual int ping(IPAddress ip, uint8_t ttl = 128, uint8_t count = 1) = 0;
62+
virtual int ping(const String &hostname, uint8_t ttl = 128, uint8_t count = 1) = 0;
63+
virtual int ping(const char* host, uint8_t ttl = 128, uint8_t count = 1) = 0;
6064
#endif
6165

6266
NetworkConnectionState getStatus() __attribute__((deprecated)) {

src/EthernetConnectionHandler.cpp

Lines changed: 25 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,28 @@ NetworkConnectionState EthernetConnectionHandler::update_handleDisconnected()
157157
}
158158
}
159159

160+
int EthernetConnectionHandler::ping(IPAddress ip, uint8_t ttl, uint8_t count) {
161+
#if defined(ARDUINO_ARCH_ZEPHYR)
162+
return 0;
163+
#else
164+
return Ethernet.ping(ip);
165+
#endif // ARDUINO_ARCH_ZEPHYR
166+
}
167+
168+
int EthernetConnectionHandler::ping(const String &hostname, uint8_t ttl, uint8_t count) {
169+
#if defined(ARDUINO_ARCH_ZEPHYR)
170+
return 0;
171+
#else
172+
return Ethernet.ping(hostname);
173+
#endif // ARDUINO_ARCH_ZEPHYR
174+
}
175+
176+
int EthernetConnectionHandler::ping(const char* host, uint8_t ttl, uint8_t count) {
177+
#if defined(ARDUINO_ARCH_ZEPHYR)
178+
return 0;
179+
#else
180+
return Ethernet.ping(host);
181+
#endif // ARDUINO_ARCH_ZEPHYR
182+
}
183+
160184
#endif /* #ifdef BOARD_HAS_ETHERNET */

src/EthernetConnectionHandler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class EthernetConnectionHandler : public ConnectionHandler
5454
unsigned long const responseTimeout = 4000,
5555
bool const keep_alive = true);
5656

57+
int ping(IPAddress ip, uint8_t ttl = 128, uint8_t count = 1) override;
58+
int ping(const String &hostname, uint8_t ttl = 128, uint8_t count = 1) override;
59+
int ping(const char* host, uint8_t ttl = 128, uint8_t count = 1) override;
60+
61+
5762
virtual unsigned long getTime() override { return 0; }
5863
virtual Client & getClient() override{ return _eth_client; }
5964
virtual UDP & getUDP() override { return _eth_udp; }

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);
153+
}
154+
155+
int GSMConnectionHandler::ping(const String &hostname, uint8_t ttl, uint8_t count) {
156+
return _gprs.ping(hostname);
157+
}
158+
159+
int GSMConnectionHandler::ping(const char* host, uint8_t ttl, uint8_t count) {
160+
return _gprs.ping(host);
161+
}
162+
151163
#endif /* #ifdef BOARD_HAS_GSM */

src/GSMConnectionHandler.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ class GSMConnectionHandler : public ConnectionHandler
3535
GSMConnectionHandler();
3636
GSMConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, bool const keep_alive = true);
3737

38+
int ping(IPAddress ip, uint8_t ttl = 128, uint8_t count = 1) override;
39+
int ping(const String &hostname, uint8_t ttl = 128, uint8_t count = 1) override;
40+
int ping(const char* host, uint8_t ttl = 128, uint8_t count = 1) override;
3841

3942
virtual unsigned long getTime() override;
4043
virtual Client & getClient() override { return _gsm_client; };
4144
virtual UDP & getUDP() override { return _gsm_udp; };
4245

43-
4446
protected:
4547

4648
virtual NetworkConnectionState update_handleInit () override;

src/GenericConnectionHandler.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@
1919
LOCAL MODULE FUNCTIONS
2020
******************************************************************************/
2121

22+
#if !defined(BOARD_HAS_LORA)
23+
int GenericConnectionHandler::ping(IPAddress ip, uint8_t ttl, uint8_t count) {
24+
return _ch != nullptr ? _ch->ping(ip, ttl, count) : 0;
25+
}
26+
27+
int GenericConnectionHandler::ping(const String &hostname, uint8_t ttl, uint8_t count) {
28+
return _ch != nullptr ? _ch->ping(hostname, ttl, count) : 0;
29+
}
30+
31+
int GenericConnectionHandler::ping(const char* host, uint8_t ttl, uint8_t count) {
32+
return _ch != nullptr ? _ch->ping(host, ttl, count) : 0;
33+
}
34+
#endif // !defined(BOARD_HAS_LORA)
35+
2236
static inline ConnectionHandler* instantiate_handler(NetworkAdapter adapter) {
2337
switch(adapter) {
2438
#if defined(BOARD_HAS_WIFI)

0 commit comments

Comments
 (0)