Skip to content

Commit 48f1e3d

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

15 files changed

Lines changed: 147 additions & 11 deletions

src/CatM1ConnectionHandler.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ unsigned long CatM1ConnectionHandler::getTime()
5353
return 0;
5454
}
5555

56+
int CatM1ConnectionHandler::ping(IPAddress ip, uint8_t ttl, uint8_t count) {
57+
return GSM.ping(ip);
58+
}
59+
60+
int CatM1ConnectionHandler::ping(const String &hostname, uint8_t ttl, uint8_t count) {
61+
return GSM.ping(hostname);
62+
}
63+
64+
int CatM1ConnectionHandler::ping(const char* host, uint8_t ttl, uint8_t count) {
65+
return GSM.ping(host);
66+
}
67+
68+
5669
/******************************************************************************
5770
PROTECTED MEMBER FUNCTIONS
5871
******************************************************************************/
@@ -95,7 +108,7 @@ NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting()
95108
}
96109

97110
DEBUG_INFO(F("Sending PING to outer space..."));
98-
int const ping_result = GSM.ping("time.arduino.cc");
111+
int const ping_result = ping("time.arduino.cc");
99112
DEBUG_INFO(F("GSM.ping(): %d"), ping_result);
100113
if (ping_result < 0)
101114
{

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
@@ -44,6 +44,18 @@ unsigned long CellularConnectionHandler::getTime()
4444
return _cellular.getCellularTime().getUNIXTimestamp();
4545
}
4646

47+
int CellularConnectionHandler::ping(IPAddress ip, uint8_t ttl, uint8_t count) {
48+
return 0;
49+
}
50+
51+
int CellularConnectionHandler::ping(const String &hostname, uint8_t ttl, uint8_t count) {
52+
return 0;
53+
}
54+
55+
int CellularConnectionHandler::ping(const char* host, uint8_t ttl, uint8_t count) {
56+
return 0;
57+
}
58+
4759
UDP & CellularConnectionHandler::getUDP()
4860
{
4961
DEBUG_ERROR(F("CellularConnectionHandler has no UDP support"));

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: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,35 @@ EthernetConnectionHandler::EthernetConnectionHandler(
6060
_settings.eth.response_timeout = responseTimeout;
6161
}
6262

63+
/******************************************************************************
64+
PUBLIC MEMBER FUNCTIONS
65+
******************************************************************************/
66+
67+
int EthernetConnectionHandler::ping(IPAddress ip, uint8_t ttl, uint8_t count) {
68+
#if defined(ARDUINO_ARCH_ZEPHYR)
69+
return 0;
70+
#else
71+
return Ethernet.ping(ip);
72+
#endif // ARDUINO_ARCH_ZEPHYR
73+
}
74+
75+
int EthernetConnectionHandler::ping(const String &hostname, uint8_t ttl, uint8_t count) {
76+
#if defined(ARDUINO_ARCH_ZEPHYR)
77+
return 0;
78+
#else
79+
return Ethernet.ping(hostname);
80+
#endif // ARDUINO_ARCH_ZEPHYR
81+
}
82+
83+
int EthernetConnectionHandler::ping(const char* host, uint8_t ttl, uint8_t count) {
84+
#if defined(ARDUINO_ARCH_ZEPHYR)
85+
return 0;
86+
#else
87+
return Ethernet.ping(host);
88+
#endif // ARDUINO_ARCH_ZEPHYR
89+
}
90+
91+
6392
/******************************************************************************
6493
PROTECTED MEMBER FUNCTIONS
6594
******************************************************************************/
@@ -110,7 +139,7 @@ NetworkConnectionState EthernetConnectionHandler::update_handleConnecting()
110139
return NetworkConnectionState::CONNECTED;
111140
}
112141

113-
int ping_result = Ethernet.ping("time.arduino.cc");
142+
int ping_result = ping("time.arduino.cc");
114143
DEBUG_INFO(F("Ethernet.ping(): %d"), ping_result);
115144
if (ping_result < 0)
116145
{

src/EthernetConnectionHandler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ 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+
5761
virtual unsigned long getTime() override { return 0; }
5862
virtual Client & getClient() override{ return _eth_client; }
5963
virtual UDP & getUDP() override { return _eth_udp; }

src/GSMConnectionHandler.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ unsigned long GSMConnectionHandler::getTime()
6363
return _gsm.getTime();
6464
}
6565

66+
int GSMConnectionHandler::ping(IPAddress ip, uint8_t ttl, uint8_t count) {
67+
return _gprs.ping(ip);
68+
}
69+
70+
int GSMConnectionHandler::ping(const String &hostname, uint8_t ttl, uint8_t count) {
71+
return _gprs.ping(hostname);
72+
}
73+
74+
int GSMConnectionHandler::ping(const char* host, uint8_t ttl, uint8_t count) {
75+
return _gprs.ping(host);
76+
}
77+
6678
/******************************************************************************
6779
PROTECTED MEMBER FUNCTIONS
6880
******************************************************************************/
@@ -105,7 +117,7 @@ NetworkConnectionState GSMConnectionHandler::update_handleConnecting()
105117
}
106118

107119
DEBUG_INFO(F("Sending PING to outer space..."));
108-
int const ping_result = _gprs.ping("time.arduino.cc");
120+
int const ping_result = ping("time.arduino.cc");
109121
DEBUG_INFO(F("GPRS.ping(): %d"), ping_result);
110122
if (ping_result < 0)
111123
{
@@ -144,7 +156,7 @@ NetworkConnectionState GSMConnectionHandler::update_handleDisconnected()
144156
}
145157
else
146158
{
147-
return NetworkConnectionState::CLOSED;
159+
return NetworkConnectionState::CLOSED;
148160
}
149161
}
150162

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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ unsigned long GenericConnectionHandler::getTime() {
109109
return _ch != nullptr ? _ch->getTime() : 0;
110110
}
111111

112+
int GenericConnectionHandler::ping(IPAddress ip, uint8_t ttl, uint8_t count) {
113+
return _ch != nullptr ? _ch->ping(ip, ttl, count) : 0;
114+
}
115+
116+
int GenericConnectionHandler::ping(const String &hostname, uint8_t ttl, uint8_t count) {
117+
return _ch != nullptr ? _ch->ping(hostname, ttl, count) : 0;
118+
}
119+
120+
int GenericConnectionHandler::ping(const char* host, uint8_t ttl, uint8_t count) {
121+
return _ch != nullptr ? _ch->ping(host, ttl, count) : 0;
122+
}
123+
112124
Client & GenericConnectionHandler::getClient() {
113125
return _ch->getClient(); // NOTE _ch may be nullptr
114126
}

0 commit comments

Comments
 (0)