changes for R412M test cases

Revision:
22:63b1a3c02fb8
Parent:
12:ff6fac481487
Child:
23:9098a541452b
--- a/TESTS/unit_tests/default/main.cpp	Tue Feb 12 18:42:43 2019 +0500
+++ b/TESTS/unit_tests/default/main.cpp	Mon May 13 13:30:24 2019 +0500
@@ -1,3 +1,4 @@
+
 #include "UbloxATCellularInterface.h"
 #include "greentea-client/test_env.h"
 #include "unity.h"
@@ -141,6 +142,8 @@
 // The maximum number of sockets that can be open at one time
 #define MAX_NUM_SOCKETS 7
 
+int previousSelectedRat = -1, previousPreferredRat = -1, previousSecondPreferredRat = -1;
+
 // ----------------------------------------------------------------
 // PRIVATE VARIABLES
 // ----------------------------------------------------------------
@@ -496,10 +499,10 @@
     const char *imsi;
     const char *iccid;
     int rssi;
-    
+
     // Power-up the modem
     interface->init();
-    
+
     // Check all of the IMEI, MEID, IMSI and ICCID calls
     imei = interface->imei();
     if (imei != NULL) {
@@ -507,37 +510,37 @@
     } else {
         TEST_ASSERT(false);
     }
-    
+
     meid = interface->meid();
     if (meid != NULL) {
         tr_debug("MEID is %s.", meid);
     } else {
         TEST_ASSERT(false);
     }
-    
+
     imsi = interface->imsi();
     if (imsi != NULL) {
         tr_debug("IMSI is %s.", imsi);
     } else {
         TEST_ASSERT(false);
     }
-    
+
     iccid = interface->iccid();
     if (iccid != NULL) {
         tr_debug("ICCID is %s.", iccid);
     } else {
         TEST_ASSERT(false);
     }
-    
+
     // Check the RSSI call at least doesn't assert
     rssi = interface->rssi();
     tr_debug("RSSI is %d dBm.", rssi);
-    
+
     // Now connect and check that the answers for the
     // static fields are the same while connected
     TEST_ASSERT(interface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN,
                                    MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0);
-    
+
     TEST_ASSERT(strcmp(imei, interface->imei()) == 0);
     TEST_ASSERT(strcmp(meid, interface->meid()) == 0);
     TEST_ASSERT(strcmp(imsi, interface->imsi()) == 0);
@@ -1066,6 +1069,138 @@
     delete pLocalInterface;
 }
 
+void test_set_new_rat() {
+
+	int currentSelectedRat = -1, currentPreferredRat = -1, currentSecondPreferredRat = -1;
+
+    // Power-up the modem
+    TEST_ASSERT(interface->init());
+
+    // Check if modem is registered with network
+    if (interface->is_registered_csd() || interface->is_registered_psd() || interface->is_registered_eps()) {
+        tr_error("RAT should only be set in detached state");
+        // Deregister from Network
+        TEST_ASSERT(interface->nwk_deregistration());
+    }
+
+    // Get and store initial RAT set on modem
+    TEST_ASSERT(interface->get_modem_rat(&previousSelectedRat, &previousPreferredRat, &previousSecondPreferredRat));
+    tr_debug("previous selected RAT: %d\nprevious preferred RAT: %d\nprevious second preferred RAT: %d\n", previousSelectedRat, previousPreferredRat, previousSecondPreferredRat);
+
+#ifdef TARGET_UBLOX_C030_U201
+    // Set new RAT
+    TEST_ASSERT(interface->set_modem_rat(UbloxATCellularInterface::GSM_UMTS, UbloxATCellularInterface::UMTS));
+    tr_debug("RAT configured\n");
+
+    // Get latest set RAT on modem
+    TEST_ASSERT(interface->get_modem_rat(&currentSelectedRat, &currentPreferredRat, &currentSecondPreferredRat));
+    tr_debug("new selected RAT: %d\nnew preferred RAT: %d\nnew second preferred RAT: %d\n", currentSelectedRat, currentPreferredRat, currentSecondPreferredRat);
+
+    // Check RAT configured correctly
+    TEST_ASSERT((currentSelectedRat == UbloxATCellularInterface::GSM_UMTS) && (currentPreferredRat == UbloxATCellularInterface::UMTS));
+#endif
+
+#ifdef TARGET_UBLOX_C030_R412M
+    // Set new RAT
+    TEST_ASSERT(interface->set_modem_rat(UbloxATCellularInterface::LTE_CATM1, UbloxATCellularInterface::LTE_CATNB1));
+    tr_debug("RAT configured\n");
+
+    // Get latest set RAT on modem
+    TEST_ASSERT(interface->get_modem_rat(&currentSelectedRat, &currentPreferredRat, &currentSecondPreferredRat));
+    tr_debug("new selected RAT: %d\nnew preferred RAT: %d\nnew second preferred RAT: %d\n", currentSelectedRat, currentPreferredRat, currentSecondPreferredRat);
+
+    // Check RAT configured correctly
+    TEST_ASSERT((currentSelectedRat == UbloxATCellularInterface::LTE_CATM1) && (currentPreferredRat == UbloxATCellularInterface::LTE_CATNB1));
+#endif
+}
+
+void test_reboot() {
+
+    // Rebooting modem for settings to take effect
+	TEST_ASSERT(interface->reboot_modem());
+}
+
+void test_registration() {
+
+    TEST_ASSERT(interface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN,
+                                   MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0);
+
+    TEST_ASSERT(interface->nwk_deregistration());
+}
+
+
+void test_set_previous_rat() {
+
+	int currentSelectedRat = -1, currentPreferredRat = -1, currentSecondPreferredRat = -1;
+
+    // Restore RAT to previous settings
+    TEST_ASSERT(interface->set_modem_rat((UbloxATCellularInterface::RAT)previousSelectedRat, (UbloxATCellularInterface::RAT)previousPreferredRat, (UbloxATCellularInterface::RAT)previousSecondPreferredRat));
+    tr_debug("RAT configured\n");
+
+    TEST_ASSERT(interface->get_modem_rat(&currentSelectedRat, &currentPreferredRat, &currentSecondPreferredRat));
+    tr_debug("current selected RAT: %d\ncurrent preferred RAT: %d\ncurrent second preferred RAT: %d\n", currentSelectedRat, currentPreferredRat, currentSecondPreferredRat);
+
+    // Check RAT configured correctly
+    TEST_ASSERT((currentSelectedRat == previousSelectedRat) && (currentPreferredRat == previousPreferredRat));
+
+    // Rebooting modem for settings to take effect
+	TEST_ASSERT(interface->reboot_modem());
+}
+
+#ifdef TARGET_UBLOX_C030_R41XM
+void test_mno_profile() {
+
+    int previous_profile, current_profile;
+
+    // Power-up the modem
+    TEST_ASSERT(interface->init());
+
+    // Check if modem is registered with network
+    if (interface->is_registered_csd() || interface->is_registered_psd() || interface->is_registered_eps()) {
+        tr_error("MNO profile should only be set in detached state");
+        // Deregister from Network
+        TEST_ASSERT(interface->nwk_deregistration());
+    }
+
+    // Getting current mno profile
+    TEST_ASSERT(interface->get_mno_profile(&previous_profile));
+    tr_debug("Previous MNO profile is: %d\n\n", previous_profile);
+
+    // Set MNO profile
+    TEST_ASSERT(interface->set_mno_profile((UbloxATCellularInterface::MNOProfile)MBED_CONF_UBLOX_CELL_DEFAULT_MNO_PROFILE));
+    tr_debug("MNO configured\n");
+
+    // Rebooting modem for settings to take effect
+	TEST_ASSERT(interface->reboot_modem());
+	tr_debug("Reboot successful\n");
+	wait_ms(5000);
+
+    // Check MNO profile configured correctly
+    TEST_ASSERT(interface->get_mno_profile(&current_profile));
+    tr_debug("New MNO profile is: %d\n\n", current_profile);
+
+    TEST_ASSERT((UbloxATCellularInterface::MNOProfile)current_profile == (UbloxATCellularInterface::MNOProfile)MBED_CONF_UBLOX_CELL_DEFAULT_MNO_PROFILE);
+
+    TEST_ASSERT(interface->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN,
+                                   MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0);
+
+    TEST_ASSERT(interface->nwk_deregistration());
+
+    // Restore MNO profile to previous settings
+    TEST_ASSERT(interface->set_mno_profile((UbloxATCellularInterface::MNOProfile)previous_profile));
+    tr_debug("Previous MNO configured\n");
+
+    // Rebooting modem for settings to take effect
+	TEST_ASSERT(interface->reboot_modem());
+	tr_debug("Reboot successful\n");
+	wait_ms(5000);
+
+    // Check MNO profile configured correctly
+    TEST_ASSERT(interface->get_mno_profile(&current_profile));
+    TEST_ASSERT((current_profile == previous_profile));
+}
+#endif
+
 // ----------------------------------------------------------------
 // TEST ENVIRONMENT
 // ----------------------------------------------------------------
@@ -1105,6 +1240,15 @@
     Case("Check SIM pin, pending", test_check_sim_pin_pending),
     Case("Check SIM pin, immediate", test_check_sim_pin_immediate),
 #endif
+#if defined (TARGET_UBLOX_C030_U201) || defined (TARGET_UBLOX_C030_R412M)
+    Case("Set RAT test", test_set_new_rat),
+    Case("Reboot test", test_reboot),
+    Case("Register with network test", test_registration),
+    Case("Set previous RAT test", test_set_previous_rat),
+#endif
+#ifdef TARGET_UBLOX_C030_R41XM
+    Case("MNO profile test", test_mno_profile),
+#endif
 #ifndef TARGET_UBLOX_C027 // Not enough RAM on little 'ole C027 for this
     Case("Connect using local instance, must be last test", test_connect_local_instance_last_test)
 #endif