Sudden discontinuation of GPS coordinates upon restart

I know it takes time to get initialised but I have been waiting for like an half an hour or so! This isnt the first time though Im experiencing this with WP7502. Upon repeated re-installation of the same application which gets GPS coordinates and sends it to UART port. I have no idea why this is happening can anyone help me with this ?

Hi,

You need to be a bit more precise on what you are ding and how you are starting/stopping the GPS on the unit.

Also what firmware are you running on the unit?

Regards

Matt

@mlw

Thanks for replying.
For some reason the GPS suddenly stopped working the board seems to be fine as I can load other applications but GPS coordinates arent comming.
1.I am not stopping the GPS manually
2. 3.14.29ltsi-961ca71325_ed9f616cc8 is the linux loaded on the device

This is the error Im getting now
3.May 25 11:42:15 | textloc[520]/textLocComponent T=main | textLoc.cpp getLocation() 141 | Checking GPS position
May 25 11:42:15 | textloc[520]/framework T=main | le_pos_client.c le_pos_Get2DLocation() 764 | Sending message to server and waiting for response : 0 bytes sent
May 25 11:42:15 | textloc[520]/textLocComponent T=main | textLoc.cpp getLocation() 190 | Failed to get reading… retrying in 1 seconds

4.This is the program in use

#include "interfaces.h"
#include "legato.h"
#include <termios.h>
#include <unistd.h>
#include <string>
#include <iostream>
#include <sstream>
//#include "util.h"

// Used to convert GPS int to double
#define GPS_DECIMAL_SHIFT 6
// Used for distance calculations
#define MIN_REQUIRED_HORIZ_ACCURACY_METRES 10  // TODO validate that this is realistic
#define POLL_PERIOD_SEC 2 * 60 // 2 minutes
#define RETRY_PERIOD_SEC 1


static le_posCtrl_ActivationRef_t posCtrlRef;
static le_timer_Ref_t pollingTimer;
using namespace std;
int serial_fd;
static struct {
double lat;
double lon;
double horizAccuracy;
uint64_t datetime;
} lastReading;

/**
 * Determine if we have a reading
 *
 * (other things make factor in here down the road)
 */
static bool hasReading() {
  return lastReading.datetime != 0;
}

/**
 * Determine if we can provide an IPC caller
 * with a location
 */
static bool canGetLocation() {
  return hasReading() && posCtrlRef != NULL;
}

/**
 * IPC function to get location
 */
le_result_t brnkl_gps_getCurrentLocation(double* latitude,
                                     double* longitude,
                                     double* horizontalAccuracy,
                                     uint64_t* readingTimestamp) {
  if (!canGetLocation()) {
    return LE_UNAVAILABLE;
  }
  *latitude = lastReading.lat;
  *longitude = lastReading.lon;
  *horizontalAccuracy = lastReading.horizAccuracy;
  *readingTimestamp = lastReading.datetime;
   return LE_OK;
 }

 /**
 * Main polling function
 *
* Change MIN_REQUIRED_HORIZ_ACCURACY_METRES if
* a more/less accurate fix is required
*/
static int open_uart1(char *dev)
{
 int     fd;

 fd = open (dev, O_RDWR | O_NOCTTY | O_NDELAY);

  struct termios options;
  // The old way. Let's not change baud settings
  fcntl (fd, F_SETFL, 0);

  // get the parameters
  tcgetattr (fd, &options);

  // Set the baud rates to 115200...
   cfsetispeed(&options, B9600);
   cfsetospeed(&options, B9600);

  // Enable the receiver and set local mode...
  options.c_cflag |= (CLOCAL | CREAD);

  // No parity (8N1):
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;

  // enable hardware flow control (CNEW_RTCCTS)
  // options.c_cflag |= CRTSCTS;
  // if(hw_handshake)
  // Disable the hardware flow control for use with mangOH RED
      options.c_cflag &= ~CRTSCTS;

  // set raw input
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  options.c_iflag &= ~(INLCR | ICRNL | IGNCR);

  // set raw output
  options.c_oflag &= ~OPOST;
  options.c_oflag &= ~OLCUC;
  options.c_oflag &= ~ONLRET;
  options.c_oflag &= ~ONOCR;
  options.c_oflag &= ~OCRNL;

  // Set the new options for the port...
  tcsetattr (fd, TCSANOW, &options);


 return fd;
}


 static void write_uart1 (int fd,char *cmd)
 {
//	fd_set  rfds;
//	struct timeval timeout;
int     wrote = 0;
wrote = write (fd, cmd,strlen (cmd));
LE_INFO("wrote  %d ",wrote);
sleep(1);
 }


 static void getLocation(le_timer_Ref_t timerRef) {
  le_timer_Stop(timerRef);
  //char north='N';
 //char east='E';
 char mystring[512];
 //double lati;
 //double longi;
  std::string x_string0;
  std::string x_string1;
   std::string data("Loc: ");
  LE_DEBUG("Checking GPS position");
   int32_t rawLat, rawLon, rawHoriz;
   le_result_t result = le_pos_Get2DLocation(&rawLat, &rawLon, &rawHoriz);
  bool isAccurate = rawHoriz <= MIN_REQUIRED_HORIZ_ACCURACY_METRES;
  bool resOk = result == LE_OK;
  if (resOk && isAccurate) {
  double denom = powf(10, GPS_DECIMAL_SHIFT);  // divide by this
   lastReading.lat = ((double)rawLat) / denom;
   lastReading.lon = ((double)rawLon) / denom;
   // no conversion required for horizontal accuracy
   //lastReading.horizAccuracy = (double)rawHoriz;
   //lastReading.datetime = GetCurrentTimestamp();
   LE_INFO("Got reading...");
   LE_INFO("lat: %f, long: %f, horiz: %f",
        lastReading.lat, lastReading.lon, lastReading.horizAccuracy);
    le_timer_SetMsInterval(timerRef, POLL_PERIOD_SEC * 1000);
  } else {
   if (!isAccurate && resOk) {
  LE_INFO("Rejected for accuracy (%d m)", rawHoriz);
  double denom = powf(10, GPS_DECIMAL_SHIFT);  // divide by this
      lastReading.lat = ((double)rawLat) / denom;
      lastReading.lon = ((double)rawLon) / denom;
      // no conversion required for horizontal accuracy
      //lastReading.horizAccuracy = (double)rawHoriz;
      //lastReading.datetime = GetCurrentTimestamp();
      LE_INFO("Got reading...");
      LE_INFO("%fN %fE , horiz: %f",lastReading.lat, lastReading.lon, lastReading.horizAccuracy);
       le_timer_SetMsInterval(timerRef, POLL_PERIOD_SEC * 100);
       //lati=lastReading.lat;
       std::stringstream x_str;
       x_str << lastReading.lat;
       x_string0=x_str.str();
       data += x_string0;
       data += "N";
       data += " ";
       //longi=lastReading.lon;
       std::stringstream x_strs;
       x_strs << lastReading.lon;
       x_string1=x_strs.str();
       data += x_string1;
       data += "E";
       data += " ";
       data += "\r\n";
      strcpy(mystring, data.c_str());
      LE_INFO("%s",mystring);
      write_uart1(serial_fd, mystring);
      LE_INFO("Sent via UART0");
     }
    LE_INFO("Failed to get reading... retrying in %d seconds",
        RETRY_PERIOD_SEC);
    le_timer_SetMsInterval(timerRef, RETRY_PERIOD_SEC * 100);
    }
  le_timer_Start(timerRef);
  }

     /**
   * Perform all required setup
   *
   * Note that we run this on a timer to avoid
   * blocking up the main (only) thread. If this
   * was run in a while(true) that sleeps,
   * the IPC caller would be blocked indefinitely
    */
    static void gps_init() {
     posCtrlRef = le_posCtrl_Request();

char myvalue[256];
std::string devdata("/dev/ttyHS0");
strcpy(myvalue, devdata.c_str());
serial_fd = open_uart1(myvalue);
cout << serial_fd;
    LE_FATAL_IF(posCtrlRef == NULL, "Couldn't activate positioning");

    pollingTimer = le_timer_Create("GPS polling timer");
    le_timer_SetHandler(pollingTimer, getLocation);
    le_timer_SetRepeat(pollingTimer, 1);
    le_timer_SetMsInterval(pollingTimer, 0);
    le_timer_Start(pollingTimer);
    }

    COMPONENT_INIT {
      gps_init();
      }