Simple detection for LE910-NA1 modules
Fork of MTS-Cellular by
Diff: Cellular/EasyIP.cpp
- Revision:
- 76:6eeffc10739d
- Parent:
- 73:bba8669d36f7
- Child:
- 78:fc9d2b983744
diff -r 60ff839c9b6d -r 6eeffc10739d Cellular/EasyIP.cpp --- a/Cellular/EasyIP.cpp Wed Mar 25 17:59:46 2015 +0000 +++ b/Cellular/EasyIP.cpp Thu Jun 25 08:27:35 2015 -0500 @@ -37,6 +37,8 @@ //Initializes the MTS IO Buffer bool EasyIP::init(MTSBufferedIO* io) { + char buf[128]; + if (! Cellular::init(io)) { return false; } @@ -48,7 +50,8 @@ } // Shorten data sending timeout from 5s to 100ms // Some servers won't handle a timeout that long - if (sendBasicCommand("AT#SCFG=1,1,300,90,600,1", 2000) != MTS_SUCCESS) { + snprintf(buf, sizeof(buf), "AT#SCFG=1,%d,300,90,600,1", type == MTSMC_LVW2 ? 3 : 1); + if (sendBasicCommand(string(buf), 2000) != MTS_SUCCESS) { logWarning("Failed to reconfigure socket timeout parameters"); } return true; @@ -57,7 +60,7 @@ bool EasyIP::connect() { //Check if APN is not set, if it is not, connect will not work. - if (type == MTSMC_H5_IP || type == MTSMC_H5 || type == MTSMC_G3 || type == MTSMC_LAT1) { + if (type == MTSMC_H5_IP || type == MTSMC_H5 || type == MTSMC_G3 || type == MTSMC_LAT1 || type == MTSMC_LEU1) { if(apn.size() == 0) { logDebug("APN is not set"); return false; @@ -101,25 +104,30 @@ } while(tmr.read() < 30); //Make PPP connection - if (type == MTSMC_H5 || type == MTSMC_G3 || type == MTSMC_LAT1) { + if (type == MTSMC_H5 || type == MTSMC_G3 || type == MTSMC_LAT1 || type == MTSMC_LEU1) { logDebug("Making PPP Connection Attempt. APN[%s]", apn.c_str()); } else { logDebug("Making PPP Connection Attempt"); } - std::string pppResult = sendCommand("AT#SGACT=1,1", 15000); + char buf[64]; + snprintf(buf, sizeof(buf), "AT#SGACT=%d,1", type == MTSMC_LVW2 ? 3 : 1); + std::string pppResult = sendCommand(string(buf), 15000); std::vector<std::string> parts; if(pppResult.find("OK") != std::string::npos) { parts = Text::split(pppResult, "\r\n"); if(parts.size() >= 2) { parts = Text::split(parts[1], " "); - local_address = parts[1]; + if (parts.size() >= 2) { + local_address = parts[1]; + } } logInfo("PPP Connection Established: IP[%s]", local_address.c_str()); pppConnected = true; } else { + snprintf(buf, sizeof(buf), "%d,1", type == MTSMC_LVW2 ? 3 : 1); pppResult = sendCommand("AT#SGACT?", 2000); - if(pppResult.find("1,1") != std::string::npos) { + if(pppResult.find(string(buf)) != std::string::npos) { logDebug("Radio is already connected"); pppConnected = true; } else { @@ -144,7 +152,9 @@ //Sends AT#SGACT=1,0 command for (int y = 0; y < 5; y++) { - Code code = sendBasicCommand("AT#SGACT=1,0", 1000); + char buf[64]; + snprintf(buf, sizeof(buf), "AT#SGACT=%d,0", type == MTSMC_LVW2 ? 3 : 1); + Code code = sendBasicCommand(string(buf), 1000); if (code == MTS_SUCCESS) { logDebug("Successfully closed PPP Connection"); break; @@ -156,8 +166,10 @@ */ tmr.start(); while(tmr.read() < 30) { + char buf[16]; + snprintf(buf, sizeof(buf), "%d,0", type == MTSMC_LVW2 ? 3 : 1); result = sendCommand("AT#SGACT?", 1000); - if(result.find("1,0") != std::string::npos) { + if(result.find(string(buf)) != std::string::npos) { break; } else if(result.find("ERROR") != std::string::npos) { break; @@ -175,9 +187,10 @@ enum RadioState {IDLE, CONNECTING, CONNECTED, DISCONNECTED}; //state flags for various connection components bool signal = false, regist = false, active = false; + char buf[16]; //1) Check if APN was set if we're on an HSPA radio - if (type == MTSMC_H5_IP || type == MTSMC_H5 || type == MTSMC_G3 || type == MTSMC_LAT1) { + if (type == MTSMC_H5_IP || type == MTSMC_H5 || type == MTSMC_G3 || type == MTSMC_LAT1 || type == MTSMC_LEU1) { if(apn.size() == 0) { logDebug("APN is not set"); return false; @@ -207,7 +220,8 @@ } string reply = sendCommand("AT#SGACT?", 1000); - if (reply.find("1,1") != std::string::npos) { + snprintf(buf, sizeof(buf), "%d,1", type == MTSMC_LVW2 ? 3 : 1); + if (reply.find(string(buf)) != std::string::npos) { active = true; } else { active = false; @@ -299,7 +313,7 @@ return false; } - if(type == MTSMC_EV3 || type == MTSMC_LAT1) { + if(type == MTSMC_EV3 || type == MTSMC_LAT1 || type == MTSMC_LEU1 || type == MTSMC_LVW2) { if(!local_port) { logDebug("Local port set to 1, port 0 not supported for %s", getRadioNames(type).c_str()); local_port = 1; @@ -510,7 +524,7 @@ } this->apn = apn; return code; - } else if (type == MTSMC_LAT1) { + } else if (type == MTSMC_LAT1 || type == MTSMC_LEU1) { //CGDCONT has options: IP,PPP,IPv6 Code code = sendBasicCommand("AT+CGDCONT=1,\"IP\",\"" + apn + "\"", 1000); if (code != MTS_SUCCESS) {