Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MTS-Cellular by
Diff: Cellular/CellularFactory.cpp
- Revision:
- 58:de5f2c001ab0
- Parent:
- 52:2cb58398a4f9
- Child:
- 69:93dace69ee98
--- a/Cellular/CellularFactory.cpp Wed Aug 13 17:13:51 2014 +0000
+++ b/Cellular/CellularFactory.cpp Wed Aug 13 19:47:19 2014 +0000
@@ -9,7 +9,7 @@
bool uip;
std::string model;
std::string reply;
- Cellular::Radio type;
+ Cellular::Radio type = Cellular::NA;
Cellular* cell;
/* wait for radio to get into a good state */
@@ -23,61 +23,64 @@
wait(1);
}
- /* "ATI4" gets us the model (HE910, DE910, etc) */
- for (int i = 0; i < 5; i++) {
- model = sendCommand(io, "ATI4", 3000);
- if (model.find("error") == string::npos && model.find("ERROR") == string::npos && !model.empty()) {
- /* didn't get an error - keep going */
- if(model.find("#STN") != string::npos) {
- //Temporary fix for unsolicited #STN from radio startup
- continue;
- }
+ while (true) {
+ /* AT#VVERSION is a UIP specific AT command
+ * if we get an error response, we're not using a UIP board */
+ reply = sendCommand(io, "AT#VVERSION", 2000);
+ if ((reply.find("ERROR") != string::npos) || (reply.find("error") != string::npos)) {
+ uip = false;
break;
+ } else if (reply.find("VVERSION:") != string::npos) {
+ uip = true;
+ break;
+ } else {
+ logTrace("Checking for UIP chip");
}
-
wait(1);
}
-
- /* AT#VVERSION is a UIP specific AT command
- * if we get an error response, we're not using a UIP board */
- reply = sendCommand(io, "AT#VVERSION", 2000);
- if ((reply.find("ERROR") != string::npos) || (reply.find("error") != string::npos)) {
- uip = false;
- } else {
- uip = true;
- }
-
- if (uip && model.find("HE910") != string::npos) {
- type = Cellular::MTSMC_H5_IP;
- logDebug("UIP radio model: HE910");
- cell = new UIP(type);
- } else if (uip && model.find("DE910") != string::npos) {
- type = Cellular::MTSMC_EV3_IP;
- logDebug("UIP radio model: DE910");
- cell = new UIP(type);
- } else if (uip && model.find("CE910") != string::npos) {
- type = Cellular::MTSMC_C2_IP;
- logDebug("UIP radio model: CE910");
- cell = new UIP(type);
- } else if (model.find("HE910") != string::npos) {
- type = Cellular::MTSMC_H5;
- logDebug("radio model: HE910");
- cell = new EasyIP(type);
- } else if (model.find("DE910") != string::npos) {
- type = Cellular::MTSMC_EV3;
- logDebug("radio model: DE910");
- cell = new EasyIP(type);
- } else if (model.find("GE910") != string::npos) {
- type = Cellular::MTSMC_G3;
- logDebug("radio model: GE910");
- cell = new EasyIP(type);
- } else if (model.find("CE910") != string::npos) {
- type = Cellular::MTSMC_C2;
- logDebug("radio model: CE910");
- cell = new EasyIP(type);
- } else {
- logError("cannot continue - could not determine radio type");
- return NULL;
+
+ /* "ATI4" gets us the model (HE910, DE910, etc) */
+ while (true) {
+ string mNumber;
+ model = sendCommand(io, "ATI4", 3000);
+ if (uip) {
+ if (model.find("HE910") != string::npos) {
+ type = Cellular::MTSMC_H5_IP;
+ mNumber = "HE910";
+ } else if (model.find("DE910") != string::npos) {
+ type = Cellular::MTSMC_EV3_IP;
+ mNumber = "DE910";
+ } else if (model.find("CE910") != string::npos) {
+ type = Cellular::MTSMC_C2_IP;
+ mNumber = "CE910";
+ }
+ if (type != Cellular::NA) {
+ cell = new UIP(type);
+ logDebug("UIP radio model: %s", mNumber.c_str());
+ break;
+ }
+ } else {
+ if (model.find("HE910") != string::npos) {
+ type = Cellular::MTSMC_H5;
+ mNumber = "HE910";
+ } else if (model.find("DE910") != string::npos) {
+ type = Cellular::MTSMC_EV3;
+ mNumber = "DE910";
+ } else if (model.find("CE910") != string::npos) {
+ type = Cellular::MTSMC_C2;
+ mNumber = "CE910";
+ } else if (model.find("GE910") != string::npos) {
+ type = Cellular::MTSMC_G3;
+ mNumber = "GE910";
+ }
+ if (type != Cellular::NA) {
+ cell = new EasyIP(type);
+ logDebug("EasyIP radio model: %s", mNumber.c_str());
+ break;
+ }
+ }
+ logTrace("Determining radio type");
+ wait(1);
}
if (! cell->init(io)) {
