ublox-cellular-base

Files at this revision

API Documentation at this revision

Comitter:
wajahat.abbas@u-blox.com
Date:
Fri Mar 22 13:45:51 2019 +0500
Parent:
19:15f31e074d67
Child:
21:98aea8f49cd8
Commit message:
Added support for +URAT and +UMNOPROF commands

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
mbed_lib.json Show annotated file Show diff for this revision Revisions of this file
--- a/UbloxCellularBase.cpp	Mon Sep 17 10:46:14 2018 +0000
+++ b/UbloxCellularBase.cpp	Fri Mar 22 13:45:51 2019 +0500
@@ -1061,5 +1061,152 @@
     return rssiRet;
 }
 
+//RAT should be set in a detached state (AT+COPS=2)
+bool UbloxCellularBase::set_modem_rat(RAT selected_rat, RAT preferred_rat, RAT second_preferred_rat)
+{
+    bool success = false;
+    char command[16] = {0x00};
+
+    //check if modem is registered with network
+    if (is_registered_csd() || is_registered_psd() || is_registered_eps()) {
+        tr_error("RAT should only be set in detached state");
+        return false;
+    }
+
+    if (preferred_rat != NOT_USED && second_preferred_rat != NOT_USED) {
+        sprintf(command, "AT+URAT=%d,%d,%d", selected_rat, preferred_rat, second_preferred_rat);
+    } else if (preferred_rat != NOT_USED) {
+        sprintf(command, "AT+URAT=%d,%d", selected_rat, preferred_rat);
+    } else if (second_preferred_rat != NOT_USED) {
+        sprintf(command, "AT+URAT=%d,%d", selected_rat, second_preferred_rat);
+    } else {
+        sprintf(command, "AT+URAT=%d", selected_rat);
+    }
+
+    LOCK();
+    if (_at->send(command) && _at->recv("OK"))  {
+        success = true;
+    } else {
+        tr_error("unable to set the specified RAT");
+        success = false;
+    }
+    UNLOCK();
+
+    return success;
+}
+
+bool UbloxCellularBase::get_modem_rat(RAT *selected_rat, RAT *preferred_rat, RAT *second_preferred_rat)
+{
+    bool success = false;
+    char buf[24] = {0x00};
+
+    if (selected_rat == NULL || preferred_rat == NULL || second_preferred_rat == NULL) {
+        tr_info("invalid pointers");
+        return false;
+    }
+
+    MBED_ASSERT(_at != NULL);
+
+    *selected_rat = NOT_USED;
+    *preferred_rat = NOT_USED;
+    *second_preferred_rat = NOT_USED;
+
+    LOCK();
+
+    if (_at->send("AT+URAT?") && _at->recv("%23[^\n]\nOK\n", buf)) {
+        if (sscanf(buf, "+URAT: %d,%d,%d", (int*)selected_rat, (int*)preferred_rat, (int*)second_preferred_rat) == 3) {
+            success = true;
+        } else if (sscanf(buf, "+URAT: %d,%d", (int*)selected_rat, (int*)preferred_rat) == 2) {
+            success = true;
+        } else if (sscanf(buf, "+URAT: %d", (int*)selected_rat) == 1) {
+            success = true;
+        }
+    }
+
+    UNLOCK();
+    return success;
+}
+
+// Power down modem via AT interface.
+bool UbloxCellularBase::reboot_modem()
+{
+    bool return_val = false;
+    int at_timeout;
+    LOCK();
+
+    MBED_ASSERT(_at != NULL);
+
+    at_timeout = _at_timeout; // Has to be inside LOCK()s
+    at_set_timeout(3*60*1000); //command has 3 minutes timeout
+    tr_info("rebooting modem...");
+
+    if (_at->send("AT+CFUN=15") && _at->recv("OK")) {
+        tr_info("reboot successful");
+        return_val = true;
+    }
+
+    _dev_info.reg_status_csd = CSD_NOT_REGISTERED_NOT_SEARCHING;
+    _dev_info.reg_status_psd = PSD_NOT_REGISTERED_NOT_SEARCHING;
+    _dev_info.reg_status_eps = EPS_NOT_REGISTERED_NOT_SEARCHING;
+    _modem_initialised = false;
+    at_set_timeout(at_timeout);
+    UNLOCK();
+
+    return return_val;
+}
+
+#ifdef TARGET_UBLOX_C030_R41XM
+bool UbloxCellularBase::set_mno_profile(MNOProfile profile)
+{
+    bool return_val = false;
+
+    MNOProfile mno_profile;
+    if (get_mno_profile(&mno_profile)) {
+        tr_info("Current MNO profile is: %d", (int)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;
+            }
+
+            LOCK();
+            if (_at->send("AT+UMNOPROF=%d", profile) && _at->recv("OK")) {
+                return_val = true;
+            } else {
+                tr_error("unable to set specified profile");
+            }
+            UNLOCK();
+
+        } else {
+            return_val = true;
+        }
+    } else {
+        tr_error("could not read MNO profile");
+    }
+
+    return return_val;
+}
+
+bool UbloxCellularBase::get_mno_profile(MNOProfile *profile)
+{
+    bool return_val = false;
+
+    if (profile == NULL) {
+        return false;
+    }
+
+    LOCK();
+    MBED_ASSERT(_at != NULL);
+
+    if ( (_at->send("AT+UMNOPROF?") && _at->recv("+UMNOPROF: %d", (int*)profile) && _at->recv("OK")) )  {
+        return_val = true;
+    }
+
+    UNLOCK();
+    return return_val;
+}
+#endif
+
 // End of File
 
--- a/UbloxCellularBase.h	Mon Sep 17 10:46:14 2018 +0000
+++ b/UbloxCellularBase.h	Fri Mar 22 13:45:51 2019 +0500
@@ -174,6 +174,89 @@
      */
     int rssi();
 
+    /** RAT values for +URAT command
+     * R412M only supports value 7 (CatM1), 8 (NB1), and 9 (GPRS)
+     */
+    typedef enum {
+        GSM_GPRS_EGPRS = 0,
+        GSM_UMTS = 1,
+        UMTS = 2,
+        URAT_LTE = 3,
+        GSM_UMTS_LTE = 4,
+        GSM_LTE = 5,
+        UMTS_LTE = 6,
+        LTE_CATM1 = 7,
+        LTE_CATNB1 = 8,
+        GPRS_EGPRS = 9,
+        NOT_USED = 255
+    } RAT;
+
+#ifdef TARGET_UBLOX_C030_R41XM
+    /** Supported MNO profiles for SARA-R4.
+     */
+    typedef enum {
+        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
+    } MNOProfile;
+
+    #if MBED_CONF_UBLOX_CELL_DEFAULT_MNO_PROFILE
+    #define DEFAULT_MNO_PROFILE     (MNOProfile)MBED_CONF_UBLOX_CELL_DEFAULT_MNO_PROFILE
+    #else
+    #define DEFAULT_MNO_PROFILE     SW_DEFAULT
+    #endif
+
+    /** Reads the current MNO profile from modem and sets it to user specified profile
+     *
+     * @return    true if operation was successful, false if there was an error
+     */
+    bool set_mno_profile(MNOProfile profile = DEFAULT_MNO_PROFILE);
+
+    /** Get current MNO profile.
+     *
+     * @param profile pointer to variable that can hold the value for returned profile
+     * @return    true if operation was successful, false if there was an error
+     */
+    bool get_mno_profile(MNOProfile *profile);
+#endif
+
+    /** Set Radio Access Technology on modem.
+     *
+     * Note: RAT should only be set in detached state and a reboot is required for settings to take effect
+     *
+     * @param selected_rat Radio Access Technology to use
+     * @param preferred_rat Radio Access Technology to use if selected_rat is not available
+     * @param second_preferred_rat Radio Access Technology to use if selected_rat and preferred_rat are not available
+     *
+     * @return        true if successful, otherwise false.
+     */
+    bool set_modem_rat(RAT selected_rat, RAT preferred_rat = NOT_USED, RAT second_preferred_rat = NOT_USED);
+
+    /** Get last saved values for RAT using +URAT read command. Note: The current selected RAT is indicated by DeviceInfo.rat
+     *
+     * @param selected_rat pointer to variable that can hold the value for selected_rat
+     * @param preferred_rat pointer to variable that can hold the value for preferred_rat
+     * @param second_preferred_rat pointer to variable that can hold the value for second_preferred_rat
+     *
+     * Note: NOT_USED will be returned in the variables if dual or tri modes are not enabled.
+     *
+     * @return        true if successful, otherwise false.
+     */
+    bool get_modem_rat(RAT *selected_rat, RAT *preferred_rat, RAT *second_preferred_rat);
+
+    /** reboot the modem using AT+CFUN=15.
+     *
+     * @return        true if successful, otherwise false.
+     */
+    bool reboot_modem();
 protected:
 
     #define OUTPUT_ENTER_KEY  "\r"
--- a/mbed_lib.json	Mon Sep 17 10:46:14 2018 +0000
+++ b/mbed_lib.json	Fri Mar 22 13:45:51 2019 +0500
@@ -3,6 +3,7 @@
     "config": {
         "baud-rate": 115200,
         "at-parser-buffer-size": 256,
-        "at-parser-timeout": 8000
+        "at-parser-timeout": 8000,
+        "default-mno-profile": 0
     }
 }