From ccd41677d998134ff501a8d6ac3a154dcaca9321 Mon Sep 17 00:00:00 2001 From: Andrii Pientsov Date: Mon, 13 Jul 2020 15:29:38 +0300 Subject: MTX-3404 Code Review --- src/MTS_IO_QuectelRadio.cpp | 75 +-------------------------------------------- 1 file changed, 1 insertion(+), 74 deletions(-) (limited to 'src/MTS_IO_QuectelRadio.cpp') diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 22374ee..bb81621 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -31,7 +31,6 @@ using namespace MTS::IO; -const size_t QuectelRadio::FILE_CHUNK_SIZE = 1024; const std::string QuectelRadio::CMD_ABORT_UPLOAD = "+++"; // It is strongly recommended to use DOS 8.3 file name format for . @@ -603,7 +602,7 @@ ICellularRadio::CODE QuectelRadio::fumoLocalApply(ICellularRadio::UpdateCb& step sCmd += VALUE_MTS_DELTA_PATH; sCmd += "\""; - rc = sendBasicCommand(sCmd, 1000); + rc = sendBasicCommand(sCmd, 10000); if (rc != SUCCESS) { printError("FUMO failed, OK not received from the radio"); @@ -985,78 +984,6 @@ uint16_t QuectelRadio::getQuectelChecksum(const void* data, size_t nBytes) { return iChecksum; } -ICellularRadio::CODE QuectelRadio::getFileSize(int fd, size_t& nBytes, size_t& nChunks) { - CODE rc = FAILURE; - - do { - ssize_t dScrollPos; - dScrollPos = lseek(fd, 0, SEEK_SET); - if (dScrollPos < 0) { - printError("Failed to seek to the start of the file: %d", errno); - break; - } - - dScrollPos = lseek(fd, 0, SEEK_END); - if (dScrollPos < 0) { - printError("Failed to determine the file size: %d", errno); - break; - } - - nBytes = static_cast(dScrollPos); - nChunks = (nBytes + FILE_CHUNK_SIZE - 1) / FILE_CHUNK_SIZE; // round up - - rc = SUCCESS; - - } while (false); - - lseek(fd, 0, SEEK_SET); - return rc; -} - -ICellularRadio::CODE QuectelRadio::readChunk(int fd, char* pChunk, size_t dChunkSize, size_t& nReadBytes) { - size_t nUsedBuffer = 0; - CODE rc = FAILURE; - - while (true) { - - if (nUsedBuffer > dChunkSize) { - printError("Internal pointer error, abort upload: %d", nUsedBuffer); - rc = ERROR; - break; - } - - if (nUsedBuffer == dChunkSize) { - // full chunk received - rc = SUCCESS; - nReadBytes = dChunkSize; - break; - } - - char* pData = pChunk + nUsedBuffer; - size_t nFreeBuffer = dChunkSize - nUsedBuffer; - - ssize_t dReadCount = read(fd, pData, nFreeBuffer); - if (dReadCount < 0) { - printError("Failed to read from the source file: %d", errno); - rc = ERROR; - break; - } - - size_t duReadCount = static_cast(dReadCount); - if (duReadCount == 0) { - // EOF. Return what was already read - nReadBytes = nUsedBuffer; - rc = SUCCESS; - break; - } - - nUsedBuffer += duReadCount; - - } - - return rc; -} - ICellularRadio::CODE QuectelRadio::fumoWaitUpgradeFinished(ICellularRadio::UpdateCb& stepCb) { const uint32_t duUrcTimeout = 4 * 60 * 1000; // wait for 4 minutes for the next URC message const std::string sFotaUrcPrefix = "+QIND: \"FOTA\""; // prefix for the URC notification messages -- cgit v1.2.3 From 8186f98913c55191b5a3610d19c8580c6a86c2f4 Mon Sep 17 00:00:00 2001 From: Andrii Pientsov Date: Wed, 15 Jul 2020 13:49:59 +0300 Subject: MTX-3404 Code Review --- src/MTS_IO_QuectelRadio.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/MTS_IO_QuectelRadio.cpp') diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index bb81621..2d1ffcd 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -31,6 +31,7 @@ using namespace MTS::IO; +const size_t QuectelRadio::FILE_CHUNK_SIZE = 1024; const std::string QuectelRadio::CMD_ABORT_UPLOAD = "+++"; // It is strongly recommended to use DOS 8.3 file name format for . @@ -836,10 +837,16 @@ ICellularRadio::CODE QuectelRadio::uploadFile(int fd, const std::string& sTarget size_t nChunks; CODE rc; - rc = getFileSize(fd, dPayloadLength, nChunks); + rc = getFileSize(fd, dPayloadLength); if (rc != SUCCESS) { return rc; } + + rc = sizeToChunks(dPayloadLength, FILE_CHUNK_SIZE, nChunks); + if (rc != SUCCESS) { + return rc; + } + printTrace("File size: %d bytes and %d chunks", dPayloadLength, nChunks); printTrace("Starting file upload..."); -- cgit v1.2.3