diff options
Diffstat (limited to 'src/MTS_IO_CellularRadio.cpp')
-rw-r--r-- | src/MTS_IO_CellularRadio.cpp | 160 |
1 files changed, 2 insertions, 158 deletions
diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index 840132f..f106b4c 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -968,167 +968,11 @@ CellularRadio::CODE CellularRadio::sendBasicCommand(const std::string& sCmd, int } std::string CellularRadio::sendCommand(const std::string& sCmd, const std::vector<std::string>& vBail, int32_t timeoutMillis, const char& ESC) { - return sendCommand(m_apIo, sCmd, vBail, timeoutMillis, ESC); -} - -std::string CellularRadio::sendCommand(MTS::AutoPtr<MTS::IO::Connection>& apIo, const std::string& sCmd, - const std::vector<std::string>& vBail, int32_t timeoutMillis, const char& ESC) { - IsNeedMoreData isNeedMoreData = [&vBail](const std::string&, const std::string& allData)->bool { - for(size_t i = 0; i < vBail.size(); i++) { - const std::string& sBail = vBail[i]; - if(sBail.size() > 0) { - if(allData.find(sBail) != std::string::npos) { - //Return when bail string is found - printTrace("RADIO| Found bail string [%s]", sBail.c_str()); - return false; - } - } - } - return true; - }; - - return sendCommand(apIo, sCmd, isNeedMoreData, timeoutMillis, ESC); + return ICellularRadio::sendCommand(m_apIo, sCmd, vBail, timeoutMillis, ESC); } std::string CellularRadio::sendCommand(const std::string& sCmd, MTS::IO::CellularRadio::IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis, const char& ESC) { - return sendCommand(m_apIo, sCmd, isNeedMoreData, timeoutMillis, ESC); -} - -std::string CellularRadio::sendCommand(MTS::AutoPtr<MTS::IO::Connection>& apIo, const std::string& sCmd, - IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis, const char& ESC) { - if(MTS::Logger::getPrintLevel() >= MTS::Logger::PrintLevel::TRACE_LEVEL) { - printTrace("RADIO| Sending command [%s]", sCmd.c_str()); - } - if(apIo.isNull()) { - printError("RADIO| IO is not set in sendCommand"); - return ""; - } - - int32_t iResult; - if(ESC == 0x00) { - iResult = apIo->write(sCmd.data(), sCmd.size()); - } else { - std::string sNewCmd(sCmd); - sNewCmd.push_back(ESC); - iResult = apIo->write(sNewCmd.data(), sNewCmd.size()); - } - - if(iResult == -1) { - printError("RADIO| Failed to send command to radio"); - return ""; - } - - bool done = false; - const uint32_t capacity = 1024; - char buffer[capacity]; - std::string sResult; - Timer timer; - timer.start(); - do { - int32_t iterationTimeout = 100; - int bytesRead = apIo->read((char*)buffer, capacity, iterationTimeout); - if(bytesRead == -1) { - printError("RADIO| Failed to read from radio"); - break; - } - - std::string sIteration((char*)buffer, bytesRead); - sResult += sIteration; - - if(isNeedMoreData && !isNeedMoreData(sIteration, sResult)) { - printTrace("RADIO| No more data needed"); - return sResult; - } - if(timeoutMillis >= 0) { - done = (timer.getMillis() >= (uint64_t)timeoutMillis); - } else { - //Do not stop looping until bail string is found - } - } while(!done); - - //Timed out - return sResult; -} - -CellularRadio::CODE CellularRadio::test(MTS::AutoPtr<MTS::IO::Connection>& apIo, uint32_t timeoutSeconds) { - printTrace("RADIO| Basic Test"); - uint32_t count = 0; - std::string sCmd("AT"); - do { - std::string sResult = sendCommand(apIo, sCmd); - if (sResult.find(RSP_OK) == std::string::npos) { - printTrace("RADIO| Waiting for basic radio communication [%s] ...", sResult.c_str()); - } else { - break; - } - count++; - } while (count < timeoutSeconds); - - if(count == timeoutSeconds) { - printWarning("RADIO| Basic radio communication FAILED"); - return NO_RESPONSE; - } - return SUCCESS; -} - -std::string CellularRadio::extractModelFromResult(const std::string& sResult) { - std::string sModel(VALUE_NOT_SUPPORTED); - - if(sResult.find("HE910-D") != std::string::npos) { - sModel = "HE910-D"; - } else if(sResult.find("HE910-EUD") != std::string::npos) { - sModel = "HE910-EUD"; - } else if(sResult.find("LE910-JN1") != std::string::npos) { - sModel = "LE910-JN1"; - } else if(sResult.find("LE866A1-JS") != std::string::npos) { - sModel = "LE866A1-JS"; - } else if(sResult.find("LE910-NAG") != std::string::npos) { - sModel = "LE910-NAG"; - } else if(sResult.find("LE910C4-NF") != std::string::npos) { - sModel = "LE910C4-NF"; - } else if(sResult.find("LE910-NA1") != std::string::npos) { - sModel = "LE910-NA1"; - } else if(sResult.find("ME910C1-NA") != std::string::npos) { - sModel = "ME910C1-NA"; - } else if(sResult.find("ME910C1-NV") != std::string::npos) { - sModel = "ME910C1-NV"; - } else if(sResult.find("ME910C1-WW") != std::string::npos) { - sModel = "ME910C1-WW"; - } else if(sResult.find("LE910-SVG") != std::string::npos) { - sModel = "LE910-SVG"; - } else if(sResult.find("LE910-EUG") != std::string::npos) { - sModel = "LE910-EUG"; - } else if(sResult.find("LE910C4-EU") != std::string::npos) { - sModel = "LE910C4-EU"; - } else if(sResult.find("LE910-EU1") != std::string::npos) { - sModel = "LE910-EU1"; - } else if(sResult.find("LE910C1-NS") != std::string::npos) { - sModel = "LE910C1-NS"; - } else if(sResult.find("LE910C1-AP") != std::string::npos) { - sModel = "LE910C1-AP"; - } else if(sResult.find("GE910") != std::string::npos) { - sModel = "GE910"; - } else if(sResult.find("DE910-DUAL") != std::string::npos) { - sModel = "DE910-DUAL"; - } else if(sResult.find("CE910") != std::string::npos) { - sModel = "CE910"; - } - return sModel; -} - -std::string CellularRadio::getCodeAsString(CODE eCode) { - switch(eCode) { - case SUCCESS: - return "SUCCESS"; - case ERROR: - return "ERROR"; - case FAILURE: - return "FAILURE"; - case NO_RESPONSE: - return "NO RESPONSE"; - default: - return "UNKNOWN"; - } + return ICellularRadio::sendCommand(m_apIo, sCmd, isNeedMoreData, timeoutMillis, ESC); } bool CellularRadio::splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType) { |