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.