A library for talking to Multi-Tech's Cellular SocketModem Devices.
Dependents: M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more
Diff: cellular/Cellular.cpp
- Revision:
- 23:bc6f98a1eb22
- Parent:
- 19:38794784e009
- Child:
- 27:8e6188cbcfd4
- Child:
- 29:7408b1bdad37
--- a/cellular/Cellular.cpp Tue Dec 17 17:23:40 2013 +0000 +++ b/cellular/Cellular.cpp Tue Dec 17 18:49:06 2013 +0000 @@ -423,6 +423,37 @@ return FAILURE; } +bool Cellular::ping(const std::string& address) { + char buffer[256] = {0}; + Code code; + + code = sendBasicCommand("AT#PINGREMOTE=\"" + address + "\"", 1000); + if (code != OK) { + return false; + } + + sprintf(buffer, "AT#PINGNUM=%d", 1); + code = sendBasicCommand(buffer , 1000); + if (code != OK) { + return false; + } + + sprintf(buffer, "AT#PINGDELAY=%d", PINGDELAY); + code = sendBasicCommand(buffer , 1000); + if (code != OK) { + return false; + } + + std::string response; + for (int i = 0; i < PINGNUM; i++) { + response = sendCommand("AT#PING", PINGDELAY * 1000); + if (response.find("alive") != std::string::npos) { + return true; + } + } + return false; +} + Cellular::Code Cellular::setSocketCloseable(bool enabled) { if(socketCloseable == enabled) { return OK;