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_TEST_OK(((le_gnss_GetState()) == LE_GNSS_STATE_READY), "Get GNSS state");
LE_TEST_OK((le_gnss_Enable()) == LE_DUPLICATE, "Enable GNSS");
// Disable GNSS device (DISABLED state)
LE_TEST_OK((le_gnss_Disable()) == LE_OK, "Disable GNSS");
LE_TEST_OK((le_gnss_Disable()) == LE_DUPLICATE, "Duplicate disable");
// Check Disabled state
LE_TEST_OK((le_gnss_GetState()) == LE_GNSS_STATE_DISABLED, "Get GNSS state");
LE_TEST_OK((le_gnss_Start()) == LE_NOT_PERMITTED, "Start GNSS in disabled state");
LE_TEST_OK((le_gnss_ForceHotRestart()) == LE_NOT_PERMITTED, "Hot restart in disabled state");
LE_TEST_OK((le_gnss_ForceWarmRestart()) == LE_NOT_PERMITTED, "Warm restart in disabled state");
LE_TEST_OK((le_gnss_ForceColdRestart()) == LE_NOT_PERMITTED, "Cold restart in disabled state");
"Factory restart in disabled state");
"Hot start in disabled state");
LE_TEST_OK((le_gnss_StartMode(LE_GNSS_WARM_START)) == LE_NOT_PERMITTED,
"Warm start in disabled state");
LE_TEST_OK((le_gnss_StartMode(LE_GNSS_COLD_START)) == LE_NOT_PERMITTED,
"Cold start in disabled state");
LE_TEST_OK((le_gnss_StartMode(LE_GNSS_FACTORY_START)) == LE_NOT_PERMITTED,
"Factory start in disabled state");
 
LE_TEST_OK((le_gnss_GetTtff(&ttffValue)) == LE_NOT_PERMITTED, "Get TTFF in disabled state");
LE_TEST_OK((le_gnss_Stop()) == LE_NOT_PERMITTED, "Stop GNSS in disabled state");
LE_TEST_OK((le_gnss_SetConstellation(LE_GNSS_CONSTELLATION_GPS)) == LE_NOT_PERMITTED,
"Set constellation in disabled state");
"Get constellation in disabled state");
 
LE_TEST_BEGIN_SKIP(!LINUX_OS, 6);
LE_TEST_OK(LE_NOT_PERMITTED == le_gnss_SetConstellationArea(LE_GNSS_SV_CONSTELLATION_GPS,
LE_GNSS_WORLDWIDE_AREA),
"Set GPS constellation area in disabled state");
LE_TEST_OK(LE_NOT_PERMITTED == le_gnss_GetConstellationArea(LE_GNSS_SV_CONSTELLATION_GPS,
&constellationArea),
"Get GPS constellation area in disabled state");
 
LE_TEST_OK(LE_NOT_PERMITTED == le_gnss_SetConstellationArea(LE_GNSS_SV_CONSTELLATION_GLONASS,
LE_GNSS_WORLDWIDE_AREA),
"Set GLONASS constellation area in disabled state");
LE_TEST_OK(LE_NOT_PERMITTED == le_gnss_GetConstellationArea(LE_GNSS_SV_CONSTELLATION_GLONASS,
&constellationArea),
"Get GLONASS constellation area in disabled state");
 
"Get acquisition rate in disabled state");
result = le_gnss_SetAcquisitionRate(acqRate);
LE_TEST_OK((result == LE_NOT_PERMITTED) || (result == LE_OUT_OF_RANGE),
"Set acquisition rate in disabled state");
 
"Set NMEA sentences in disabled state");
"Get NMEA sentences in disabled state");
 
// test le_gnss_Get/SetMinElevation when GNSS device is disabled and the engine is not started.
LE_TEST_BEGIN_SKIP(!LINUX_OS, 3);
minElevation = 40;
LE_TEST_OK((le_gnss_SetMinElevation(minElevation)) == LE_OK, "Set min elevation");
LE_TEST_OK((le_gnss_GetMinElevation(&minElevation)) == LE_OK, "Get min elevation");
LE_INFO("GNSS min elevation obtained: %d",minElevation);
LE_TEST_OK(minElevation == 40, "Confirm min elevation is set to %d", minElevation);
 
// Enable GNSS device (READY state)
LE_TEST_OK((le_gnss_Enable()) == LE_OK, "Enable GNSS");
LE_TEST_OK((le_gnss_GetState()) == LE_GNSS_STATE_READY, "Get GNSS state");
LE_TEST_OK((le_gnss_Disable()) == LE_OK, "Disable GNSS");
LE_TEST_OK((le_gnss_GetState()) == LE_GNSS_STATE_DISABLED, "Get GNSS state");
LE_TEST_OK((le_gnss_Enable()) == LE_OK, "Enable GNSS");
LE_TEST_OK((le_gnss_GetState()) == LE_GNSS_STATE_READY, "Get GNSS state");
 
LE_TEST_OK((le_gnss_Stop()) == LE_DUPLICATE, "Duplicate GNSS stop");
 
// Unpermitted force restart in READY state
LE_TEST_OK((le_gnss_ForceHotRestart()) == LE_NOT_PERMITTED, "Unpermitted hot restart");
LE_TEST_OK((le_gnss_ForceWarmRestart()) == LE_NOT_PERMITTED, "Unpermitted warm restart");
LE_TEST_OK((le_gnss_ForceColdRestart()) == LE_NOT_PERMITTED, "Unpermitted cold restart");
LE_TEST_OK((le_gnss_ForceFactoryRestart()) == LE_NOT_PERMITTED, "Unpermitted factory restart");
 
LE_TEST_OK(le_gnss_SetConstellation(LE_GNSS_CONSTELLATION_GPS) == LE_OK,
"Set constellation GPS");
LE_TEST_OK(le_gnss_GetConstellation(&constellationMask) == LE_OK, "Get contellation");
LE_TEST_OK(constellationMask == LE_GNSS_CONSTELLATION_GPS,
"Confirm constellation is set to %d", LE_GNSS_CONSTELLATION_GPS);
 
LE_TEST_BEGIN_SKIP(!LINUX_OS, 7);
LE_TEST_OK(LE_BAD_PARAMETER == (le_gnss_SetConstellationArea(LE_GNSS_SV_CONSTELLATION_GALILEO,
LE_GNSS_UNSET_AREA)),
"Set invalid Galileo constellation area");
 
LE_TEST_OK(LE_OK == le_gnss_SetConstellationArea(LE_GNSS_SV_CONSTELLATION_GALILEO,
LE_GNSS_OUTSIDE_US_AREA),
"Set Galileo constellation area outside US");
LE_TEST_OK(LE_OK == le_gnss_GetConstellationArea(LE_GNSS_SV_CONSTELLATION_GALILEO,
&constellationArea),
"Get Galileo constellation area");
LE_TEST_OK(LE_GNSS_OUTSIDE_US_AREA == constellationArea,
"Confirm Galileo constellation area is set to %d", LE_GNSS_OUTSIDE_US_AREA);
 
LE_TEST_OK(LE_OK == le_gnss_SetConstellationArea(LE_GNSS_SV_CONSTELLATION_GALILEO,
LE_GNSS_WORLDWIDE_AREA),
"Set Galileo constellation area worldwide");
LE_TEST_OK(LE_OK == le_gnss_GetConstellationArea(LE_GNSS_SV_CONSTELLATION_GALILEO,
&constellationArea),
"Get Galileo constellation area");
LE_TEST_OK(LE_GNSS_WORLDWIDE_AREA == constellationArea,
"Confirm Galileo constellation area is set to %d", LE_GNSS_WORLDWIDE_AREA);
 
// Get/Set AcquisitionRate
LE_TEST_BEGIN_SKIP(!LINUX_OS, 3);
LE_TEST_OK((le_gnss_GetAcquisitionRate(&acqRate)) == LE_OK, "Get acquisition rate");
acqRate = 0;
"Set invalid acquisition rate");
acqRate = 1100;
LE_TEST_OK((le_gnss_SetAcquisitionRate(acqRate)) == LE_OK, "Set acquisition rate");
 
LE_TEST_OK((le_gnss_GetNmeaSentences(&nmeaMask)) == LE_OK, "Get NMEA sentences");
LE_TEST_INFO("NMEA mask: %x",nmeaMask);
LE_TEST_OK((le_gnss_SetNmeaSentences(nmeaMask)) == LE_OK, "Set NMEA sentences");
 
// test le_gnss_Get/SetMinElevation when GNSS device is enabled and the engine is not started.
LE_TEST_BEGIN_SKIP(!LINUX_OS, 3);
minElevation = 0;
LE_TEST_OK((le_gnss_SetMinElevation(minElevation)) == LE_OK, "Set min elevation");
LE_TEST_OK((le_gnss_GetMinElevation(&minElevation)) == LE_OK, "Get min elevation");
LE_TEST_INFO("GNSS min elevation obtained: %d",minElevation);
LE_TEST_OK(minElevation == 0, "Confirm min elevation is set to 0");
 
// Start GNSS device (ACTIVE state)
LE_TEST_ASSERT(((le_gnss_Start()) == LE_OK), "Start GNSS");
LE_TEST_OK((le_gnss_GetState()) == LE_GNSS_STATE_ACTIVE, "Get GNSS state");
LE_TEST_OK((le_gnss_Start()) == LE_DUPLICATE, "Duplicate GNSS start");
LE_TEST_OK((le_gnss_Enable()) == LE_DUPLICATE, "Duplicate GNSS enable");
LE_TEST_OK((le_gnss_Disable()) == LE_NOT_PERMITTED, "Disable in wrong state");
LE_TEST_OK((le_gnss_SetConstellation(LE_GNSS_CONSTELLATION_GPS)) == LE_NOT_PERMITTED,
"Set constellation in wrong state");
"Get constellation in wrong state");
 
// Test le_gnss_StartMode() in ACTIVE state
LE_TEST_OK((le_gnss_StartMode(LE_GNSS_HOT_START)) == LE_DUPLICATE,
"Hot start in active state");
LE_TEST_OK((le_gnss_StartMode(LE_GNSS_WARM_START)) == LE_DUPLICATE,
"Warm start in active state");
LE_TEST_OK((le_gnss_StartMode(LE_GNSS_COLD_START)) == LE_DUPLICATE,
"Cold start in active state");
LE_TEST_OK((le_gnss_StartMode(LE_GNSS_FACTORY_START)) == LE_DUPLICATE,
"Factory start in active state");
 
LE_TEST_BEGIN_SKIP(!LINUX_OS, 2);
"Get acquisition rate in wrong state");
result = le_gnss_SetAcquisitionRate(acqRate);
LE_TEST_OK((result == LE_NOT_PERMITTED) || (result == LE_OUT_OF_RANGE),
"Set acquisition rate in wrong state");
 
"Set NMEA sentences in wrong state");
"Get NMEA sentences in wrong state");
 
// test le_gnss_Get/SetMinElevation when le_gnss_ENABLE ON and le_gnss_Start ON
LE_TEST_BEGIN_SKIP(!LINUX_OS, 4);
minElevation = LE_GNSS_MIN_ELEVATION_MAX_DEGREE;
LE_TEST_OK((le_gnss_SetMinElevation(minElevation)) == LE_OK, "Set minimum elevation");
LE_TEST_OK((le_gnss_GetMinElevation(&minElevation)) == LE_OK, "Get minimum elevation");
LE_TEST_INFO("GNSS min elevation obtained: %d",minElevation);
LE_TEST_OK(minElevation == LE_GNSS_MIN_ELEVATION_MAX_DEGREE,
"Confirm min elevation is set to %d", 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;
"Set invalid min elevation");
 
// Stop GNSS device (READY state)
LE_TEST_OK((le_gnss_Stop()) == LE_OK, "Stop GNSS");
LE_TEST_OK((le_gnss_GetState()) == LE_GNSS_STATE_READY, "Confirm GNSS is ready");
LE_TEST_OK((le_gnss_Enable()) == LE_DUPLICATE, "Duplicate GNSS enable");
LE_TEST_OK((le_gnss_Disable()) == LE_OK, "Disable GNSS");
LE_TEST_OK((le_gnss_GetState()) == LE_GNSS_STATE_DISABLED, "Confirm GNSS is disabled");
LE_TEST_OK((le_gnss_Enable()) == LE_OK, "Enable GNSS");
LE_TEST_OK((le_gnss_GetState()) == LE_GNSS_STATE_READY, "Confirm GNSS is ready");
LE_TEST_OK((le_gnss_SetConstellation(LE_GNSS_CONSTELLATION_GPS)) == LE_OK,
"Set GPS constellation");
LE_TEST_OK((le_gnss_GetConstellation(&constellationMask)) == LE_OK, "Get constellation");
LE_TEST_OK(constellationMask == LE_GNSS_CONSTELLATION_GPS,
"Confirm constellation is set to GPS");
LE_TEST_OK((le_gnss_Stop()) == LE_DUPLICATE, "Duplicate GNSS stop");
 
LE_TEST_BEGIN_SKIP(!LINUX_OS, 2);
LE_TEST_OK((le_gnss_GetAcquisitionRate(&acqRate)) == LE_OK, "Get acquisition rate");
LE_TEST_OK((le_gnss_SetAcquisitionRate(acqRate)) == LE_OK, "Set acquisition rate");
 
LE_TEST_OK((le_gnss_GetNmeaSentences(&nmeaMask)) == LE_OK, "Get NMEA sentences");
LE_TEST_OK((le_gnss_SetNmeaSentences(nmeaMask)) == LE_OK, "Set NMEA sentences");
 
// test le_gnss_ConvertDataCoordinate error cases
LE_TEST_BEGIN_SKIP(!LINUX_OS, 5);
LE_TEST_OK(LE_FAULT == (le_gnss_ConvertDataCoordinateSystem(LE_GNSS_COORDINATE_SYSTEM_WGS84,
LE_GNSS_COORDINATE_SYSTEM_PZ90,
LE_GNSS_POS_LATITUDE,
altitudeOnWgs84,
NULL)),
"ConvertDataCoordinateSystem error test: NULL pointer");
LE_GNSS_COORDINATE_SYSTEM_MAX,
LE_GNSS_COORDINATE_SYSTEM_PZ90,
LE_GNSS_POS_LATITUDE,
altitudeOnWgs84,
&altitudeOnPZ90)),
"ConvertDataCoordinateSystem error test: invalid source coordinate");
LE_GNSS_COORDINATE_SYSTEM_PZ90,
LE_GNSS_COORDINATE_SYSTEM_PZ90,
LE_GNSS_POS_LATITUDE,
altitudeOnWgs84,
&altitudeOnPZ90)),
"ConvertDataCoordinateSystem error test: wrong source coordinate");
LE_GNSS_COORDINATE_SYSTEM_WGS84,
LE_GNSS_COORDINATE_SYSTEM_PZ90,
LE_GNSS_POS_MAX,
altitudeOnWgs84,
&altitudeOnPZ90)),
"ConvertDataCoordinateSystem error test: invalid data type");
LE_TEST_OK(LE_FAULT == (le_gnss_ConvertDataCoordinateSystem(LE_GNSS_COORDINATE_SYSTEM_PZ90,
LE_GNSS_COORDINATE_SYSTEM_WGS84,
LE_GNSS_POS_ALTITUDE,
altitudeOnWgs84,
&altitudeOnPZ90)),
"ConvertDataCoordinateSystem error test: mismatched coordinates");
}