summaryrefslogtreecommitdiff
path: root/src/MTS_IO_CellularRadio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/MTS_IO_CellularRadio.cpp')
-rw-r--r--src/MTS_IO_CellularRadio.cpp63
1 files changed, 62 insertions, 1 deletions
diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp
index 3de96ce..069d5fa 100644
--- a/src/MTS_IO_CellularRadio.cpp
+++ b/src/MTS_IO_CellularRadio.cpp
@@ -1868,4 +1868,65 @@ ICellularRadio::CODE CellularRadio::setPdpContext(const std::string& sId, const
rc = sendBasicCommand(sCommand, dTimeout);
return rc;
-} \ No newline at end of file
+}
+
+ICellularRadio::CODE CellularRadio::getDiagnostics(std::string& sReport) {
+ // Clear the original content before using the string as a buffer.
+ sReport.clear();
+
+ // Determine whether the SIM card is locked to select the appropriate
+ // list of commands for this radio.
+ std::string sSimLockStatus;
+ CODE iSimLockRet = getSimLockStatus(sSimLockStatus);
+
+ // Re-use the SIM status detection logic from TelitRadio::getNetworkStatus.
+ // The SIM should be inserted and NOT locked.
+ bool bIsSimReady = (iSimLockRet == CODE::SUCCESS
+ && sSimLockStatus != "SIM PIN"
+ && sSimLockStatus != "SIM PUK");
+
+ // Determine the list of diagnostic commands required for this radio.
+ const auto& vCommands = getDiagCommands(bIsSimReady);
+
+ // For all commands - set the maximum timeout to 2 seconds.
+ const int iMaxTimeout = 2000;
+
+ // Allow the radio to ignore up to 2 consecutive queries before giving up.
+ int iMaxNoResponseCount = 2;
+ int iNoResponseCount = 0;
+
+ // Execute each of the commands, add their output to the report.
+ for (const auto& sCmd : vCommands) {
+ // First line - the command to execute.
+ sReport.append(sCmd);
+ sReport.push_back(ICellularRadio::CR);
+ sReport.push_back(ICellularRadio::NL);
+
+ // Execute the command.
+ std::string sResult = sendCommand(sCmd, ICellularRadio::DEFAULT_BAIL_STRINGS, iMaxTimeout);
+
+ // Count the number of commands ignored by the radio.
+ // Normally, the radio should not ignore any of the commands,
+ // but radios have their own bugs.
+ if (sResult.empty()) {
+ printWarning("%s| Failed to execute the [%s] command - no response from the radio in [%d] ms", getName().c_str(), sCmd.c_str(), iMaxTimeout);
+ sResult = "<NO RESPONSE FROM THE RADIO>\r\n";
+ ++iNoResponseCount;
+ } else {
+ iNoResponseCount = 0;
+ }
+
+ // If the radio ignored too many commands - probably it is stuck and will not
+ // return to operation on its own. There is no point in waiting any longer.
+ if (iNoResponseCount >= iMaxNoResponseCount) {
+ printError("%s| Failed to execute the diagnostic commands - the radio has stopped responding", getName().c_str());
+ return CODE::NO_RESPONSE;
+ }
+
+ // Append the command output to the report.
+ sReport.append(sResult);
+ }
+
+ // All commands returned a non-empty output.
+ return CODE::SUCCESS;
+}