Sample code for Enable/Disable GNSS device

//--------------------------------------------------------------------------------------------------
/**
* Test: Legato GNSS functions.
*
*/
//--------------------------------------------------------------------------------------------------
static void TestLeGnssDevice
(
void
)
{
uint32_t ttffValue;
uint32_t acqRate;
uint8_t minElevation;
le_result_t result;
int32_t altitudeOnWgs84=0;
int64_t altitudeOnPZ90;
 
le_gnss_ConstellationBitMask_t constellationMask;
le_gnss_NmeaBitMask_t nmeaMask = 0;
le_gnss_ConstellationArea_t constellationArea;
 
LE_INFO("Start Test Testle_gnss_DeviceTest");
// GNSS device enabled by default
LE_ASSERT((le_gnss_GetState()) == LE_GNSS_STATE_READY);
// Disable GNSS device (DISABLED state)
// Check Disabled state
LE_ASSERT((le_gnss_GetState()) == LE_GNSS_STATE_DISABLED);
LE_ASSERT((le_gnss_SetConstellation(LE_GNSS_CONSTELLATION_GPS)) == LE_NOT_PERMITTED);
 
LE_ASSERT(LE_NOT_PERMITTED == (le_gnss_SetConstellationArea(LE_GNSS_SV_CONSTELLATION_GPS,
LE_GNSS_WORLDWIDE_AREA)));
LE_ASSERT(LE_NOT_PERMITTED == (le_gnss_GetConstellationArea(LE_GNSS_SV_CONSTELLATION_GPS,
&constellationArea)));
 
LE_ASSERT(LE_NOT_PERMITTED == (le_gnss_SetConstellationArea(LE_GNSS_SV_CONSTELLATION_GLONASS,
LE_GNSS_WORLDWIDE_AREA)));
LE_ASSERT(LE_NOT_PERMITTED == (le_gnss_GetConstellationArea(LE_GNSS_SV_CONSTELLATION_GLONASS,
&constellationArea)));
 
result = le_gnss_SetAcquisitionRate(acqRate);
LE_ASSERT((result == LE_NOT_PERMITTED) || (result == LE_OUT_OF_RANGE));
 
// test le_gnss_Get/SetMinElevation when GNSS device is disabled and the engine is not started.
minElevation = 40;
LE_ASSERT((le_gnss_GetMinElevation(&minElevation)) == LE_OK);
LE_INFO("GNSS min elevation obtained: %d",minElevation);
LE_ASSERT(minElevation == 40);
 
// Enable GNSS device (READY state)
LE_ASSERT((le_gnss_GetState()) == LE_GNSS_STATE_READY);
LE_ASSERT((le_gnss_GetState()) == LE_GNSS_STATE_DISABLED);
LE_ASSERT((le_gnss_GetState()) == LE_GNSS_STATE_READY);
LE_ASSERT_OK(le_gnss_SetConstellation(LE_GNSS_CONSTELLATION_GPS));
LE_ASSERT_OK(le_gnss_GetConstellation(&constellationMask));
LE_ASSERT(constellationMask == LE_GNSS_CONSTELLATION_GPS);
 
LE_ASSERT(LE_BAD_PARAMETER == (le_gnss_SetConstellationArea(LE_GNSS_SV_CONSTELLATION_GALILEO,
LE_GNSS_UNSET_AREA)));
 
LE_ASSERT_OK(le_gnss_SetConstellationArea(LE_GNSS_SV_CONSTELLATION_GALILEO,
LE_GNSS_OUTSIDE_US_AREA));
LE_ASSERT_OK(le_gnss_GetConstellationArea(LE_GNSS_SV_CONSTELLATION_GALILEO,
&constellationArea));
LE_ASSERT(LE_GNSS_OUTSIDE_US_AREA == constellationArea);
 
LE_ASSERT_OK(le_gnss_SetConstellationArea(LE_GNSS_SV_CONSTELLATION_GALILEO,
LE_GNSS_WORLDWIDE_AREA));
LE_ASSERT_OK(le_gnss_GetConstellationArea(LE_GNSS_SV_CONSTELLATION_GALILEO,
&constellationArea));
LE_ASSERT(LE_GNSS_WORLDWIDE_AREA == constellationArea);
 
acqRate = 0;
acqRate = 1100;
LE_INFO("NMEA mask: %x",nmeaMask);
 
// test le_gnss_Get/SetMinElevation when GNSS device is enabled and the engine is not started.
minElevation = 0;
LE_ASSERT((le_gnss_GetMinElevation(&minElevation)) == LE_OK);
LE_INFO("GNSS min elevation obtained: %d",minElevation);
LE_ASSERT(minElevation == 0);
 
// Start GNSS device (ACTIVE state)
LE_ASSERT((le_gnss_GetState()) == LE_GNSS_STATE_ACTIVE);
LE_ASSERT((le_gnss_SetConstellation(LE_GNSS_CONSTELLATION_GPS)) == LE_NOT_PERMITTED);
result = le_gnss_SetAcquisitionRate(acqRate);
LE_ASSERT((result == LE_NOT_PERMITTED) || (result == LE_OUT_OF_RANGE));
 
// test le_gnss_Get/SetMinElevation when le_gnss_ENABLE ON and le_gnss_Start ON
minElevation = LE_GNSS_MIN_ELEVATION_MAX_DEGREE;
LE_ASSERT((le_gnss_GetMinElevation(&minElevation)) == LE_OK);
LE_INFO("GNSS min elevation obtained: %d",minElevation);
LE_ASSERT(minElevation == LE_GNSS_MIN_ELEVATION_MAX_DEGREE);
 
// test le_gnss_SetMinElevation wrong value (when le_gnss_ENABLE ON and le_gnss_Start ON)
minElevation = LE_GNSS_MIN_ELEVATION_MAX_DEGREE+1;
 
// Stop GNSS device (READY state)
LE_ASSERT((le_gnss_GetState()) == LE_GNSS_STATE_READY);
LE_ASSERT((le_gnss_GetState()) == LE_GNSS_STATE_DISABLED);
LE_ASSERT((le_gnss_GetState()) == LE_GNSS_STATE_READY);
LE_ASSERT((le_gnss_SetConstellation(LE_GNSS_CONSTELLATION_GPS)) == LE_OK);
LE_ASSERT((le_gnss_GetConstellation(&constellationMask)) == LE_OK);
LE_ASSERT(constellationMask == LE_GNSS_CONSTELLATION_GPS);
 
// test le_gnss_ConvertDataCoordinate error cases
LE_ASSERT(LE_FAULT == (le_gnss_ConvertDataCoordinateSystem(LE_GNSS_COORDINATE_SYSTEM_WGS84,
LE_GNSS_COORDINATE_SYSTEM_PZ90,
LE_GNSS_POS_LATITUDE,
altitudeOnWgs84,
NULL)));
LE_GNSS_COORDINATE_SYSTEM_MAX,
LE_GNSS_COORDINATE_SYSTEM_PZ90,
LE_GNSS_POS_LATITUDE,
altitudeOnWgs84,
&altitudeOnPZ90)));
LE_GNSS_COORDINATE_SYSTEM_PZ90,
LE_GNSS_COORDINATE_SYSTEM_PZ90,
LE_GNSS_POS_LATITUDE,
altitudeOnWgs84,
&altitudeOnPZ90)));
LE_GNSS_COORDINATE_SYSTEM_WGS84,
LE_GNSS_COORDINATE_SYSTEM_PZ90,
LE_GNSS_POS_MAX,
altitudeOnWgs84,
&altitudeOnPZ90)));
LE_ASSERT(LE_FAULT == (le_gnss_ConvertDataCoordinateSystem(LE_GNSS_COORDINATE_SYSTEM_PZ90,
LE_GNSS_COORDINATE_SYSTEM_WGS84,
LE_GNSS_POS_ALTITUDE,
altitudeOnWgs84,
&altitudeOnPZ90)));
}