in source/demo-tasks/ota_over_mqtt_demo.c [1033:1125]
static void prvOTADemoTask( void * pvParam )
{
( void ) pvParam;
/* FreeRTOS APIs return status. */
BaseType_t xResult = pdPASS;
/* OTA library return status. */
OtaErr_t otaRet = OtaErrNone;
/* OTA event message used for sending event to OTA Agent.*/
OtaEventMsg_t eventMsg = { 0 };
/* OTA interface context required for library interface functions.*/
OtaInterfaces_t otaInterfaces;
/* OTA library packet statistics per job.*/
OtaAgentStatistics_t otaStatistics = { 0 };
/* OTA Agent state returned from calling OTA_GetAgentState.*/
OtaState_t state = OtaAgentStateStopped;
/* Set OTA Library interfaces.*/
setOtaInterfaces( &otaInterfaces );
LogInfo( ( "OTA over MQTT demo, Application version %u.%u.%u",
appFirmwareVersion.u.x.major,
appFirmwareVersion.u.x.minor,
appFirmwareVersion.u.x.build ) );
/****************************** Init OTA Library. ******************************/
xBufferSemaphore = xSemaphoreCreateMutex();
if( xBufferSemaphore == NULL )
{
xResult = pdFAIL;
}
if( xResult == pdPASS )
{
memset( eventBuffer, 0x00, sizeof( eventBuffer ) );
if( ( otaRet = OTA_Init( &otaBuffer,
&otaInterfaces,
( const uint8_t * ) ( democonfigCLIENT_IDENTIFIER ),
otaAppCallback ) ) != OtaErrNone )
{
LogError( ( "Failed to initialize OTA Agent, exiting = %u.",
otaRet ) );
xResult = pdFAIL;
}
}
if( xResult == pdPASS )
{
if( ( xResult = xTaskCreate( prvOTAAgentTask,
"OTAAgentTask",
otaexampleAGENT_TASK_STACK_SIZE,
NULL,
otaexampleAGENT_TASK_PRIORITY,
NULL ) ) != pdPASS )
{
LogError( ( "Failed to start OTA Agent task: "
",errno=%d",
xResult ) );
}
}
/***************************Start OTA demo loop. ******************************/
if( xResult == pdPASS )
{
/* Start the OTA Agent.*/
eventMsg.eventId = OtaAgentEventStart;
OTA_SignalEvent( &eventMsg );
while( ( ( state = OTA_GetState() ) != OtaAgentStateStopped ) )
{
/* Get OTA statistics for currently executing job. */
OTA_GetStatistics( &otaStatistics );
LogInfo( ( " Received: %u Queued: %u Processed: %u Dropped: %u",
otaStatistics.otaPacketsReceived,
otaStatistics.otaPacketsQueued,
otaStatistics.otaPacketsProcessed,
otaStatistics.otaPacketsDropped ) );
vTaskDelay( pdMS_TO_TICKS( otaexampleTASK_DELAY_MS ) );
}
}
LogInfo( ( "OTA agent task stopped. Exiting OTA demo." ) );
vTaskDelete( NULL );
}