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 110:8f3149c99112, committed 2013-12-31
- Comitter:
- sgodinez
- Date:
- Tue Dec 31 17:30:07 2013 +0000
- Parent:
- 104:93f448577daf
- Child:
- 111:d1c563341d84
- Commit message:
- Improved robustness of close() call
Changed in this revision
--- a/cellular/Cellular.cpp Mon Dec 30 23:57:23 2013 +0000 +++ b/cellular/Cellular.cpp Tue Dec 31 17:30:07 2013 +0000 @@ -161,10 +161,25 @@ return true; } //2) Query the radio - pppConnected = false; - std::string result = sendCommand("AT#VSTATE", 1000); + std::string result = sendCommand("AT#VSTATE", 3000); if(result.find("CONNECTED") != std::string::npos) { + if(pppConnected == false) { + printf("[WARNING] Internal PPP state tracking differs from radio (DISCONNECTED:CONNECTED)\r\n"); + } pppConnected = true; + } else { + if(pppConnected == true) { + //Find out what state is + size_t pos = result.find("STATE:"); + if(pos != std::string::npos) { + result = Text::getLine(result, pos + sizeof("STATE:"), pos); + printf("[WARNING] Internal PPP state tracking differs from radio (CONNECTED:%s)\r\n", result.c_str()); + } else { + printf("[ERROR] Unable to parse radio state: [%s]\r\n", result.c_str()); + } + + } + pppConnected = false; } return pppConnected; @@ -312,24 +327,27 @@ return false; } - Timer tmr; - int timeout = 1000; - int written = 0; - tmr.start(); - do { - written = io->write(ETX); - if(written < 0) { - printf("[ERROR] Failed to write to MTSBufferedIO\r\n"); - return false; - } - wait(0.05); - } while(tmr.read_ms() <= timeout && written != 1); - - if(written != 1) { + + + if(io->write(ETX, 1000) != 1) { printf("[ERROR] Timed out attempting to close socket\r\n"); return false; } - + + Timer tmr; + int counter = 0; + char tmp[256]; + tmr.start(); + do { + if(socketOpened == false) { + break; + } + read(tmp, 256, 1000); + } while(counter++ < 10); + + io->rxClear(); + io->txClear(); + socketOpened = false; return true; } @@ -834,7 +852,7 @@ done = (result.size() == previous); } if(timer >= timeoutMillis) { - printf("[WARNING] sendCommand timed out after %d milliseconds\r\n", timeoutMillis); + printf("[WARNING] sendCommand [%s] timed out after %d milliseconds\r\n", command.c_str(), timeoutMillis); done = true; } } while (!done);
--- a/io/MTSBufferedIO.cpp Mon Dec 30 23:57:23 2013 +0000 +++ b/io/MTSBufferedIO.cpp Tue Dec 31 17:30:07 2013 +0000 @@ -20,6 +20,7 @@ int bytesWritten = 0; Timer tmr; tmr.start(); + length = MAX(0,length); do { int bytesWrittenSwBuffer = txBuffer.write(&data[bytesWritten], length - bytesWritten); if(bytesWrittenSwBuffer > 0) { @@ -36,6 +37,7 @@ { //Blocks until all bytes are written (different implementation planned once tx isr is working) int bytesWritten = 0; + length = MAX(0,length); do { int bytesWrittenSwBuffer = txBuffer.write(&data[bytesWritten], length - bytesWritten); handleWrite(); @@ -65,6 +67,7 @@ int bytesRead = 0; Timer tmr; tmr.start(); + length = MAX(0,length); do { bytesRead += rxBuffer.read(&data[bytesRead], length - bytesRead); } while(tmr.read_ms() <= timeoutMillis && bytesRead < length); @@ -74,6 +77,7 @@ int MTSBufferedIO::read(char* data, int length) { int bytesRead = 0; + length = MAX(0,length); while(bytesRead < length) { bytesRead += rxBuffer.read(&data[bytesRead], length - bytesRead); }
--- a/io/MTSSerialFlowControl.cpp Mon Dec 30 23:57:23 2013 +0000 +++ b/io/MTSSerialFlowControl.cpp Tue Dec 31 17:30:07 2013 +0000 @@ -31,7 +31,7 @@ if(!rxReadyFlag) { rts.write(0); rxReadyFlag = true; - //printf("RTS LOW: START SENDING US BYTES - RX[%d/%d]\r\n", rxBuffer.size(), rxBuffer.capacity()); + //printf("RTS LOW: READY - RX[%d/%d]\r\n", rxBuffer.size(), rxBuffer.capacity()); } } @@ -40,7 +40,7 @@ if(rxReadyFlag) { rts.write(1); rxReadyFlag = false; - //printf("RTS HIGH: STOP SENDING US BYTES - RX[%d/%d]\r\n", rxBuffer.size(), rxBuffer.capacity()); + //printf("RTS HIGH: NOT-READY - RX[%d/%d]\r\n", rxBuffer.size(), rxBuffer.capacity()); } } @@ -49,8 +49,10 @@ while (serial.readable()) { char byte = serial.getc(); if(rxBuffer.write(byte) != 1) { + rts.write(1); + rxReadyFlag = false; printf("[ERROR] Serial Rx Byte Dropped [%c][0x%02X]\r\n", byte, byte); - notifyStopSending(); + return; } if (rxBuffer.size() > highThreshold) { notifyStopSending();