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

Dependents:   mtsas mtsas mtsas mtsas

Committer:
Mike Fiore
Date:
Thu May 22 09:26:51 2014 -0500
Revision:
11:4e428f689069
Child:
14:614952fb3af3
add CellularFactory to automatically detect and create right type of Cellular class
add static sendCommand function to CellUtils so we can talk to radio before instantiating Cellular
add Cellular::Radio param to UIP constructor

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) {
Mike Fiore 11:4e428f689069 18 logDebug("radio replied");
Mike Fiore 11:4e428f689069 19 break;
Mike Fiore 11:4e428f689069 20 } else {
Mike Fiore 11:4e428f689069 21 logDebug("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) */
Mike Fiore 11:4e428f689069 28 model = sendCommand(io, "ATI4", 2000);
Mike Fiore 11:4e428f689069 29
Mike Fiore 11:4e428f689069 30 /* AT#VVERSION is a IUP specific AT command
Mike Fiore 11:4e428f689069 31 * if we get an error response, we're not using a UIP board */
Mike Fiore 11:4e428f689069 32 reply = sendCommand(io, "AT#VVERSION", 2000);
Mike Fiore 11:4e428f689069 33 if (reply.find("error") != string::npos) {
Mike Fiore 11:4e428f689069 34 uip = false;
Mike Fiore 11:4e428f689069 35 } else {
Mike Fiore 11:4e428f689069 36 uip = true;
Mike Fiore 11:4e428f689069 37 }
Mike Fiore 11:4e428f689069 38
Mike Fiore 11:4e428f689069 39 if (uip && model.find("HE910") != string::npos) {
Mike Fiore 11:4e428f689069 40 type = Cellular::MTSMC_H5_IP;
Mike Fiore 11:4e428f689069 41 cell = new UIP(type);
Mike Fiore 11:4e428f689069 42 } else if (uip && model.find("DE910") != string::npos) {
Mike Fiore 11:4e428f689069 43 type = Cellular::MTSMC_EV3_IP;
Mike Fiore 11:4e428f689069 44 cell = new UIP(type);
Mike Fiore 11:4e428f689069 45 } else if (uip && model.find("CE910") != string::npos) {
Mike Fiore 11:4e428f689069 46 type = Cellular::MTSMC_C2_IP;
Mike Fiore 11:4e428f689069 47 cell = new UIP(type);
Mike Fiore 11:4e428f689069 48 /*
Mike Fiore 11:4e428f689069 49 } else if (model.find("HE910") != string::npos) {
Mike Fiore 11:4e428f689069 50 type = Cellular::MTSMC_H5;
Mike Fiore 11:4e428f689069 51 logDebug("%s", Cellular::getRadioNames(type).data());
Mike Fiore 11:4e428f689069 52 cell = new EasyIP(type);
Mike Fiore 11:4e428f689069 53 } else if (model.find("DE910") != string::npos) {
Mike Fiore 11:4e428f689069 54 type = Cellular::MTSMC_EV3;
Mike Fiore 11:4e428f689069 55 logDebug("%s", Cellular::getRadioNames(type).data());
Mike Fiore 11:4e428f689069 56 cell = new EasyIP(type);
Mike Fiore 11:4e428f689069 57 } else if (model.find("GE910") != string::npos) {
Mike Fiore 11:4e428f689069 58 type = Cellular::MTSMC_G3;
Mike Fiore 11:4e428f689069 59 logDebug("%s", Cellular::getRadioNames(type).data());
Mike Fiore 11:4e428f689069 60 cell = new EasyIP(type);
Mike Fiore 11:4e428f689069 61 } else if (model.find("CE910") != string::npos) {
Mike Fiore 11:4e428f689069 62 type = Cellular::MTSMC_C2;
Mike Fiore 11:4e428f689069 63 logDebug("%s", Cellular::getRadioNames(type).data());
Mike Fiore 11:4e428f689069 64 cell = new EasyIP(type);
Mike Fiore 11:4e428f689069 65 */
Mike Fiore 11:4e428f689069 66 } else {
Mike Fiore 11:4e428f689069 67 logError("cannot continue - could not determine radio type");
Mike Fiore 11:4e428f689069 68 return NULL;
Mike Fiore 11:4e428f689069 69 }
Mike Fiore 11:4e428f689069 70
Mike Fiore 11:4e428f689069 71 if (! cell->init(io)) {
Mike Fiore 11:4e428f689069 72 logError("cellular initialization failed");
Mike Fiore 11:4e428f689069 73 return NULL;
Mike Fiore 11:4e428f689069 74 }
Mike Fiore 11:4e428f689069 75
Mike Fiore 11:4e428f689069 76 return cell;
Mike Fiore 11:4e428f689069 77 }