Sample code for Radio Access Technology
//--------------------------------------------------------------------------------------------------/*** Test: Radio Access Technology.**///--------------------------------------------------------------------------------------------------static void Testle_mrc_GetRat(void){le_result_t res;le_mrc_Rat_t rat;res = le_mrc_GetRadioAccessTechInUse(&rat);LE_INFO("le_mrc_GetRadioAccessTechInUse return rat 0x%02X",rat);}
//--------------------------------------------------------------------------------------------------/*** Display bitmask RAT*///--------------------------------------------------------------------------------------------------static void PrintRat(le_mrc_RatBitMask_t bitMask){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;le_result_t res;le_mrc_Rat_t rat;bool lteSupported = false;le_clk_Time_t time;time.sec = 30;time.usec = 0;// Create a semaphore for asynchronous RAT change indicationThreadSemaphore = 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.LE_ASSERT_OK(le_mrc_GetRatPreferences(&bitMaskOrigin));PrintRat(bitMaskOrigin);// If current RAT in use is not LTE, then set RAT to LTE// and test if RAT change indication is received.res = le_mrc_GetRadioAccessTechInUse(&rat);if (rat != LE_MRC_RAT_LTE){res = le_mrc_SetRatPreferences(LE_MRC_BITMASK_RAT_LTE);if (LE_OK == res){//LTE supported, waiting for RAT change indicationlteSupported = true;res = le_sem_WaitWithTimeOut(ThreadSemaphore, time);LE_ASSERT_OK(le_mrc_GetRatPreferences(&bitMask));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.res = le_mrc_GetRadioAccessTechInUse(&rat);if (rat != LE_MRC_RAT_GSM){LE_ASSERT_OK(le_mrc_SetRatPreferences(LE_MRC_BITMASK_RAT_GSM));//GSM supported, waiting for RAT change indicationres = le_sem_WaitWithTimeOut(ThreadSemaphore, time);LE_ASSERT_OK(le_mrc_GetRatPreferences(&bitMask));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.res = le_mrc_GetRadioAccessTechInUse(&rat);if (rat != LE_MRC_RAT_UMTS){LE_ASSERT_OK(le_mrc_SetRatPreferences(LE_MRC_BITMASK_RAT_UMTS));//GSM and UMTS supported, waiting for RAT change indicationres = le_sem_WaitWithTimeOut(ThreadSemaphore, time);// RAT change indication not receivedLE_ASSERT_OK(le_mrc_GetRatPreferences(&bitMask));PrintRat(bitMask);LE_ASSERT(LE_MRC_BITMASK_RAT_UMTS == bitMask);}if (lteSupported){LE_INFO("Set RAT to AUTO mode");LE_ASSERT_OK(le_mrc_SetRatPreferences(LE_MRC_BITMASK_RAT_ALL));// (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)");}LE_ASSERT_OK(le_mrc_GetRatPreferences(&bitMask));PrintRat(bitMask);}res = le_mrc_GetRadioAccessTechInUse(&rat);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);if (LE_OK == res){//CDMA supported, waiting for RAT change indicationres = le_sem_WaitWithTimeOut(ThreadSemaphore, time);LE_ASSERT_OK(le_mrc_GetRatPreferences(&bitMask));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.res = le_mrc_GetRadioAccessTechInUse(&rat);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);if (LE_OK == res){// CDMA supported, waiting for RAT change indicationres = le_sem_WaitWithTimeOut(ThreadSemaphore, time);LE_ASSERT_OK(le_mrc_GetRatPreferences(&bitMask));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.res = le_mrc_GetRadioAccessTechInUse(&rat);if (rat != LE_MRC_RAT_UMTS){LE_ASSERT_OK(le_mrc_SetRatPreferences(LE_MRC_BITMASK_RAT_UMTS));//UMTS supported, waiting for RAT change indicationres = le_sem_WaitWithTimeOut(ThreadSemaphore, time);LE_ASSERT_OK(le_mrc_GetRatPreferences(&bitMask));PrintRat(bitMask);LE_ASSERT(LE_MRC_BITMASK_RAT_UMTS == bitMask);}//restore RATLE_ASSERT_OK(le_mrc_SetRatPreferences(bitMaskOrigin));LE_ASSERT_OK(le_mrc_GetRatPreferences(&bitMask));PrintRat(bitMask);le_thread_Cancel(RegistrationThreadRef);le_mrc_RemoveRatChangeHandler(RatChangeHdlrRef);le_sem_Delete(ThreadSemaphore);}