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
Revision 148:df9feef182b4, committed 2014-07-11
- Comitter:
- mfiore
- Date:
- Fri Jul 11 16:45:35 2014 +0000
- Parent:
- 146:efc4db23a564
- Child:
- 149:e0a437f61854
- Commit message:
- prepend status enum with "MTS_" to avoid conflicts with ST's SUCCESS, ERROR, etc
Changed in this revision
--- a/cellular/Cellular.cpp Mon Jan 20 15:33:54 2014 +0000 +++ b/cellular/Cellular.cpp Fri Jul 11 16:45:35 2014 +0000 @@ -89,7 +89,7 @@ reset(); test(); - return SUCCESS; + return MTS_SUCCESS; } @@ -161,7 +161,7 @@ } Code code = sendBasicCommand("AT#CONNECTIONSTOP", 10000); - if(code == SUCCESS) { + if(code == MTS_SUCCESS) { printf("[DEBUG] Successfully closed PPP Connection\r\n"); } else { printf("[ERROR] Closing PPP Connection [%d]. Continuing ...\r\n", (int)code); @@ -265,7 +265,7 @@ //Attempt to set local port sprintf(buffer, "AT#OUTPORT=%d", local_port); Code code = sendBasicCommand(buffer, 1000); - if(code != SUCCESS) { + if(code != MTS_SUCCESS) { printf("[WARNING] Unable to set local port (%d) [%d]\r\n", local_port, (int) code); } } @@ -274,7 +274,7 @@ if(mode == TCP) { if(socketCloseable) { Code code = sendBasicCommand("AT#DLEMODE=1,1", 1000); - if(code != SUCCESS) { + if(code != MTS_SUCCESS) { printf("[WARNING] Unable to set socket closeable [%d]\r\n", (int) code); } } @@ -284,7 +284,7 @@ } else { if(socketCloseable) { Code code = sendBasicCommand("AT#UDPDLEMODE=1", 1000); - if(code != SUCCESS) { + if(code != MTS_SUCCESS) { printf("[WARNING] Unable to set socket closeable [%d]\r\n", (int) code); } } @@ -293,13 +293,13 @@ addressCode = sendBasicCommand("AT#UDPSERV=\"" + address + "\"", 1000); } - if(portCode == SUCCESS) { + if(portCode == MTS_SUCCESS) { host_port = port; } else { printf("[ERROR] Host port could not be set\r\n"); } - if(addressCode == SUCCESS) { + if(addressCode == MTS_SUCCESS) { host_address = address; } else { printf("[ERROR] Host address could not be set\r\n"); @@ -564,7 +564,7 @@ { disconnect(); Code code = sendBasicCommand("AT#RESET=0", 10000); - if(code != SUCCESS) { + if(code != MTS_SUCCESS) { 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"); @@ -579,7 +579,7 @@ Code Cellular::test() { int i = 0; - while (sendBasicCommand("AT", 1000) != SUCCESS) { + while (sendBasicCommand("AT", 1000) != MTS_SUCCESS) { i++; if (i >= 30) { printf("[ERROR] Could not talk to radio after 30 tries\r\n"); @@ -587,7 +587,7 @@ } wait(1); } - return SUCCESS; + return MTS_SUCCESS; } Code Cellular::echo(bool state) @@ -595,10 +595,10 @@ Code code; if (state) { code = sendBasicCommand("ATE0", 1000); - echoMode = (code == SUCCESS) ? false : echoMode; + echoMode = (code == MTS_SUCCESS) ? false : echoMode; } else { code = sendBasicCommand("ATE1", 1000); - echoMode = (code == SUCCESS) ? true : echoMode; + echoMode = (code == MTS_SUCCESS) ? true : echoMode; } return code; } @@ -648,7 +648,7 @@ Code Cellular::setApn(const std::string& apn) { Code code = sendBasicCommand("AT#APNSERV=\"" + apn + "\"", 1000); - if (code != SUCCESS) { + if (code != MTS_SUCCESS) { return code; } this->apn = apn; @@ -667,19 +667,19 @@ Code code; code = sendBasicCommand("AT#PINGREMOTE=\"" + address + "\"", 1000); - if (code != SUCCESS) { + if (code != MTS_SUCCESS) { return false; } sprintf(buffer, "AT#PINGNUM=%d", 1); code = sendBasicCommand(buffer , 1000); - if (code != SUCCESS) { + if (code != MTS_SUCCESS) { return false; } sprintf(buffer, "AT#PINGDELAY=%d", PINGDELAY); code = sendBasicCommand(buffer , 1000); - if (code != SUCCESS) { + if (code != MTS_SUCCESS) { return false; } @@ -696,17 +696,17 @@ Code Cellular::setSocketCloseable(bool enabled) { if(socketCloseable == enabled) { - return SUCCESS; + return MTS_SUCCESS; } if(socketOpened) { printf("[ERROR] socket is already opened. Can not set closeable\r\n"); - return ERROR; + return MTS_ERROR; } socketCloseable = enabled; - return SUCCESS; + return MTS_SUCCESS; } Code Cellular::sendSMS(const Sms& sms) @@ -717,7 +717,7 @@ Code Cellular::sendSMS(const std::string& phoneNumber, const std::string& message) { Code code = sendBasicCommand("AT+CMGF=1", 1000); - if (code != SUCCESS) { + if (code != MTS_SUCCESS) { return code; } string cmd = "AT+CMGS=\"+"; @@ -725,15 +725,15 @@ cmd.append("\""); string response1 = sendCommand(cmd, 1000); if (response1.find('>') == string::npos) { - return NO_RESPONSE; + return MTS_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 MTS_FAILURE; } - return SUCCESS; + return MTS_SUCCESS; } std::vector<Cellular::Sms> Cellular::getReceivedSms() @@ -803,18 +803,18 @@ { if(socketOpened) { printf("[ERROR] socket is open. Can not send AT commands\r\n"); - return ERROR; + return MTS_ERROR; } string response = sendCommand(command, timeoutMillis, esc); if (response.size() == 0) { - return NO_RESPONSE; + return MTS_NO_RESPONSE; } else if (response.find("OK") != string::npos) { - return SUCCESS; + return MTS_SUCCESS; } else if (response.find("ERROR") != string::npos) { - return ERROR; + return MTS_ERROR; } else { - return FAILURE; + return MTS_FAILURE; } }
--- a/utils/Vars.h Mon Jan 20 15:33:54 2014 +0000 +++ b/utils/Vars.h Fri Jul 11 16:45:35 2014 +0000 @@ -33,7 +33,7 @@ /// An enumeration for common responses. enum Code { - SUCCESS, ERROR, FAILURE, NO_RESPONSE + MTS_SUCCESS, MTS_ERROR, MTS_FAILURE, MTS_NO_RESPONSE }; /** A static method for getting a string representation for the Code @@ -45,13 +45,13 @@ static std::string getCodeNames(Code code) { switch(code) { - case SUCCESS: + case MTS_SUCCESS: return "SUCCESS"; - case ERROR: + case MTS_ERROR: return "ERROR"; - case NO_RESPONSE: + case MTS_NO_RESPONSE: return "NO_RESPONSE"; - case FAILURE: + case MTS_FAILURE: return "FAILURE"; default: return "UNKNOWN ENUM";
--- a/wifi/Wifi.cpp Mon Jan 20 15:33:54 2014 +0000 +++ b/wifi/Wifi.cpp Fri Jul 11 16:45:35 2014 +0000 @@ -67,36 +67,36 @@ } //Set device to non-echo mode - while (sendBasicCommand("set uart mode 1", 1000) != SUCCESS) { + while (sendBasicCommand("set uart mode 1", 1000) != MTS_SUCCESS) { printf("[ERROR] Failed to set to non-echo mode\n\r"); //return false; } // do this twice because the module response doesnt seem to always take - while (sendBasicCommand("set uart mode 1", 1000) != SUCCESS) { + while (sendBasicCommand("set uart mode 1", 1000) != MTS_SUCCESS) { printf("[ERROR] Failed to set to non-echo mode\n\r"); //return false; } //Set device to manual infrastructure mode - if (sendBasicCommand("set wlan join 0", 1000) != SUCCESS) { + if (sendBasicCommand("set wlan join 0", 1000) != MTS_SUCCESS) { printf("[ERROR] Failed to set join mode\n\r"); return false; } //Set device to channel auto-scanning mode - if (sendBasicCommand("set wlan channel 0", 1000) != SUCCESS) { + if (sendBasicCommand("set wlan channel 0", 1000) != MTS_SUCCESS) { printf("[ERROR] Failed to set auto-scanning mode\n\r"); return false; } //Set device so no data is transmitted immediately following a socket connection - if (sendBasicCommand("set comm remote 0", 1000) != SUCCESS) { + if (sendBasicCommand("set comm remote 0", 1000) != MTS_SUCCESS) { printf("[ERROR] Failed to set remote transmit mode\n\r"); return false; } //Set device into DHCP mode by default - if (sendBasicCommand("set ip dhcp 1", 1000) != SUCCESS) { + if (sendBasicCommand("set ip dhcp 1", 1000) != MTS_SUCCESS) { printf("[ERROR] Failed to set to default DHCP mode\n\r"); return false; } @@ -290,14 +290,14 @@ //Attempt to set local port sprintf(buffer, "set ip localport %d", local_port); Code code = sendBasicCommand(buffer, 1000); - if(code != SUCCESS) { + if(code != MTS_SUCCESS) { printf("[WARNING] Unable to set local port (%d) [%d]. Continuing...\r\n", local_port, (int) code); } } //Set TCP/UDP parameters sprintf(buffer, "set ip remote %d", port); - if(sendBasicCommand(buffer, 1000) == SUCCESS) { + if(sendBasicCommand(buffer, 1000) == MTS_SUCCESS) { host_port = port; } else { printf("[ERROR] Host port could not be set\r\n"); @@ -318,12 +318,12 @@ //Set Address printf("[DEBUG] Host address: %s\n\r", host_address.c_str()); - if(sendBasicCommand("set ip host " + host_address, 1000) != SUCCESS) { + if(sendBasicCommand("set ip host " + host_address, 1000) != MTS_SUCCESS) { printf("[ERROR] Host address could not be set\r\n"); return false; } - if(sendBasicCommand("set ip protocol 8", 1000) != SUCCESS) { + if(sendBasicCommand("set ip protocol 8", 1000) != MTS_SUCCESS) { printf("[ERROR] Failed to set TCP mode\r\n"); return false; } @@ -525,7 +525,7 @@ //Check for command mode if(!setCmdMode(true)) { printf("[ERROR] Failed to set IP due to mode issue\r\n"); - return FAILURE; + return MTS_FAILURE; } //Set to DHCP mode @@ -535,15 +535,15 @@ //Set to static mode and set address Code code = sendBasicCommand("set ip address " + address, 1000); - if(code != SUCCESS) { + if(code != MTS_SUCCESS) { return code; } code = sendBasicCommand("set ip dhcp 0", 1000); - if(code != SUCCESS) { + if(code != MTS_SUCCESS) { return code; } local_address = address; - return SUCCESS; + return MTS_SUCCESS; } std::string Wifi::getDeviceIP() @@ -555,14 +555,14 @@ { //Check the command mode if(!setCmdMode(true)) { - return FAILURE; + return MTS_FAILURE; } Code code; //Set the appropraite SSID code = sendBasicCommand("set wlan ssid " + ssid, 1000); - if (code != SUCCESS) { + if (code != MTS_SUCCESS) { return code; } @@ -570,26 +570,26 @@ if (type == WEP64 || type == WEP128) { //Set the WEP key if using WEP encryption code = sendBasicCommand("set wlan key " + key, 1000); - if (code != SUCCESS) { + if (code != MTS_SUCCESS) { return code; } } else if (type == WPA || type == WPA2) { //Set the WPA key if using WPA encryption code = sendBasicCommand("set wlan phrase " + key, 1000); - if (code != SUCCESS) { + if (code != MTS_SUCCESS) { return code; } } _ssid = ssid; - return SUCCESS; + return MTS_SUCCESS; } Code Wifi::setDNS(const std::string& dnsName) { //Check the command mode if(!setCmdMode(true)) { - return FAILURE; + return MTS_FAILURE; } return sendBasicCommand("set dns name " + dnsName, 1000); @@ -687,19 +687,19 @@ { if(socketOpened) { printf("[ERROR] socket is open. Can not send AT commands\r\n"); - return ERROR; + return MTS_ERROR; } string response = sendCommand(command, timeoutMillis, "AOK", esc); //printf("Response: %s\n\r", response.c_str()); if (response.size() == 0) { - return NO_RESPONSE; + return MTS_NO_RESPONSE; } else if (response.find("AOK") != string::npos) { - return SUCCESS; + return MTS_SUCCESS; } else if (response.find("ERR") != string::npos) { - return ERROR; + return MTS_ERROR; } else { - return FAILURE; + return MTS_FAILURE; } }