static int mqttClient_processUnSubAck(mqttClient_t* clientData) { int32_t rc = LE_OK; uint16_t packetId; LE_DEBUG("---> UNSUBACK"); LE_ASSERT(clientData); rc = le_timer_Stop(clientData->session.cmdTimer); if (rc) { LE_ERROR("le_timer_Stop() failed(%d)", rc); goto cleanup; } rc = MQTTDeserialize_unsuback(&packetId, clientData->session.rx.buf, sizeof(clientData->session.rx.buf)); if (rc != 1) { LE_ERROR("MQTTDeserialize_unsuback() failed"); rc = LE_BAD_PARAMETER; goto cleanup; } else if (clientData->session.nextPacketId != packetId) { LE_ERROR("invalid packet ID(%u != %u)", clientData->session.nextPacketId, packetId); rc = LE_BAD_PARAMETER; goto cleanup; } cleanup: return rc; }
static void mqttClient_connExpiryHndlr(le_timer_Ref_t timer) { mqttClient_t* clientData = le_timer_GetContextPtr(timer); int32_t rc = LE_OK; LE_ASSERT(clientData); rc = mqttClient_close(clientData); if (rc) { LE_ERROR("mqttClient_close() failed(%d)", rc); goto cleanup; } LE_DEBUG("<--- reconnect"); rc = mqttClient_connect(clientData); if (rc) { LE_ERROR("mqttClient_connect() failed(%d)", rc); goto cleanup; } cleanup: return; }
static void mqttClient_pingExpiryHndlr(le_timer_Ref_t timer) { mqttClient_t* clientData = le_timer_GetContextPtr(timer); int32_t rc = LE_OK; LE_ASSERT(clientData); int len = MQTTSerialize_pingreq(clientData->session.tx.buf, sizeof(clientData->session.tx.buf)); if (len < 0) { LE_ERROR("MQTTSerialize_pingreq() failed(%d)", len); goto cleanup; } LE_DEBUG("<--- PING"); rc = mqttClient_write(clientData, len); if (rc) { LE_ERROR("mqttClient_write() failed(%d)", rc); goto cleanup; } cleanup: return; }
//-------------------------------------------------------------------------------------------------- static void Testle_Temp_RemoveHandlers ( void ) { int i; // Remove handlers: add le_temp_RemoveThresholdEventHandler to the eventLoop of tasks for (i=0; i<NB_CLIENT; i++) { le_event_QueueFunctionToThread( AppCtx[i].appThreadRef, RemoveHandler, &AppCtx[i], NULL ); } // Wait for the tasks SynchTest(); // trigger an event report ExpectedStatus = 0; pa_tempSimu_TriggerEventReport(ExpectedStatus); // Wait for the semaphore timeout to check that handlers are not called LE_ASSERT( le_sem_WaitWithTimeOut(ThreadSemaphore, TimeToWait) == LE_TIMEOUT ); }
static int mqttClient_close(mqttClient_t* clientData) { int rc = LE_OK; LE_ASSERT(clientData); if (clientData->session.sock != MQTT_CLIENT_INVALID_SOCKET) { le_fdMonitor_Delete(clientData->session.sockFdMonitor); rc = close(clientData->session.sock); if (rc == -1) { LE_ERROR("close() failed(%d)", errno); rc = LE_FAULT; goto cleanup; } clientData->session.sock = MQTT_CLIENT_INVALID_SOCKET; } else { LE_WARN("socket already closed"); } cleanup: return rc; }
//-------------------------------------------------------------------------------------------------- void ni_Release ( ni_IteratorRef_t iteratorRef ///< [IN] Free the resources used by this iterator. ) //-------------------------------------------------------------------------------------------------- { LE_ASSERT(iteratorRef != NULL); // Make sure that the transaction timer isn't still running. if (iteratorRef->timerRef != NULL) { if (le_timer_GetExpiryCount(iteratorRef->timerRef) == 0) { le_timer_Stop(iteratorRef->timerRef); } le_timer_Delete(iteratorRef->timerRef); iteratorRef->timerRef = NULL; } // Release the rest of the iterator's resources. LE_DEBUG("Releasing iterator, <%p> with a lifetime of %d seconds.", iteratorRef, (uint32_t)(le_clk_GetRelativeTime().sec - iteratorRef->creationTime.sec)); ni_Close(iteratorRef); tdb_UnregisterIterator(iteratorRef->treeRef, iteratorRef); le_pathIter_Delete(iteratorRef->pathIterRef); tdb_ReleaseTree(iteratorRef->treeRef); le_mem_Release(iteratorRef); }
//-------------------------------------------------------------------------------------------------- le_result_t ni_GoToParent ( ni_IteratorRef_t iteratorRef ///< [IN] The iterator object to access. ) //-------------------------------------------------------------------------------------------------- { // Update our path. if (le_pathIter_Append(iteratorRef->pathIterRef, "..") == LE_UNDERFLOW) { // Looks like there are no more parents in the chain. return LE_NOT_FOUND; } // Now, if we have a current node, just get it's parent node. Otherwise make an attempt to see // if the requested parent node exists. if (iteratorRef->currentNodeRef != NULL) { iteratorRef->currentNodeRef = tdb_GetNodeParent(iteratorRef->currentNodeRef); LE_ASSERT(iteratorRef->currentNodeRef != NULL); } else { // Make an attempt to get the new current node. iteratorRef->currentNodeRef = ni_GetNode(iteratorRef, ""); } return LE_OK; }
//-------------------------------------------------------------------------------------------------- le_cfg_IteratorRef_t ni_CreateRef ( ni_IteratorRef_t iteratorRef ///< [IN] The iterator to generate a reference for. ) //-------------------------------------------------------------------------------------------------- { LE_ASSERT(iteratorRef != NULL); LE_ASSERT(iteratorRef->reference == NULL); iteratorRef->reference = le_ref_CreateRef(IteratorRefMap, iteratorRef); LE_DEBUG("Created a new reference <%p> for iterator <%p>.", iteratorRef->reference, iteratorRef); return iteratorRef->reference; }
//-------------------------------------------------------------------------------------------------- static void OnTransactionTimeout ( le_timer_Ref_t timerRef ///< The timer that expired. ) //-------------------------------------------------------------------------------------------------- { // Extract the iterator reference out of the timer object. Then perform a sanity check to make // sure everything is going to plan. ni_IteratorRef_t iteratorRef = (ni_IteratorRef_t)le_timer_GetContextPtr(timerRef); LE_ASSERT(iteratorRef->timerRef == timerRef); // For clearer message reporting, figure out if this is a read or write transaction. char* iterTypePtr = "Read"; if (ni_IsWriteable(iteratorRef)) { iterTypePtr = "Write"; } if (iteratorRef->isTerminated) { LE_DEBUG("Previously terminated iterator, <%p> timed out.", iteratorRef); return; } // Report the failure in the log, and close the client session. Once the session is closed all // of that user's resources within the configTree will be naturally cleaned up. LE_EMERG("%s transaction <%p> timer expired, for user %s, <%d>.", iterTypePtr, iteratorRef->reference, tu_GetUserName(iteratorRef->userRef), tu_GetUserId(iteratorRef->userRef)); tu_TerminateConfigClient(iteratorRef->sessionRef, "Transaction timeout."); }
//-------------------------------------------------------------------------------------------------- static void ResetClientWatchdog ( int32_t timeout ///< [IN] The timeout to reset the watchdog timer to (in milliseconds). ) { le_clk_Time_t timeoutValue; WatchdogObj_t* watchDogPtr = GetClientWatchdogPtr(); if (watchDogPtr != NULL) { le_timer_Stop(watchDogPtr->timer); if (timeout == TIMEOUT_KICK) { timeoutValue = watchDogPtr->kickTimeoutInterval; } else { timeoutValue = MakeTimerInterval(timeout); } if (timeout != LE_WDOG_TIMEOUT_NEVER) { // timer should be stopped here so this should never fail // testing LE_ASSERT(LE_OK == le_timer_SetInterval(watchDogPtr->timer, timeoutValue)); le_timer_Start(watchDogPtr->timer); } else { LE_DEBUG("Timeout set to NEVER!"); } } }
//-------------------------------------------------------------------------------------------------- le_result_t le_utf8_Append ( char* destStr, ///< [IN] The destination string. const char* srcStr, ///< [IN] The UTF-8 source string. const size_t destSize, ///< [IN] Size of the destination buffer in bytes. size_t* destStrLenPtr ///< [OUT] The number of bytes in the resultant destination string (not /// including the NULL-terminator). This parameter can be set to /// NULL if the destination string size is not needed. ) { // Check parameters. LE_ASSERT( (destStr != NULL) && (srcStr != NULL) && (destSize > 0) ); size_t destStrSize = strlen(destStr); le_result_t result = le_utf8_Copy(&(destStr[destStrSize]), srcStr, destSize - destStrSize, destStrLenPtr); if (destStrLenPtr) { *destStrLenPtr += destStrSize; } return result; }
//-------------------------------------------------------------------------------------------------- le_avdata_AssetInstanceRef_t le_avdata_Create ( const char* assetName ///< [IN] ) { // Get the client's credentials. pid_t pid; uid_t uid; if (le_msg_GetClientUserCreds(le_avdata_GetClientSessionRef(), &uid, &pid) != LE_OK) { LE_KILL_CLIENT("Could not get credentials for the client."); return NULL; } // Look up the process's application name. char appName[LE_LIMIT_APP_NAME_LEN+1]; le_result_t result = le_appInfo_GetName(pid, appName, sizeof(appName)); LE_FATAL_IF(result == LE_OVERFLOW, "Buffer too small to contain the application name."); // TODO: Should this be LE_KILL_CLIENT instead? LE_FATAL_IF(result != LE_OK, "Could not get app name"); // Create an instance of the asset assetData_InstanceDataRef_t instRef; int instanceId; LE_ASSERT( assetData_CreateInstanceByName(appName, assetName, -1, &instRef) == LE_OK ); LE_ASSERT( instRef != NULL ); LE_ASSERT( assetData_GetInstanceId(instRef, &instanceId) == LE_OK ); LE_PRINT_VALUE("%i", instanceId); // Return a safe reference for the instance InstanceRefData_t* instRefDataPtr = le_mem_ForceAlloc(InstanceRefDataPoolRef); instRefDataPtr->clientSessionRef = le_avdata_GetClientSessionRef(); instRefDataPtr->instRef = instRef; instRef = le_ref_CreateRef(InstanceRefMap, instRefDataPtr); return instRef; }
//-------------------------------------------------------------------------------------------------- static void AddWatchdog ( WatchdogObj_t* newDogPtr ///< A pointer to the watchdog that is to be added to our container ) { // The procId is the unique identifier for this watchdog. There shouldn't already be one. LE_ASSERT(NULL == le_hashmap_Put(WatchdogRefsContainer, &(newDogPtr->procId), newDogPtr)); }
//-------------------------------------------------------------------------------------------------- void TestSim_Stk ( void ) { // Stk handler semaphore StkHandlerSem = (le_sem_Ref_t) le_sem_Create("StkHandlerSem",1); // each thread subscribes to state handler using le_sim_AddSimToolkitEventHandler // This API has to be called by threads int i=0; for (; i<NB_CLIENT; i++) { le_event_QueueFunctionToThread( AppCtx[i].appThreadRef, AddStkHandler, &AppCtx[i], NULL ); } // Wait for the tasks SynchTest(); StkEvent = LE_SIM_REFRESH; // Invoke Stk event pa_simSimu_ReportStkEvent(StkEvent); // Wait for the call of the handlers SynchTest(); // Check the result for (i=0; i<NB_CLIENT; i++) { LE_ASSERT(AppCtx[i].stkEvent == StkEvent); AppCtx[i].stkEvent = 0; } // Test le_sim_AcceptSimToolkitCommand and le_sim_RejectSimToolkitCommand pa_simSimu_SetExpectedStkConfirmationCommand(true); LE_ASSERT( le_sim_AcceptSimToolkitCommand(CurrentSimId) == LE_OK ); pa_simSimu_SetExpectedStkConfirmationCommand(false); LE_ASSERT( le_sim_RejectSimToolkitCommand(CurrentSimId) == LE_OK ); // Check that all handlers have been called as expected LE_ASSERT( le_sem_GetValue(ThreadSemaphore) == 0 ); }
//-------------------------------------------------------------------------------------------------- le_result_t pa_audio_GetGain ( pa_audio_If_t interface, ///< [IN] audio interface uint32_t *gainPtr ///< [OUT] gain value [0..100] (0 means 'muted', 100 is the /// maximum gain value) ) { LE_ASSERT(gainPtr); LE_DEBUG("Get gain for [%d]",interface); switch (interface) { case PA_AUDIO_IF_CODEC_MIC: { unsigned value; GetMixerParameter("ADC1 Volume",&value); if (value == 3) { *gainPtr = 100; } else if (value == 2) { *gainPtr = 66; } else if (value == 1) { *gainPtr = 33; } else { *gainPtr = 0; } return LE_OK; } case PA_AUDIO_IF_CODEC_SPEAKER: { unsigned value; GetMixerParameter("RX1 Digital Volume",&value); *gainPtr = (100*value)/124; return LE_OK; } case PA_AUDIO_IF_DSP_FRONTEND_USB_RX: case PA_AUDIO_IF_DSP_FRONTEND_USB_TX: case PA_AUDIO_IF_DSP_BACKEND_MODEM_VOICE_RX: case PA_AUDIO_IF_DSP_BACKEND_MODEM_VOICE_TX: case PA_AUDIO_IF_DSP_FRONTEND_PCM_RX: case PA_AUDIO_IF_DSP_FRONTEND_PCM_TX: case PA_AUDIO_IF_FILE_PLAYING: case PA_AUDIO_IF_DSP_FRONTEND_I2S_RX: case PA_AUDIO_IF_DSP_FRONTEND_I2S_TX: case PA_AUDIO_IF_END: { break; } } LE_ERROR("This interface (%d) is not supported",interface); return LE_FAULT; }
//-------------------------------------------------------------------------------------------------- static void DisconnectedProfile ( le_mdc_ProfileRef_t profileRef ) { char ipAddrStr[IP_STR_SIZE]; char dns1AddrStr[IP_STR_SIZE]; char dns2AddrStr[IP_STR_SIZE]; char gatewayAddrStr[IP_STR_SIZE]; char interfaceName[10]; /* Expected value: LE_FAULT as the frofile is supposed to be disconnected */ LE_ASSERT(le_mdc_GetInterfaceName(profileRef, interfaceName, sizeof(interfaceName)) == LE_FAULT); LE_ASSERT(le_mdc_GetIPv4Address(profileRef, ipAddrStr, IP_STR_SIZE) == LE_FAULT); LE_ASSERT(le_mdc_GetIPv6Address(profileRef, ipAddrStr, IP_STR_SIZE) == LE_FAULT); LE_ASSERT(le_mdc_GetIPv4DNSAddresses( profileRef, dns1AddrStr, IP_STR_SIZE, dns2AddrStr, IP_STR_SIZE) == LE_FAULT); LE_ASSERT(le_mdc_GetIPv6DNSAddresses( profileRef, dns1AddrStr, IP_STR_SIZE, dns2AddrStr, IP_STR_SIZE) == LE_OVERFLOW); LE_ASSERT(le_mdc_GetIPv4GatewayAddress( profileRef, gatewayAddrStr, IP_STR_SIZE ) == LE_FAULT); LE_ASSERT(le_mdc_GetIPv6GatewayAddress( profileRef, gatewayAddrStr, IP_STR_SIZE ) == LE_FAULT); }
//-------------------------------------------------------------------------------------------------- void TestMdc_Stat ( void ) { pa_mdc_PktStatistics_t dataStatistics; dataStatistics.transmittedBytesCount = 123456789; dataStatistics.receivedBytesCount = 369258147; /* Set the statistics value to the pa */ pa_mdcSimu_SetDataFlowStatistics(&dataStatistics); uint64_t rxBytes; uint64_t txBytes; /* Get the statistics and check the values */ le_result_t res = le_mdc_GetBytesCounters(&rxBytes, &txBytes); LE_ASSERT(res == LE_OK); LE_ASSERT(rxBytes == dataStatistics.receivedBytesCount); LE_ASSERT(txBytes == dataStatistics.transmittedBytesCount); /* Reset counter, check again statistics (0 values expected) */ res = le_mdc_ResetBytesCounter(); LE_ASSERT(res == LE_OK); res = le_mdc_GetBytesCounters(&rxBytes, &txBytes); LE_ASSERT(res == LE_OK); LE_ASSERT(rxBytes == 0); LE_ASSERT(txBytes == 0); }
static int mangoh_bridge_air_vantage_sessionStart(void* param, const unsigned char* data, uint32_t size) { mangoh_bridge_air_vantage_t* airVantage = (mangoh_bridge_air_vantage_t*)param; int32_t res = LE_OK; LE_ASSERT(airVantage); LE_ASSERT(data); LE_DEBUG("---> SESSION START"); uint8_t* ptr = (uint8_t*)data; uint8_t pushAv = *ptr; ptr += sizeof(pushAv); LE_DEBUG("AV push(%u)", pushAv); uint8_t storage = *ptr; ptr += sizeof(storage); LE_DEBUG("storage(%u)", storage); uint8_t len = 0; memcpy(&len, ptr, sizeof(len)); LE_DEBUG("len(%u)", len); ptr += sizeof(len); char url[MANGOH_BRIDGE_AIR_VANTAGE_VALUE_MAX_LEN] = {0}; memcpy(url, ptr, len); LE_DEBUG("url('%s')", url); ptr += len; char pw[MANGOH_BRIDGE_AIR_VANTAGE_VALUE_MAX_LEN] = {0}; memcpy(pw, ptr, size - len - sizeof(len) - sizeof(pushAv) - sizeof(storage)); LE_DEBUG("pw('%s')", pw); dataRouter_SessionStart(url, pw, pushAv, storage); res = mangoh_bridge_sendResult(airVantage->bridge, 0); if (res != LE_OK) { LE_ERROR("ERROR mangoh_bridge_sendResult() failed(%d)", res); goto cleanup; } cleanup: return res; }
//-------------------------------------------------------------------------------------------------- static void Testle_temp_RadioThresholdEventSetting ( ) { int32_t warningTemperature = 0; int32_t criticalTemperature = 0; int32_t temperature = 0; le_result_t res = LE_FAULT; TimeCounter = 0; PoolTemp = 1; LE_INFO("Set PoolTemp %d", PoolTemp); le_thread_Ref_t thread = le_thread_Create("tempTest",DisplayTempThread,NULL); le_thread_Start(thread); LE_INFO("!!!!!!! YOU HAVE %d SECOND TO SET THE MODULE AT" " THE TEMP REFERENCE !!!!!!!", WAIT_TIME); TimeCounter = 0; PoolTemp = 2; LE_INFO("Set PoolTemp %d", PoolTemp); sleep(WAIT_TIME); // Get current PA Tempeartaure res = le_temp_GetRadioTemperature(&temperature); LE_ASSERT(res == LE_OK); LE_INFO("le_temp_GetRadioTemperature return %d degree Celcus", temperature); // Set Warning threshold Tempeartaure warningTemperature = temperature + 10; criticalTemperature = temperature + 20; LE_INFO("temperature threshold are set tole_temp_SetThreshold(%d, %d) in degree Celcus", warningTemperature, criticalTemperature); res = le_temp_SetRadioThresholds(warningTemperature, criticalTemperature); LE_ASSERT(res == LE_OK); PoolTemp = 0; LE_INFO("Set PoolTemp %d", PoolTemp); LE_INFO("!!!!!!! YOU MUST REBOOT THE MODULE !!!!!!!"); sleep(2); }
//-------------------------------------------------------------------------------------------------- static void SynchTest( void ) { int i=0; for (;i<NB_CLIENT;i++) { LE_ASSERT(le_sem_WaitWithTimeOut(ThreadSemaphore, TimeToWait) == LE_OK); } }
//-------------------------------------------------------------------------------------------------- tdb_TreeRef_t ni_GetTree ( ni_ConstIteratorRef_t iteratorRef ///< The iterator object to read. ) //-------------------------------------------------------------------------------------------------- { LE_ASSERT(iteratorRef != NULL); return iteratorRef->treeRef; }
//-------------------------------------------------------------------------------------------------- tu_UserRef_t ni_GetUser ( ni_ConstIteratorRef_t iteratorRef ///< The iterator object to read. ) //-------------------------------------------------------------------------------------------------- { LE_ASSERT(iteratorRef != NULL); return iteratorRef->userRef; }
//-------------------------------------------------------------------------------------------------- le_msg_SessionRef_t ni_GetSession ( ni_ConstIteratorRef_t iteratorRef ///< The iterator object to read. ) //-------------------------------------------------------------------------------------------------- { LE_ASSERT(iteratorRef != NULL); return iteratorRef->sessionRef; }
//-------------------------------------------------------------------------------------------------- bool ni_IsWriteable ( ni_ConstIteratorRef_t iteratorRef ///< Does this iterator represent a write transaction? ) //-------------------------------------------------------------------------------------------------- { LE_ASSERT(iteratorRef != NULL); return iteratorRef->type == NI_WRITE; }
//-------------------------------------------------------------------------------------------------- bool ni_IsClosed ( ni_ConstIteratorRef_t iteratorRef ///< The iterator object to check. ) //-------------------------------------------------------------------------------------------------- { LE_ASSERT(iteratorRef != NULL); return iteratorRef->isClosed; }
//-------------------------------------------------------------------------------------------------- static void StartBridge ( void *param1Ptr, void *param2Ptr ) { // dup stdout FdAtClient = dup(2); le_atServer_BridgeRef_t bridgeRef = le_atServer_OpenBridge(FdAtClient); LE_ASSERT(bridgeRef != NULL); *(le_atServer_BridgeRef_t*) param1Ptr = bridgeRef; le_atServer_DeviceRef_t devRef = param2Ptr; LE_ASSERT_OK(le_atServer_AddDeviceToBridge(devRef, bridgeRef)); LE_ASSERT(le_atServer_AddDeviceToBridge(devRef, bridgeRef) == LE_BUSY); le_sem_Post(BridgeSemaphore); }
static void IdDestructor(void* objPtr) { NumRelease++; ReleaseId = ((idObj_t*)objPtr)->id; // Test for deadlock on Memory Pool's internal mutex. // Also test that the ID Pool (from which this object was allocated) can be found. LE_ASSERT(le_mem_FindPool("ID Pool") != NULL); }
//-------------------------------------------------------------------------------------------------- le_result_t pa_audio_ResetDspAudioPath ( le_audio_Stream_t* inputStreamPtr, ///< [IN] input audio stream le_audio_Stream_t* outputStreamPtr ///< [IN] output audio stream ) { le_audio_If_t inputInterface = inputStreamPtr->audioInterface; le_audio_If_t outputInterface = outputStreamPtr->audioInterface; LE_ASSERT( IS_INPUT_STREAM(inputInterface) == true ); LE_ASSERT( IS_OUTPUT_STREAM(outputInterface) == true ); BuildAudioPath[inputInterface][outputInterface] -= 1; LE_ASSERT( BuildAudioPath[inputInterface][outputInterface] >= 0 ); return LE_OK; }
//-------------------------------------------------------------------------------------------------- le_result_t pa_audio_StopDtmfDecoder ( le_audio_Stream_t* streamPtr ///< [IN] input audio stream ) { LE_ASSERT( streamPtr->audioInterface == LE_AUDIO_IF_DSP_BACKEND_MODEM_VOICE_RX ); return LE_OK; }
//-------------------------------------------------------------------------------------------------- static void HandlerFunc ( le_mdc_ProfileRef_t profileRef, le_mdc_ConState_t ConnectionStatus, void* contextPtr ) { ConnectionStateReceivedByHandler = ( ConnectionStatus == LE_MDC_CONNECTED ) ? true : false; ProfileRefReceivedByHandler = (le_mdc_ProfileRef_t) profileRef; if (ConnectionStatus == LE_MDC_DISCONNECTED) { LE_ASSERT( le_mdc_GetDisconnectionReason(profileRef) == LE_MDC_DISC_REGULAR_DEACTIVATION ); LE_ASSERT( le_mdc_GetPlatformSpecificDisconnectionCode(profileRef) == 2 ); } le_sem_Post(ThreadSemaphore); }