Simple detection for LE910-NA1 modules

Fork of MTS-Cellular by MultiTech

Revision:
11:4e428f689069
Child:
14:614952fb3af3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Cellular/CellularFactory.cpp	Thu May 22 09:26:51 2014 -0500
@@ -0,0 +1,77 @@
+#include "mbed.h"
+#include "CellularFactory.h"
+#include "MTSLog.h"
+#include <string>
+
+using namespace mts;
+
+Cellular* CellularFactory::create(MTSBufferedIO* io) {
+    bool uip;
+    std::string model;
+    std::string reply;
+    Cellular::Radio type;
+    Cellular* cell;
+
+    /* wait for radio to get into a good state */
+    while (true) {
+        if (sendCommand(io, "AT", 1000).find("OK") != string::npos) {
+            logDebug("radio replied");
+            break;
+        } else {
+            logDebug("waiting on radio...");
+        }
+
+        wait(1);
+    }
+
+    /* "ATI4" gets us the model (HE910, DE910, etc) */
+    model = sendCommand(io, "ATI4", 2000);
+
+    /* AT#VVERSION is a IUP specific AT command
+     * if we get an error response, we're not using a UIP board */
+    reply = sendCommand(io, "AT#VVERSION", 2000);
+    if (reply.find("error") != string::npos) {
+        uip = false;
+    } else {
+        uip = true;
+    }
+
+    if (uip && model.find("HE910") != string::npos) {
+        type = Cellular::MTSMC_H5_IP;
+        cell = new UIP(type);
+    } else if (uip && model.find("DE910") != string::npos) {
+        type = Cellular::MTSMC_EV3_IP;
+        cell = new UIP(type);
+    } else if (uip && model.find("CE910") != string::npos) {
+        type = Cellular::MTSMC_C2_IP;
+        cell = new UIP(type);
+    /*
+    } else if (model.find("HE910") != string::npos) {
+        type = Cellular::MTSMC_H5;
+        logDebug("%s", Cellular::getRadioNames(type).data());
+        cell = new EasyIP(type);
+    } else if (model.find("DE910") != string::npos) {
+        type = Cellular::MTSMC_EV3;
+        logDebug("%s", Cellular::getRadioNames(type).data());
+        cell = new EasyIP(type);
+    } else if (model.find("GE910") != string::npos) {
+        type = Cellular::MTSMC_G3;
+        logDebug("%s", Cellular::getRadioNames(type).data());
+        cell = new EasyIP(type);
+    } else if (model.find("CE910") != string::npos) {
+        type = Cellular::MTSMC_C2;
+        logDebug("%s", Cellular::getRadioNames(type).data());
+        cell = new EasyIP(type);
+    */
+    } else {
+        logError("cannot continue - could not determine radio type");
+        return NULL;
+    }
+
+    if (! cell->init(io)) {
+        logError("cellular initialization failed");
+        return NULL;
+    }
+
+    return cell;
+}