Cellular library for MTS Socket Modem Arduino Shield devices from Multi-Tech Systems
Dependents: mtsas mtsas mtsas mtsas
Revision 63:f46ef5823ab5, committed 2014-08-18
- Comitter:
- Vanger
- Date:
- Mon Aug 18 17:16:27 2014 +0000
- Parent:
- 62:c171606f7318
- Child:
- 64:6b6ccf11fb4c
- Commit message:
- Added IMEI/MEID function for Cellular.cpp and Cellular.h ; (CDMA and HSPA should be identical on this point)
Changed in this revision
Cellular/Cellular.cpp | Show annotated file Show diff for this revision Revisions of this file |
Cellular/Cellular.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Cellular/Cellular.cpp Wed Aug 13 21:50:43 2014 +0000 +++ b/Cellular/Cellular.cpp Mon Aug 18 17:16:27 2014 +0000 @@ -400,6 +400,25 @@ return io->readable(); } +std::string Cellular::getEquipmentIdentifier() +{ + string num = "0123456789"; //string containing numerics to parse for + string equipmentIdentifier = sendCommand("AT+CGSN", 2000); + + if (equipmentIdentifier.find("OK") != string::npos) { + size_t posStart = equipmentIdentifier.find_first_of(num); + size_t posEnd = equipmentIdentifier.find_last_of(num); + + //Remove all except IMEI or MEID number + equipmentIdentifier = equipmentIdentifier.substr(posStart, posEnd - posStart); + } else { + //Empty string signifies failure to find Identifier + equipmentIdentifier.clear(); + } + + return equipmentIdentifier; +} + unsigned int Cellular::writeable() { if(io == NULL) {
--- a/Cellular/Cellular.h Wed Aug 13 21:50:43 2014 +0000 +++ b/Cellular/Cellular.h Mon Aug 18 17:16:27 2014 +0000 @@ -462,6 +462,12 @@ * @returns true if the IP was set, false if IP address assignment failed. */ virtual bool setDeviceIP(std::string address = "DHCP"); + + /** Get the device IMEI or MEID (whichever is available) + * @returns string containing the IMEI for GSM, the MEID for CDMA, or an empty string + * if it failed to parse the number. + */ + std::string getEquipmentIdentifier(); protected: MTSBufferedIO* io; //IO interface obect that the radio is accessed through.