diff options
author | Jeff Hatch <jhatch@multitech.com> | 2022-12-28 10:36:52 -0600 |
---|---|---|
committer | Jeff Hatch <jhatch@multitech.com> | 2022-12-28 10:36:52 -0600 |
commit | 6d75c847ab716dd377bdf1e0a4bff1fbce235121 (patch) | |
tree | f3ba4159fc60dc385b1019dca521dad1b9763fdd /src/MTS_IO_CellularRadio.cpp | |
parent | 3f374f40900e9f6618509de9a52a1a415e54de8f (diff) | |
parent | 4b448e3c5daf34062861d0261c5a2253638b8100 (diff) | |
download | libmts-io-6d75c847ab716dd377bdf1e0a4bff1fbce235121.tar.gz libmts-io-6d75c847ab716dd377bdf1e0a4bff1fbce235121.tar.bz2 libmts-io-6d75c847ab716dd377bdf1e0a4bff1fbce235121.zip |
Merge branch 'sk/GP-1195/cell-diag' into 'master'
[GP-1195] Cellular debugging - add a query
See merge request !51
Diffstat (limited to 'src/MTS_IO_CellularRadio.cpp')
-rw-r--r-- | src/MTS_IO_CellularRadio.cpp | 63 |
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; +} |