ublox-cellular-base

Revision:
31:915ce07813da
Parent:
30:38230504a646
--- a/UbloxCellularBase.cpp	Tue Aug 27 18:38:29 2019 +0500
+++ b/UbloxCellularBase.cpp	Wed Aug 28 16:42:48 2019 +0500
@@ -799,7 +799,7 @@
  **********************************************************************/
 
 // Initialise the modem.
-bool UbloxCellularBase::init(const char *pin)
+bool UbloxCellularBase::init(const char *pin, bool disable_mno_params)
 {
 	int x;
     MBED_ASSERT(_at != NULL);
@@ -816,29 +816,33 @@
             if (set_functionality_mode(FUNC_AIRPLANE)) {
 #endif
                 if (initialise_sim_card()) {
-                    int mno_profile;
-
 #ifdef TARGET_UBLOX_C030_R412M
-                    if (_psm_status ==  false) { //psm is not enabled by application yet so disable it at start-up
-                        set_power_saving_mode(0, 0);
+                    if (_psm_status == false) { //PSM is not yet configured by driver or application
+                        if (disable_mno_params) {
+                            set_power_saving_mode(0, 0);
+                        } else {
+                            int status = 0, periodic_time = 0, active_time = 0;
+                            if (get_power_saving_mode(&status, &periodic_time, &active_time)) {
+                                if (status) { //PSM is already enabled either by a previous run or MNO profile
+                                    tr_info("PSM is already enabled, periodic_time %d, active_time %d", periodic_time, active_time);
+                                    _psm_status = true;
+                                    if ( !(set_psm_urcs(1)) ) { //enable PSM URCs
+                                        tr_error("Modem does not support PSM URCs, disabling PSM");
+                                        set_power_saving_mode(0, 0);
+                                    }
+                                }
+                            }
+                        }
                     }
 #endif
 #ifdef TARGET_UBLOX_C030_R41XM
                     if (_at->is_idle_mode_enabled() == false) {
                         set_idle_mode(false); //disable idle mode at start up
                     }
-                    if(_edrx_configured == false) {
-                        // A special form of the command can be given as +CEDRXS=3.
-                        // In this form, eDRX will be disabled and data for all parameters in the command +CEDRXS will be removed or,
-                        // if available, set to the manufacturer specific default values.
-                        set_receive_period(3,UbloxCellularBase::EDRXGSM_A_Gb_mode);
-                        set_receive_period(3,UbloxCellularBase::EDRXEUTRAN_WB_S1_mode);
-                        set_receive_period(3,UbloxCellularBase::EDRXEUTRAN_NB_S1_mode);
+                    int mno_profile;
+                    if (get_mno_profile(&mno_profile)) {
+                        tr_info("Current MNO profile is: %d", mno_profile);
                     }
-                    get_receive_period();
-
-                    if (get_mno_profile(&mno_profile))
-                        tr_info("Current MNO profile is: %d", mno_profile);
 #endif
                     if (set_device_identity(&_dev_info.dev) && // Set up device identity
                         device_init(_dev_info.dev)) {// Initialise this device
@@ -1557,7 +1561,7 @@
 
     LOCK();
     //+UCPSMS:1,,,"01000011","01000011"
-    if (_at->send("AT+UCPSMS?") && _at->recv("+UCPSMS:%d,,,\"%8c\",\"%8c\"\n", status, pt_encoded, at_encoded)) {
+    if (_at->send("AT+UCPSMS?") && _at->recv("+UCPSMS:%d,,,\"%8c\",\"%8c\"\nOK\n", status, pt_encoded, at_encoded)) {
         if (*status == true) {
             //PSM is enabled, decode the timer values, periodic TAU first
             value =  (pt_encoded[7]- '0');
@@ -1669,7 +1673,7 @@
         if (periodic_time == 0 && active_time == 0) {
             // disable PSM
             if (_at->send("AT+CPSMS=0") && _at->recv("OK")) {
-                if (_at->send("AT+UPSMR=0") && _at->recv("OK")) {//disable the URC
+                if (set_psm_urcs(0)) {//disable the URC
                     //de-register the callback
                     detach_cb_psm_going_in();
                     detach_cb_psm_coming_out();
@@ -1775,7 +1779,7 @@
             at[8] = '\0';
 
             if (_at->send("AT+CPSMS=1,,,\"%s\",\"%s\"", pt, at) && _at->recv("OK")) {
-                if (_at->send("AT+UPSMR=1") && _at->recv("OK")) {//enable the PSM URC
+                if (set_psm_urcs(1)) {//enable the PSM URC
                     tr_info("PSM enabled successfully!");
                     _psm_status = true;
                     return_val = true;
@@ -1819,6 +1823,22 @@
 
     UNLOCK();
 }
+
+bool UbloxCellularBase::set_psm_urcs(bool enable)
+{
+
+    bool success = false;
+    LOCK();
+
+    MBED_ASSERT(_at != NULL);
+
+    if (_at->send("AT+UPSMR=%d", enable ? 1 : 0) && _at->recv("OK")) {
+        success = true;
+    }
+
+    UNLOCK();
+    return success;
+}
 #endif
 
 // End of File