ublox-cellular-base_mno

Revision:
25:e67d3d9d2e7e
Parent:
24:e26a6ab0dd75
Child:
26:e4e444cc7b14
--- a/UbloxCellularBase.cpp	Tue May 28 15:39:51 2019 +0500
+++ b/UbloxCellularBase.cpp	Wed May 29 12:39:28 2019 +0500
@@ -532,8 +532,13 @@
         _fh = new UARTSerial(tx, rx, baud);
 
         // Set up the AT parser
+#ifdef TARGET_UBLOX_C030_R41XM
+        _at = new UbloxATCmdParser(_fh, OUTPUT_ENTER_KEY, AT_PARSER_BUFFER_SIZE,
+                              _at_timeout, _debug_trace_on);
+#else
         _at = new ATCmdParser(_fh, OUTPUT_ENTER_KEY, AT_PARSER_BUFFER_SIZE,
                               _at_timeout, _debug_trace_on);
+#endif
 
         // Error cases, out of band handling
         _at->oob("ERROR", callback(this, &UbloxCellularBase::parser_abort_cb));
@@ -813,6 +818,11 @@
                         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
+                    }
+#endif
                     if (set_device_identity(&_dev_info.dev) && // Set up device identity
                         device_init(_dev_info.dev)) {// Initialise this device
                         // Get the integrated circuit ID of the SIM
@@ -1296,7 +1306,57 @@
     UNLOCK();
     return return_val;
 }
+// Enable or Disable the UPSV power saving mode
+bool UbloxCellularBase::set_idle_mode(bool enable)
+{
+#ifdef TARGET_UBLOX_C030_R412M
+    if (_psm_status == true && enable == true) {
+        return false;
+    }
 #endif
+
+    bool success = false;
+    LOCK();
+
+    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();
+        }
+        success = true;
+    }
+
+    UNLOCK();
+    return success;
+}
+
+bool UbloxCellularBase::get_idle_mode(int *status)
+{
+    bool return_val = false;
+
+    if (status == NULL) {
+        return false;
+    }
+
+    LOCK();
+    MBED_ASSERT(_at != NULL);
+
+    if ( (_at->send("AT+UPSV?") && _at->recv("+UPSV: %d", status) && _at->recv("OK")) )  {
+        if (*status == 4) {
+            *status = 1;
+        }
+        return_val = true;
+    }
+
+    UNLOCK();
+    return return_val;
+}
+#endif
+
 #ifdef TARGET_UBLOX_C030_R412M
 bool UbloxCellularBase::get_power_saving_mode(int *status, int *periodic_time, int *active_time)
 {
@@ -1305,6 +1365,10 @@
     int value, multiplier;
     bool return_val;
 
+    if (status == NULL || periodic_time == NULL || active_time == NULL) {
+        return false;
+    }
+
     LOCK();
     //+UCPSMS:1,,,"01000011","01000011"
     if (_at->send("AT+UCPSMS?") && _at->recv("+UCPSMS:%d,,,\"%8c\",\"%8c\"\n", status, pt_encoded, at_encoded)) {
@@ -1405,6 +1469,9 @@
 
 bool UbloxCellularBase::set_power_saving_mode(int periodic_time, int active_time)
 {
+    if (_at->is_idle_mode_enabled() == true && periodic_time != 0 && active_time != 0 ) {
+        return false;
+    }
     bool return_val = false;
 
     LOCK();