ublox-cellular-base-SARA-R5

Dependents:   example-ublox-cellular-psm

Files at this revision

API Documentation at this revision

Comitter:
fahimalavi
Date:
Wed Feb 12 15:45:55 2020 +0500
Parent:
37:a2466fcd63c3
Child:
39:945019c3d194
Commit message:
Initial SARA-R5 PSM commit

Changed in this revision

UbloxCellularBase.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/UbloxCellularBase.cpp	Mon Jan 06 14:25:07 2020 +0500
+++ b/UbloxCellularBase.cpp	Wed Feb 12 15:45:55 2020 +0500
@@ -737,7 +737,7 @@
             *dev = DEV_LISA_U2;
         else if (strstr(buf, "SARA-U2"))
             *dev = DEV_SARA_U2;
-        else if (strstr(buf, "SARA-R4"))
+        else if (strstr(buf, "SARA-R4") || strstr(buf, "SARA-R5"))
             *dev = DEV_SARA_R4;
         else if (strstr(buf, "LEON-G2"))
             *dev = DEV_LEON_G2;
@@ -745,8 +745,12 @@
             *dev = DEV_TOBY_L2;
         else if (strstr(buf, "MPCI-L2"))
             *dev = DEV_MPCI_L2;
+        else
+            *dev = DEV_SARA_R4;
     }
 
+    //_at->send("AT+CGMR") && _at->recv("%5[^\n]\nOK\n", buf);
+
     UNLOCK();
     return success;
 }
@@ -841,7 +845,8 @@
 #ifdef TARGET_UBLOX_C027
             if (set_functionality_mode(FUNC_MIN)) {
 #else
-            if (set_functionality_mode(FUNC_AIRPLANE)) {
+	        // MAke sure it is valid of SARA-R5 only
+            if (set_functionality_mode(FUNC_MIN)) {
 #endif
                 if (initialise_sim_card()) {
 #ifdef TARGET_UBLOX_C030_R41XM
@@ -857,11 +862,11 @@
                             mno_profile = MBED_CONF_APP_DEFAULT_MNO_PROFILE;
                         }
 #endif
-                        if (mno_profile == SW_DEFAULT) {
+                        /*if (mno_profile == SW_DEFAULT) {
                             tr_critical("!!CANNOT USE PROFILE 0(SW_DEFAULT). PLEASE SET AN APPROPRIATE MNO PROFILE!!");
                             _default_profile_is_set = true;
                             return false;
-                        }
+                        }*/
                     }
 #ifdef TARGET_UBLOX_C030_R412M
                     int status = 0, periodic_time = 0, active_time = 0;
@@ -872,7 +877,7 @@
                                 _psm_status = ENABLED;
                                 if ( !(set_psm_urcs(true)) ) { //enable PSM URCs
                                     tr_error("Modem does not support PSM URCs, disabling PSM");
-                                    disable_power_saving_mode();
+                                    //disable_power_saving_mode();
                                 } else if (!_func_psm_going_in){
                                     tr_critical("!!PSM IS ENABLED, CALLBACK NOT ATTACHED. PLEASE REGISTER ONE!!");
                                 }
@@ -887,7 +892,7 @@
                     if (_at->is_idle_mode_enabled() == false || _psm_status == ENABLED) {
                         //application has not yet enabled idle mode so disable it
                         //PSM got enabled by MNO, disable idle mode.
-                        set_idle_mode(false);
+                        //set_idle_mode(false);
                     }
 #endif
                     if (set_device_identity(&_dev_info.dev) && // Set up device identity
@@ -907,6 +912,8 @@
                                     set_sms()) { // And set up SMS
                                     // The modem is initialised.
                                     _modem_initialised = true;
+                                    _at->send("AT+CSCON=1") && _at->recv("OK");
+                                    _at->send("AT+CPSMS=1") && _at->recv("OK");
                                     tr_info("Modem initialized");
                                 }
                             }
@@ -1294,7 +1301,8 @@
 //application should call init() or connect() in order to initialize the modem
 bool UbloxCellularBase::reboot_modem()
 {
-    return (set_functionality_mode(FUNC_RESET));
+	// SARA-R5 only
+    return (set_functionality_mode(FUNC_RESET_WITH_SIM));
 }
 
 bool UbloxCellularBase::set_functionality_mode(FunctionalityMode mode)
@@ -1427,13 +1435,14 @@
 
     MBED_ASSERT(_at != NULL);
 
-    if (_at->send("AT+UPSV=%d", enable ? 4 : 0) && _at->recv("OK")) {
-        if (enable == true) {
-            _at->idle_mode_enabled();
-        }
-        else {
-            _at->idle_mode_disabled();
-        }
+	// SARA-R5 only
+    if (_at->send("AT+UPSV=1") && _at->recv("OK")) {
+//        if (enable == true) {
+//            _at->idle_mode_enabled();
+//        }
+//        else {
+//            _at->idle_mode_disabled();
+//        }
         success = true;
     }
 
@@ -1769,9 +1778,11 @@
 bool UbloxCellularBase::set_power_saving_mode(int periodic_time, int active_time)
 {
 
-    if (_at->is_idle_mode_enabled() == true) {
-        tr_error("Please disable idle mode(+UPSV) first");
-        return false;
+    // SARA-R5 only
+    if (_at->send("AT+CPSMS=1,,,\"%s\",\"%s\"", "10000101","00000011") && _at->recv("OK")) {
+        //tr_error("Please disable idle mode(+UPSV) first");
+        _psm_status = ENABLED;
+        return true;
     }
     bool return_val = false;
 
@@ -1779,7 +1790,8 @@
     int at_timeout = _at_timeout;
     at_set_timeout(10000); //AT+CPSMS has response time of < 10s
 
-    if (_at->send("AT+UPSMR?") && _at->recv("OK")) { //PSM string encoding code borrowed from AT_CellularPower.cpp
+    // SARA-R5 only
+    if (_at->send("AT+UPSMR?") && _at->recv("OK") || 1) { //PSM string encoding code borrowed from AT_CellularPower.cpp
         /**
             Table 10.5.163a/3GPP TS 24.008: GPRS Timer 3 information element
 
@@ -1877,7 +1889,8 @@
         at[8] = '\0';
 
         if (_at->send("AT+CPSMS=1,,,\"%s\",\"%s\"", pt, at) && _at->recv("OK")) {
-            if (set_psm_urcs(true)) {//enable the PSM URC
+            //SARA-R5 only
+            if (!set_psm_urcs(true)) {//enable the PSM URC
                 tr_info("PSM enabled successfully!");
                 _psm_status = ENABLED;
                 return_val = true;