Cellular library for MTS Socket Modem Arduino Shield devices from Multi-Tech Systems
Dependents: mtsas mtsas mtsas mtsas
Cellular/CellularFactory.cpp@51:ffc556ba33f7, 2014-08-05 (annotated)
- Committer:
- Vanger
- Date:
- Tue Aug 05 18:35:22 2014 +0000
- Revision:
- 51:ffc556ba33f7
- Parent:
- 41:8b9b5098696f
- Child:
- 52:2cb58398a4f9
Changed some comment lines in CellularFactory.cpp, EasyIP.cpp, UIP.cpp; Changed Cellular.cpp sendCommand() function to explicitly check for UIP responses, and removed 5ms wait between read cycles.
Who changed what in which revision?
User | Revision | Line number | New 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 | 41:8b9b5098696f | 32 | //If response found is from unsolicited response #STN: from the radio, |
Vanger | 51:ffc556ba33f7 | 33 | //then we got an unsolicited response, and to try again. |
Vanger | 41:8b9b5098696f | 34 | continue; |
Vanger | 41:8b9b5098696f | 35 | } |
Vanger | 41:8b9b5098696f | 36 | break; |
mfiore | 16:1bc3e44d4746 | 37 | } |
mfiore | 16:1bc3e44d4746 | 38 | |
mfiore | 16:1bc3e44d4746 | 39 | wait(1); |
mfiore | 16:1bc3e44d4746 | 40 | } |
Mike Fiore |
11:4e428f689069 | 41 | |
Vanger | 26:2b769ed8de4f | 42 | /* AT#VVERSION is a UIP specific AT command |
Mike Fiore |
11:4e428f689069 | 43 | * if we get an error response, we're not using a UIP board */ |
Mike Fiore |
11:4e428f689069 | 44 | reply = sendCommand(io, "AT#VVERSION", 2000); |
Vanger | 27:ec44d5a9544f | 45 | if ((reply.find("ERROR") != string::npos) || (reply.find("error") != string::npos)) { |
Mike Fiore |
11:4e428f689069 | 46 | uip = false; |
Mike Fiore |
11:4e428f689069 | 47 | } else { |
Mike Fiore |
11:4e428f689069 | 48 | uip = true; |
Mike Fiore |
11:4e428f689069 | 49 | } |
Vanger | 26:2b769ed8de4f | 50 | |
Mike Fiore |
11:4e428f689069 | 51 | |
Mike Fiore |
11:4e428f689069 | 52 | if (uip && model.find("HE910") != string::npos) { |
Mike Fiore |
11:4e428f689069 | 53 | type = Cellular::MTSMC_H5_IP; |
mfiore | 16:1bc3e44d4746 | 54 | logDebug("radio model: HE910"); |
Mike Fiore |
11:4e428f689069 | 55 | cell = new UIP(type); |
Mike Fiore |
11:4e428f689069 | 56 | } else if (uip && model.find("DE910") != string::npos) { |
Mike Fiore |
11:4e428f689069 | 57 | type = Cellular::MTSMC_EV3_IP; |
mfiore | 16:1bc3e44d4746 | 58 | logDebug("radio model: DE910"); |
Mike Fiore |
11:4e428f689069 | 59 | cell = new UIP(type); |
Mike Fiore |
11:4e428f689069 | 60 | } else if (uip && model.find("CE910") != string::npos) { |
Mike Fiore |
11:4e428f689069 | 61 | type = Cellular::MTSMC_C2_IP; |
mfiore | 16:1bc3e44d4746 | 62 | logDebug("radio model: CE910"); |
Mike Fiore |
11:4e428f689069 | 63 | cell = new UIP(type); |
Vanger | 26:2b769ed8de4f | 64 | |
Mike Fiore |
11:4e428f689069 | 65 | } else if (model.find("HE910") != string::npos) { |
Mike Fiore |
11:4e428f689069 | 66 | type = Cellular::MTSMC_H5; |
mfiore | 16:1bc3e44d4746 | 67 | logDebug("radio model: HE910"); |
Mike Fiore |
11:4e428f689069 | 68 | cell = new EasyIP(type); |
Mike Fiore |
11:4e428f689069 | 69 | } else if (model.find("DE910") != string::npos) { |
Mike Fiore |
11:4e428f689069 | 70 | type = Cellular::MTSMC_EV3; |
mfiore | 16:1bc3e44d4746 | 71 | logDebug("radio model: DE910"); |
Mike Fiore |
11:4e428f689069 | 72 | cell = new EasyIP(type); |
Mike Fiore |
11:4e428f689069 | 73 | } else if (model.find("GE910") != string::npos) { |
Mike Fiore |
11:4e428f689069 | 74 | type = Cellular::MTSMC_G3; |
mfiore | 16:1bc3e44d4746 | 75 | logDebug("radio model: GE910"); |
Mike Fiore |
11:4e428f689069 | 76 | cell = new EasyIP(type); |
Mike Fiore |
11:4e428f689069 | 77 | } else if (model.find("CE910") != string::npos) { |
Mike Fiore |
11:4e428f689069 | 78 | type = Cellular::MTSMC_C2; |
mfiore | 16:1bc3e44d4746 | 79 | logDebug("radio model: CE910"); |
Mike Fiore |
11:4e428f689069 | 80 | cell = new EasyIP(type); |
Vanger | 26:2b769ed8de4f | 81 | |
Mike Fiore |
11:4e428f689069 | 82 | } else { |
Mike Fiore |
11:4e428f689069 | 83 | logError("cannot continue - could not determine radio type"); |
Mike Fiore |
11:4e428f689069 | 84 | return NULL; |
Mike Fiore |
11:4e428f689069 | 85 | } |
Mike Fiore |
11:4e428f689069 | 86 | |
Mike Fiore |
11:4e428f689069 | 87 | if (! cell->init(io)) { |
Mike Fiore |
11:4e428f689069 | 88 | logError("cellular initialization failed"); |
Mike Fiore |
11:4e428f689069 | 89 | return NULL; |
Mike Fiore |
11:4e428f689069 | 90 | } |
Mike Fiore |
11:4e428f689069 | 91 | |
Mike Fiore |
11:4e428f689069 | 92 | return cell; |
Mike Fiore |
11:4e428f689069 | 93 | } |