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:
- 41:81d035fb0b6a
- Parent:
- 35:f28acb1be52d
- Child:
- 43:3cacf019ed7d
--- a/cellular/Cellular.cpp Thu Dec 19 15:56:05 2013 +0000 +++ b/cellular/Cellular.cpp Thu Dec 19 21:16:30 2013 +0000 @@ -18,8 +18,9 @@ Cellular* Cellular::getInstance(MTSBufferedIO* io) { if(instance == NULL) { instance = new Cellular(io); + } else { + instance->io = io; } - instance->io = io; return instance; } @@ -29,7 +30,7 @@ , pppConnected(false) , mode(TCP) , socketOpened(false) -, socketCloseable(false) +, socketCloseable(true) , local_port(0) , host_port(0) { @@ -144,6 +145,16 @@ //1) Check that we do not have a live connection up if(socketOpened) { + //Check that the address, port, and mode match + if(host_address != address || host_port != port || this->mode != mode) { + if(this->mode == TCP) { + printf("[ERROR] TCP socket already opened (%s:%d)\r\n", host_address.c_str(), host_port); + } else { + printf("[ERROR] UDP socket already opened (%s:%d)\r\n", host_address.c_str(), host_port); + } + return false; + } + printf("[DEBUG] Socket already opened\r\n"); return true; } @@ -323,7 +334,7 @@ return bytesRead; } -int Cellular::write(char* data, int length, int timeout) { +int Cellular::write(const char* data, int length, int timeout) { if(io == NULL) { printf("[ERROR] MTSBufferedIO not set\r\n"); return -1; @@ -547,8 +558,8 @@ return code; } -Cellular::Code Cellular::setDns(const std::string& address) { - return FAILURE; +Cellular::Code Cellular::setDns(const std::string& primary, const std::string& secondary) { + return sendBasicCommand("AT#DNS=1," + primary + "," + secondary, 1000); } bool Cellular::ping(const std::string& address) {