Sample code for Radio Access Technology

//--------------------------------------------------------------------------------------------------
/**
* Test: Radio Access Technology.
*
*/
//--------------------------------------------------------------------------------------------------
static void Testle_mrc_GetRat
(
void
)
{
 
LE_ASSERT(res == LE_OK);
 
 
LE_INFO("le_mrc_GetRadioAccessTechInUse return rat 0x%02X",rat);
}
//--------------------------------------------------------------------------------------------------
/**
* Display bitmask RAT
*/
//--------------------------------------------------------------------------------------------------
static void PrintRat
(
)
{
if(LE_MRC_BITMASK_RAT_ALL != bitMask)
{
LE_INFO("Rat preferences %02X=> CDMA.%c GSM.%c LTE.%c UMTS.%c TD-SCDMA.%c", bitMask,
((bitMask & LE_MRC_BITMASK_RAT_CDMA) ? 'Y' : 'N'),
((bitMask & LE_MRC_BITMASK_RAT_GSM) ? 'Y' : 'N'),
((bitMask & LE_MRC_BITMASK_RAT_LTE) ? 'Y' : 'N'),
((bitMask & LE_MRC_BITMASK_RAT_UMTS) ? 'Y' : 'N'),
((bitMask & LE_MRC_BITMASK_RAT_TDSCDMA) ? 'Y' : 'N'));
}
else
{
LE_INFO("Rat preferences => LE_MRC_BITMASK_RAT_ALL");
}
}
 
//--------------------------------------------------------------------------------------------------
/**
* Thread for Rat Preferences test
*/
//--------------------------------------------------------------------------------------------------
static void* MyRatPreferencesThread
(
void* contextPtr ///< Context
)
{
 
RatChangeHdlrRef = le_mrc_AddRatChangeHandler(TestRatHandler, NULL);
LE_ASSERT(RatChangeHdlrRef);
 
return NULL;
}
 
//--------------------------------------------------------------------------------------------------
/**
* Test: rat preferences mode. Module must supported GSM and LTEs
*
* le_mrc_GetRatPreferences() API test
* le_mrc_SetRatPreferences() API test
*/
//--------------------------------------------------------------------------------------------------
static void Testle_mrc_RatPreferences
(
void
)
{
le_mrc_RatBitMask_t bitMask = 0;
le_mrc_RatBitMask_t bitMaskOrigin = 0;
bool lteSupported = false;
time.sec = 30;
time.usec = 0;
 
// Create a semaphore for asynchronous RAT change indication
ThreadSemaphore = le_sem_Create("HandlerRatChange", 0);
// Start a thread to receive RAT change indication.
RegistrationThreadRef = le_thread_Create("MyRatPreferencesThread",
MyRatPreferencesThread,
NULL);
le_thread_Start(RegistrationThreadRef);
 
// Backup current rat preference.
PrintRat(bitMaskOrigin);
 
// If current RAT in use is not LTE, then set RAT to LTE
// and test if RAT change indication is received.
LE_ASSERT(res == LE_OK);
 
if (rat != LE_MRC_RAT_LTE)
{
LE_INFO("Set RAT from %s to %s", RatTypeName[rat], RatTypeName[LE_MRC_RAT_LTE]);
res = le_mrc_SetRatPreferences(LE_MRC_BITMASK_RAT_LTE);
LE_ASSERT((LE_OK == res) || (LE_UNSUPPORTED == res));
 
if (LE_OK == res)
{
//LTE supported, waiting for RAT change indication
lteSupported = true;
res = le_sem_WaitWithTimeOut(ThreadSemaphore, time);
LE_ASSERT(res == LE_OK);
PrintRat(bitMask);
 
if ((LE_MRC_BITMASK_RAT_LTE != bitMask))
{
if ((LE_MRC_BITMASK_RAT_LTE | LE_MRC_BITMASK_RAT_GSM) == bitMask)
{
LE_WARN("LTE only not supported");
}
}
 
LE_ASSERT(bitMask & LE_MRC_BITMASK_RAT_LTE);
}
}
else
{
lteSupported = true;
}
 
// If current RAT in use is not GSM, then set RAT to GSM
// and test if RAT change indication is received.
LE_ASSERT(res == LE_OK);
 
if (rat != LE_MRC_RAT_GSM)
{
LE_INFO("Set RAT from %s to %s", RatTypeName[rat], RatTypeName[LE_MRC_RAT_GSM]);
LE_ASSERT_OK(le_mrc_SetRatPreferences(LE_MRC_BITMASK_RAT_GSM));
 
//GSM supported, waiting for RAT change indication
res = le_sem_WaitWithTimeOut(ThreadSemaphore, time);
LE_ASSERT(res == LE_OK);
 
PrintRat(bitMask);
 
LE_ASSERT(LE_MRC_BITMASK_RAT_GSM == bitMask);
}
 
// If current RAT in use is not UMTS, then set RAT to UMTS
// and test if RAT change indication is received.
LE_ASSERT(res == LE_OK);
 
if (rat != LE_MRC_RAT_UMTS)
{
LE_INFO("Set RAT from %s to %s", RatTypeName[rat], RatTypeName[LE_MRC_RAT_UMTS]);
//GSM and UMTS supported, waiting for RAT change indication
res = le_sem_WaitWithTimeOut(ThreadSemaphore, time);
// RAT change indication not received
LE_ASSERT(res == LE_OK);
 
PrintRat(bitMask);
 
}
 
 
if (lteSupported)
{
LE_INFO("Set RAT to AUTO mode");
// (AUTO) supported, waiting for RAT change indication if needed.
res = le_sem_WaitWithTimeOut(ThreadSemaphore, time);
if (LE_TIMEOUT == res)
{
LE_WARN("RAT change indication not received, (RAT change may noy occur)");
}
PrintRat(bitMask);
 
}
 
LE_ASSERT(res == LE_OK);
 
if ((bitMaskOrigin & LE_MRC_BITMASK_RAT_CDMA) && (rat != LE_MRC_RAT_CDMA))
{
LE_INFO("Set RAT to CDMA");
 
res = le_mrc_SetRatPreferences(LE_MRC_BITMASK_RAT_CDMA);
LE_ASSERT((LE_OK == res) || (LE_UNSUPPORTED == res));
 
if (LE_OK == res)
{
//CDMA supported, waiting for RAT change indication
res = le_sem_WaitWithTimeOut(ThreadSemaphore, time);
LE_ASSERT(res == LE_OK);
PrintRat(bitMask);
 
LE_ASSERT(LE_MRC_BITMASK_RAT_CDMA == bitMask);
}
else
{
LE_WARN("CDMA is not supported");
}
}
 
// If current RAT in use is not TDSCDMA, then set RAT to TDSCDMA
// and test if RAT change indication is received.
LE_ASSERT(res == LE_OK);
 
if ((bitMaskOrigin & LE_MRC_BITMASK_RAT_TDSCDMA) && (rat != LE_MRC_RAT_TDSCDMA))
{
LE_INFO("Set RAT to TD-SCDMA");
 
res = le_mrc_SetRatPreferences(LE_MRC_BITMASK_RAT_TDSCDMA);
LE_ASSERT((LE_OK == res) || (LE_UNSUPPORTED == res));
 
if (LE_OK == res)
{
// CDMA supported, waiting for RAT change indication
res = le_sem_WaitWithTimeOut(ThreadSemaphore, time);
LE_ASSERT(res == LE_OK);
PrintRat(bitMask);
 
LE_ASSERT(LE_MRC_BITMASK_RAT_CDMA == bitMask);
}
else
{
LE_INFO("TD-SCDMA is not supported");
}
}
 
// If current RAT in use is not UMTS, then set RAT to UMTS
// and test if RAT change indication is received.
LE_ASSERT(res == LE_OK);
 
if (rat != LE_MRC_RAT_UMTS)
{
LE_INFO("Set RAT from %s to %s", RatTypeName[rat], RatTypeName[LE_MRC_RAT_UMTS]);
//UMTS supported, waiting for RAT change indication
res = le_sem_WaitWithTimeOut(ThreadSemaphore, time);
LE_ASSERT(res == LE_OK);
PrintRat(bitMask);
 
}
 
//restore RAT
PrintRat(bitMask);
 
le_thread_Cancel(RegistrationThreadRef);
le_mrc_RemoveRatChangeHandler(RatChangeHdlrRef);
le_sem_Delete(ThreadSemaphore);
}