Cellular library for MTS Socket Modem Arduino Shield devices from Multi-Tech Systems

Dependents:   mtsas mtsas mtsas mtsas

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CellularFactory.cpp Source File

CellularFactory.cpp

00001 #include "mbed.h"
00002 #include "CellularFactory.h"
00003 #include "MTSLog.h"
00004 #include <string>
00005 
00006 using namespace mts;
00007 
00008 Cellular* CellularFactory::create(MTSBufferedIO* io) {
00009     bool uip;
00010     std::string model;
00011     std::string reply;
00012     Cellular::Radio type = Cellular::NA;
00013     Cellular* cell;
00014     
00015     /* wait for radio to get into a good state */
00016     while (true) {
00017         if (sendCommand(io, "AT", 1000).find("OK") != string::npos) {
00018             logTrace("radio replied");
00019             break;
00020         } else {
00021             logTrace("waiting on radio...");
00022         }
00023         wait(1);
00024     }
00025     
00026     while (true) {
00027         /* AT#VVERSION is a UIP specific AT command
00028          * if we get an error response, we're not using a UIP board */
00029         reply = sendCommand(io, "AT#VVERSION", 2000);
00030         if ((reply.find("ERROR") != string::npos) || (reply.find("error") != string::npos)) {
00031             uip = false;
00032             break;
00033         } else if (reply.find("VVERSION:") != string::npos) {
00034             uip = true;
00035             break;
00036         } else {
00037             logTrace("Checking for UIP chip");
00038         }
00039         wait(1);
00040     }
00041     
00042     /* "ATI4" gets us the model (HE910, DE910, etc) */
00043     while (true) {
00044         string mNumber;
00045         model = sendCommand(io, "ATI4", 3000);
00046         if (uip) {
00047             if (model.find("HE910") != string::npos) {
00048                 type = Cellular::MTSMC_H5_IP;
00049                 mNumber = "HE910";
00050             } else if (model.find("DE910") != string::npos) {
00051                 type = Cellular::MTSMC_EV3_IP;
00052                 mNumber = "DE910";
00053             } else if (model.find("CE910") != string::npos) {
00054                 type = Cellular::MTSMC_C2_IP;
00055                 mNumber = "CE910";
00056             }
00057             if (type != Cellular::NA) {
00058                 cell = new UIP(type);
00059                 logDebug("UIP radio model: %s", mNumber.c_str());
00060                 break;
00061             }
00062         } else {
00063             if (model.find("HE910") != string::npos) {
00064                 type = Cellular::MTSMC_H5;
00065                 mNumber = "HE910";
00066             } else if (model.find("DE910") != string::npos) {
00067                 type = Cellular::MTSMC_EV3;
00068                 mNumber = "DE910";
00069             } else if (model.find("CE910") != string::npos) {
00070                 type = Cellular::MTSMC_C2;
00071                 mNumber = "CE910";
00072             } else if (model.find("GE910") != string::npos) {
00073                 type = Cellular::MTSMC_G3;
00074                 mNumber = "GE910";
00075             } else if (model.find("LE910-NAG") != string::npos) {
00076                 type = Cellular::MTSMC_LAT1;
00077                 mNumber = "LE910-NAG";
00078             } else if (model.find("LE910-SVG") != string::npos) {
00079                 type = Cellular::MTSMC_LVW2;
00080                 mNumber = "LE910-SVG";
00081             } else if (model.find("LE910-EUG") != string::npos) {
00082                 type = Cellular::MTSMC_LEU1;
00083                 mNumber = "LE910-EUG";
00084             } else if (model.find("LE910-NA1") != string::npos) {
00085                 type = Cellular::MTQ_LAT3;
00086                 mNumber = "LE910-NA1";
00087             } else if (model.find("LE910-SV1") != string::npos) {
00088                 type = Cellular::MTQ_LVW3;
00089                 mNumber = "LE910-SV1";
00090             } else if (model.find("ME910C1-NA") != string::npos) {
00091                 type = Cellular::MTQ_MAT1;
00092                 mNumber = "ME910C1-NA";
00093             } else if (model.find("ME910C1-NV") != string::npos) {
00094                 type = Cellular::MTQ_MVW1;
00095                 mNumber = "ME910C1-NV";
00096             }
00097             if (type != Cellular::NA) {
00098                 cell = new EasyIP(type);
00099                 logDebug("EasyIP radio model: %s", mNumber.c_str());
00100                 break;
00101             }
00102         }
00103         logTrace("Determining radio type");
00104         wait(1);
00105     }
00106 
00107     if (! cell->init(io)) {
00108         logError("cellular initialization failed");
00109         return NULL;
00110     }
00111 
00112     return cell;
00113 }