Skip to content

Commit dba9910

Browse files
committed
Update code to remove constness related and unused function warnings for the latest ESP-IDF v5.4
1 parent f4c15d5 commit dba9910

File tree

3 files changed

+11
-145
lines changed

3 files changed

+11
-145
lines changed

Diff for: main/demo_tasks/ota_over_mqtt_demo/ota_over_mqtt_demo.c

+2-142
Original file line numberDiff line numberDiff line change
@@ -289,25 +289,6 @@ static OtaMqttStatus_t prvMQTTSubscribe( const char * pTopicFilter,
289289
uint16_t topicFilterLength,
290290
uint8_t ucQoS );
291291

292-
/**
293-
* @brief Function is used by OTA agent to unsubscribe a topicfilter from MQTT broker.
294-
*
295-
* The implementation queues an UNSUBSCRIBE request for the topic filter with the MQTT agent. It then waits
296-
* for a successful completion of the request from the agent. Notification along with results of
297-
* operation is sent using xTaskNotify API to the caller task. MQTT agent also removes the topic filter
298-
* subscription from its memory so any future
299-
* packets on this topic will not be routed to the OTA agent.
300-
*
301-
* @param[in] pTopicFilter Topic filter to be unsubscribed.
302-
* @param[in] topicFilterLength Length of the topic filter.
303-
* @param[in] ucQos Qos value for the topic.
304-
* @return OtaMqttSuccess if successful. Appropriate error code otherwise.
305-
*
306-
*/
307-
static OtaMqttStatus_t prvMQTTUnsubscribe( const char * pTopicFilter,
308-
uint16_t topicFilterLength,
309-
uint8_t ucQoS );
310-
311292
/**
312293
* @brief The function which runs the OTA demo task.
313294
*
@@ -319,21 +300,6 @@ static OtaMqttStatus_t prvMQTTUnsubscribe( const char * pTopicFilter,
319300
*/
320301
static void prvOTADemoTask( void * pvParam );
321302

322-
/**
323-
* @brief Matches a client identifier within an OTA topic.
324-
* This function is used to validate that topic is valid and intended for this device thing name.
325-
*
326-
* @param[in] pTopic Pointer to the topic
327-
* @param[in] topicNameLength length of the topic
328-
* @param[in] pClientIdentifier Client identifier, should be null terminated.
329-
* @param[in] clientIdentifierLength Length of the client identifier.
330-
* @return true if client identifier is found within the topic at the right index.
331-
*/
332-
static bool prvMatchClientIdentifierInTopic( const char * pTopic,
333-
size_t topicNameLength,
334-
const char * pClientIdentifier,
335-
size_t clientIdentifierLength );
336-
337303
/**
338304
* @brief Suspends the OTA agent.
339305
*/
@@ -356,39 +322,6 @@ static void prvCoreMqttAgentEventHandler( void * pvHandlerArg,
356322

357323
/* Static function definitions ************************************************/
358324

359-
static bool prvMatchClientIdentifierInTopic( const char * pTopic,
360-
size_t topicNameLength,
361-
const char * pClientIdentifier,
362-
size_t clientIdentifierLength )
363-
{
364-
bool isMatch = false;
365-
size_t idx, matchIdx = 0;
366-
367-
for( idx = OTA_TOPIC_CLIENT_IDENTIFIER_START_IDX; idx < topicNameLength; idx++ )
368-
{
369-
if( matchIdx == clientIdentifierLength )
370-
{
371-
if( pTopic[ idx ] == '/' )
372-
{
373-
isMatch = true;
374-
}
375-
376-
break;
377-
}
378-
else
379-
{
380-
if( pClientIdentifier[ matchIdx ] != pTopic[ idx ] )
381-
{
382-
break;
383-
}
384-
}
385-
386-
matchIdx++;
387-
}
388-
389-
return isMatch;
390-
}
391-
392325
static void prvCommandCallback( MQTTAgentCommandContext_t * pCommandContext,
393326
MQTTAgentReturnInfo_t * pxReturnInfo )
394327
{
@@ -534,80 +467,6 @@ static OtaMqttStatus_t prvMQTTPublish( const char * const pacTopic,
534467
return otaRet;
535468
}
536469

537-
static OtaMqttStatus_t prvMQTTUnsubscribe( const char * pTopicFilter,
538-
uint16_t topicFilterLength,
539-
uint8_t ucQoS )
540-
{
541-
MQTTStatus_t mqttStatus;
542-
uint32_t ulNotifiedValue;
543-
MQTTAgentSubscribeArgs_t xSubscribeArgs = { 0 };
544-
MQTTSubscribeInfo_t xSubscribeInfo = { 0 };
545-
BaseType_t result;
546-
MQTTAgentCommandInfo_t xCommandParams = { 0 };
547-
MQTTAgentCommandContext_t xApplicationDefinedContext = { 0 };
548-
OtaMqttStatus_t otaRet = OtaMqttSuccess;
549-
550-
configASSERT( pTopicFilter != NULL );
551-
configASSERT( topicFilterLength > 0 );
552-
553-
xSubscribeInfo.pTopicFilter = pTopicFilter;
554-
xSubscribeInfo.topicFilterLength = topicFilterLength;
555-
xSubscribeInfo.qos = ucQoS;
556-
xSubscribeArgs.pSubscribeInfo = &xSubscribeInfo;
557-
xSubscribeArgs.numSubscriptions = 1;
558-
559-
560-
xApplicationDefinedContext.xTaskToNotify = xTaskGetCurrentTaskHandle();
561-
562-
xCommandParams.blockTimeMs = otademoconfigMQTT_TIMEOUT_MS;
563-
xCommandParams.cmdCompleteCallback = prvCommandCallback;
564-
xCommandParams.pCmdCompleteCallbackContext = ( void * ) &xApplicationDefinedContext;
565-
566-
ESP_LOGI( TAG, "Unsubscribing to topic filter: %s", pTopicFilter );
567-
xTaskNotifyStateClear( NULL );
568-
569-
570-
mqttStatus = MQTTAgent_Unsubscribe( &xGlobalMqttAgentContext,
571-
&xSubscribeArgs,
572-
&xCommandParams );
573-
574-
/* Wait for command to complete so MQTTSubscribeInfo_t remains in scope for the
575-
* duration of the command. */
576-
if( mqttStatus == MQTTSuccess )
577-
{
578-
result = xTaskNotifyWait( 0, MAX_UINT32, &ulNotifiedValue, portMAX_DELAY );
579-
580-
if( result == pdTRUE )
581-
{
582-
mqttStatus = xApplicationDefinedContext.xReturnStatus;
583-
}
584-
else
585-
{
586-
mqttStatus = MQTTRecvFailed;
587-
}
588-
}
589-
590-
if( mqttStatus != MQTTSuccess )
591-
{
592-
ESP_LOGE( TAG, "Failed to UNSUBSCRIBE from topic %.*s with error = %u.",
593-
topicFilterLength,
594-
pTopicFilter,
595-
mqttStatus );
596-
597-
otaRet = OtaMqttUnsubscribeFailed;
598-
}
599-
else
600-
{
601-
ESP_LOGI( TAG, "UNSUBSCRIBED from topic %.*s.\n\n",
602-
topicFilterLength,
603-
pTopicFilter );
604-
605-
otaRet = OtaMqttSuccess;
606-
}
607-
608-
return otaRet;
609-
}
610-
611470
/*-----------------------------------------------------------*/
612471

613472
static void requestJobDocumentHandler( void )
@@ -825,7 +684,7 @@ static OtaPalJobDocProcessingResult_t receivedJobDocumentHandler( OtaJobEventDat
825684
{
826685
bool parseJobDocument = false;
827686
bool handled = false;
828-
char * jobId;
687+
const char * jobId;
829688
const char ** jobIdptr = &jobId;
830689
size_t jobIdLength = 0U;
831690
OtaPalStatus_t palStatus;
@@ -1304,6 +1163,7 @@ static void processOTAEvents( void )
13041163
case OtaAgentEventRequestFileBlock:
13051164
case OtaAgentEventReceivedFileBlock:
13061165
nextEvent.eventId = OtaAgentEventRequestFileBlock;
1166+
break;
13071167

13081168
case OtaAgentEventCloseFile:
13091169
nextEvent.eventId = OtaAgentEventActivateImage;

Diff for: main/main.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ static BaseType_t prvInitializeNetworkContext( void )
130130
/* This is used to store the error return of ESP-IDF functions. */
131131
esp_err_t xEspErrRet;
132132

133+
/* This is used as a temporary buffer for anything */
134+
char *variableBuffer = NULL;
135+
133136
/* Verify that the MQTT endpoint and thing name have been configured by the
134137
* user. */
135138
if( strlen( CONFIG_GRI_MQTT_ENDPOINT ) == 0 )
@@ -155,8 +158,9 @@ static BaseType_t prvInitializeNetworkContext( void )
155158

156159
/* Get the device certificate from esp_secure_crt_mgr and put into network
157160
* context. */
158-
xEspErrRet = esp_secure_cert_get_device_cert( &xNetworkContext.pcClientCert,
161+
xEspErrRet = esp_secure_cert_get_device_cert( &variableBuffer,
159162
&xNetworkContext.pcClientCertSize );
163+
xNetworkContext.pcClientCert = variableBuffer;
160164

161165
if( xEspErrRet == ESP_OK )
162166
{
@@ -208,8 +212,10 @@ static BaseType_t prvInitializeNetworkContext( void )
208212
xRet = pdFAIL;
209213
}
210214
#else /* if CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL */
211-
xEspErrRet = esp_secure_cert_get_priv_key( &xNetworkContext.pcClientKey,
215+
xEspErrRet = esp_secure_cert_get_priv_key( &variableBuffer,
212216
&xNetworkContext.pcClientKeySize );
217+
218+
xNetworkContext.pcClientKey = variableBuffer;
213219

214220
if( xEspErrRet == ESP_OK )
215221
{

0 commit comments

Comments
 (0)