summaryrefslogtreecommitdiff
path: root/src/MTS_IO_EG95Radio.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/MTS_IO_EG95Radio.cpp')
-rw-r--r--src/MTS_IO_EG95Radio.cpp71
1 files changed, 71 insertions, 0 deletions
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;
+}