Sample code for restart GNSS device and get TTFF

//--------------------------------------------------------------------------------------------------
/**
* Test: Restart to Cold start.
*
*/
//--------------------------------------------------------------------------------------------------
static void TestLeGnssRestart
(
void
)
{
uint32_t ttff = 0;
uint64_t epochTime;
le_gnss_SampleRef_t positionSampleRef;
 
LE_TEST_INFO("Start Test le_pos_RestartTest");
 
LE_TEST_ASSERT((le_gnss_Start()) == LE_OK, "Start GNSS");
 
/* Wait for a position fix */
LE_TEST_INFO("Wait 60 seconds for a 3D fix");
le_thread_Sleep(60);
// Get TTFF
result = le_gnss_GetTtff(&ttff);
LE_TEST_OK((result == LE_OK) || (result == LE_BUSY), "Get TTFF");
if(result == LE_OK)
{
LE_TEST_INFO("TTFF start = %d msec", ttff);
}
else
{
LE_TEST_INFO("TTFF start not available");
}
 
/* HOT Restart */
LE_TEST_INFO("Ask for a Hot restart in 3 seconds...");
le_thread_Sleep(3);
LE_TEST_OK(le_gnss_ForceHotRestart() == LE_OK, "Force hot restart");
// Wait for a 3D fix
LE_TEST_INFO("Wait 60 seconds for a 3D fix");
le_thread_Sleep(60);
// Get TTFF
result = le_gnss_GetTtff(&ttff);
LE_TEST_OK((result == LE_OK) || (result == LE_BUSY), "Get TTFF");
if(result == LE_OK)
{
LE_TEST_INFO("TTFF Hot restart = %d msec", ttff);
}
else
{
LE_TEST_INFO("TTFF Hot restart not available");
}
 
/* WARM Restart */
LE_TEST_INFO("Ask for a Warm restart in 3 seconds...");
le_thread_Sleep(3);
LE_TEST_OK(le_gnss_ForceWarmRestart() == LE_OK, "Force warm restart");
// Wait for a 3D fix
LE_TEST_INFO("Wait 60 seconds for a 3D fix");
le_thread_Sleep(60);
// Get TTFF
result = le_gnss_GetTtff(&ttff);
LE_TEST_OK((result == LE_OK) || (result == LE_BUSY), "Get TTFF");
if(result == LE_OK)
{
LE_TEST_INFO("TTFF Warm restart = %d msec", ttff);
}
else
{
LE_TEST_INFO("TTFF Warm restart not available");
}
 
/* COLD Restart */
LE_TEST_INFO("Ask for a Cold restart in 3 seconds...");
le_thread_Sleep(3);
LE_TEST_OK(le_gnss_ForceColdRestart() == LE_OK, "Force cold restart");
 
le_thread_Sleep(5);
// Get Epoch time : it should be 0 after a COLD restart
positionSampleRef = le_gnss_GetLastSampleRef();
LE_TEST_OK((LE_OUT_OF_RANGE == le_gnss_GetEpochTime(positionSampleRef, &epochTime)),
"Get epoch time after cold restart");
LE_TEST_OK(0 == epochTime, "Confirm epoch time is invalid");
 
// Wait for a 3D fix
LE_TEST_INFO("Wait 60 seconds for a 3D fix");
le_thread_Sleep(60);
// Get TTFF
result = le_gnss_GetTtff(&ttff);
LE_TEST_OK((result == LE_OK) || (result == LE_BUSY), "Get TTFF");
if(result == LE_OK)
{
LE_TEST_INFO("TTFF Cold restart = %d msec", ttff);
}
else
{
LE_TEST_INFO("TTFF Cold restart not available");
}
 
/* FACTORY Restart */
LE_TEST_INFO("Ask for a Factory restart in 3 seconds...");
le_thread_Sleep(3);
LE_TEST_OK(le_gnss_ForceFactoryRestart() == LE_OK, "Force factory restart");
// Get TTFF,position fix should be still in progress for the FACTORY start
result = le_gnss_GetTtff(&ttff);
LE_TEST_OK(result == LE_BUSY, "Get TTFF after factory restart");
LE_TEST_INFO("TTFF is checked as not available immediatly after a FACTORY start");
 
le_thread_Sleep(5);
// Get Epoch time : it should be 0 after a FACTORY restart
positionSampleRef = le_gnss_GetLastSampleRef();
LE_TEST_OK((LE_OUT_OF_RANGE == le_gnss_GetEpochTime(positionSampleRef, &epochTime)),
"Get epoch time after factory restart");
LE_TEST_OK(0 == epochTime, "Confirm epoch time is invalid");
 
// Wait for a 3D fix
LE_TEST_INFO("Wait 60 seconds for a 3D fix");
le_thread_Sleep(60);
// Get TTFF
result = le_gnss_GetTtff(&ttff);
LE_TEST_OK((result == LE_OK) || (result == LE_BUSY), "Get TTFF");
if(result == LE_OK)
{
LE_TEST_INFO("TTFF Factory restart = %d msec", ttff);
}
else
{
LE_TEST_INFO("TTFF Factory restart not available");
}
 
/* Stop GNSS engine*/
le_thread_Sleep(1);
LE_TEST_ASSERT((le_gnss_Stop()) == LE_OK, "Stop GNSS");
EpochTime=0;
TimeAccuracy=0;
}