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:
- 40:14342c4de476
- Parent:
- 38:4739e039421a
- Parent:
- 39:6e94520a3217
- Child:
- 43:3cacf019ed7d
--- a/cellular/Cellular.cpp Thu Dec 19 16:54:09 2013 +0000 +++ b/cellular/Cellular.cpp Thu Dec 19 19:53:43 2013 +0000 @@ -5,6 +5,8 @@ #include "MTSText.h" #include "MTSSerial.h" +using namespace mts; + Cellular* Cellular::instance = NULL; Cellular* Cellular::getInstance() { @@ -102,7 +104,7 @@ } Code code = sendBasicCommand("AT#CONNECTIONSTOP", 10000); - if(code == OK) { + if(code == CELL_OK) { printf("[DEBUG] Successfully closed PPP Connection\r\n"); } else { printf("[ERROR] Closing PPP Connection [%d]. Continuing ...\r\n", (int)code); @@ -163,7 +165,7 @@ if(mode == TCP) { if(socketCloseable) { Code code = sendBasicCommand("AT#DLEMODE=1,0", 1000); - if(code != OK) { + if(code != CELL_OK) { printf("[WARNING] Unable to set socket closeable [%d]\r\n", (int) code); } } @@ -173,7 +175,7 @@ } else { if(socketCloseable) { Code code = sendBasicCommand("AT#UDPDLEMODE=1", 1000); - if(code != OK) { + if(code != CELL_OK) { printf("[WARNING] Unable to set socket closeable [%d]\r\n", (int) code); } } @@ -182,13 +184,13 @@ addressCode = sendBasicCommand("AT#UDPSERV=1,\"" + address + "\"", 1000); } - if(portCode == OK) { + if(portCode == CELL_OK) { host_port = port; } else { printf("[ERROR] Host port could not be set\r\n"); } - if(addressCode == OK) { + if(addressCode == CELL_OK) { host_address = address; } else { printf("[ERROR] Host address could not be set\r\n"); @@ -438,7 +440,7 @@ void Cellular::reset() { disconnect(); Code code = sendBasicCommand("AT#RESET=0", 10000); - if(code != OK) { + if(code != CELL_OK) { printf("[ERROR] Socket Modem did not accept RESET command\n\r"); } else { printf("[WARNING] Socket Modem is resetting, allow 30 seconds for it to come back\n\r"); @@ -449,7 +451,7 @@ { Code code = sendBasicCommand("AT", 1000); - if(code != OK) { + if(code != CELL_OK) { printf("[Error] Failed basic AT command"); return code; } @@ -457,7 +459,7 @@ //AT#VSTATE != "CHECKING" //AT#GPRSMODE == - return OK; + return CELL_OK; } Cellular::Code Cellular::echo(bool state) @@ -465,10 +467,10 @@ Code code; if (state) { code = sendBasicCommand("ATE0", 1000); - echoMode = (code == OK) ? false : echoMode; + echoMode = (code == CELL_OK) ? false : echoMode; } else { code = sendBasicCommand("ATE1", 1000); - echoMode = (code == OK) ? true : echoMode; + echoMode = (code == CELL_OK) ? true : echoMode; } return code; } @@ -523,24 +525,24 @@ { if(socketOpened) { printf("[ERROR] socket is open. Can not send AT commands\r\n"); - return ERROR; + return CELL_ERROR; } string response = sendCommand(command, timeoutMillis, esc); if (response.size() == 0) { - return NO_RESPONSE; + return CELL_NO_RESPONSE; } else if (response.find("OK") != string::npos) { - return OK; + return CELL_OK; } else if (response.find("ERROR") != string::npos) { - return ERROR; + return CELL_ERROR; } else { - return FAILURE; + return CELL_FAILURE; } } Cellular::Code Cellular::setApn(const std::string& apn) { Code code = sendBasicCommand("AT#APNSERV=\"" + apn + "\"", 1000); - if (code != OK) { + if (code != CELL_OK) { return code; } this->apn = apn; @@ -548,7 +550,7 @@ } Cellular::Code Cellular::setDns(const std::string& address) { - return FAILURE; + return CELL_FAILURE; } bool Cellular::ping(const std::string& address) { @@ -556,19 +558,19 @@ Code code; code = sendBasicCommand("AT#PINGREMOTE=\"" + address + "\"", 1000); - if (code != OK) { + if (code != CELL_OK) { return false; } sprintf(buffer, "AT#PINGNUM=%d", 1); code = sendBasicCommand(buffer , 1000); - if (code != OK) { + if (code != CELL_OK) { return false; } sprintf(buffer, "AT#PINGDELAY=%d", PINGDELAY); code = sendBasicCommand(buffer , 1000); - if (code != OK) { + if (code != CELL_OK) { return false; } @@ -584,17 +586,17 @@ Cellular::Code Cellular::setSocketCloseable(bool enabled) { if(socketCloseable == enabled) { - return OK; + return CELL_OK; } if(socketOpened) { printf("[ERROR] socket is already opened. Can not set closeable\r\n"); - return ERROR; + return CELL_ERROR; } socketCloseable = enabled; - return OK; + return CELL_OK; } Cellular::Code Cellular::sendSMS(const Sms& sms) { @@ -604,7 +606,7 @@ Cellular::Code Cellular::sendSMS(const std::string& phoneNumber, const std::string& message) { Code code = sendBasicCommand("AT+CMGF=1", 1000); - if (code != OK) { + if (code != CELL_OK) { return code; } string cmd = "AT+CMGS=\"+"; @@ -612,15 +614,15 @@ cmd.append("\""); string response1 = sendCommand(cmd, 1000); if (response1.find('>') == string::npos) { - return NO_RESPONSE; + return CELL_NO_RESPONSE; } wait(.2); string response2 = sendCommand(message, 4000, CTRL_Z); printf("SMS Response: %s\r\n", response2.c_str()); if (response2.find("+CMGS:") == string::npos) { - return FAILURE; + return CELL_FAILURE; } - return OK; + return CELL_OK; } std::vector<Cellular::Sms> Cellular::getReceivedSms() {