ublox-cellular-base-n2xx

Revision:
10:1afe5ed24f0c
Parent:
9:4368e434de4e
Child:
11:e9b490d21afb
--- a/UbloxCellularBaseN2xx.cpp	Tue Jan 09 15:25:11 2018 +0500
+++ b/UbloxCellularBaseN2xx.cpp	Tue Jan 09 14:35:43 2018 +0000
@@ -29,6 +29,27 @@
 
 #define ATOK _at->recv("OK")
 
+/* Array to convert the 3G qual number into a median EC_NO_LEV number.
+ */
+                            /* 0   1   2   3   4   5   6  7 */
+const int qualConvert3G[] = {44, 41, 35, 29, 23, 17, 11, 7};
+ 
+/* Array to convert the 3G "rssi" number into a dBm RSCP value rounded up to the
+ * nearest whole number.
+ */
+const int rscpConvert3G[] = {-108, -105, -103, -100,  -98,  -96,  -94,  -93,   /* 0 - 7 */
+                              -91,  -89,  -88,  -85,  -83,  -80,  -78,  -76,   /* 8 - 15 */
+                              -74,  -73,  -70,  -68,  -66,  -64,  -63,  -60,   /* 16 - 23 */
+                              -58,  -56,  -54,  -53,  -51,  -49,  -48,  -46};  /* 24 - 31 */
+ 
+/* Array to convert the LTE rssi number into a dBm value rounded up to the
+ * nearest whole number.
+ */
+const int rssiConvertLte[] = {-118, -115, -113, -110, -108, -105, -103, -100,   /* 0 - 7 */
+                               -98,  -95,  -93,  -90,  -88,  -85,  -83,  -80,   /* 8 - 15 */
+                               -78,  -76,  -74,  -73,  -71,  -69,  -68,  -65,   /* 16 - 23 */
+                               -63,  -61,  -60,  -59,  -58,  -55,  -53,  -48};  /* 24 - 31 */
+
 /**********************************************************************
  * PRIVATE METHODS
  **********************************************************************/
@@ -553,12 +574,19 @@
     if (_at == NULL) {
         if (_debug_trace_on == false) {
             _debug_trace_on = debug_on;
-        }
+        }                
 
         // 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
         _at = new ATCmdParser(_fh, OUTPUT_ENTER_KEY, AT_PARSER_BUFFER_SIZE,
                            _at_timeout, _debug_trace_on);
@@ -884,5 +912,93 @@
 
     return count;
 }
+
+// Get the IMEI of the module.
+const char *UbloxCellularBaseN2xx::imei()
+{
+    return _dev_info.imei;
+}
+ 
+// Get the Mobile Equipment ID (which may be the same as the IMEI).
+const char *UbloxCellularBaseN2xx::meid()
+{
+    return _dev_info.meid;
+}
+ 
+// Get the IMSI of the SIM.
+const char *UbloxCellularBaseN2xx::imsi()
+{
+    // (try) to update the IMSI, just in case the SIM has changed
+    get_imsi();
+    
+    return _dev_info.imsi;
+}
+ 
+// Get the ICCID of the SIM.
+const char *UbloxCellularBaseN2xx::iccid()
+{
+    // (try) to update the ICCID, just in case the SIM has changed
+    get_iccid();
+    
+    return _dev_info.iccid;
+}
+
+// Get the RSSI in dBm.
+int UbloxCellularBaseN2xx::rssi()
+{
+    char buf[7] = {0};
+    int rssi = 0;
+    int qual = 0;
+    int rssiRet = 0;
+    bool success;
+    LOCK();
+ 
+    MBED_ASSERT(_at != NULL);
+ 
+    success = _at->send("AT+CSQ") && _at->recv("+CSQ: %6[^\n]\nOK\n", buf);
+ 
+    if (success) {
+        if (sscanf(buf, "%d,%d", &rssi, &qual) == 2) {
+            // AT+CSQ returns a coded RSSI value and an RxQual value
+            // For 2G an RSSI of 0 corresponds to -113 dBm or less, 
+            // an RSSI of 31 corresponds to -51 dBm or less and hence
+            // each value is a 2 dB step.
+            // For LTE the mapping is defined in the array rssiConvertLte[].
+            // For 3G the mapping to RSCP is defined in the array rscpConvert3G[]
+            // and the RSSI value is then RSCP - the EC_NO_LEV number derived
+            // by putting the qual number through qualConvert3G[].
+            if ((rssi >= 0) && (rssi <= 31)) {
+                switch (_dev_info.rat) {
+                    case UTRAN:
+                    case HSDPA:
+                    case HSUPA:
+                    case HSDPA_HSUPA:
+                        // 3G
+                        if ((qual >= 0) && (qual <= 7)) {
+                            qual = qualConvert3G[qual];
+                        }
+                        rssiRet = rscpConvert3G[rssi];
+                        rssiRet -= qual;
+                        break;
+                    case LTE:
+                        // LTE
+                        rssiRet = rssiConvertLte[rssi];
+                        break;
+                    case GSM:
+                    case COMPACT_GSM:
+                    case EDGE:
+                    default:
+                        // GSM or assumed GSM if the RAT is not known
+                        rssiRet = -(113 - (rssi << 2));
+                        break;
+                }
+            }
+        }
+    }
+ 
+    UNLOCK();
+    return rssiRet;
+}
+
 // End of File