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

Dependents:   mtsas mtsas mtsas mtsas

Committer:
Vanger
Date:
Thu Jun 26 21:12:37 2014 +0000
Revision:
26:2b769ed8de4f
Parent:
16:1bc3e44d4746
Child:
27:ec44d5a9544f
Made setApn() a pure virtual in Cellular.; Implemented setApn in both UIP and EasyIP; Implemented connect(), disconnect(), and ping() in EasyIP; Uncommented cell instantiation for EasyIP type models in CellularFactory

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
Vanger 26:2b769ed8de4f 38 /* AT#VVERSION is a UIP 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);
Vanger 26:2b769ed8de4f 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 }
Vanger 26:2b769ed8de4f 46
Mike Fiore 11:4e428f689069 47
Mike Fiore 11:4e428f689069 48 if (uip && model.find("HE910") != string::npos) {
Mike Fiore 11:4e428f689069 49 type = Cellular::MTSMC_H5_IP;
mfiore 16:1bc3e44d4746 50 logDebug("radio model: HE910");
Mike Fiore 11:4e428f689069 51 cell = new UIP(type);
Mike Fiore 11:4e428f689069 52 } else if (uip && model.find("DE910") != string::npos) {
Mike Fiore 11:4e428f689069 53 type = Cellular::MTSMC_EV3_IP;
mfiore 16:1bc3e44d4746 54 logDebug("radio model: DE910");
Mike Fiore 11:4e428f689069 55 cell = new UIP(type);
Mike Fiore 11:4e428f689069 56 } else if (uip && model.find("CE910") != string::npos) {
Mike Fiore 11:4e428f689069 57 type = Cellular::MTSMC_C2_IP;
mfiore 16:1bc3e44d4746 58 logDebug("radio model: CE910");
Mike Fiore 11:4e428f689069 59 cell = new UIP(type);
Vanger 26:2b769ed8de4f 60
Mike Fiore 11:4e428f689069 61 } else if (model.find("HE910") != string::npos) {
Mike Fiore 11:4e428f689069 62 type = Cellular::MTSMC_H5;
mfiore 16:1bc3e44d4746 63 logDebug("radio model: HE910");
Mike Fiore 11:4e428f689069 64 cell = new EasyIP(type);
Mike Fiore 11:4e428f689069 65 } else if (model.find("DE910") != string::npos) {
Mike Fiore 11:4e428f689069 66 type = Cellular::MTSMC_EV3;
mfiore 16:1bc3e44d4746 67 logDebug("radio model: DE910");
Mike Fiore 11:4e428f689069 68 cell = new EasyIP(type);
Mike Fiore 11:4e428f689069 69 } else if (model.find("GE910") != string::npos) {
Mike Fiore 11:4e428f689069 70 type = Cellular::MTSMC_G3;
mfiore 16:1bc3e44d4746 71 logDebug("radio model: GE910");
Mike Fiore 11:4e428f689069 72 cell = new EasyIP(type);
Mike Fiore 11:4e428f689069 73 } else if (model.find("CE910") != string::npos) {
Mike Fiore 11:4e428f689069 74 type = Cellular::MTSMC_C2;
mfiore 16:1bc3e44d4746 75 logDebug("radio model: CE910");
Mike Fiore 11:4e428f689069 76 cell = new EasyIP(type);
Vanger 26:2b769ed8de4f 77
Mike Fiore 11:4e428f689069 78 } else {
Mike Fiore 11:4e428f689069 79 logError("cannot continue - could not determine radio type");
Mike Fiore 11:4e428f689069 80 return NULL;
Mike Fiore 11:4e428f689069 81 }
Mike Fiore 11:4e428f689069 82
Mike Fiore 11:4e428f689069 83 if (! cell->init(io)) {
Mike Fiore 11:4e428f689069 84 logError("cellular initialization failed");
Mike Fiore 11:4e428f689069 85 return NULL;
Mike Fiore 11:4e428f689069 86 }
Mike Fiore 11:4e428f689069 87
Mike Fiore 11:4e428f689069 88 return cell;
Mike Fiore 11:4e428f689069 89 }