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

Dependents:   mtsas mtsas mtsas mtsas

Committer:
mfiore
Date:
Thu Jun 05 14:52:59 2014 +0000
Revision:
16:1bc3e44d4746
Parent:
14:614952fb3af3
Child:
26:2b769ed8de4f
APN and SMS fixes/improvements;     don't try to set APN on CDMA radios;     add SMS support for C2 and EV3 radios

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;
Mike Fiore 11:4e428f689069 12 Cellular::Radio type;
Mike Fiore 11:4e428f689069 13 Cellular* cell;
Mike Fiore 11:4e428f689069 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
Mike Fiore 11:4e428f689069 24 wait(1);
Mike Fiore 11:4e428f689069 25 }
Mike Fiore 11:4e428f689069 26
Mike Fiore 11:4e428f689069 27 /* "ATI4" gets us the model (HE910, DE910, etc) */
mfiore 16:1bc3e44d4746 28 for (int i = 0; i < 5; i++) {
mfiore 16:1bc3e44d4746 29 model = sendCommand(io, "ATI4", 2000);
mfiore 16:1bc3e44d4746 30 if (model.find("error") == string::npos && model.find("ERROR") == string::npos) {
mfiore 16:1bc3e44d4746 31 /* didn't get an error - keep going */
mfiore 16:1bc3e44d4746 32 break;
mfiore 16:1bc3e44d4746 33 }
mfiore 16:1bc3e44d4746 34
mfiore 16:1bc3e44d4746 35 wait(1);
mfiore 16:1bc3e44d4746 36 }
Mike Fiore 11:4e428f689069 37
Mike Fiore 11:4e428f689069 38 /* AT#VVERSION is a IUP specific AT command
Mike Fiore 11:4e428f689069 39 * if we get an error response, we're not using a UIP board */
Mike Fiore 11:4e428f689069 40 reply = sendCommand(io, "AT#VVERSION", 2000);
Mike Fiore 11:4e428f689069 41 if (reply.find("error") != string::npos) {
Mike Fiore 11:4e428f689069 42 uip = false;
Mike Fiore 11:4e428f689069 43 } else {
Mike Fiore 11:4e428f689069 44 uip = true;
Mike Fiore 11:4e428f689069 45 }
Mike Fiore 11:4e428f689069 46
Mike Fiore 11:4e428f689069 47 if (uip && model.find("HE910") != string::npos) {
Mike Fiore 11:4e428f689069 48 type = Cellular::MTSMC_H5_IP;
mfiore 16:1bc3e44d4746 49 logDebug("radio model: HE910");
Mike Fiore 11:4e428f689069 50 cell = new UIP(type);
Mike Fiore 11:4e428f689069 51 } else if (uip && model.find("DE910") != string::npos) {
Mike Fiore 11:4e428f689069 52 type = Cellular::MTSMC_EV3_IP;
mfiore 16:1bc3e44d4746 53 logDebug("radio model: DE910");
Mike Fiore 11:4e428f689069 54 cell = new UIP(type);
Mike Fiore 11:4e428f689069 55 } else if (uip && model.find("CE910") != string::npos) {
Mike Fiore 11:4e428f689069 56 type = Cellular::MTSMC_C2_IP;
mfiore 16:1bc3e44d4746 57 logDebug("radio model: CE910");
Mike Fiore 11:4e428f689069 58 cell = new UIP(type);
Mike Fiore 11:4e428f689069 59 /*
Mike Fiore 11:4e428f689069 60 } else if (model.find("HE910") != string::npos) {
Mike Fiore 11:4e428f689069 61 type = Cellular::MTSMC_H5;
mfiore 16:1bc3e44d4746 62 logDebug("radio model: HE910");
Mike Fiore 11:4e428f689069 63 cell = new EasyIP(type);
Mike Fiore 11:4e428f689069 64 } else if (model.find("DE910") != string::npos) {
Mike Fiore 11:4e428f689069 65 type = Cellular::MTSMC_EV3;
mfiore 16:1bc3e44d4746 66 logDebug("radio model: DE910");
Mike Fiore 11:4e428f689069 67 cell = new EasyIP(type);
Mike Fiore 11:4e428f689069 68 } else if (model.find("GE910") != string::npos) {
Mike Fiore 11:4e428f689069 69 type = Cellular::MTSMC_G3;
mfiore 16:1bc3e44d4746 70 logDebug("radio model: GE910");
Mike Fiore 11:4e428f689069 71 cell = new EasyIP(type);
Mike Fiore 11:4e428f689069 72 } else if (model.find("CE910") != string::npos) {
Mike Fiore 11:4e428f689069 73 type = Cellular::MTSMC_C2;
mfiore 16:1bc3e44d4746 74 logDebug("radio model: CE910");
Mike Fiore 11:4e428f689069 75 cell = new EasyIP(type);
Mike Fiore 11:4e428f689069 76 */
Mike Fiore 11:4e428f689069 77 } else {
Mike Fiore 11:4e428f689069 78 logError("cannot continue - could not determine radio type");
Mike Fiore 11:4e428f689069 79 return NULL;
Mike Fiore 11:4e428f689069 80 }
Mike Fiore 11:4e428f689069 81
Mike Fiore 11:4e428f689069 82 if (! cell->init(io)) {
Mike Fiore 11:4e428f689069 83 logError("cellular initialization failed");
Mike Fiore 11:4e428f689069 84 return NULL;
Mike Fiore 11:4e428f689069 85 }
Mike Fiore 11:4e428f689069 86
Mike Fiore 11:4e428f689069 87 return cell;
Mike Fiore 11:4e428f689069 88 }