diff options
| author | andrii.davydenko <andrii.davydenko@globallogic.com> | 2021-11-16 11:51:32 +0200 | 
|---|---|---|
| committer | John Klug <john.klug@multitech.com> | 2022-04-18 13:47:07 -0500 | 
| commit | 4322fabc71ddc54c19dd0e54a0b5248da372e9e5 (patch) | |
| tree | 6eaf7db557e91e1f6b6c29885d5fddc3c584c457 /src/MTS_IO_CellularRadio.cpp | |
| parent | 166af1c1bd7c9a0368d046261bab2162a37a7dc2 (diff) | |
| download | libmts-io-4322fabc71ddc54c19dd0e54a0b5248da372e9e5.tar.gz libmts-io-4322fabc71ddc54c19dd0e54a0b5248da372e9e5.tar.bz2 libmts-io-4322fabc71ddc54c19dd0e54a0b5248da372e9e5.zip | |
Update MODBUS slave feature, Rogers Certification issue1.0.28
Diffstat (limited to 'src/MTS_IO_CellularRadio.cpp')
| -rw-r--r-- | src/MTS_IO_CellularRadio.cpp | 122 | 
1 files changed, 107 insertions, 15 deletions
| diff --git a/src/MTS_IO_CellularRadio.cpp b/src/MTS_IO_CellularRadio.cpp index 6236c3f..afdfc1e 100644 --- a/src/MTS_IO_CellularRadio.cpp +++ b/src/MTS_IO_CellularRadio.cpp @@ -147,7 +147,9 @@ bool CellularRadio::resetConnection(uint32_t iTimeoutMillis) {          } else {              printInfo("%s| Successfully re-opened radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str());              printDebug("%s| Recovering 'echo' after connection reset", m_sName.c_str()); // see CellularRadio::initialize -            setEcho(m_bEchoEnabled); +            if (setEcho(m_bEchoEnabled) != SUCCESS) { +                printWarning("%s| Failed to recover 'echo' after connection reset", m_sName.c_str()); +            }              break;          } @@ -425,26 +427,110 @@ ICellularRadio::CODE CellularRadio::getType(std::string& sType) {  ICellularRadio::CODE CellularRadio::getCarrier(std::string& sCarrier) {      printTrace("%s| Get Carrier", m_sName.c_str()); -    if (m_sCarrier == "") { -        std::string sMcc; -        std::string sMnc; -        if (getSimMccMnc(sMcc, sMnc) == CODE::SUCCESS) { -            Json::Value jLookup = MccMncTable::getInstance()->lookup(sMcc, sMnc); -            printTrace("%s| MCC-MNC Lookup: [%s][%s][%s]", m_sName.c_str(), -                       sMcc.c_str(), sMnc.c_str(), jLookup.toStyledString().c_str()); -            if (jLookup.isMember(ICellularRadio::KEY_CARRIER)) { -                m_sCarrier = jLookup[ICellularRadio::KEY_CARRIER].asString(); -            } else { -                printWarning("%s| MCC-MNC Lookup did not contain carrier", m_sName.c_str()); -                return FAILURE; + +    CODE rc = SUCCESS; +    std::string t_sCarrier; + +    do { +        if (m_sCarrier == "") { +            rc = getCarrierFromSimSpn(t_sCarrier); +            if (rc == SUCCESS) { +                m_sCarrier = t_sCarrier; +                break; +            } + +            rc = getCarrierFromSimMccMnc(t_sCarrier); +            if (rc == SUCCESS) { +                m_sCarrier = t_sCarrier; +                break;              } +        } +    } while (false); + +    sCarrier = m_sCarrier; +    return rc; +} + +ICellularRadio::CODE CellularRadio::getCarrierFromSimMccMnc(std::string& sCarrier) { +    printTrace("%s| Get Carrier from SIM MCC/MNC", m_sName.c_str()); + +    std::string sMcc; +    std::string sMnc; + +    CODE rc; + +    rc = getSimMccMnc(sMcc, sMnc); +    if (rc == SUCCESS) { +        Json::Value jLookup = MccMncTable::getInstance()->lookup(sMcc, sMnc); +        printTrace("%s| MCC-MNC Lookup: [%s][%s][%s]", m_sName.c_str(), +                    sMcc.c_str(), sMnc.c_str(), jLookup.toStyledString().c_str()); +        if (jLookup.isMember(ICellularRadio::KEY_CARRIER)) { +            sCarrier = jLookup[ICellularRadio::KEY_CARRIER].asString();          } else { -            printWarning("%s| SIM did no contain MCC or MNC", m_sName.c_str()); +            printWarning("%s| MCC-MNC Lookup does not contain the carrier", m_sName.c_str());              return FAILURE;          } +    } else { +        printWarning("%s| SIM did no contain MCC or MNC", m_sName.c_str()); +        return rc; +    } + +    return SUCCESS; +} + +ICellularRadio::CODE CellularRadio::getCarrierFromSimSpn(std::string& sCarrier) { +    printTrace("%s| Get Carrier from SIM SPN", m_sName.c_str()); + +    const int iEfspnId = 0x6F46; +    const uint8_t iOffsetHigh = 1; +    const uint8_t iOffsetLow = 0; +    const uint8_t iNumBytes = 16; + +    CODE rc; +    std::string sEFspnContent; + +    rc = simAccessReadBinary(iEfspnId, iOffsetLow, iOffsetHigh, iNumBytes, sEFspnContent); +    if (rc != SUCCESS) { +        printError("%s| Failed to determine the service provider name", m_sName.c_str()); +        return rc; +    } + +    if (sEFspnContent.length() != 32) { +        printError("%s| Invalid length of the service provider name: expected [32], actual: [%d]", m_sName.c_str(), sEFspnContent.length()); +        return FAILURE; +    } + +    uint8_t iSpnPart; + +    for (size_t i = 0; i < sEFspnContent.length(); i += 2) { +        std::string sPart = sEFspnContent.substr(i, 2); + +        // parse hex to unsigned byte +        if (!MTS::Text::parseHex(iSpnPart, sPart)) { +            printError("%s| Unexpected SIM EFspn content: [%s]", m_sName.c_str(), sEFspnContent.c_str()); +            return FAILURE; +        } + +        // skip 0xFF bytes +        if (iSpnPart == 0xFF) { +            continue; +        } + +        sCarrier.push_back(iSpnPart); +    } + +    /** +     * Example of radio response when SIM card does not contain the service provider name: +     * Raw response from the radio: [ +     *   +CRSM: 144,0,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF +     *   OK +     * ] +     */ +    if (sCarrier.empty()) { +        printError("%s| SIM EFspn does not contain the service provider name", m_sName.c_str()); +        return FAILURE;      } -    sCarrier = m_sCarrier;      return SUCCESS;  } @@ -1663,3 +1749,9 @@ ICellularRadio::CODE CellularRadio::sendBasicQuery(const std::string& sCmd, cons      return SUCCESS;  } + +ICellularRadio::CODE CellularRadio::getSelectedBandsRaw(std::string& sRawBands) +{ +    printTrace("%s| Acquiring selected bands: not applicable", m_sName.c_str()); +    return NOT_APPLICABLE; +} | 
