ublox-cellular-base_mno

Revision:
4:2e640a101db1
Parent:
3:f9b2cd6f72b1
Child:
5:05fa111c1cf3
--- a/UbloxCellularBase.cpp	Mon Jun 19 15:00:42 2017 +0100
+++ b/UbloxCellularBase.cpp	Mon Jul 31 11:42:37 2017 +0100
@@ -427,9 +427,17 @@
         if (_debug_trace_on == false) {
             _debug_trace_on = debug_on;
         }
+        _baud = baud;
 
         // Set up File Handle for buffered serial comms with cellular module
         // (which will be used by the AT parser)
+        // Note: the UART is initialised to run no faster than 115200 because
+        // the modems cannot reliably auto-baud at faster rates.  The faster
+        // rate is adopted later with a specific AT command and the
+        // UARTSerial rate is adjusted at that time
+        if (baud > 115200) {
+            baud = 115200;
+        }
         _fh = new UARTSerial(tx, rx, baud);
 
         // Set up the AT parser
@@ -523,16 +531,25 @@
         at_set_timeout(at_timeout);
     }
 
+    if (success) {
+        // Set the final baud rate
+        if (_at->send("AT+IPR=%d", _baud) && _at->recv("OK")) {
+            // Need to wait for things to be sorted out on the modem side
+            wait_ms(100);
+            ((UARTSerial *)_fh)->set_baud(_baud);
+        }
+        
+        // Turn off modem echoing and turn on verbose responses
+        success = _at->send("ATE0;+CMEE=2") && _at->recv("OK") &&
+                  // The following commands are best sent separately
+                  _at->send("AT&K0") && _at->recv("OK") && // Turn off RTC/CTS handshaking
+                  _at->send("AT&C1") && _at->recv("OK") && // Set DCD circuit(109), changes in accordance with the carrier detect status
+                  _at->send("AT&D0") && _at->recv("OK"); // Set DTR circuit, we ignore the state change of DTR
+    }
 
-    if (success) {
-        success = _at->send("ATE0;" // Turn off modem echoing
-                            "+CMEE=2;" // Turn on verbose responses
-                            "&K0" //turn off RTC/CTS handshaking
-                            "+IPR=%d;" // Set baud rate
-                            "&C1;"  // Set DCD circuit(109), changes in accordance with the carrier detect status
-                            "&D0", MBED_CONF_UBLOX_CELL_BAUD_RATE) && // Set DTR circuit, we ignore the state change of DTR
-                  _at->recv("OK");
-    }
+#if DEVICE_SERIAL_FC
+    ((UARTSerial *)_fh)->set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
+#endif
 
     if (!success) {
         tr_error("Preliminary modem setup failed.");
@@ -828,7 +845,7 @@
 }
 
 // Enable or disable SIM pin checking.
-bool UbloxCellularBase:: sim_pin_check_enable(bool enableNotDisable)
+bool UbloxCellularBase::sim_pin_check_enable(bool enableNotDisable)
 {
     bool success = false;;
     LOCK();