Simple detection for LE910-NA1 modules

Fork of MTS-Cellular by MultiTech

Committer:
Vanger
Date:
Mon Aug 11 16:03:19 2014 +0000
Revision:
52:2cb58398a4f9
Parent:
51:ffc556ba33f7
Child:
58:de5f2c001ab0
Removed parse response '>' from sendCommand() under Cellular.cpp, changed sendSMS() to verify sending SMS message under Cellular.cpp, changed disconnect() to have better flow under EasyIP.cpp, changed isConnected() to be simpler under EasyIP.cpp

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++) {
Vanger 41:8b9b5098696f 28 model = sendCommand(io, "ATI4", 3000);
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 */
Vanger 41:8b9b5098696f 31 if(model.find("#STN") != string::npos) {
Vanger 52:2cb58398a4f9 32 //Temporary fix for unsolicited #STN from radio startup
Vanger 41:8b9b5098696f 33 continue;
Vanger 41:8b9b5098696f 34 }
Vanger 52:2cb58398a4f9 35 break;
mfiore 16:1bc3e44d4746 36 }
mfiore 16:1bc3e44d4746 37
mfiore 16:1bc3e44d4746 38 wait(1);
mfiore 16:1bc3e44d4746 39 }
Mike Fiore 11:4e428f689069 40
Vanger 26:2b769ed8de4f 41 /* AT#VVERSION is a UIP specific AT command
Mike Fiore 11:4e428f689069 42 * if we get an error response, we're not using a UIP board */
Mike Fiore 11:4e428f689069 43 reply = sendCommand(io, "AT#VVERSION", 2000);
Vanger 27:ec44d5a9544f 44 if ((reply.find("ERROR") != string::npos) || (reply.find("error") != string::npos)) {
Mike Fiore 11:4e428f689069 45 uip = false;
Mike Fiore 11:4e428f689069 46 } else {
Mike Fiore 11:4e428f689069 47 uip = true;
Mike Fiore 11:4e428f689069 48 }
Mike Fiore 11:4e428f689069 49
Mike Fiore 11:4e428f689069 50 if (uip && model.find("HE910") != string::npos) {
Mike Fiore 11:4e428f689069 51 type = Cellular::MTSMC_H5_IP;
Vanger 52:2cb58398a4f9 52 logDebug("UIP radio model: HE910");
Mike Fiore 11:4e428f689069 53 cell = new UIP(type);
Mike Fiore 11:4e428f689069 54 } else if (uip && model.find("DE910") != string::npos) {
Mike Fiore 11:4e428f689069 55 type = Cellular::MTSMC_EV3_IP;
Vanger 52:2cb58398a4f9 56 logDebug("UIP radio model: DE910");
Mike Fiore 11:4e428f689069 57 cell = new UIP(type);
Mike Fiore 11:4e428f689069 58 } else if (uip && model.find("CE910") != string::npos) {
Mike Fiore 11:4e428f689069 59 type = Cellular::MTSMC_C2_IP;
Vanger 52:2cb58398a4f9 60 logDebug("UIP radio model: CE910");
Mike Fiore 11:4e428f689069 61 cell = new UIP(type);
Mike Fiore 11:4e428f689069 62 } else if (model.find("HE910") != string::npos) {
Mike Fiore 11:4e428f689069 63 type = Cellular::MTSMC_H5;
mfiore 16:1bc3e44d4746 64 logDebug("radio model: HE910");
Mike Fiore 11:4e428f689069 65 cell = new EasyIP(type);
Mike Fiore 11:4e428f689069 66 } else if (model.find("DE910") != string::npos) {
Mike Fiore 11:4e428f689069 67 type = Cellular::MTSMC_EV3;
mfiore 16:1bc3e44d4746 68 logDebug("radio model: DE910");
Mike Fiore 11:4e428f689069 69 cell = new EasyIP(type);
Mike Fiore 11:4e428f689069 70 } else if (model.find("GE910") != string::npos) {
Mike Fiore 11:4e428f689069 71 type = Cellular::MTSMC_G3;
mfiore 16:1bc3e44d4746 72 logDebug("radio model: GE910");
Mike Fiore 11:4e428f689069 73 cell = new EasyIP(type);
Mike Fiore 11:4e428f689069 74 } else if (model.find("CE910") != string::npos) {
Mike Fiore 11:4e428f689069 75 type = Cellular::MTSMC_C2;
mfiore 16:1bc3e44d4746 76 logDebug("radio model: CE910");
Mike Fiore 11:4e428f689069 77 cell = new EasyIP(type);
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 }