Can't get location data from GNSS control API


#1

Hello,

I am using WP8548 and trying to get location data with GNSS control API’s le_gnss_GetLocation().
But it always fails with -3(LE_OUT_OF_RANGE).
(Before executing le_gnss_GetLocation(), le_gnss_Start() is executed and no error is occured.)

I also tried it using the following target tool command and it could get correct location data.
gnss start
gnss get posInfo

Why can’t it get location data with le_gnss_GetLocation()?

Legato version : 18.10.2
Firmware Version : SWI9X15Y_07.13.07.00


#2

Don’t forget to connect antenna to your module and try move on outside !


#3

Hi Andy_5,

I tried them with a GPS antenna and I did them at same place in both case of using API and using tool commands.

Thx


#4

Hi kndu_t,
I used to use le_pos_Get2DLocation () API instead of le_gnss_GetLocation(), flow this link https://docs.legato.io/latest/c_posSampleCodeNavigation.html to get location, it worked fine or you can install Developer studio and try with a example code, It called Texloc.


#5

Hi Andy_5,
Is the program Texloc the same as textLoc on this link https://github.com/legatoproject/legato-af/tree/master/apps/sample/textLoc ?
If so, I made the program with reference to it.
And I first used le_pos_Get2DLocation() API but it was failed, then I used le_gnss_GetLocation() API and it was failed too.

I’m sorry that information I wrote was insufficient.
I put the code below.

#define GPS_TIMEOUT_SEC     120

static le_result_t GetCurrentLocation(
    int32_t *latitudePtr,
    int32_t *longitudePtr,
    int32_t *horizontalAccuracyPtr,
    uint32_t timeoutInSeconds
);


void gps_Receiver(void)
{
    le_result_t res;
    int32_t gps_latitude;
    int32_t gps_longitude;
    int32_t gps_horizontalAccuracy;

    res = GetCurrentLocation(&gps_latitude, &gps_longitude, &gps_horizontalAccuracy, GPS_TIMEOUT_SEC);

    if(res == LE_OK){
        LE_INFO("GPS_Loc:latitude -> %d, longitude -> %d", gps_latitude, gps_longitude); 
    }else{
        LE_INFO("GPS_Loc:unknown");
    }

}



static le_result_t GetCurrentLocation(
    int32_t *latitudePtr,
    int32_t *longitudePtr,
    int32_t *horizontalAccuracyPtr,
    uint32_t timeoutInSeconds )
{
    le_result_t result;
    le_gnss_State_t gnss_state_result;
    const time_t startTime = time(NULL);
    le_gnss_SampleRef_t gnss_sampleRef;
    uint32_t ttff;
    le_gnss_FixState_t gnss_fixState;

    gnss_state_result = le_gnss_GetState();
    if(LE_GNSS_STATE_ACTIVE == gnss_state_result){
         le_gnss_Stop();
    }
    

    result = le_gnss_Start();
    if(result != LE_OK){
        LE_ERROR("Can't activate the Positioning service : %d", result);
        return LE_UNAVAILABLE;
    }

    gnss_sampleRef = le_gnss_GetLastSampleRef();
    //gnss_sampleRef= NULL;

    LE_INFO("Checking 2D position");
    while(true){

        result = le_gnss_GetTtff(&ttff);
        LE_INFO("result = %d, TTFF = %d", result, ttff);
        result = le_gnss_GetPositionState(gnss_sampleRef, &gnss_fixState);
        LE_INFO("result = %d, Position state: %d", result, gnss_state_result);
        
        result = le_gnss_GetLocation(gnss_sampleRef, latitudePtr, longitudePtr, horizontalAccuracyPtr);
        if(result == LE_OK){
            break;
        }else if(
            (timeoutInSeconds != 0) &&
            (difftime(time(NULL), startTime) > (double)timeoutInSeconds))
        {
            result = LE_TIMEOUT;
            break;
        }else{
            LE_ERROR("GPS position getting error:%d", result);
            LE_INFO("GPS_Loc:latitude -> %d, longitude -> %d", *latitudePtr, *longitudePtr); 

            // Sleep for one second before requesting the location again.
            sleep(1);
        }

    }

    le_gnss_Stop();

    return result;
}

Thx


#6

Yes, this link https://github.com/legatoproject/legato-af/blob/master/apps/sample/textLoc/textLocComponent/textLoc.c is right and you should flow this code and I think that you should modify several things like below :

  • declare 3 global variable like that
    int32_t lat
    int32_t long;
    int32_t horiz;

  • In COMPONENT_INIT
    { le_result_t res ;
    res = GetCurrentLocation (&lat, &long, &horiz, GPSTIMEOUT);
    if ( res == LE_FAULT)
    LE_INFO (" FAILED \n") ;

    LE_INFO (" lat = %d , long= %d , horiz= %d , \n", lat,long,horiz ) ;

}


#7

Hi Andy_5,

I omitted COMPONENT_INIT part in previous reply.
OK, I put all code and project files below.

gpsComponent/helloGps.c

#include "legato.h"
#include "interfaces.h"
#include "helloGps.h"

#define GPS_TIMEOUT_SEC     120

static le_result_t GetCurrentLocation(
    int32_t *latitudePtr,
    int32_t *longitudePtr,
    int32_t *horizontalAccuracyPtr,
    uint32_t timeoutInSeconds
);


void gps_Receiver(void)
{
    le_result_t res;
    int32_t gps_latitude;
    int32_t gps_longitude;
    int32_t gps_horizontalAccuracy;

    res = GetCurrentLocation(&gps_latitude, &gps_longitude, &gps_horizontalAccuracy, GPS_TIMEOUT_SEC);

    if(res == LE_OK){
        LE_INFO("GPS_Loc:latitude -> %d, longitude -> %d", gps_latitude, gps_longitude); 
    }else{
        LE_INFO("GPS_Loc:unknown");
    }

}



static le_result_t GetCurrentLocation(
    int32_t *latitudePtr,
    int32_t *longitudePtr,
    int32_t *horizontalAccuracyPtr,
    uint32_t timeoutInSeconds )
{
    le_result_t result;
    le_gnss_State_t gnss_state_result;
    const time_t startTime = time(NULL);
    le_gnss_SampleRef_t gnss_sampleRef;
    uint32_t ttff;
    le_gnss_FixState_t gnss_fixState;

    gnss_state_result = le_gnss_GetState();
    if(LE_GNSS_STATE_ACTIVE == gnss_state_result){
         le_gnss_Stop();
    }
    

    result = le_gnss_Start();
    if(result != LE_OK){
        LE_ERROR("Can't activate the Positioning service : %d", result);
        return LE_UNAVAILABLE;
    }

    gnss_sampleRef = le_gnss_GetLastSampleRef();
    //gnss_sampleRef= NULL;

    LE_INFO("Checking 2D position");
    while(true){

        result = le_gnss_GetTtff(&ttff);
        LE_INFO("result = %d, TTFF = %d", result, ttff);
        result = le_gnss_GetPositionState(gnss_sampleRef, &gnss_fixState);
        LE_INFO("result = %d, Position state: %d", result, gnss_state_result);
        
        result = le_gnss_GetLocation(gnss_sampleRef, latitudePtr, longitudePtr, horizontalAccuracyPtr);
        if(result == LE_OK){
            break;
        }else if(
            (timeoutInSeconds != 0) &&
            (difftime(time(NULL), startTime) > (double)timeoutInSeconds))
        {
            result = LE_TIMEOUT;
            break;
        }else{
            LE_ERROR("GPS position getting error:%d", result);
            LE_INFO("GPS_Loc:latitude -> %d, longitude -> %d", *latitudePtr, *longitudePtr); 

            // Sleep for one second before requesting the location again.
            sleep(1);
        }

    }

    le_gnss_Stop();

    return result;
}

COMPONENT_INIT
{
    LE_INFO("Start GPS Sample!");

    gps_Receiver();
}

helloGps.adef

executables:
{
    helloGps = ( gpsComponent )
}

processes:
{
    run:
    {
        ( helloGps )
    }
}

start:manual

bindings:
{
    helloGps.gpsComponent.le_gnss -> positioningService.le_gnss
    helloGps.gpsComponent.le_pos -> positioningService.le_pos
    helloGps.gpsComponent.le_posCtrl -> positioningService.le_posCtrl
}

gpsComponent/Component.cdef

requires:
{
    api:
    {
        positioning/le_gnss.api
        positioning/le_pos.api
        positioning/le_posCtrl.api
    }
}

sources:
{
    helloGps.c
}

Please point out if something is wrong.

Thx.


#8

Can you give me the log ?


#9

Yes, the result of “logread -f” is below.

Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c app_Start() 3385 | Starting app 'helloGps'
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c CreateFileLink() 2069 | Created file link '/dev/log' to '/legato/systems/current/appsWriteable/helloGps/dev/log'.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c CreateFileLink() 2069 | Created file link '/dev/null' to '/legato/systems/current/appsWriteable/helloGps/dev/null'.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c CreateFileLink() 2069 | Created file link '/dev/zero' to '/legato/systems/current/appsWriteable/helloGps/dev/zero'.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c CreateFileLink() 2069 | Created file link '/legato/systems/current/lib/liblegato.so' to '/legato/systems/current/appsWriteable/helloGps/lib/liblegato.so'.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c CreateFileLink() 2069 | Created file link '/lib/ld-linux.so.3' to '/legato/systems/current/appsWriteable/helloGps/lib/ld-linux.so.3'.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c CreateFileLink() 2069 | Created file link '/lib/libc.so.6' to '/legato/systems/current/appsWriteable/helloGps/lib/libc.so.6'.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c CreateFileLink() 2069 | Created file link '/lib/libpthread.so.0' to '/legato/systems/current/appsWriteable/helloGps/lib/libpthread.so.0'.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c CreateFileLink() 2069 | Created file link '/lib/librt.so.1' to '/legato/systems/current/appsWriteable/helloGps/lib/librt.so.1'.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c CreateFileLink() 2069 | Created file link '/lib/libdl.so.2' to '/legato/systems/current/appsWriteable/helloGps/lib/libdl.so.2'.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c CreateFileLink() 2069 | Created file link '/lib/libgcc_s.so.1' to '/legato/systems/current/appsWriteable/helloGps/lib/libgcc_s.so.1'.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c CreateFileLink() 2069 | Created file link '/lib/libm.so.6' to '/legato/systems/current/appsWriteable/helloGps/lib/libm.so.6'.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c CreateFileLink() 2069 | Created file link '/usr/lib/libstdc++.so.6' to '/legato/systems/current/appsWriteable/helloGps/lib/libstdc++.so.6'.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c CreateFileLink() 2069 | Created file link '/legato/systems/current/apps/helloGps/read-only/lib/libComponent_gpsComponent.so' to '/legato/systems/current/appsWriteable/helloGps/l
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c CreateFileLink() 2069 | Created file link '/legato/systems/current/apps/helloGps/read-only/bin/helloGps' to '/legato/systems/current/appsWriteable/helloGps/bin/helloGps'.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c CreateTmpFs() 1703 | Mounted tmpfs at /legato/systems/current/appsWriteable/helloGps/tmp.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c CreateFileLink() 2069 | Created file link '/tmp/legato/serviceDirectoryServer' to '/legato/systems/current/appsWriteable/helloGps/tmp/legato/serviceDirectoryServer'.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | app.c CreateFileLink() 2069 | Created file link '/tmp/legato/serviceDirectoryClient' to '/legato/systems/current/appsWriteable/helloGps/tmp/legato/serviceDirectoryClient'.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxCoreDumpFileBytes to value 102400.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxFileBytes to value 102400.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxLockedMemoryBytes to value 8192.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxFileDescriptors to value 256.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxMQueueBytes to value 512.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxThreads to value 20.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | resourceLimits.c SetRLimitValue() 282 | Setting resource limit maxQueuedSignals to value 100.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | proc.c proc_Start() 1389 | Starting process 'helloGps' with pid 13653
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[645]/supervisor T=main | supervisor.c SigChildHandler() 784 | Reaping unconfigured child process 13652.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | supervisor[13653]/supervisor T=main | proc.c proc_Start() 1354 | Execing 'helloGps'
Feb  5 06:45:48 swi-mdm9x15 user.warn Legato: -WRN- | _UNKNOWN_[13653]/framework T=main | LE_FILENAME le_fdMonitor_Create() 672 | FD Monitor object name 'helloGps.gpsComponent.le_posCtrl' truncated to 'helloGps.gpsComponent.le_posCtr'.
Feb  5 06:45:48 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | helloGps.c _gpsComponent_COMPONENT_INIT() 7 | Start GPS Sample!
Feb  5 06:45:49 swi-mdm9x15 authpriv.info dropbear[13645]: Exit (root): Disconnect received
Feb  5 06:45:49 swi-mdm9x15 user.info Legato:  INFO | posDaemon[1046]/le_pa_gnss T=main | pa_gnss_qmi.c pa_gnss_Start() 3445 | EngineState ON
Feb  5 06:45:49 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 62 | Checking 2D position
Feb  5 06:45:49 swi-mdm9x15 user.warn Legato: -WRN- | posDaemon[1046]/le_pa_gnss T=main | pa_gnss_qmi.c pa_gnss_GetTtff() 4036 | TTFF not available
Feb  5 06:45:49 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 66 | result = -17, TTFF = 0
Feb  5 06:45:49 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 68 | result = 0, Position state: 1
Feb  5 06:45:49 swi-mdm9x15 user.err Legato: =ERR= | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 80 | GPS position getting error:-3
Feb  5 06:45:49 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 81 | GPS_Loc:latitude -> 34770001, longitude -> 138460007
Feb  5 06:45:50 swi-mdm9x15 user.warn Legato: -WRN- | posDaemon[1046]/le_pa_gnss T=main | pa_gnss_qmi.c pa_gnss_GetTtff() 4036 | TTFF not available
Feb  5 06:45:50 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 66 | result = -17, TTFF = 0
Feb  5 06:45:50 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 68 | result = 0, Position state: 1
Feb  5 06:45:50 swi-mdm9x15 user.err Legato: =ERR= | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 80 | GPS position getting error:-3
Feb  5 06:45:50 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 81 | GPS_Loc:latitude -> 34770001, longitude -> 138460007
Feb  5 06:45:51 swi-mdm9x15 user.warn Legato: -WRN- | posDaemon[1046]/le_pa_gnss T=main | pa_gnss_qmi.c pa_gnss_GetTtff() 4036 | TTFF not available
Feb  5 06:45:51 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 66 | result = -17, TTFF = 0
Feb  5 06:45:51 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 68 | result = 0, Position state: 1
Feb  5 06:45:51 swi-mdm9x15 user.err Legato: =ERR= | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 80 | GPS position getting error:-3
Feb  5 06:45:51 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 81 | GPS_Loc:latitude -> 34770001, longitude -> 138460007
Feb  5 06:45:52 swi-mdm9x15 user.warn Legato: -WRN- | posDaemon[1046]/le_pa_gnss T=main | pa_gnss_qmi.c pa_gnss_GetTtff() 4036 | TTFF not available
Feb  5 06:45:52 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 66 | result = -17, TTFF = 0
Feb  5 06:45:52 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 68 | result = 0, Position state: 1
Feb  5 06:45:52 swi-mdm9x15 user.err Legato: =ERR= | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 80 | GPS position getting error:-3
Feb  5 06:45:52 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 81 | GPS_Loc:latitude -> 34770001, longitude -> 138460007
Feb  5 06:45:53 swi-mdm9x15 user.warn Legato: -WRN- | posDaemon[1046]/le_pa_gnss T=main | pa_gnss_qmi.c pa_gnss_GetTtff() 4036 | TTFF not available
Feb  5 06:45:53 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 66 | result = -17, TTFF = 0
Feb  5 06:45:53 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 68 | result = 0, Position state: 1
Feb  5 06:45:53 swi-mdm9x15 user.err Legato: =ERR= | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 80 | GPS position getting error:-3
Feb  5 06:45:53 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 81 | GPS_Loc:latitude -> 34770001, longitude -> 138460007
Feb  5 06:45:54 swi-mdm9x15 user.debug kernel: [ 6770.876757] NMEA read driver miss interrupt, abandon current buff
    .
    . (Repeat)
    .
Feb  5 06:47:48 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 81 | GPS_Loc:latitude -> 34770001, longitude -> 138460007
Feb  5 06:47:49 swi-mdm9x15 user.warn Legato: -WRN- | posDaemon[1046]/le_pa_gnss T=main | pa_gnss_qmi.c pa_gnss_GetTtff() 4036 | TTFF not available
Feb  5 06:47:49 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 66 | result = -17, TTFF = 0
Feb  5 06:47:49 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c GetCurrentLocation() 68 | result = 0, Position state: 1
Feb  5 06:47:49 swi-mdm9x15 user.warn Legato: -WRN- | posDaemon[1046]/le_pa_gnss T=unknown | pa_gnss_qmi.c PositionHandler() 1441 | Bad position indication
Feb  5 06:47:49 swi-mdm9x15 user.info Legato:  INFO | helloGps[13653]/gpsComponent T=main | gpsRcv.c gps_Receiver() 27 | GPS_Loc:unknown

#10

I think that you got location data
GPS_Loc:latitude -> 34770001, longitude -> 138460007


#11

Hi Andy_5,

Its location data is invalid data.
For confirmation, the program also displays the variable value even if an error is returned.
In case of LE_OK, it leaves from the while loop and displays valid values.

Certainly it was a confusing log.

Thx


#12

Supplementally, the latitude and longitude in the log points to the sea. By the way, I am trying it in Tokyo, Japan.


#13

I could get location data using handler function for EVENT ‘le_gnss_Position’ and executing le_gnss_GetPositionState() in the handler instead of polling.
In case of using handler, it seems to be called per one second and it looks same as doing in case of polling.

The GNSS data could be got in up to 3 minutes using handler.
But in case of polling, it could’t be got even in 5 minutes.

It’s good that the data can be got but I could’t understand why it can’t get them in case of polling.

Thx.