Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0912a22

Browse files
Ryanwinter/components (#342)
* Extend to support receiving of pnp components
1 parent 50cb275 commit 0912a22

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

‎MXChip/AZ3166/app/nx_client.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737
#define TELEMETRY_GYROSCOPEY "gyroscopeY"
3838
#define TELEMETRY_GYROSCOPEZ "gyroscopeZ"
3939
#define TELEMETRY_INTERVAL_PROPERTY "telemetryInterval"
40+
41+
// Properties
4042
#define LED_STATE_PROPERTY "ledState"
43+
44+
// Commands
4145
#define SET_LED_STATE_COMMAND "setLedState"
4246
#define SET_DISPLAY_TEXT_COMMAND "setDisplayText"
4347

‎shared/src/azure_iot_connect.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ VOID connection_status_set(AZURE_IOT_NX_CONTEXT* nx_context, UINT connection_sta
9797
//
9898
//---------------------------------------------------------------------------------
9999
VOID connection_monitor(
100-
AZURE_IOT_NX_CONTEXT* nx_context, UINT (*iothub_init)(AZURE_IOT_NX_CONTEXT* nx_context), UINT (*network_connect)())
100+
AZURE_IOT_NX_CONTEXT* nx_context, UINT (*iot_initialize)(AZURE_IOT_NX_CONTEXT* nx_context), UINT (*network_connect)())
101101
{
102102
// Check parameters
103-
if ((nx_context == NX_NULL) || (iothub_init == NX_NULL))
103+
if ((nx_context == NX_NULL) || (iot_initialize == NX_NULL))
104104
{
105105
return;
106106
}
@@ -150,7 +150,7 @@ VOID connection_monitor(
150150

151151
// Initialize IoT Hub
152152
exponential_backoff_with_jitter();
153-
if (iothub_init(nx_context) == NX_SUCCESS)
153+
if (iot_initialize(nx_context) == NX_SUCCESS)
154154
{
155155
// Connect IoT Hub
156156
iothub_connect(nx_context);

‎shared/src/azure_iot_nx_client.c‎

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,18 @@ static UINT iot_hub_initialize(AZURE_IOT_NX_CONTEXT* nx_context)
216216
printf("Error: device twin desired property callback set (0x%08x)\r\n", status);
217217
}
218218

219+
// Register the pnp components for receiving
220+
for (int i = 0; i < nx_context->azure_iot_component_count; ++i)
221+
{
222+
if ((status = nx_azure_iot_hub_client_component_add(&nx_context->iothub_client,
223+
(UCHAR*)nx_context->azure_iot_components[i],
224+
strlen(nx_context->azure_iot_components[i]))))
225+
{
226+
printf("ERROR: nx_azure_iot_hub_client_component_add failed (0x%08x)\r\n", status);
227+
break;
228+
}
229+
}
230+
219231
if (status != NX_AZURE_IOT_SUCCESS)
220232
{
221233
nx_azure_iot_hub_client_deinitialize(&nx_context->iothub_client);
@@ -480,13 +492,7 @@ static UINT process_properties_shared(AZURE_IOT_NX_CONTEXT* nx_context,
480492
return status;
481493
}
482494

483-
if ((status = nx_azure_iot_json_reader_init(&json_reader, packet_ptr)))
484-
{
485-
printf("Init json reader failed!: error code = 0x%08x\r\n", status);
486-
nx_packet_release(packet_ptr);
487-
return status;
488-
}
489-
495+
// reinitialize the json reader after reading the version to reset
490496
if ((status = nx_azure_iot_json_reader_init(&json_reader, packet_ptr)))
491497
{
492498
printf("Error: failed to initialize json reader (0x%08x)\r\n", status);
@@ -937,6 +943,23 @@ UINT azure_iot_nx_client_register_timer_callback(
937943
return NX_SUCCESS;
938944
}
939945

946+
UINT azure_iot_nx_client_add_component(AZURE_IOT_NX_CONTEXT* nx_context, CHAR* component_name)
947+
{
948+
if (nx_context == NULL || component_name == NULL)
949+
{
950+
return NX_PTR_ERROR;
951+
}
952+
953+
if (nx_context->azure_iot_component_count >= NX_AZURE_IOT_HUB_CLIENT_MAX_COMPONENT_LIST)
954+
{
955+
return NX_AZURE_IOT_INSUFFICIENT_BUFFER_SPACE;
956+
}
957+
958+
nx_context->azure_iot_components[nx_context->azure_iot_component_count] = component_name;
959+
nx_context->azure_iot_component_count++;
960+
return NX_SUCCESS;
961+
}
962+
940963
UINT azure_iot_nx_client_sas_set(AZURE_IOT_NX_CONTEXT* context, CHAR* device_sas_key)
941964
{
942965
if (device_sas_key[0] == 0)

‎shared/src/azure_iot_nx_client.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ struct AZURE_IOT_NX_CONTEXT_STRUCT
5353
CHAR* azure_iot_model_id;
5454
UINT azure_iot_model_id_len;
5555

56+
// pnp components
57+
CHAR* azure_iot_components[NX_AZURE_IOT_HUB_CLIENT_MAX_COMPONENT_LIST];
58+
UINT azure_iot_component_count;
59+
5660
// auth config
5761
CHAR* azure_iot_device_sas_key;
5862
UINT azure_iot_device_sas_key_len;
@@ -126,6 +130,8 @@ UINT azure_iot_nx_client_register_properties_complete_callback(
126130
UINT azure_iot_nx_client_register_timer_callback(
127131
AZURE_IOT_NX_CONTEXT* nx_context, func_ptr_timer callback, int32_t interval);
128132

133+
UINT azure_iot_nx_client_add_component(AZURE_IOT_NX_CONTEXT* nx_context, CHAR* component_name);
134+
129135
UINT azure_iot_nx_client_sas_set(AZURE_IOT_NX_CONTEXT* context, CHAR* device_sas_key);
130136
UINT azure_iot_nx_client_cert_set(AZURE_IOT_NX_CONTEXT* context,
131137
UCHAR* device_x509_cert,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /