Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename ADU *device_information, send update result details #204

Merged
merged 10 commits into from
Jul 12, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,20 @@ static bool prvIsUpdateAlreadyInstalled(
const AzureIoTADUUpdateRequest_t * pxAduUpdateRequest )
{
if ( pxAduUpdateRequest->xUpdateManifest.xUpdateId.ulNameLength ==
xADUDeviceInformation.xCurrentUpdateId.ulNameLength &&
xADUDeviceProperties.xCurrentUpdateId.ulNameLength &&
strncmp( ( const char * ) pxAduUpdateRequest->xUpdateManifest.xUpdateId.pucName,
( const char * ) xADUDeviceInformation.xCurrentUpdateId.ucName,
( size_t ) xADUDeviceInformation.xCurrentUpdateId.ulNameLength ) == 0 &&
( const char * ) xADUDeviceProperties.xCurrentUpdateId.ucName,
( size_t ) xADUDeviceProperties.xCurrentUpdateId.ulNameLength ) == 0 &&
pxAduUpdateRequest->xUpdateManifest.xUpdateId.ulProviderLength ==
xADUDeviceInformation.xCurrentUpdateId.ulProviderLength &&
xADUDeviceProperties.xCurrentUpdateId.ulProviderLength &&
strncmp( ( const char * ) pxAduUpdateRequest->xUpdateManifest.xUpdateId.pucProvider,
( const char * ) xADUDeviceInformation.xCurrentUpdateId.ucProvider,
( size_t ) xADUDeviceInformation.xCurrentUpdateId.ulProviderLength ) == 0 &&
( const char * ) xADUDeviceProperties.xCurrentUpdateId.ucProvider,
( size_t ) xADUDeviceProperties.xCurrentUpdateId.ulProviderLength ) == 0 &&
pxAduUpdateRequest->xUpdateManifest.xUpdateId.ulVersionLength ==
xADUDeviceInformation.xCurrentUpdateId.ulVersionLength &&
xADUDeviceProperties.xCurrentUpdateId.ulVersionLength &&
strncmp( ( const char * ) pxAduUpdateRequest->xUpdateManifest.xUpdateId.pucVersion,
( const char * ) xADUDeviceInformation.xCurrentUpdateId.ucVersion,
( size_t ) xADUDeviceInformation.xCurrentUpdateId.ulVersionLength ) == 0 )
( const char * ) xADUDeviceProperties.xCurrentUpdateId.ucVersion,
( size_t ) xADUDeviceProperties.xCurrentUpdateId.ulVersionLength ) == 0 )
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,4 @@ void vSampleHandleWritablePropertiesUpdate( AzureIoTHubClientPropertiesResponse_
uint32_t ulSampleCreateReportedPropertiesUpdate( uint8_t * pucPropertiesData,
uint32_t ulPropertiesDataSize );

// Azure Device Update
extern az_iot_adu_client_update_request xUpdateRequest;
extern az_iot_adu_client_device_information xDeviceInformation;
extern az_iot_adu_client_workflow * pxLastWorkflow;
extern double xLastInstalledVersion;
extern az_span xGetLastInstalledVersion( );

#endif // AZURE_IOT_FREERTOS_ESP32_PNP_MODEL_H
28 changes: 17 additions & 11 deletions demos/sample_azure_iot_adu/sample_azure_iot_adu.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ AzureIoTADUClient_t xAzureIoTADUClient;
AzureIoTADUUpdateRequest_t xAzureIoTAduUpdateRequest;
bool xProcessUpdateRequest = false;

AzureIoTADUClientDeviceInformation_t xADUDeviceInformation =
AzureIoTADUClientDeviceProperties_t xADUDeviceProperties =
{
.ucManufacturer = ( const uint8_t * ) democonfigADU_DEVICE_MANUFACTURER,
.ulManufacturerLength = sizeof( democonfigADU_DEVICE_MANUFACTURER ) - 1,
Expand All @@ -170,7 +170,7 @@ AzureIoTADUClientDeviceInformation_t xADUDeviceInformation =
static AzureADUImage_t xImage;

/* Telemetry buffers */
static uint8_t ucScratchBuffer[ 512 ];
static uint8_t ucScratchBuffer[ 600 ];

/* Command buffers */
static uint8_t ucCommandResponsePayloadBuffer[ 128 ];
Expand All @@ -181,13 +181,19 @@ static uint32_t ulReportedPropertiesUpdateLength;

uint8_t ucAduContextBuffer[ ADU_CONTEXT_BUFFER_SIZE ];

const uint8_t sampleaduDEFAULT_RESULT_DETAILS[] = "Ok";

#define sampleaduPNP_COMPONENTS_LIST_LENGTH 1
static AzureIoTHubClientComponent_t pnp_components[ sampleaduPNP_COMPONENTS_LIST_LENGTH ] =
{
azureiothubCREATE_COMPONENT( AZ_IOT_ADU_CLIENT_PROPERTIES_COMPONENT_NAME )
};
#define sampleaduPNP_COMPONENTS_LIST pnp_components

/* This is an user-defined code to be reported as the result of the */
/* OTA update on the Azure Device Update portal. */
#define sampleaduSAMPLE_EXTENDED_RESULT_CODE 1234

/* TODO: REMOVE THIS BLOCKER ONCE ADU IS IMPLEMENTED */
/* This does not affect devices that actually implement the ADU process */
/* as they will reboot before getting to the place where this is used. */
Expand Down Expand Up @@ -444,7 +450,7 @@ static AzureIoTResult_t prvDownloadUpdateImageIntoFlash()

xResult = AzureIoTADUClient_SendAgentState( &xAzureIoTADUClient,
&xAzureIoTHubClient,
&xADUDeviceInformation,
&xADUDeviceProperties,
&xAzureIoTAduUpdateRequest,
eAzureIoTADUAgentStateDeploymentInProgress,
NULL,
Expand Down Expand Up @@ -577,9 +583,9 @@ static AzureIoTResult_t prvEnableImageAndResetDevice()
* through pucResultDetails.
*/
xUpdateResults.lResultCode = 0;
xUpdateResults.lExtendedResultCode = 0;
xUpdateResults.pucResultDetails = NULL;
xUpdateResults.ulResultDetailsLength = 0;
xUpdateResults.lExtendedResultCode = sampleaduSAMPLE_EXTENDED_RESULT_CODE;
xUpdateResults.pucResultDetails = sampleaduDEFAULT_RESULT_DETAILS;
xUpdateResults.ulResultDetailsLength = sizeof( sampleaduDEFAULT_RESULT_DETAILS ) - 1;
xUpdateResults.ulStepResultsCount =
xAzureIoTAduUpdateRequest.xUpdateManifest.xInstructions.ulStepsCount;

Expand All @@ -590,16 +596,16 @@ static AzureIoTResult_t prvEnableImageAndResetDevice()
for( int32_t ulStepIndex = 0; ulStepIndex < xUpdateResults.ulStepResultsCount; ulStepIndex++ )
{
xUpdateResults.pxStepResults[ ulStepIndex ].ulResultCode = 0;
xUpdateResults.pxStepResults[ ulStepIndex ].ulExtendedResultCode = 0;
xUpdateResults.pxStepResults[ ulStepIndex ].pucResultDetails = NULL;
xUpdateResults.pxStepResults[ ulStepIndex ].ulResultDetailsLength = 0;
xUpdateResults.pxStepResults[ ulStepIndex ].ulExtendedResultCode = sampleaduSAMPLE_EXTENDED_RESULT_CODE;
xUpdateResults.pxStepResults[ ulStepIndex ].pucResultDetails = sampleaduDEFAULT_RESULT_DETAILS;
xUpdateResults.pxStepResults[ ulStepIndex ].ulResultDetailsLength = sizeof( sampleaduDEFAULT_RESULT_DETAILS ) - 1;
}

LogInfo( ( "[ADU] Send property update.\r\n" ) );

xResult = AzureIoTADUClient_SendAgentState( &xAzureIoTADUClient,
&xAzureIoTHubClient,
&xADUDeviceInformation,
&xADUDeviceProperties,
&xAzureIoTAduUpdateRequest,
eAzureIoTADUAgentStateDeploymentInProgress,
&xUpdateResults,
Expand Down Expand Up @@ -766,7 +772,7 @@ static void prvAzureDemoTask( void * pvParameters )

xResult = AzureIoTADUClient_SendAgentState( &xAzureIoTADUClient,
&xAzureIoTHubClient,
&xADUDeviceInformation,
&xADUDeviceProperties,
NULL,
eAzureIoTADUAgentStateIdle,
NULL,
Expand Down
2 changes: 1 addition & 1 deletion demos/sample_azure_iot_adu/sample_azure_iot_pnp_data_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern AzureIoTHubClient_t xAzureIoTHubClient;
extern AzureIoTADUClient_t xAzureIoTADUClient;
extern AzureIoTADUUpdateRequest_t xAzureIoTAduUpdateRequest;
extern bool xProcessUpdateRequest;
extern AzureIoTADUClientDeviceInformation_t xADUDeviceInformation;
extern AzureIoTADUClientDeviceProperties_t xADUDeviceProperties;

#define ADU_CONTEXT_BUFFER_SIZE 10240
extern uint8_t ucAduContextBuffer[ ADU_CONTEXT_BUFFER_SIZE ];
Expand Down
18 changes: 9 additions & 9 deletions demos/sample_azure_iot_adu/sample_azure_iot_pnp_simulated_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,20 @@ static uint32_t prvGetNewMaxTemp( double xUpdatedTemperature,
static bool prvIsUpdateAlreadyInstalled( const AzureIoTADUUpdateRequest_t * pxAduUpdateRequest )
{
if( ( pxAduUpdateRequest->xUpdateManifest.xUpdateId.ulNameLength ==
xADUDeviceInformation.xCurrentUpdateId.ulNameLength ) &&
xADUDeviceProperties.xCurrentUpdateId.ulNameLength ) &&
( strncmp( ( const char * ) pxAduUpdateRequest->xUpdateManifest.xUpdateId.pucName,
( const char * ) xADUDeviceInformation.xCurrentUpdateId.ucName,
( size_t ) xADUDeviceInformation.xCurrentUpdateId.ulNameLength ) == 0 ) &&
( const char * ) xADUDeviceProperties.xCurrentUpdateId.ucName,
( size_t ) xADUDeviceProperties.xCurrentUpdateId.ulNameLength ) == 0 ) &&
( pxAduUpdateRequest->xUpdateManifest.xUpdateId.ulProviderLength ==
xADUDeviceInformation.xCurrentUpdateId.ulProviderLength ) &&
xADUDeviceProperties.xCurrentUpdateId.ulProviderLength ) &&
( strncmp( ( const char * ) pxAduUpdateRequest->xUpdateManifest.xUpdateId.pucProvider,
( const char * ) xADUDeviceInformation.xCurrentUpdateId.ucProvider,
( size_t ) xADUDeviceInformation.xCurrentUpdateId.ulProviderLength ) == 0 ) &&
( const char * ) xADUDeviceProperties.xCurrentUpdateId.ucProvider,
( size_t ) xADUDeviceProperties.xCurrentUpdateId.ulProviderLength ) == 0 ) &&
( pxAduUpdateRequest->xUpdateManifest.xUpdateId.ulVersionLength ==
xADUDeviceInformation.xCurrentUpdateId.ulVersionLength ) &&
xADUDeviceProperties.xCurrentUpdateId.ulVersionLength ) &&
( strncmp( ( const char * ) pxAduUpdateRequest->xUpdateManifest.xUpdateId.pucVersion,
( const char * ) xADUDeviceInformation.xCurrentUpdateId.ucVersion,
( size_t ) xADUDeviceInformation.xCurrentUpdateId.ulVersionLength ) == 0 ) )
( const char * ) xADUDeviceProperties.xCurrentUpdateId.ucVersion,
( size_t ) xADUDeviceProperties.xCurrentUpdateId.ulVersionLength ) == 0 ) )
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ typedef struct
az_span adu_version;
az_span do_version;
az_iot_adu_client_update_id update_id;
} az_iot_adu_client_device_information;
} az_iot_adu_client_device_properties;

typedef struct
{
Expand Down Expand Up @@ -213,7 +213,7 @@ AZ_NODISCARD bool az_iot_adu_client_is_component_device_update(
* with the state of the ADU agent.
*
* @param[in] client The #az_iot_adu_client to use for this call.
* @param[in] device_information A pointer to a #az_iot_adu_client_device_information
* @param[in] device_properties A pointer to a #az_iot_adu_client_device_properties
* structure with all the details of the device,
* as required by the ADU service.
* @param[in] agent_state An integer value indicating the current state of
Expand All @@ -235,7 +235,7 @@ AZ_NODISCARD bool az_iot_adu_client_is_component_device_update(
*/
AZ_NODISCARD az_result az_iot_adu_client_get_agent_state_payload(
az_iot_adu_client* client,
az_iot_adu_client_device_information* device_information,
az_iot_adu_client_device_properties* device_properties,
int32_t agent_state,
az_iot_adu_client_workflow* workflow,
az_iot_adu_client_install_result* last_install_result,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static bool did_update = false;
static char adu_scratch_buffer[10000];

#define AZ_IOT_ADU_AGENT_VERSION "DU;agent/0.8.0-rc1-public-preview"
az_iot_adu_device_information adu_device_information
az_iot_adu_device_properties adu_device_properties
= { .manufacturer = AZ_SPAN_LITERAL_FROM_STR(ADU_DEVICE_MANUFACTURER),
.model = AZ_SPAN_LITERAL_FROM_STR(ADU_DEVICE_MODEL),
.adu_version = AZ_SPAN_LITERAL_FROM_STR(AZ_IOT_ADU_AGENT_VERSION),
Expand Down Expand Up @@ -107,7 +107,7 @@ static void process_device_property_message(
static void download_and_write_to_flash(az_span url);
static void verify_image_and_reboot(void);
static void spoof_new_image(void);
static void send_adu_device_information_property(void);
static void send_adu_device_properties_property(void);
static void send_adu_accept_manifest_property(int32_t version_number);
static void send_adu_in_progress_property(void);
static void send_adu_completed_property(void);
Expand All @@ -130,7 +130,7 @@ void paho_iot_adu_sample_device_implement(void)
subscribe_mqtt_client_to_iot_hub_topics();
IOT_SAMPLE_LOG_SUCCESS("Client subscribed to IoT Hub topics.");

send_adu_device_information_property();
send_adu_device_properties_property();
IOT_SAMPLE_LOG_SUCCESS("Publishing device information for ADU. Response will be "
"received asynchronously.");

Expand Down Expand Up @@ -212,7 +212,7 @@ static void send_adu_in_progress_property(void)
char property_payload_buffer[SAMPLE_MQTT_PAYLOAD_LENGTH];
az_span property_buffer = AZ_SPAN_FROM_BUFFER(property_payload_buffer);
rc = az_iot_adu_get_properties_payload(
&adu_device_information,
&adu_device_properties,
AZ_IOT_ADU_AGENT_STATE_DEPLOYMENT_IN_PROGRESS,
NULL,
NULL,
Expand Down Expand Up @@ -265,7 +265,7 @@ static void send_adu_completed_property(void)
char property_payload_buffer[SAMPLE_MQTT_PAYLOAD_LENGTH];
az_span property_buffer = AZ_SPAN_FROM_BUFFER(property_payload_buffer);
rc = az_iot_adu_get_properties_payload(
&adu_device_information,
&adu_device_properties,
AZ_IOT_ADU_AGENT_STATE_IDLE,
NULL,
NULL,
Expand Down Expand Up @@ -296,10 +296,10 @@ static void spoof_new_image(void)
// Changing device version to new version.
az_span new_version = az_span_create(adu_new_version, sizeof(adu_new_version));
az_span_copy(new_version, xBaseUpdateManifest.update_id.version);
adu_device_information.update_id.version = new_version;
adu_device_information.update_id.version
adu_device_properties.update_id.version = new_version;
adu_device_properties.update_id.version
= az_span_slice(new_version, 0, az_span_size(xBaseUpdateManifest.update_id.version));
IOT_SAMPLE_LOG_AZ_SPAN("New version ", adu_device_information.update_id.version);
IOT_SAMPLE_LOG_AZ_SPAN("New version ", adu_device_properties.update_id.version);
}
// receive_messages_and_send_telemetry_loop will loop to check if there are incoming MQTT
// messages, waiting up to MQTT_TIMEOUT_RECEIVE_MS. It will also send a telemetry message
Expand Down Expand Up @@ -574,7 +574,7 @@ static void process_device_property_message(

// send_adu_device_reported_property writes a property payload reporting device state and then sends
// it to Azure IoT Hub.
static void send_adu_device_information_property(void)
static void send_adu_device_properties_property(void)
{
az_result rc;

Expand All @@ -593,7 +593,7 @@ static void send_adu_device_information_property(void)
az_span reported_property_payload = AZ_SPAN_FROM_BUFFER(reported_property_payload_buffer);

rc = az_iot_adu_get_properties_payload(
&adu_device_information,
&adu_device_properties,
AZ_IOT_ADU_AGENT_STATE_IDLE,
NULL,
NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,20 @@ static az_result generate_step_id(az_span buffer, uint32_t step_index, az_span*

AZ_NODISCARD az_result az_iot_adu_client_get_agent_state_payload(
az_iot_adu_client* client,
az_iot_adu_client_device_information* device_information,
az_iot_adu_client_device_properties* device_properties,
int32_t agent_state,
az_iot_adu_client_workflow* workflow,
az_iot_adu_client_install_result* last_install_result,
az_json_writer* ref_json_writer)
{
_az_PRECONDITION_NOT_NULL(client);
_az_PRECONDITION_NOT_NULL(device_information);
_az_PRECONDITION_VALID_SPAN(device_information->manufacturer, 1, false);
_az_PRECONDITION_VALID_SPAN(device_information->model, 1, false);
_az_PRECONDITION_VALID_SPAN(device_information->update_id.provider, 1, false);
_az_PRECONDITION_VALID_SPAN(device_information->update_id.name, 1, false);
_az_PRECONDITION_VALID_SPAN(device_information->update_id.version, 1, false);
_az_PRECONDITION_VALID_SPAN(device_information->adu_version, 1, false);
_az_PRECONDITION_NOT_NULL(device_properties);
_az_PRECONDITION_VALID_SPAN(device_properties->manufacturer, 1, false);
_az_PRECONDITION_VALID_SPAN(device_properties->model, 1, false);
_az_PRECONDITION_VALID_SPAN(device_properties->update_id.provider, 1, false);
_az_PRECONDITION_VALID_SPAN(device_properties->update_id.name, 1, false);
_az_PRECONDITION_VALID_SPAN(device_properties->update_id.version, 1, false);
_az_PRECONDITION_VALID_SPAN(device_properties->adu_version, 1, false);
_az_PRECONDITION_NOT_NULL(ref_json_writer);

/* Update reported property */
Expand All @@ -200,11 +200,11 @@ AZ_NODISCARD az_result az_iot_adu_client_get_agent_state_payload(
_az_RETURN_IF_FAILED(az_json_writer_append_property_name(
ref_json_writer, AZ_SPAN_FROM_STR(AZ_IOT_ADU_CLIENT_AGENT_PROPERTY_NAME_MANUFACTURER)));
_az_RETURN_IF_FAILED(
az_json_writer_append_string(ref_json_writer, device_information->manufacturer));
az_json_writer_append_string(ref_json_writer, device_properties->manufacturer));

_az_RETURN_IF_FAILED(az_json_writer_append_property_name(
ref_json_writer, AZ_SPAN_FROM_STR(AZ_IOT_ADU_CLIENT_AGENT_PROPERTY_NAME_MODEL)));
_az_RETURN_IF_FAILED(az_json_writer_append_string(ref_json_writer, device_information->model));
_az_RETURN_IF_FAILED(az_json_writer_append_string(ref_json_writer, device_properties->model));

// TODO: verify if this needs to be exposed as an option.
_az_RETURN_IF_FAILED(az_json_writer_append_property_name(
Expand All @@ -215,17 +215,17 @@ AZ_NODISCARD az_result az_iot_adu_client_get_agent_state_payload(
_az_RETURN_IF_FAILED(az_json_writer_append_property_name(
ref_json_writer, AZ_SPAN_FROM_STR(AZ_IOT_ADU_CLIENT_AGENT_PROPERTY_NAME_ADU_VERSION)));
_az_RETURN_IF_FAILED(
az_json_writer_append_string(ref_json_writer, device_information->adu_version));
az_json_writer_append_string(ref_json_writer, device_properties->adu_version));

if (!az_span_is_content_equal(device_information->do_version, AZ_SPAN_EMPTY))
if (!az_span_is_content_equal(device_properties->do_version, AZ_SPAN_EMPTY))
{
// TODO: verify if 'doVer' is required.
// Ref:
// https://docs.microsoft.com/en-us/azure/iot-hub-device-update/device-update-plug-and-play
_az_RETURN_IF_FAILED(az_json_writer_append_property_name(
ref_json_writer, AZ_SPAN_FROM_STR(AZ_IOT_ADU_CLIENT_AGENT_PROPERTY_NAME_DO_VERSION)));
_az_RETURN_IF_FAILED(
az_json_writer_append_string(ref_json_writer, device_information->do_version));
az_json_writer_append_string(ref_json_writer, device_properties->do_version));
}

_az_RETURN_IF_FAILED(az_json_writer_append_end_object(ref_json_writer));
Expand Down Expand Up @@ -339,8 +339,6 @@ AZ_NODISCARD az_result az_iot_adu_client_get_agent_state_payload(
}

/* Fill installed update id. */
// TODO: move last_installed_update_id out of this device_information structure.
// TODO: rename device_information var and struct to device_properties to match json prop name.
// TODO: Find way to not use internal field
az_span update_id_string = az_span_slice_to_end(
ref_json_writer->_internal.destination_buffer,
Expand All @@ -356,7 +354,7 @@ AZ_NODISCARD az_result az_iot_adu_client_get_agent_state_payload(
ref_json_writer,
AZ_SPAN_FROM_STR(AZ_IOT_ADU_CLIENT_AGENT_PROPERTY_NAME_INSTALLED_UPDATE_ID)));
_az_RETURN_IF_FAILED(az_json_writer_append_json_text(
ref_json_writer, generate_update_id_string(device_information->update_id, update_id_string)));
ref_json_writer, generate_update_id_string(device_properties->update_id, update_id_string)));

_az_RETURN_IF_FAILED(az_json_writer_append_end_object(ref_json_writer));

Expand All @@ -366,7 +364,6 @@ AZ_NODISCARD az_result az_iot_adu_client_get_agent_state_payload(
return AZ_OK;
}

// Reference: AzureRTOS/AZ_IOT_ADU_CLIENT_agent_service_properties_get(...)
AZ_NODISCARD az_result az_iot_adu_client_parse_service_properties(
az_iot_adu_client* client,
az_json_reader* ref_json_reader,
Expand Down
Loading