summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrii Pientsov <andrii.pientsov@globallogic.com>2020-07-15 13:49:59 +0300
committerAndrii Pientsov <andrii.pientsov@globallogic.com>2020-07-15 13:49:59 +0300
commit8186f98913c55191b5a3610d19c8580c6a86c2f4 (patch)
tree34daf8e9219c894ca36dd1f7ddf4560aa395c659
parentccd41677d998134ff501a8d6ac3a154dcaca9321 (diff)
downloadlibmts-io-8186f98913c55191b5a3610d19c8580c6a86c2f4.tar.gz
libmts-io-8186f98913c55191b5a3610d19c8580c6a86c2f4.tar.bz2
libmts-io-8186f98913c55191b5a3610d19c8580c6a86c2f4.zip
MTX-3404 Code Review
-rw-r--r--include/mts/MTS_IO_CellularRadio.h4
-rw-r--r--include/mts/MTS_IO_QuectelRadio.h1
-rw-r--r--include/mts/MTS_IO_TelitRadio.h1
-rw-r--r--src/MTS_IO_CellularRadio.cpp8
-rw-r--r--src/MTS_IO_QuectelRadio.cpp9
-rw-r--r--src/MTS_IO_TelitRadio.cpp39
6 files changed, 41 insertions, 21 deletions
diff --git a/include/mts/MTS_IO_CellularRadio.h b/include/mts/MTS_IO_CellularRadio.h
index 6b23986..57a4de6 100644
--- a/include/mts/MTS_IO_CellularRadio.h
+++ b/include/mts/MTS_IO_CellularRadio.h
@@ -217,8 +217,8 @@ namespace MTS {
std::string m_sRadioType;
};
- static const size_t FILE_CHUNK_SIZE = 1024;
- static CODE getFileSize(int fd, size_t& nBytes, size_t& nFileChunks);
+ static CODE getFileSize(int fd, size_t& nBytes);
+ static CODE sizeToChunks(const size_t nBytes, const size_t chunkSize, size_t& nChunks);
static CODE readChunk(int fd, char* pChunk, size_t dChunkSize, size_t& nReadBytes);
private:
diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h
index 2121f7c..6e7372b 100644
--- a/include/mts/MTS_IO_QuectelRadio.h
+++ b/include/mts/MTS_IO_QuectelRadio.h
@@ -67,6 +67,7 @@ namespace MTS {
// private variable to save old firmware versions during FOTA
std::string m_sQuectelFirmware;
+ static const size_t FILE_CHUNK_SIZE;
static const std::string CMD_ABORT_UPLOAD;
static const std::string VALUE_MTS_DELTA_NAME;
static const std::string VALUE_MTS_DELTA_PATH;
diff --git a/include/mts/MTS_IO_TelitRadio.h b/include/mts/MTS_IO_TelitRadio.h
index fdf8a20..a3425f9 100644
--- a/include/mts/MTS_IO_TelitRadio.h
+++ b/include/mts/MTS_IO_TelitRadio.h
@@ -76,6 +76,7 @@ namespace MTS {
// private variable to save old firmware versions during FOTA
std::string m_sTelitFirmware;
+ static const size_t FILE_CHUNK_SIZE;
static const std::string CMD_ABORT_UPLOAD;
CODE getTelitFirmware(std::string& sFirmware);
diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp
index 0acf607..c4514e6 100644
--- a/src/MTS_IO_CellularRadio.cpp
+++ b/src/MTS_IO_CellularRadio.cpp
@@ -1263,7 +1263,7 @@ const char *CellularRadio::RadioBandMap::getRadioBandName(const std::string &cha
return band;
}
-ICellularRadio::CODE CellularRadio::getFileSize(int fd, size_t& nBytes, size_t& nChunks) {
+ICellularRadio::CODE CellularRadio::getFileSize(int fd, size_t& nBytes) {
CODE rc = FAILURE;
do {
@@ -1281,7 +1281,6 @@ ICellularRadio::CODE CellularRadio::getFileSize(int fd, size_t& nBytes, size_t&
}
nBytes = static_cast<size_t>(dScrollPos);
- nChunks = (nBytes + FILE_CHUNK_SIZE - 1) / FILE_CHUNK_SIZE; // round up
rc = SUCCESS;
@@ -1291,6 +1290,11 @@ ICellularRadio::CODE CellularRadio::getFileSize(int fd, size_t& nBytes, size_t&
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;
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 <filename>.
@@ -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...");
diff --git a/src/MTS_IO_TelitRadio.cpp b/src/MTS_IO_TelitRadio.cpp
index 86c3565..52b5664 100644
--- a/src/MTS_IO_TelitRadio.cpp
+++ b/src/MTS_IO_TelitRadio.cpp
@@ -28,6 +28,7 @@
using namespace MTS::IO;
+const size_t TelitRadio::FILE_CHUNK_SIZE = 1024;
const std::string TelitRadio::CMD_ABORT_UPLOAD = "+++";
@@ -855,10 +856,16 @@ ICellularRadio::CODE TelitRadio::fumoWriteGroupsABD(int fd, ICellularRadio::Upda
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...");
@@ -927,25 +934,25 @@ ICellularRadio::CODE TelitRadio::abortWrite() {
* 2) Input “+++” within 1s, and no other characters can be inputted during the time.
* 3) Do not input any character within 1s after “+++” has been inputted.
*/
- sleep(1);
- return sendBasicCommand(CMD_ABORT_UPLOAD, 2000, 0x00);
+ sleep(1);
+ return sendBasicCommand(CMD_ABORT_UPLOAD, 2000, 0x00);
}
ICellularRadio::CODE TelitRadio::getTelitFirmware(std::string& sFirmware) {
/*
- * Currently, AT+CGMR command is used to determine the radio firmware version.
- *
- * AT+CGMR
+ * Currently, AT+CGMR command is used to determine the radio firmware version.
+ *
+ * AT+CGMR
+ * M0F.670006
+ *
+ * Perhaps in the future we will use AT#SWPKGV command.
+ *
+ * AT#SWPKGV
+ * 25.20.676-P0F.670690
* M0F.670006
- *
- * Perhaps in the future we will use AT#SWPKGV command.
- *
- * AT#SWPKGV
- * 25.20.676-P0F.670690
- * M0F.670006
- * P0F.670690
- * A0F.670006
- */
+ * P0F.670690
+ * A0F.670006
+ */
printTrace("%s| Get Telit-specific firmware version", getName().c_str());
sFirmware = ICellularRadio::VALUE_NOT_SUPPORTED;
@@ -968,7 +975,7 @@ ICellularRadio::CODE TelitRadio::getTelitFirmware(std::string& sFirmware) {
ICellularRadio::CODE TelitRadio::fumoWaitUpgradeFinished(ICellularRadio::UpdateCb& stepCb) {
const uint32_t duAttachTimeout = 300000; // wait for 300 seconds for the radio to attach
- const uint32_t duUrcTimeout = 60 * 1000; // wait for 1 minutes for the next URC message
+ const uint32_t duUrcTimeout = 60 * 1000; // wait for 1 minutes for the next URC message
const std::string sFotaUrcPrefix = "#OTAEV:"; // prefix for the URC notification messages
const std::string sFotaUrcEndSuccess = "Module Upgraded To New Fw";
const std::string sFotaUrcEndFailed = "OTA Fw Upgrade Failed";