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

Dependents:   mtsas mtsas mtsas mtsas

Committer:
Vanger
Date:
Mon Jul 14 17:33:24 2014 +0000
Revision:
30:1326b623919a
Parent:
27:ec44d5a9544f
Child:
41:8b9b5098696f
For EasyIP.cpp:; Made sendEscapeCommand() and socketCheck() socket closed verification; connect(), disconnect(), and isConnected() were tweaked; IMPL. bind(),open(),isOpen(),close(),read(),write(),readable(),writeable(),reset(); Fixed bug in CellUtils.h;

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;
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
Mike Fiore 11:4e428f689069 26 /* "ATI4" gets us the model (HE910, DE910, etc) */
mfiore 16:1bc3e44d4746 27 for (int i = 0; i < 5; i++) {
mfiore 16:1bc3e44d4746 28 model = sendCommand(io, "ATI4", 2000);
Vanger 30:1326b623919a 29 if (model.find("error") == string::npos && model.find("ERROR") == string::npos && !model.empty()) {
mfiore 16:1bc3e44d4746 30 /* didn't get an error - keep going */
mfiore 16:1bc3e44d4746 31 break;
mfiore 16:1bc3e44d4746 32 }
mfiore 16:1bc3e44d4746 33
mfiore 16:1bc3e44d4746 34 wait(1);
mfiore 16:1bc3e44d4746 35 }
Mike Fiore 11:4e428f689069 36
Vanger 26:2b769ed8de4f 37 /* AT#VVERSION is a UIP specific AT command
Mike Fiore 11:4e428f689069 38 * if we get an error response, we're not using a UIP board */
Mike Fiore 11:4e428f689069 39 reply = sendCommand(io, "AT#VVERSION", 2000);
Vanger 27:ec44d5a9544f 40 if ((reply.find("ERROR") != string::npos) || (reply.find("error") != string::npos)) {
Mike Fiore 11:4e428f689069 41 uip = false;
Mike Fiore 11:4e428f689069 42 } else {
Mike Fiore 11:4e428f689069 43 uip = true;
Mike Fiore 11:4e428f689069 44 }
Vanger 26:2b769ed8de4f 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);
Vanger 26:2b769ed8de4f 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);
Vanger 26:2b769ed8de4f 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 }