diff options
| author | Jeff Hatch <jhatch@multitech.com> | 2020-01-10 14:24:22 -0600 | 
|---|---|---|
| committer | Jeff Hatch <jhatch@multitech.com> | 2020-01-10 14:24:22 -0600 | 
| commit | 21026c29f774ba4ba9f9af7cda7ea5fbfb17728b (patch) | |
| tree | 542975a2d23c421333ba12db32ec26c60cb65663 | |
| parent | 35dcb6fcfec3b7dfd1b7717b441fcd94997bddf5 (diff) | |
| download | libmts-io-21026c29f774ba4ba9f9af7cda7ea5fbfb17728b.tar.gz libmts-io-21026c29f774ba4ba9f9af7cda7ea5fbfb17728b.tar.bz2 libmts-io-21026c29f774ba4ba9f9af7cda7ea5fbfb17728b.zip | |
IN003925 Fix EG95 Cellular network registration checking
| -rw-r--r-- | include/mts/MTS_IO_EG95Radio.h | 1 | ||||
| -rw-r--r-- | src/MTS_IO_EG95Radio.cpp | 71 | 
2 files changed, 72 insertions, 0 deletions
| diff --git a/include/mts/MTS_IO_EG95Radio.h b/include/mts/MTS_IO_EG95Radio.h index 5296e16..5c093db 100644 --- a/include/mts/MTS_IO_EG95Radio.h +++ b/include/mts/MTS_IO_EG95Radio.h @@ -41,6 +41,7 @@ namespace MTS {              private:                  CODE getSupportedCellularModes(CELLULAR_MODES &networks) override;                  CODE setCellularMode(CELLULAR_MODES networks) override; +                CODE getRegistration(REGISTRATION& eRegistration) override;          };      }  } diff --git a/src/MTS_IO_EG95Radio.cpp b/src/MTS_IO_EG95Radio.cpp index f1c040a..cdd750e 100644 --- a/src/MTS_IO_EG95Radio.cpp +++ b/src/MTS_IO_EG95Radio.cpp @@ -87,3 +87,74 @@ ICellularRadio::CODE EG95Radio::setCellularMode(CELLULAR_MODES networks) {      }      return SUCCESS;  } + +ICellularRadio::REGISTRATION parseRegResponse(std::string sResult) +{ +    size_t start = sResult.find(','); +    size_t stop = sResult.find(' ', start); +    std::string sRegStat = sResult.substr(start + 1, stop - start - 1); +    int32_t value; +    sscanf(sRegStat.c_str(), "%d", &value); + +    return (ICellularRadio::REGISTRATION)value; +} + +ICellularRadio::CODE EG95Radio::getRegistration(REGISTRATION& eRegistration) { +    std::string sCmd; +    std::string sResp; + +    // On the EG95 we need to check CREG, CGREG, and CEREG for possible success. +    // Depending on the carrier, roaming, and some other factors the registration +    // will come back differently depending on the type of connection that is possible. + +    sCmd = "AT+CREG?"; +    sResp = "+CREG: "; +    std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 5000); +    if (sResult.find(sResp) == std::string::npos) { +        if(sResult.size() == 0) { +            printDebug("%s| Registration command returned no response: [EG95]"); +        } +        printDebug("%s| Registration command returned unexpected response: [EG95]"); +    } + +    eRegistration = parseRegResponse(sResult); +    if (eRegistration == REGISTERED) { +    	return SUCCESS; +    } + + +    sCmd = "AT+CGREG?"; +    sResp = "+CGREG: "; +    sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 5000); +    if (sResult.find(sResp) == std::string::npos) { +        if(sResult.size() == 0) { +            printDebug("%s| Registration command returned no response: [EG95]"); +        } +        printDebug("%s| Registration command returned unexpected response: [EG95]"); +    } + + +    eRegistration = parseRegResponse(sResult); +    if (eRegistration == REGISTERED) { +    	return SUCCESS; +    } + +    sCmd = "AT+CEREG?"; +    sResp = "+CEREG: "; +    sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 5000); +    if (sResult.find(sResp) == std::string::npos) { +        if(sResult.size() == 0) { +            printDebug("%s| Registration command returned no response: [EG95]"); +            return NO_RESPONSE; +        } +        printDebug("%s| Registration command returned unexpected response: [EG95]"); +        return FAILURE; +    } + +    eRegistration = parseRegResponse(sResult); +    if (eRegistration == REGISTERED) { +    	return SUCCESS; +    } + +    return SUCCESS; +} | 
