ublox-cellular-base_mno

Files at this revision

API Documentation at this revision

Comitter:
wajahat.abbas@u-blox.com
Date:
Mon Aug 26 14:55:37 2019 +0500
Parent:
28:a8e1f25a8a52
Commit message:
MNO set mechanism changed

Changed in this revision

UbloxCellularBase.cpp Show annotated file Show diff for this revision Revisions of this file
UbloxCellularBase.h Show annotated file Show diff for this revision Revisions of this file
diff -r a8e1f25a8a52 -r 8a38f91009ad UbloxCellularBase.cpp
--- a/UbloxCellularBase.cpp	Mon Aug 05 11:55:52 2019 +0500
+++ b/UbloxCellularBase.cpp	Mon Aug 26 14:55:37 2019 +0500
@@ -1281,28 +1281,41 @@
 bool UbloxCellularBase::set_mno_profile(MNOProfile profile)
 {
     bool return_val = false;
+    int current_profile;
+    MNOProfile arr[MAX_NUM_PROFILES] = { SW_DEFAULT, SIM_ICCID, ATT, TMO, VODAFONE, DT, STANDARD_EU
+#ifdef  TARGET_UBLOX_C030_R410M
+                                         , VERIZON, TELSTRA, CT, SPRINT, TELUS
+#endif
+                                       };
 
-    int mno_profile;
-    if (get_mno_profile(&mno_profile)) {
-        tr_info("Current MNO profile is: %d", mno_profile);
-        if (mno_profile != profile) {
+    if (is_registered_csd() || is_registered_psd() || is_registered_eps()) {
+        tr_error("MNO profile should only be set in detached state");
+        return false;
+    }
 
-            if (is_registered_csd() || is_registered_psd() || is_registered_eps()) {
-                tr_error("MNO profile should only be set in detached state");
-                return false;
+    if (get_mno_profile(&current_profile)) {
+        if (current_profile == profile) { //Ref to UBX-18019856 7.1.7, parameters will be updated only if we switch to another profile first
+            for (uint8_t index = 0; index < MAX_NUM_PROFILES; index++) { //get the index of current profile and use the next one
+                if (arr[index] == current_profile) {
+                    index = ((index + 1) % MAX_NUM_PROFILES);
+                    current_profile = arr[index];
+                    break;
+                }
             }
 
             LOCK();
-            if (_at->send("AT+UMNOPROF=%d", profile) && _at->recv("OK")) {
-                return_val = true;
-            } else {
-                tr_error("unable to set specified profile");
+            if (_at->send("AT+UMNOPROF=%d", current_profile) && _at->recv("OK")) {
+                tr_error("temporary MNO profile set: %d", current_profile);
             }
             UNLOCK();
-
+        }
+        LOCK();
+        if (_at->send("AT+UMNOPROF=%d", profile) && _at->recv("OK")) {
+            return_val = true;
         } else {
-            return_val = true;
+            tr_error("unable to set user specified profile");
         }
+        UNLOCK();
     } else {
         tr_error("could not read MNO profile");
     }
@@ -1313,6 +1326,7 @@
 bool UbloxCellularBase::get_mno_profile(int *profile)
 {
     bool return_val = false;
+    char buf[4] = {0x00};
 
     if (profile == NULL) {
         return false;
@@ -1321,7 +1335,8 @@
     LOCK();
     MBED_ASSERT(_at != NULL);
 
-    if ( (_at->send("AT+UMNOPROF?") && _at->recv("+UMNOPROF: %d", profile) && _at->recv("OK")) )  {
+    if (_at->send("AT+UMNOPROF?") && _at->recv("+UMNOPROF: %3[^\n]\nOK\n", buf))  {
+        *profile = atoi(buf);
         return_val = true;
     }
 
@@ -1377,6 +1392,125 @@
     UNLOCK();
     return return_val;
 }
+
+int UbloxCellularBase::set_receive_period(int mode, tEDRXAccessTechnology act_type, uint8_t edrx_value) {
+    char edrx[5];
+    uint_to_binary_str(edrx_value, edrx, 5, 4);
+    edrx[4] = '\0';
+    int status = 1;
+
+    LOCK();
+
+    if (_at->send("AT+CEDRXS=%d,%d,\"%s\"", mode, act_type, edrx) && _at->recv("OK")) {
+        _edrx_configured = true;
+        status = 0;
+    }
+    else {
+        status = 1;
+    }
+
+
+    UNLOCK();
+
+    return status;
+}
+
+int UbloxCellularBase::set_receive_period(int mode, tEDRXAccessTechnology act_type) {
+    int status = 1;
+
+    LOCK();
+
+    if (_at->send("AT+CEDRXS=%d,%d", mode, act_type) && _at->recv("OK")) {
+
+        status = 0;
+    }
+    else {
+        status = 1;
+    }
+
+    UNLOCK();
+
+    return status;
+}
+
+int UbloxCellularBase::set_receive_period(int mode) {
+    int status = 1;
+
+    LOCK();
+
+    if (_at->send("AT+CEDRXS=%d", mode) && _at->recv("OK")) {
+
+        status = 0;
+    }
+    else {
+        status = 1;
+    }
+
+    UNLOCK();
+
+    return status;
+}
+
+uint32_t UbloxCellularBase::get_receive_period() {
+    uint32_t edrx_value = 2;
+    char buf[24] = {0x00};
+    char edrx_val[5];
+    tEDRXAccessTechnology act_type;
+
+    LOCK();
+
+    if (_at->send("AT+CEDRXS?") && _at->recv("%23[^\n]\nOK\n", buf)) {
+        if (sscanf(buf, "+CEDRXS: %d,\"%s\"", (int *)&act_type, edrx_val) == 2) {
+
+            edrx_value = binary_str_to_uint(edrx_val,4);
+        }
+    }
+
+    if (_at->send("AT+CEDRXRDP") && _at->recv("OK")) {
+    }
+
+    tr_info("edrx_value. %d", edrx_value);
+
+    UNLOCK();
+    return edrx_value;
+}
+
+void UbloxCellularBase::uint_to_binary_str(uint32_t num, char* str, int str_size, int bit_cnt)
+{
+    if (!str || str_size < bit_cnt) {
+        return;
+    }
+    int tmp, pos = 0;
+
+    for (int i = 31; i >= 0; i--) {
+        tmp = num >> i;
+        if (i < bit_cnt) {
+            if (tmp&1) {
+                str[pos] = 1 + '0';
+            } else {
+                str[pos] = 0 + '0';
+            }
+            pos++;
+        }
+    }
+}
+
+uint32_t UbloxCellularBase::binary_str_to_uint(const char *binary_string, int binary_string_length)
+{
+    if (!binary_string || !binary_string_length) {
+        return 0;
+    }
+
+    int integer_output = 0, base_exp = 1;
+
+    for (int i = binary_string_length - 1; i >= 0; i--) {
+        if (binary_string[i] == '1') {
+            integer_output += (base_exp << (binary_string_length - (i+1)));
+        }
+    }
+
+    return integer_output;
+}
 #endif
 
 #ifdef TARGET_UBLOX_C030_R412M
@@ -1632,132 +1766,11 @@
     return return_val;
 }
 
-void UbloxCellularBase::uint_to_binary_str(uint32_t num, char* str, int str_size, int bit_cnt)
-{
-    if (!str || str_size < bit_cnt) {
-        return;
-    }
-    int tmp, pos = 0;
-
-    for (int i = 31; i >= 0; i--) {
-        tmp = num >> i;
-        if (i < bit_cnt) {
-            if (tmp&1) {
-                str[pos] = 1 + '0';
-            } else {
-                str[pos] = 0 + '0';
-            }
-            pos++;
-        }
-    }
-}
-
-uint32_t UbloxCellularBase::binary_str_to_uint(const char *binary_string, int binary_string_length)
-{
-    if (!binary_string || !binary_string_length) {
-        return 0;
-    }
-
-    int integer_output = 0, base_exp = 1;
-
-    for (int i = binary_string_length - 1; i >= 0; i--) {
-        if (binary_string[i] == '1') {
-            integer_output += (base_exp << (binary_string_length - (i+1)));
-        }
-    }
-
-    return integer_output;
-}
-
 bool UbloxCellularBase::is_modem_awake()
 {
   return (_dev_info.modem_psm_state == AWAKE);
 }
 
-#ifdef TARGET_UBLOX_C030_R41XM
-int UbloxCellularBase::set_receive_period(int mode, tEDRXAccessTechnology act_type, uint8_t edrx_value) {
-    char edrx[5];
-    uint_to_binary_str(edrx_value, edrx, 5, 4);
-    edrx[4] = '\0';
-    int status = 1;
-
-    LOCK();
-
-    if (_at->send("AT+CEDRXS=%d,%d,\"%s\"", mode, act_type, edrx) && _at->recv("OK")) {
-        _edrx_configured = true;
-        status = 0;
-    }
-    else {
-        status = 1;
-    }
-
-
-    UNLOCK();
-
-    return status;
-}
-
-int UbloxCellularBase::set_receive_period(int mode, tEDRXAccessTechnology act_type) {
-    int status = 1;
-
-    LOCK();
-
-    if (_at->send("AT+CEDRXS=%d,%d", mode, act_type) && _at->recv("OK")) {
-
-        status = 0;
-    }
-    else {
-        status = 1;
-    }
-
-    UNLOCK();
-
-    return status;
-}
-
-int UbloxCellularBase::set_receive_period(int mode) {
-    int status = 1;
-
-    LOCK();
-
-    if (_at->send("AT+CEDRXS=%d", mode) && _at->recv("OK")) {
-
-        status = 0;
-    }
-    else {
-        status = 1;
-    }
-
-    UNLOCK();
-
-    return status;
-}
-
-uint32_t UbloxCellularBase::get_receive_period() {
-    uint32_t edrx_value = 2;
-    char buf[24] = {0x00};
-    char edrx_val[5];
-    tEDRXAccessTechnology act_type;
-
-    LOCK();
-
-    if (_at->send("AT+CEDRXS?") && _at->recv("%23[^\n]\nOK\n", buf)) {
-        if (sscanf(buf, "+CEDRXS: %d,\"%s\"", (int *)&act_type, edrx_val) == 2) {
-
-            edrx_value = binary_str_to_uint(edrx_val,4);
-        }
-    }
-
-    if (_at->send("AT+CEDRXRDP") && _at->recv("OK")) {
-    }
-
-    tr_info("edrx_value. %d", edrx_value);
-
-    UNLOCK();
-    return edrx_value;
-}
-#endif //TARGET_UBLOX_C030_R41XM
-
 //application should call init() or connect() in order to initialize the modem
 void UbloxCellularBase::wakeup_modem()
 {
@@ -1777,5 +1790,6 @@
     UNLOCK();
 }
 #endif
+
 // End of File
 
diff -r a8e1f25a8a52 -r 8a38f91009ad UbloxCellularBase.h
--- a/UbloxCellularBase.h	Mon Aug 05 11:55:52 2019 +0500
+++ b/UbloxCellularBase.h	Mon Aug 26 14:55:37 2019 +0500
@@ -21,6 +21,12 @@
 #include "ubloxATCmdParser.h"
 #include "FileHandle.h"
 
+#ifdef TARGET_UBLOX_C030_R410M
+#define MAX_NUM_PROFILES 12 //ref to enum MNOProfile
+#elif TARGET_UBLOX_C030_R412M
+#define MAX_NUM_PROFILES 7
+#endif
+
 /**********************************************************************
  * CLASSES
  **********************************************************************/
@@ -232,14 +238,17 @@
         SW_DEFAULT = 0,
         SIM_ICCID = 1,
         ATT = 2,
-        VERIZON = 3,
-        TELSTRA = 4,
         TMO = 5,
-        CT = 6,
         VODAFONE = 19,
-        TELUS = 21,
         DT = 31,
         STANDARD_EU = 100
+#ifdef TARGET_UBLOX_C030_R410M
+        , VERIZON = 3,
+        TELSTRA = 4,
+        CT = 6,
+        SPRINT = 8,
+        TELUS = 21
+#endif
     } MNOProfile;
 
     #if MBED_CONF_UBLOX_CELL_DEFAULT_MNO_PROFILE
@@ -252,7 +261,8 @@
      * User can also specify profile in mbed_lib.json file and call set_mno_profile without any arguments.
      *
      * Note: MNO profile should only be set in detached state and a reboot is required for settings to take effect
-     *
+     * Note 2: ref to UBX-17003787 B.5, setting MNO profile can change other parameters such as PSM, Band mask, URAT etc.
+     *         Application must always set a profile first and if required, change parameters afterwards.
      * @param profile MNO profile to use
      * @return    true if operation was successful, false if there was an error
      */
@@ -697,7 +707,7 @@
      */
     bool initialise_sim_card();
 
-#ifdef TARGET_UBLOX_C030_R412M
+#ifdef TARGET_UBLOX_C030_R41XM
     /** Converts the given uint to binary string. Fills the given str starting from [0] with the number of bits defined by bit_cnt
      *  For example uint_to_binary_string(9, str, 10) would fill str "0000001001"
      *  For example uint_to_binary_string(9, str, 3) would fill str "001"