ewrq

Fork of ublox-cellular-base-n2xx by u-blox

Revision:
2:30cf9c0797cd
Parent:
1:d4ff95ab40ae
--- a/UbloxCellularBaseN2xx.cpp	Mon Jun 26 13:48:04 2017 +0100
+++ b/UbloxCellularBaseN2xx.cpp	Tue Jul 11 21:22:58 2017 +0000
@@ -455,6 +455,7 @@
 
 void UbloxCellularBaseN2xx::parser_abort_cb()
 {
+tr_debug("Tomek ERROR - parser jest abortowany...\n\n");
     _at->abort(); 
 }
 
@@ -527,7 +528,8 @@
 void UbloxCellularBaseN2xx::modem_init()
 {
     // Meant to be overridden
-    #error need to do something here!
+    //#error need to do something here!
+    //TOMEK modem jest już uruchomiony
 }
 
 void UbloxCellularBaseN2xx::modem_deinit()
@@ -656,7 +658,8 @@
 
     /* Initialize GPIO lines */
     tr_info("Powering up modem...");
-    onboard_modem_init();
+    //onboard_modem_init();
+    modem_init();
     /* Give SARA-N2XX time to reset */
     tr_debug("Waiting for 5 seconds (booting SARA-N2xx)...");
     wait_ms(5000);
@@ -697,8 +700,10 @@
     }
 
     // Now do a hard power-off
-    onboard_modem_power_down();
-    onboard_modem_deinit();
+    //onboard_modem_power_down();
+    //onboard_modem_deinit();
+    modem_power_down();
+    modem_deinit();    
 
     _dev_info.reg_status_csd = CSD_NOT_REGISTERED_NOT_SEARCHING;
     _dev_info.reg_status_psd = PSD_NOT_REGISTERED_NOT_SEARCHING;
@@ -720,7 +725,7 @@
 
     if (success) {
         if (strstr(buf, "Neul Hi2110"))
-            *dev = DEV_SARA_N2;           
+            *dev = DEV_SARA_N2;    
     }
 
     UNLOCK();
@@ -782,6 +787,7 @@
 // Perform registration.
 bool UbloxCellularBaseN2xx::nwk_registration()
 {    
+//tr_debug("TOMEK DEBUG nwk_registration 1");
     bool registered = false;
     int status;
     int at_timeout;
@@ -790,31 +796,69 @@
     at_timeout = _at_timeout; // Has to be inside LOCK()s
 
     MBED_ASSERT(_at != NULL);
-
+    
+    cereg(1);
+/*
     // Enable the packet switched and network registration unsolicited result codes
     if (cereg(1)) {        
+tr_debug("TOMEK DEBUG nwk_registration 2");
         // See if we are already in automatic mode
         if (get_cops(&status)) {
+tr_debug("TOMEK DEBUG nwk_registration 1");
             if (status != 0) {
                 // Don't check return code here as there's not much
                 // we can do if this fails.
+tr_debug("TOMEK DEBUG nwk_registration 3");                
                 cops(0);
             }
         }
-        
+tr_debug("TOMEK DEBUG nwk_registration 4");        
         // query cereg just in case
         get_cereg();
         registered = is_registered_eps();
-        
+tr_debug("TOMEK DEBUG nwk_registration 5");        
         at_set_timeout(1000);
         for (int waitSeconds = 0; !registered && (waitSeconds < 180); waitSeconds++) {
             _at->recv(UNNATURAL_STRING);
             registered = is_registered_eps();        
+tr_debug("TOMEK DEBUG nwk_registration 6");            
         }
         at_set_timeout(at_timeout);
     } else {
         tr_error("Failed to set CEREG=1");
     }
+tr_debug("TOMEK DEBUG nwk_registration 7");
+*/
+    reboot(); // rebot potrzebuje więcej czasu, niż ta funkcja mu daje. Dlatego jest error, ale on w niczym nie przeszkadza..
+//    _at->recv("OK");
+    wait(14);
+
+bool success = false;
+    for(int i = 3; i>0;i--)
+    {
+        success = _at->send("AT+CFUN=1\r")
+                && _at->recv("OK")
+                && _at->send("AT+CGDCONT=1,\"IP\",\"test-ap-2\"\r") // do przetestowania..
+                && _at->recv("OK")
+                && _at->send("AT+CGATT=1\r")
+                && _at->recv("OK")
+                && _at->send("AT+COPS=1,2,\"24408\"\r")// do sparametryzowania..
+                && _at->recv("OK");
+        if (success)
+            break;
+    }
+
+    wait(5);
+    for(int i=40;i>0;i--)      
+    {
+        get_cereg();
+        wait(3); 
+        if(is_registered_eps())
+        {
+            registered = true;    
+            break;
+        }
+    } 
 
     UNLOCK();
     return registered;