Cellular library for MTS Socket Modem Arduino Shield devices from Multi-Tech Systems

Dependents:   mtsas mtsas mtsas mtsas

Files at this revision

API Documentation at this revision

Comitter:
Vanger
Date:
Mon Aug 18 18:42:24 2014 +0000
Parent:
63:f46ef5823ab5
Child:
65:2cdd943bb3a3
Commit message:
Changed getEquipmentIdentifier() under Cellular.cpp to be more robust; (Will now work for MEID hex resposnes, as well as decimal responses)

Changed in this revision

Cellular/Cellular.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Cellular/Cellular.cpp	Mon Aug 18 17:16:27 2014 +0000
+++ b/Cellular/Cellular.cpp	Mon Aug 18 18:42:24 2014 +0000
@@ -402,17 +402,17 @@
 
 std::string Cellular::getEquipmentIdentifier()
 {
-    string num = "0123456789"; //string containing numerics to parse for
-    string equipmentIdentifier = sendCommand("AT+CGSN", 2000);
+    string command = "AT+CGSN";
+    string equipmentIdentifier = sendCommand(command, 2000);
     
-    if (equipmentIdentifier.find("OK") != string::npos) {
-        size_t posStart = equipmentIdentifier.find_first_of(num);
-        size_t posEnd = equipmentIdentifier.find_last_of(num);
+    if (equipmentIdentifier.find("OK") != string::npos) {                
+        size_t cursor; //Dummy var
         
-        //Remove all except IMEI or MEID number
-        equipmentIdentifier = equipmentIdentifier.substr(posStart, posEnd - posStart);
+        //Need +3 due to /r from echo, and /r/n from radio 
+        //between command echo and equipment identifier number.
+        equipmentIdentifier = Text::getLine(equipmentIdentifier, command.size() + 3, cursor);
     } else {
-        //Empty string signifies failure to find Identifier
+        //Empty string signifies failure
         equipmentIdentifier.clear();
     }