Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MTS-Cellular by
Diff: Cellular/Cellular.cpp
- Revision:
- 56:43205bd2752a
- Parent:
- 55:85c04afa939a
- Child:
- 59:5535f14e3cc4
--- a/Cellular/Cellular.cpp Mon Aug 11 21:01:50 2014 +0000
+++ b/Cellular/Cellular.cpp Wed Aug 13 16:46:10 2014 +0000
@@ -211,7 +211,7 @@
if(result.size() > (command.size() + 2)) {
if(result.find("OK\r\n",command.size()) != std::string::npos) {
done = true;
- } else if (result.find("ERROR\r\n") != std::string::npos) {
+ } else if (result.find("ERROR") != std::string::npos) {
done = true;
} else if (result.find("NO CARRIER\r\n") != std::string::npos) {
done = true;
@@ -260,7 +260,7 @@
return MTS_FAILURE;
}
- Code code = sendBasicCommand("AT+CMGF=1", 1000);
+ Code code = sendBasicCommand("AT+CMGF=1", 2000);
if (code != MTS_SUCCESS) {
logError("CMGF failed");
return code;
@@ -289,7 +289,7 @@
}
wait(.2);
- string response2 = sendCommand(message, 12000, CTRL_Z);
+ string response2 = sendCommand(message, 15000, CTRL_Z);
if (response2.find("+CMGS:") == string::npos) {
logError("CMGS message failed");
return MTS_FAILURE;
@@ -305,7 +305,7 @@
std::string received;
size_t pos;
- Code code = sendBasicCommand("AT+CMGF=1", 1000);
+ Code code = sendBasicCommand("AT+CMGF=1", 2000);
if (code != MTS_SUCCESS) {
logError("CMGF failed");
return vSms;
@@ -322,7 +322,7 @@
}
//Start of SMS message
std::vector<std::string> vSmsParts = Text::split(line, ',');
- if (type == MTSMC_H5_IP || type == MTSMC_H5) {
+ if (type == MTSMC_H5_IP || type == MTSMC_H5 || type == MTSMC_G3) {
/* format for H5 and H5-IP radios
* <index>, <status>, <oa>, <alpha>, <scts>
* scts contains a comma, so splitting on commas should give us 6 items
@@ -388,3 +388,102 @@
{
return sendBasicCommand("AT+CMGD=1,4", 1000);
}
+
+unsigned int Cellular::readable()
+{
+ if(io == NULL) {
+ logWarning("MTSBufferedIO not set");
+ return 0;
+ }
+ if(!socketOpened && !io->readable()) {
+ logWarning("Socket is not open");
+ return 0;
+ }
+ return io->readable();
+}
+
+unsigned int Cellular::writeable()
+{
+ if(io == NULL) {
+ logWarning("MTSBufferedIO not set");
+ return 0;
+ }
+ if(!socketOpened) {
+ logWarning("Socket is not open");
+ return 0;
+ }
+
+ return io->writeable();
+}
+
+bool Cellular::setDeviceIP(std::string address)
+{
+ if (address.compare("DHCP") == 0) {
+ return true;
+ } else {
+ logWarning("Radio does not support static IPs, using DHCP.");
+ return false;
+ }
+}
+
+std::string Cellular::getDeviceIP()
+{
+ return local_address;
+}
+
+//Turns off echo when it receives a true, turns on when it receives false
+Code Cellular::echo(bool state)
+{
+ Code code;
+ if (state) {
+ code = sendBasicCommand("ATE0", 1000);
+ echoMode = (code == MTS_SUCCESS) ? false : echoMode;
+ } else {
+ code = sendBasicCommand("ATE1", 1000);
+ echoMode = (code == MTS_SUCCESS) ? true : echoMode;
+ }
+ return code;
+}
+
+//Pass 1 to enable socket closeable
+//Pass 0 to disable socket closeable
+Code Cellular::setSocketCloseable(bool enabled)
+{
+ if(socketCloseable == enabled) {
+ return MTS_SUCCESS;
+ }
+
+ if(socketOpened) {
+ logError("socket is already opened. Can not set closeable");
+ return MTS_ERROR;
+ }
+
+ socketCloseable = enabled;
+
+ return MTS_SUCCESS;
+}
+
+bool Cellular::isOpen()
+{
+ if(io->readable()) {
+ logDebug("Assuming open, data available to read.");
+ return true;
+ }
+ return socketOpened;
+}
+
+//Binds the socket to a specific port if able
+bool Cellular::bind(unsigned int port)
+{
+ if(socketOpened) {
+ logError("socket is open. Can not set local port");
+ return false;
+ }
+ if(port > 65535) {
+ logError("port out of range (0-65535)");
+ return false;
+ }
+ local_port = port;
+ return true;
+}
+
