Simple detection for LE910-NA1 modules
Fork of MTS-Cellular by
Cellular/CellularFactory.cpp@81:87c20e68b7e7, 2017-09-26 (annotated)
- Committer:
- pferland
- Date:
- Tue Sep 26 04:52:47 2017 +0000
- Revision:
- 81:87c20e68b7e7
- Parent:
- 76:6eeffc10739d
Changed LE910-NA detection to recognize cat 1 modules
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; |
Vanger | 58:de5f2c001ab0 | 12 | Cellular::Radio type = Cellular::NA; |
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 | |
Vanger | 58:de5f2c001ab0 | 26 | while (true) { |
Vanger | 58:de5f2c001ab0 | 27 | /* AT#VVERSION is a UIP specific AT command |
Vanger | 58:de5f2c001ab0 | 28 | * if we get an error response, we're not using a UIP board */ |
Vanger | 58:de5f2c001ab0 | 29 | reply = sendCommand(io, "AT#VVERSION", 2000); |
Vanger | 58:de5f2c001ab0 | 30 | if ((reply.find("ERROR") != string::npos) || (reply.find("error") != string::npos)) { |
Vanger | 58:de5f2c001ab0 | 31 | uip = false; |
Vanger | 52:2cb58398a4f9 | 32 | break; |
Vanger | 58:de5f2c001ab0 | 33 | } else if (reply.find("VVERSION:") != string::npos) { |
Vanger | 58:de5f2c001ab0 | 34 | uip = true; |
Vanger | 58:de5f2c001ab0 | 35 | break; |
Vanger | 58:de5f2c001ab0 | 36 | } else { |
Vanger | 58:de5f2c001ab0 | 37 | logTrace("Checking for UIP chip"); |
mfiore | 16:1bc3e44d4746 | 38 | } |
mfiore | 16:1bc3e44d4746 | 39 | wait(1); |
mfiore | 16:1bc3e44d4746 | 40 | } |
Vanger | 58:de5f2c001ab0 | 41 | |
Vanger | 58:de5f2c001ab0 | 42 | /* "ATI4" gets us the model (HE910, DE910, etc) */ |
Vanger | 58:de5f2c001ab0 | 43 | while (true) { |
Vanger | 58:de5f2c001ab0 | 44 | string mNumber; |
Vanger | 58:de5f2c001ab0 | 45 | model = sendCommand(io, "ATI4", 3000); |
Vanger | 58:de5f2c001ab0 | 46 | if (uip) { |
Vanger | 58:de5f2c001ab0 | 47 | if (model.find("HE910") != string::npos) { |
Vanger | 58:de5f2c001ab0 | 48 | type = Cellular::MTSMC_H5_IP; |
Vanger | 58:de5f2c001ab0 | 49 | mNumber = "HE910"; |
Vanger | 58:de5f2c001ab0 | 50 | } else if (model.find("DE910") != string::npos) { |
Vanger | 58:de5f2c001ab0 | 51 | type = Cellular::MTSMC_EV3_IP; |
Vanger | 58:de5f2c001ab0 | 52 | mNumber = "DE910"; |
Vanger | 58:de5f2c001ab0 | 53 | } else if (model.find("CE910") != string::npos) { |
Vanger | 58:de5f2c001ab0 | 54 | type = Cellular::MTSMC_C2_IP; |
Vanger | 58:de5f2c001ab0 | 55 | mNumber = "CE910"; |
Vanger | 58:de5f2c001ab0 | 56 | } |
Vanger | 58:de5f2c001ab0 | 57 | if (type != Cellular::NA) { |
Vanger | 58:de5f2c001ab0 | 58 | cell = new UIP(type); |
Vanger | 58:de5f2c001ab0 | 59 | logDebug("UIP radio model: %s", mNumber.c_str()); |
Vanger | 58:de5f2c001ab0 | 60 | break; |
Vanger | 58:de5f2c001ab0 | 61 | } |
Vanger | 58:de5f2c001ab0 | 62 | } else { |
Vanger | 58:de5f2c001ab0 | 63 | if (model.find("HE910") != string::npos) { |
Vanger | 58:de5f2c001ab0 | 64 | type = Cellular::MTSMC_H5; |
Vanger | 58:de5f2c001ab0 | 65 | mNumber = "HE910"; |
Vanger | 58:de5f2c001ab0 | 66 | } else if (model.find("DE910") != string::npos) { |
Vanger | 58:de5f2c001ab0 | 67 | type = Cellular::MTSMC_EV3; |
Vanger | 58:de5f2c001ab0 | 68 | mNumber = "DE910"; |
Vanger | 58:de5f2c001ab0 | 69 | } else if (model.find("CE910") != string::npos) { |
Vanger | 58:de5f2c001ab0 | 70 | type = Cellular::MTSMC_C2; |
Vanger | 58:de5f2c001ab0 | 71 | mNumber = "CE910"; |
Vanger | 58:de5f2c001ab0 | 72 | } else if (model.find("GE910") != string::npos) { |
Vanger | 58:de5f2c001ab0 | 73 | type = Cellular::MTSMC_G3; |
Vanger | 58:de5f2c001ab0 | 74 | mNumber = "GE910"; |
pferland | 81:87c20e68b7e7 | 75 | } else if (model.find("LE910-NA") != string::npos) { |
Vanger | 69:93dace69ee98 | 76 | type = Cellular::MTSMC_LAT1; |
Vanger | 69:93dace69ee98 | 77 | mNumber = "LE910-NAG"; |
Mike Fiore |
76:6eeffc10739d | 78 | } else if (model.find("LE910-SVG") != string::npos) { |
Mike Fiore |
76:6eeffc10739d | 79 | type = Cellular::MTSMC_LVW2; |
Mike Fiore |
76:6eeffc10739d | 80 | mNumber = "LE910-SVG"; |
Mike Fiore |
76:6eeffc10739d | 81 | } else if (model.find("LE910-EUG") != string::npos) { |
Mike Fiore |
76:6eeffc10739d | 82 | type = Cellular::MTSMC_LEU1; |
Mike Fiore |
76:6eeffc10739d | 83 | mNumber = "LE910-EUG"; |
Vanger | 58:de5f2c001ab0 | 84 | } |
Vanger | 58:de5f2c001ab0 | 85 | if (type != Cellular::NA) { |
Vanger | 58:de5f2c001ab0 | 86 | cell = new EasyIP(type); |
Vanger | 58:de5f2c001ab0 | 87 | logDebug("EasyIP radio model: %s", mNumber.c_str()); |
Vanger | 58:de5f2c001ab0 | 88 | break; |
Vanger | 58:de5f2c001ab0 | 89 | } |
Vanger | 58:de5f2c001ab0 | 90 | } |
Vanger | 58:de5f2c001ab0 | 91 | logTrace("Determining radio type"); |
Vanger | 58:de5f2c001ab0 | 92 | wait(1); |
Mike Fiore |
11:4e428f689069 | 93 | } |
Mike Fiore |
11:4e428f689069 | 94 | |
Mike Fiore |
11:4e428f689069 | 95 | if (! cell->init(io)) { |
Mike Fiore |
11:4e428f689069 | 96 | logError("cellular initialization failed"); |
Mike Fiore |
11:4e428f689069 | 97 | return NULL; |
Mike Fiore |
11:4e428f689069 | 98 | } |
Mike Fiore |
11:4e428f689069 | 99 | |
Mike Fiore |
11:4e428f689069 | 100 | return cell; |
Mike Fiore |
11:4e428f689069 | 101 | } |