Peter Ferland / MTS-Cellular_lat1

Fork of MTS-Cellular by MultiTech

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-NA") != 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             }
00085             if (type != Cellular::NA) {
00086                 cell = new EasyIP(type);
00087                 logDebug("EasyIP radio model: %s", mNumber.c_str());
00088                 break;
00089             }
00090         }
00091         logTrace("Determining radio type");
00092         wait(1);
00093     }
00094 
00095     if (! cell->init(io)) {
00096         logError("cellular initialization failed");
00097         return NULL;
00098     }
00099 
00100     return cell;
00101 }