diff options
author | Serhii Kostiuk <serhii.o.kostiuk@globallogic.com> | 2020-07-15 06:06:43 -0500 |
---|---|---|
committer | Serhii Kostiuk <serhii.o.kostiuk@globallogic.com> | 2020-07-15 06:06:43 -0500 |
commit | f0be0e4a343f9a600fe8c9fc34fa580c548a4e9e (patch) | |
tree | 34daf8e9219c894ca36dd1f7ddf4560aa395c659 /src/MTS_IO_CellularRadio.cpp | |
parent | b4b5e4958a11cc9e969355f60e08d0631b01c402 (diff) | |
parent | 8186f98913c55191b5a3610d19c8580c6a86c2f4 (diff) | |
download | libmts-io-f0be0e4a343f9a600fe8c9fc34fa580c548a4e9e.tar.gz libmts-io-f0be0e4a343f9a600fe8c9fc34fa580c548a4e9e.tar.bz2 libmts-io-f0be0e4a343f9a600fe8c9fc34fa580c548a4e9e.zip |
Merge branch 'ap/l4e1-delta-fwu' into 'delta-radio-fwu'
MTX-3404 mPower Oct20: Delta Radio Firmware Upgrade - L4E1 - libmts-io support
See merge request !28
Diffstat (limited to 'src/MTS_IO_CellularRadio.cpp')
-rw-r--r-- | src/MTS_IO_CellularRadio.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index bb7cd40..c4514e6 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -1262,3 +1262,79 @@ const char *CellularRadio::RadioBandMap::getRadioBandName(const std::string &cha return band; } + +ICellularRadio::CODE CellularRadio::getFileSize(int fd, size_t& nBytes) { + 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<size_t>(dScrollPos); + + rc = SUCCESS; + + } while (false); + + lseek(fd, 0, SEEK_SET); + return rc; +} + +ICellularRadio::CODE CellularRadio::sizeToChunks(const size_t nBytes, const size_t chunkSize, size_t& nChunks) { + nChunks = (nBytes + chunkSize - 1) / chunkSize; + return SUCCESS; +} + +ICellularRadio::CODE CellularRadio::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<size_t>(dReadCount); + if (duReadCount == 0) { + // EOF. Return what was already read + nReadBytes = nUsedBuffer; + rc = SUCCESS; + break; + } + + nUsedBuffer += duReadCount; + + } + + return rc; +} |