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

Dependents:   mtsas mtsas mtsas mtsas

Committer:
Vanger
Date:
Wed Aug 13 19:47:19 2014 +0000
Revision:
58:de5f2c001ab0
Parent:
52:2cb58398a4f9
Child:
69:93dace69ee98
Rewrote radio model init function under CellularFactory.cpp to be more robust (will now be able to deal with unexpected characters and output);

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Mike Fiore 11:4e428f689069 1 #include "mbed.h"
Mike Fiore 11:4e428f689069 2 #include "CellularFactory.h"
Mike Fiore 11:4e428f689069 3 #include "MTSLog.h"
Mike Fiore 11:4e428f689069 4 #include <string>
Mike Fiore 11:4e428f689069 5
Mike Fiore 11:4e428f689069 6 using namespace mts;
Mike Fiore 11:4e428f689069 7
Mike Fiore 11:4e428f689069 8 Cellular* CellularFactory::create(MTSBufferedIO* io) {
Mike Fiore 11:4e428f689069 9 bool uip;
Mike Fiore 11:4e428f689069 10 std::string model;
Mike Fiore 11:4e428f689069 11 std::string reply;
Vanger 58:de5f2c001ab0 12 Cellular::Radio type = Cellular::NA;
Mike Fiore 11:4e428f689069 13 Cellular* cell;
Vanger 30:1326b623919a 14
Mike Fiore 11:4e428f689069 15 /* wait for radio to get into a good state */
Mike Fiore 11:4e428f689069 16 while (true) {
Mike Fiore 11:4e428f689069 17 if (sendCommand(io, "AT", 1000).find("OK") != string::npos) {
mfiore 14:614952fb3af3 18 logTrace("radio replied");
Mike Fiore 11:4e428f689069 19 break;
Mike Fiore 11:4e428f689069 20 } else {
mfiore 14:614952fb3af3 21 logTrace("waiting on radio...");
Mike Fiore 11:4e428f689069 22 }
Mike Fiore 11:4e428f689069 23 wait(1);
Mike Fiore 11:4e428f689069 24 }
Vanger 30:1326b623919a 25
Vanger 58:de5f2c001ab0 26 while (true) {
Vanger 58:de5f2c001ab0 27 /* AT#VVERSION is a UIP specific AT command
Vanger 58:de5f2c001ab0 28 * if we get an error response, we're not using a UIP board */
Vanger 58:de5f2c001ab0 29 reply = sendCommand(io, "AT#VVERSION", 2000);
Vanger 58:de5f2c001ab0 30 if ((reply.find("ERROR") != string::npos) || (reply.find("error") != string::npos)) {
Vanger 58:de5f2c001ab0 31 uip = false;
Vanger 52:2cb58398a4f9 32 break;
Vanger 58:de5f2c001ab0 33 } else if (reply.find("VVERSION:") != string::npos) {
Vanger 58:de5f2c001ab0 34 uip = true;
Vanger 58:de5f2c001ab0 35 break;
Vanger 58:de5f2c001ab0 36 } else {
Vanger 58:de5f2c001ab0 37 logTrace("Checking for UIP chip");
mfiore 16:1bc3e44d4746 38 }
mfiore 16:1bc3e44d4746 39 wait(1);
mfiore 16:1bc3e44d4746 40 }
Vanger 58:de5f2c001ab0 41
Vanger 58:de5f2c001ab0 42 /* "ATI4" gets us the model (HE910, DE910, etc) */
Vanger 58:de5f2c001ab0 43 while (true) {
Vanger 58:de5f2c001ab0 44 string mNumber;
Vanger 58:de5f2c001ab0 45 model = sendCommand(io, "ATI4", 3000);
Vanger 58:de5f2c001ab0 46 if (uip) {
Vanger 58:de5f2c001ab0 47 if (model.find("HE910") != string::npos) {
Vanger 58:de5f2c001ab0 48 type = Cellular::MTSMC_H5_IP;
Vanger 58:de5f2c001ab0 49 mNumber = "HE910";
Vanger 58:de5f2c001ab0 50 } else if (model.find("DE910") != string::npos) {
Vanger 58:de5f2c001ab0 51 type = Cellular::MTSMC_EV3_IP;
Vanger 58:de5f2c001ab0 52 mNumber = "DE910";
Vanger 58:de5f2c001ab0 53 } else if (model.find("CE910") != string::npos) {
Vanger 58:de5f2c001ab0 54 type = Cellular::MTSMC_C2_IP;
Vanger 58:de5f2c001ab0 55 mNumber = "CE910";
Vanger 58:de5f2c001ab0 56 }
Vanger 58:de5f2c001ab0 57 if (type != Cellular::NA) {
Vanger 58:de5f2c001ab0 58 cell = new UIP(type);
Vanger 58:de5f2c001ab0 59 logDebug("UIP radio model: %s", mNumber.c_str());
Vanger 58:de5f2c001ab0 60 break;
Vanger 58:de5f2c001ab0 61 }
Vanger 58:de5f2c001ab0 62 } else {
Vanger 58:de5f2c001ab0 63 if (model.find("HE910") != string::npos) {
Vanger 58:de5f2c001ab0 64 type = Cellular::MTSMC_H5;
Vanger 58:de5f2c001ab0 65 mNumber = "HE910";
Vanger 58:de5f2c001ab0 66 } else if (model.find("DE910") != string::npos) {
Vanger 58:de5f2c001ab0 67 type = Cellular::MTSMC_EV3;
Vanger 58:de5f2c001ab0 68 mNumber = "DE910";
Vanger 58:de5f2c001ab0 69 } else if (model.find("CE910") != string::npos) {
Vanger 58:de5f2c001ab0 70 type = Cellular::MTSMC_C2;
Vanger 58:de5f2c001ab0 71 mNumber = "CE910";
Vanger 58:de5f2c001ab0 72 } else if (model.find("GE910") != string::npos) {
Vanger 58:de5f2c001ab0 73 type = Cellular::MTSMC_G3;
Vanger 58:de5f2c001ab0 74 mNumber = "GE910";
Vanger 58:de5f2c001ab0 75 }
Vanger 58:de5f2c001ab0 76 if (type != Cellular::NA) {
Vanger 58:de5f2c001ab0 77 cell = new EasyIP(type);
Vanger 58:de5f2c001ab0 78 logDebug("EasyIP radio model: %s", mNumber.c_str());
Vanger 58:de5f2c001ab0 79 break;
Vanger 58:de5f2c001ab0 80 }
Vanger 58:de5f2c001ab0 81 }
Vanger 58:de5f2c001ab0 82 logTrace("Determining radio type");
Vanger 58:de5f2c001ab0 83 wait(1);
Mike Fiore 11:4e428f689069 84 }
Mike Fiore 11:4e428f689069 85
Mike Fiore 11:4e428f689069 86 if (! cell->init(io)) {
Mike Fiore 11:4e428f689069 87 logError("cellular initialization failed");
Mike Fiore 11:4e428f689069 88 return NULL;
Mike Fiore 11:4e428f689069 89 }
Mike Fiore 11:4e428f689069 90
Mike Fiore 11:4e428f689069 91 return cell;
Mike Fiore 11:4e428f689069 92 }