ublox-cellular-driver-gen Fork
Fork of ublox-cellular-driver-gen by
Diff: UbloxCellularDriverGen.cpp
- Revision:
- 5:b935404dcf7c
- Parent:
- 4:4f2c12992e17
- Child:
- 7:a9eea2dbdd68
--- a/UbloxCellularDriverGen.cpp Tue Jun 13 10:45:14 2017 +0100 +++ b/UbloxCellularDriverGen.cpp Thu Jun 15 01:14:18 2017 +0100 @@ -90,7 +90,7 @@ // +CCWA: <status>[, <class>] numChars = read_at_to_char(buf, sizeof (buf), '\n'); if (numChars > 0) { - if (sscanf(buf, ": %d, %d", &a, &b) > 0) { + if (sscanf(buf, ": %d,%d", &a, &b) > 0) { if (_ssUrcBuf == NULL) { _ssUrcBuf = (char *) malloc(numChars + 5 + 1); if (_ssUrcBuf != NULL) { @@ -413,7 +413,7 @@ // by +CMT, should it ever occur _at->oob("+CMTI:", callback(this, &UbloxCellularDriverGen::CMTI_URC)); - // URCs relater to supplementary services + // URCs related to supplementary services _at->oob("+CCWA", callback(this, &UbloxCellularDriverGen::CCWA_URC)); _at->oob("+CCFC", callback(this, &UbloxCellularDriverGen::CCFC_URC)); _at->oob("+CLIR", callback(this, &UbloxCellularDriverGen::CLIR_URC)); @@ -554,12 +554,12 @@ // Wait for either +CUSD to come back or // one of the other SS related URCs to trigger if (_ssUrcBuf != NULL) { - free (_ssUrcBuf); + free(_ssUrcBuf); _ssUrcBuf = NULL; } timer.start(); _at->set_timeout(1000); - while (!success && (timer.read_ms() < atTimeout)) { + while (!success && (timer.read_ms() < 30000)) { if (_at->recv("+CUSD: %*d,\"")) { // Note: don't wait for "OK" here as the +CUSD response may come // before or after the OK @@ -641,6 +641,7 @@ int blockSize = FILE_BUFFER_SIZE; char respFilename[48 + 1]; int sz, sz_read; + char * endQuote; bool success = true; int ch = 0; int timeLimit; @@ -664,34 +665,46 @@ if (blockSize > 0) { if (_at->send("AT+URDBLOCK=\"%s\",%d,%d\r\n", filename, offset, blockSize) && - _at->recv("+URDBLOCK: \"%48[^\"]\",%d,\"", respFilename, &sz) && - (strcmp(filename, respFilename) == 0)) { + _at->recv("+URDBLOCK: %48[^,],%d,\"", respFilename, &sz)) { + // On some modules the response filename is not in quotes, + // on others it is, so strip them here + if ((*respFilename == '"') && ((endQuote = strchr(respFilename + 1, '"')) != NULL)) { + memcpy (respFilename, respFilename + 1, endQuote - respFilename - 1); + *(endQuote - 1) = 0; + } + if (strcmp(filename, respFilename) == 0) { + // Would use _at->read() here, but if it runs ahead of the + // serial stream it returns -1 instead of the number of characters + // read so far, which is not very helpful so instead use _at->getc() and + // a time limit. The time limit is three times the amount of time it + // should take to read the block at the working baud rate with a minimum + // of 10 ms (for short files) + timer.reset(); + timer.start(); + timeLimit = blockSize * 3 / ((MBED_CONF_UBLOX_CELL_BAUD_RATE / 8) / 1000); + if (timeLimit < 10) { + timeLimit = 10; + } + sz_read = 0; + while ((sz_read < blockSize) && (timer.read_ms() < timeLimit)) { + ch = _at->getc(); + if (ch >= 0) { + *buf = ch; + buf++; + sz_read++; + } + } + timer.stop(); - // Would use _at->read() here, but if it runs ahead of the - // serial stream it returns -1 instead of the number of characters - // read so far, which is not very helpful so instead use _at->getc() and - // a time limit. The time limit is twice the amount of time it should take to - // read the block at the working baud rate - timer.reset(); - timer.start(); - timeLimit = blockSize * 2 / ((MBED_CONF_UBLOX_CELL_BAUD_RATE / 8) / 1000); - sz_read = 0; - while ((sz_read < blockSize) && (timer.read_ms() < timeLimit)) { - ch = _at->getc(); - if (ch >= 0) { - *buf = ch; - buf++; - sz_read++; + if (sz_read == blockSize) { + bytesToRead -= sz_read; + offset += sz_read; + _at->recv("OK"); + } else { + debug_if(_debug_trace_on, "blockSize %d but only received %d bytes\n", blockSize, sz_read); + success = false; } - } - timer.stop(); - - if (sz_read == blockSize) { - bytesToRead -= sz_read; - offset += sz_read; - _at->recv("OK"); } else { - debug_if(_debug_trace_on, "blockSize %d but only received %d bytes\n", blockSize, sz_read); success = false; } } else {