#include "legato.h"
#include <stdio.h>
#include "interfaces.h"
static le_pos_MovementHandlerRef_t NavigationHandlerRef;
static le_pos_MovementHandlerRef_t FiftyNavigationHandlerRef;
#define DEFAULT_ACQUISITION_RATE 1000
#ifdef LE_CONFIG_LINUX
#define LINUX_OS 1
#else
#define LINUX_OS 0
#endif
static void NavigationHandler
(
le_pos_SampleRef_t positionSampleRef,
void* contextPtr
)
{
int32_t val, val1, accuracy;
uint32_t uval, uAccuracy;
uint16_t year;
uint16_t month;
uint16_t day;
uint16_t hours;
uint16_t minutes;
uint16_t seconds;
uint16_t milliseconds;
le_pos_FixState_t fixState;
if (NULL == positionSampleRef)
{
LE_ERROR(
"New Position sample is NULL!");
}
else
{
LE_INFO(
"New Position sample %p", positionSampleRef);
}
LE_INFO(
"GetFixState: %d", fixState);
LE_INFO(
"Get2DLocation: lat.%d, long.%d, accuracy.%d", val, val1, accuracy);
LE_INFO(
"GetDate: year.%d, month.%d, day.%d", year, month, day);
LE_INFO(
"GetTime: hours.%d, minutes.%d, seconds.%d, milliseconds.%d", hours, minutes, seconds,
milliseconds);
LE_INFO(
"GetAltitude: alt.%d, accuracy.%d", val, accuracy);
LE_INFO(
"GetHorizontalSpeed: hSpeed.%u, accuracy.%u", uval, uAccuracy);
LE_INFO(
"GetVerticalSpeed: vSpeed.%d, accuracy.%d", val, accuracy);
LE_INFO(
"GetHeading: heading.%u, accuracy.%u", uval, uAccuracy);
LE_INFO(
"GetDirection: direction.%u, accuracy.%u", uval, uAccuracy);
}
static void FiftyMeterNavigationHandler
(
le_pos_SampleRef_t positionSampleRef,
void* contextPtr
)
{
int32_t val, val1, accuracy;
uint32_t uval, uAccuracy;
le_pos_FixState_t fixState;
if (NULL == positionSampleRef)
{
LE_ERROR(
"New Position sample is NULL!");
}
else
{
LE_INFO(
"New Position sample %p", positionSampleRef);
}
LE_INFO(
"GetFixState: %d", fixState);
LE_INFO(
"Get2DLocation: lat.%d, long.%d, accuracy.%d", val, val1, accuracy);
LE_INFO(
"GetAltitude: alt.%d, accuracy.%d", val, accuracy);
LE_INFO(
"GetHorizontalSpeed: hSpeed.%u, accuracy.%u", uval, uAccuracy);
LE_INFO(
"GetVerticalSpeed: vSpeed.%d, accuracy.%d", val, accuracy);
LE_INFO(
"GetHeading: heading.%u, accuracy.%u", uval, uAccuracy);
LE_INFO(
"GetDirection: direction.%u, accuracy.%u", uval, uAccuracy);
}
static void* NavigationThread
(
void* context
)
{
LE_INFO(
"======== Navigation Handler thread ========");
LE_ASSERT(NULL != FiftyNavigationHandlerRef);
return NULL;
}
static void Testle_pos_DistanceResolutionUpdate
(
void
)
{
int32_t latitude;
int32_t longitude;
int32_t altitude, altitudeSav;
int32_t hAccuracy, hAccuracySav;
int32_t vAccuracy, vAccuracySav;
LE_INFO(
"Meter resolution: hAccuracy %d, altitude %d, vAccuracy %d",
hAccuracy, altitude, vAccuracy);
altitudeSav = altitude;
hAccuracySav = hAccuracy;
vAccuracySav = vAccuracy;
LE_INFO(
"Decimeter: hAccuracy %d, altitude %d, vAccuracy %d", hAccuracy, altitude, vAccuracy);
if ((UINT32_MAX != hAccuracy) && (UINT32_MAX != hAccuracySav))
{
}
if ((UINT32_MAX != vAccuracy) && (UINT32_MAX != vAccuracySav))
{
}
if ((UINT32_MAX != altitude) && (UINT32_MAX != altitudeSav))
{
}
altitudeSav = altitude;
hAccuracySav = hAccuracy;
vAccuracySav = vAccuracy;
LE_INFO(
"Centimeter: hAccuracy.%d, altitude.%d, vAccuracy.%d", hAccuracy, altitude, vAccuracy);
if ((UINT32_MAX != hAccuracy) && (UINT32_MAX != hAccuracySav))
{
}
if ((UINT32_MAX != vAccuracy) && (UINT32_MAX != vAccuracySav))
{
}
if ((UINT32_MAX != altitude) && (UINT32_MAX != altitudeSav))
{
}
altitudeSav = altitude;
hAccuracySav = hAccuracy;
vAccuracySav = vAccuracy;
LE_INFO(
"Millimeter: hAccuracy.%d, altitude.%d, vAccuracy.%d", hAccuracy, altitude, vAccuracy);
if ((UINT32_MAX != hAccuracy) && (UINT32_MAX != hAccuracySav))
{
}
if ((UINT32_MAX != vAccuracy) && (UINT32_MAX != vAccuracySav))
{
}
if ((UINT32_MAX != altitude) && (UINT32_MAX != altitudeSav))
{
}
altitudeSav = altitude;
hAccuracySav = hAccuracy;
vAccuracySav = vAccuracy;
LE_INFO(
"Meter: hAccuracy.%d, altitude.%d, vAccuracy.%d", hAccuracy, altitude, vAccuracy);
if ((UINT32_MAX != hAccuracy) && (UINT32_MAX != hAccuracySav))
{
}
if ((UINT32_MAX != vAccuracy) && (UINT32_MAX != vAccuracySav))
{
}
if ((UINT32_MAX != altitude) && (UINT32_MAX != altitudeSav))
{
}
}
static void Testle_pos_GetInfo
(
void
)
{
int32_t latitude;
int32_t longitude;
int32_t altitude;
int32_t hAccuracy;
int32_t vAccuracy;
uint32_t hSpeed;
uint32_t hSpeedAccuracy;
int32_t vSpeed;
int32_t vSpeedAccuracy;
uint32_t heading;
uint32_t headingAccuracy=0;
uint32_t direction;
uint32_t directionAccuracy=0;
uint16_t year = 0;
uint16_t month = 0;
uint16_t day = 0;
uint16_t hours = 0;
uint16_t minutes = 0;
uint16_t seconds = 0;
uint16_t milliseconds = 0;
le_pos_FixState_t fixState;
LE_INFO(
"position fix state %d", fixState);
LE_INFO(
"Check le_pos_Get2DLocation latitude.%d, longitude.%d, hAccuracy.%d",
latitude, longitude, hAccuracy);
LE_INFO(
"Check le_pos_Get3DLocation latitude.%d, longitude.%d, hAccuracy.%d, altitude.%d" ", vAccuracy.%d",
latitude, longitude, hAccuracy, altitude, vAccuracy);
LE_INFO(
"Check le_pos_GetDate year.%d, month.%d, day.%d",
year, month, day);
LE_INFO(
"Check le_pos_GetTime hours.%d, minutes.%d, seconds.%d, milliseconds.%d",
hours, minutes, seconds, milliseconds);
LE_INFO(
"Check le_pos_GetMotion hSpeed.%u, hSpeedAccuracy.%u, vSpeed.%d, vSpeedAccuracy.%d",
hSpeed, hSpeedAccuracy, vSpeed, vSpeedAccuracy);
LE_INFO(
"Check le_pos_GetHeading heading.%u, headingAccuracy.%u",
heading, headingAccuracy);
LE_INFO(
"Check le_pos_GetDirection direction.%u, directionAccuracy.%u",
direction, directionAccuracy);
}
static void Testle_pos_TestAcquisitionRate
(
void
)
{
uint32_t acquisitionRate=0;
LE_ASSERT((3000 == acquisitionRate) || (DEFAULT_ACQUISITION_RATE == acquisitionRate));
LE_ASSERT((1000 == acquisitionRate) || (DEFAULT_ACQUISITION_RATE == acquisitionRate));
}
static void Testle_pos_ActivateGpsNmeaSentences
(
void
)
{
int i = 0;
le_gnss_NmeaBitMask_t nmeaMask;
le_gnss_NmeaBitMask_t saveNmeaMask;
nmeaMask = (LE_GNSS_NMEA_SENTENCES_MAX << 1) | 1;
"Set invalid NMEA mask %d", nmeaMask);
le_gnss_NmeaBitMask_t nmeaSentencesList[] = {
LE_GNSS_NMEA_MASK_GPGGA,
LE_GNSS_NMEA_MASK_GPGSA,
LE_GNSS_NMEA_MASK_GPGSV,
LE_GNSS_NMEA_MASK_GPRMC,
LE_GNSS_NMEA_MASK_GPVTG,
LE_GNSS_NMEA_MASK_GPGLL,
#ifdef LE_CONFIG_LINUX
LE_GNSS_NMEA_MASK_GLGSV,
LE_GNSS_NMEA_MASK_GNGNS,
LE_GNSS_NMEA_MASK_GNGSA,
LE_GNSS_NMEA_MASK_GAGGA,
LE_GNSS_NMEA_MASK_GAGSA,
LE_GNSS_NMEA_MASK_GAGSV,
LE_GNSS_NMEA_MASK_GARMC,
LE_GNSS_NMEA_MASK_GAVTG,
#else
LE_GNSS_NMEA_MASK_GPGNS,
LE_GNSS_NMEA_MASK_GPZDA,
LE_GNSS_NMEA_MASK_GPGST,
#endif
0
};
for (i = 0; nmeaSentencesList[i]; i++)
{
"Set NMEA sentence mask to 0x%08X",nmeaSentencesList[i]);
"Confirm NMEA sentence mask is set to 0x%08X", nmeaSentencesList[i]);
}
"Set NMEA sentence mask to %08X", LE_GNSS_NMEA_MASK_PQXFI);
LE_TEST_OK(nmeaMask == (LE_GNSS_NMEA_MASK_PQXFI | LE_GNSS_NMEA_MASK_PTYPE),
"Confirm NMEA sentence mask is set to %08X",
(LE_GNSS_NMEA_MASK_PQXFI | LE_GNSS_NMEA_MASK_PTYPE));
"Set NMEA sentence mask to %08X",LE_GNSS_NMEA_MASK_PTYPE);
LE_TEST_OK(nmeaMask == (LE_GNSS_NMEA_MASK_PQXFI | LE_GNSS_NMEA_MASK_PTYPE),
"Confirm NMEA sentence mask is set to %08X",
(LE_GNSS_NMEA_MASK_PQXFI | LE_GNSS_NMEA_MASK_PTYPE));
"Set NMEA sentence mask to %08X", LE_GNSS_NMEA_MASK_PSTIS);
LE_TEST_OK((LE_GNSS_NMEA_MASK_PSTIS == nmeaMask) || (0 == nmeaMask),
"Confirm NMEA sentence mask is set to %08X or 0", LE_GNSS_NMEA_MASK_PSTIS);
"set NMEA sentence mask to %08X", LE_GNSS_NMEA_MASK_GPGRS);
"Get NMEA sentences");
LE_TEST_OK((LE_GNSS_NMEA_MASK_GPGRS == nmeaMask) || (0 == nmeaMask),
"Confirm NMEA sentence mas is set to %08X or 0", LE_GNSS_NMEA_MASK_GPGRS);
"Set NMEA sentence mask to %08X", LE_GNSS_NMEA_MASK_DEBUG);
LE_TEST_OK((LE_GNSS_NMEA_MASK_DEBUG == nmeaMask) || (0 == nmeaMask),
"Confirm NMEA sentence mask is set to %08X or 0", LE_GNSS_NMEA_MASK_DEBUG);
"Set NMEA sentence mask to %08X", LE_GNSS_NMEA_MASK_GPDTM);
"Get NMEA sentences");
LE_TEST_OK((LE_GNSS_NMEA_MASK_GPDTM == nmeaMask) || (0 == nmeaMask),
"Confirm NMEA sentence mask is set to %08X or 0", LE_GNSS_NMEA_MASK_GPDTM);
"Set NMEA sentences to %08X", LE_GNSS_NMEA_MASK_GAGNS);
"Get NMEA sentences");
LE_TEST_OK((LE_GNSS_NMEA_MASK_GAGNS == nmeaMask) || (0 == nmeaMask),
"Confirm NMEA sentence mask is set to %08X or 0", LE_GNSS_NMEA_MASK_GAGNS);
"Set NMEA sentence mask to %08X", LE_GNSS_NMEA_MASK_GPGLL);
"Get NMEA sentences");
LE_TEST_OK((LE_GNSS_NMEA_MASK_GPGLL == nmeaMask) || (0 == nmeaMask),
"Confirm NMEA sentence mask is set to %08X or 0", LE_GNSS_NMEA_MASK_GPGLL);
saveNmeaMask = LE_GNSS_NMEA_MASK_GPGGA | LE_GNSS_NMEA_MASK_GPGSA | LE_GNSS_NMEA_MASK_GPGSV;
"Set NMEA sentence mask to %08X", saveNmeaMask);
"Get NMEA sentences");
"Confirm NMEA sentence mask is set to %08X", saveNmeaMask);
"Set NMEA sentence mask to %08X", (saveNmeaMask | LE_GNSS_NMEA_MASK_GPRMC));
LE_TEST_OK(((saveNmeaMask | LE_GNSS_NMEA_MASK_GPRMC) == nmeaMask) || (saveNmeaMask == nmeaMask),
"Confirm NMEA mask is set correctly");
"Set NMEA sentence mask to %08X", (saveNmeaMask | LE_GNSS_NMEA_MASK_GPGLL));
LE_TEST_OK(((saveNmeaMask | LE_GNSS_NMEA_MASK_GPGLL) == nmeaMask) || (saveNmeaMask == nmeaMask),
"Confirm NMEA mask is set correctly");
"Set NMEA sentence mask to %08X", (saveNmeaMask | LE_GNSS_NMEA_MASK_DEBUG));
LE_TEST_OK(((saveNmeaMask | LE_GNSS_NMEA_MASK_DEBUG) == nmeaMask) ||
(saveNmeaMask == nmeaMask), "Confirm NMEA sentence mask is set correctly");
"Set NMEA sentence mask to %08X", (saveNmeaMask | LE_GNSS_NMEA_MASK_GPDTM));
LE_TEST_OK(((saveNmeaMask | LE_GNSS_NMEA_MASK_GPDTM) == nmeaMask) || (saveNmeaMask == nmeaMask),
"Confirm NMEA sentence mask is set correctly");
"Set NMEA sentence mask to %08X", (saveNmeaMask | LE_GNSS_NMEA_MASK_GAGNS));
LE_TEST_OK(((saveNmeaMask | LE_GNSS_NMEA_MASK_GAGNS) == nmeaMask) || (saveNmeaMask == nmeaMask),
"Confirm NMEA sentence mask is set correctly");
LE_TEST_INFO(
"Test Testle_pos_ActivateGpsNmeaSentences OK");
}
static void Testle_pos_ResetGpsNmeaSentences
(
void
)
{
le_gnss_NmeaBitMask_t gpsNmeaMask = 0;
le_gnss_NmeaBitMask_t nmeaMask;
}
static void RemoveMovementHandlers
(
void
)
{
NavigationHandlerRef = NULL;
FiftyNavigationHandlerRef = NULL;
}
{
le_posCtrl_ActivationRef_t activationRef;
le_thread_Ref_t navigationThreadRef;
LE_INFO(
"======== Positioning Test started ========");
Testle_pos_TestAcquisitionRate();
navigationThreadRef = le_thread_Create("NavigationThread",NavigationThread,NULL);
le_thread_Start(navigationThreadRef);
Testle_pos_GetInfo();
LE_INFO(
"Request activation of the positioning service");
LE_INFO(
"Wait 120 seconds for a 3D fix");
sleep(120);
Testle_pos_DistanceResolutionUpdate();
Testle_pos_GetInfo();
sleep(1);
LE_INFO(
"Release the positioning service");
RemoveMovementHandlers();
le_thread_Cancel(navigationThreadRef);
Testle_pos_ActivateGpsNmeaSentences();
Testle_pos_ResetGpsNmeaSentences();
LE_INFO(
"======== Positioning Test finished ========");
exit(EXIT_SUCCESS);
}