#include <zephyr.h>
#include <net/socket.h>
#include <stdio.h>
#include "lte_post_get.c"
#include "gps.c"
#include <lte_lc.h>



/********************************************/
int main (void)
{
  printk("Test is starting \n"); 
 // lte_lc_offline(); 
       
  nrf_gnss_data_frame_t gps_data;
  char posdata[200];
  u8_t	cnt = 0;
        
  printk("Staring GPS application\n");

  if (init_app() != 0) {
		return -1;
	}

  printk("Getting GPS data...\n");

  while (1) {

      do {
			
	} while (process_gps_data(&gps_data) > 0);

       if (!got_first_fix) {
	   cnt++;
	   printk("\033[1;1H");
	   printk("\033[2J");
	   print_satellite_stats(&gps_data);
	   printk("\nScanning [%c] ",
	   update_indicator[cnt%4]);
		}

	if (((k_uptime_get() - fix_timestamp) >= 1) && (got_first_fix)) {
	   printk("\033[1;1H");
	   printk("\033[2J");
           print_satellite_stats(&gps_data);
          
           printk("---------------------------------\n");
            memset(posdata, 0, sizeof(posdata));
	   print_pvt_data(&last_fix,posdata);
	   printk("\n");
	   print_nmea_data();
	   printk("---------------------------------\n");
           char sendStr[200];
           memset(sendStr, 0, sizeof(sendStr));
           printk("Postdata: %s\n",posdata); 
         
           printk(" enable LTE............ \n");
           nRF_offGPS_onLTE(); 
           k_sleep(2500);
           int lte_err= nRF_LTE_check();
           if(lte_err==0){ printk("  find LTE_M signal........... \n");
                        app_http_post(posdata); 
                        app_http_post("1234566677778\r"); 
                                   }
           else{ 
           //     app_http_post("from nRF91\r");
                printk(" Couldnt find LTE_M signal........... \n");}
                k_sleep(5000);
		}
            update_terminal = false; 
	    k_sleep(K_MSEC(500));
	}

	return 0;

}
