summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhii Kostiuk <serhii.o.kostiuk@globallogic.com>2020-08-06 13:11:42 +0300
committerSerhii Kostiuk <serhii.o.kostiuk@globallogic.com>2020-08-06 13:22:34 +0300
commit96445eaa166dd8f4ba99014f5eea2c1146b9db80 (patch)
treeb40d7cd34bafb5b088fa91eb4167553751b93277
parentc7f63212d7e6596975835f23150ef20aea3b7b96 (diff)
downloadlibmts-io-96445eaa166dd8f4ba99014f5eea2c1146b9db80.tar.gz
libmts-io-96445eaa166dd8f4ba99014f5eea2c1146b9db80.tar.bz2
libmts-io-96445eaa166dd8f4ba99014f5eea2c1146b9db80.zip
Quectel EG25-G Delta Radio Firmware Upgrade support - libmts-io implementation
Refactored MTS::IO::ICellularRadio::sendCommand. Moved response waiting code to the MTS::IO::ICellularRadio::waitResponse function. **Motivation** In many places in the modern libmts-io implementation there are cases when we need to wait for some response from the radio without executing or sending any commands. Such places may wait for some URC messages, acknowledge strings during data transmission and so on. One way to handle such cases is to use `sendCommand` with `cmd` argument set to an empty string. It generally works but according to POSIX: "If count is zero and fd refers to a file other than a regular file, the results are not specified." The other way to handle such cases is to use `isNeedMoreData` callback of `sendCommand` function to analyze all the data on the fly. But this approach may not work for data transfers when `sendCommand` and its std::string argument may not be used to store binary data with null characters within. This commit moves the "wait for the radio to answer" part to the separate function which allows reusablity of such a code.
-rw-r--r--include/mts/MTS_IO_ICellularRadio.h6
-rw-r--r--src/MTS_IO_ICellularRadio.cpp4
2 files changed, 10 insertions, 0 deletions
diff --git a/include/mts/MTS_IO_ICellularRadio.h b/include/mts/MTS_IO_ICellularRadio.h
index 085c217..e4456cc 100644
--- a/include/mts/MTS_IO_ICellularRadio.h
+++ b/include/mts/MTS_IO_ICellularRadio.h
@@ -83,6 +83,12 @@ namespace MTS {
const std::vector<std::string>& vBail = DEFAULT_BAIL_STRINGS,
int32_t timeoutMillis = 100,
const char& ESC = CR);
+
+ //! Wait for response from the radio without sending any data to it
+ static std::string waitResponse(MTS::AutoPtr<MTS::IO::Connection>& apIo,
+ IsNeedMoreData& isNeedMoreData,
+ int32_t timeoutMillis = 100);
+
static CODE test(MTS::AutoPtr<MTS::IO::Connection>& apIo, uint32_t timeoutSeconds = 30);
static std::string extractModelFromResult(const std::string& sResult);
static std::string getCodeAsString(CODE code);
diff --git a/src/MTS_IO_ICellularRadio.cpp b/src/MTS_IO_ICellularRadio.cpp
index 9dbfad1..69f731a 100644
--- a/src/MTS_IO_ICellularRadio.cpp
+++ b/src/MTS_IO_ICellularRadio.cpp
@@ -376,6 +376,10 @@ std::string MTS::IO::ICellularRadio::sendCommand(MTS::AutoPtr<MTS::IO::Connectio
return "";
}
+ return waitResponse(apIo, isNeedMoreData, timeoutMillis);
+}
+
+std::string MTS::IO::ICellularRadio::waitResponse(MTS::AutoPtr<MTS::IO::Connection>& apIo, MTS::IO::ICellularRadio::IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis) {
bool done = false;
const uint32_t capacity = 1024;
char buffer[capacity];