ublox-cellular-base_r4

Files at this revision

API Documentation at this revision

Comitter:
wajahat.abbas@u-blox.com
Date:
Thu Sep 05 15:38:21 2019 +0500
Parent:
33:093da9fe13ed
Commit message:
read PSM status only if not known

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 093da9fe13ed -r 869b2f035721 UbloxCellularBase.cpp
--- a/UbloxCellularBase.cpp	Thu Sep 05 11:16:16 2019 +0500
+++ b/UbloxCellularBase.cpp	Thu Sep 05 15:38:21 2019 +0500
@@ -494,7 +494,7 @@
     _dev_info.reg_status_eps = EPS_NOT_REGISTERED_NOT_SEARCHING;
 #ifdef TARGET_UBLOX_C030_R412M
     _dev_info.modem_psm_state = AWAKE;
-    _psm_status = false;
+    _psm_status = UNKNOWN;
     _cb_param_psm_going_in = NULL;
     _func_psm_going_in = NULL;
     _cb_param_psm_coming_out = NULL;
@@ -618,7 +618,7 @@
 
     for (int retry_count = 0; !success && (retry_count < 20); retry_count++) {
         //In case of SARA-R4, modem takes a while to turn on, constantly toggling the power pin every ~2 secs causes the modem to never power up.
-        if ( (retry_count % 5) == 0) { 
+        if ( (retry_count % 5) == 0) {
             modem_power_up();
         }
         wait_ms(500);
@@ -825,17 +825,21 @@
                     }
 #ifdef TARGET_UBLOX_C030_R412M
                     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(true)) ) { //enable PSM URCs
-                                tr_error("Modem does not support PSM URCs, disabling PSM");
-                                set_power_saving_mode(0, 0);
-                            } else if (!_func_psm_going_in){
-                                tr_critical("!!PSM IS ENABLED, CALLBACK NOT ATTACHED. PLEASE REGISTER ONE!!");
+                    if (_psm_status == UNKNOWN) {
+                        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 = ENABLED;
+                                if ( !(set_psm_urcs(true)) ) { //enable PSM URCs
+                                    tr_error("Modem does not support PSM URCs, disabling PSM");
+                                    set_power_saving_mode(0, 0);
+                                } else if (!_func_psm_going_in){
+                                    tr_critical("!!PSM IS ENABLED, CALLBACK NOT ATTACHED. PLEASE REGISTER ONE!!");
+                                }
                             }
                         }
+                    } else if (_psm_status == ENABLED && !_func_psm_going_in){
+                        tr_critical("!!PSM IS ENABLED, CALLBACK NOT ATTACHED. PLEASE REGISTER ONE!!");
                     }
 #endif
                     if (_at->is_idle_mode_enabled() == false) {
@@ -1369,7 +1373,7 @@
 bool UbloxCellularBase::set_idle_mode(bool enable)
 {
 #ifdef TARGET_UBLOX_C030_R412M
-    if (_psm_status == true && enable == true) {
+    if (_psm_status == ENABLED && enable == true) {
         return false;
     }
 #endif
@@ -1720,7 +1724,7 @@
                     //de-register the callback
                     detach_cb_psm_going_in();
                     detach_cb_psm_coming_out();
-                    _psm_status = false;
+                    _psm_status = DISABLED;
                     return_val = true;
                 }
             }
@@ -1824,7 +1828,7 @@
             if (_at->send("AT+CPSMS=1,,,\"%s\",\"%s\"", pt, at) && _at->recv("OK")) {
                 if (set_psm_urcs(true)) {//enable the PSM URC
                     tr_info("PSM enabled successfully!");
-                    _psm_status = true;
+                    _psm_status = ENABLED;
                     return_val = true;
                 } else {
                     tr_error("PSM URCs not supported");
diff -r 093da9fe13ed -r 869b2f035721 UbloxCellularBase.h
--- a/UbloxCellularBase.h	Thu Sep 05 11:16:16 2019 +0500
+++ b/UbloxCellularBase.h	Thu Sep 05 15:38:21 2019 +0500
@@ -775,9 +775,14 @@
     void CEREG_URC();
     void UMWI_URC();
 #ifdef TARGET_UBLOX_C030_R412M
+    typedef enum {
+       DISABLED = 0,
+       ENABLED = 1,
+       UNKNOWN = 2
+    } PSMStatus;
     bool set_psm_urcs(bool enable);
     void UUPSMR_URC();
-    bool _psm_status;
+    PSMStatus _psm_status;
     void *_cb_param_psm_going_in;
     Callback<void(void*)>    _func_psm_going_in;  /**< Callback. */
     void *_cb_param_psm_coming_out;