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

Azure RTOS 6.1.9 #298

Merged
merged 21 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[submodule "core/lib/threadx"]
path = core/lib/threadx
[submodule "shared/lib/threadx"]
path = shared/lib/threadx
url = /~https://github.com/azure-rtos/threadx.git
[submodule "core/lib/netxduo"]
path = core/lib/netxduo
[submodule "shared/lib/netxduo"]
path = shared/lib/netxduo
url = /~https://github.com/azure-rtos/netxduo.git
[submodule "core/lib/jsmn/src"]
path = core/lib/jsmn/src
[submodule "shared/lib/jsmn/src"]
path = shared/lib/jsmn/src
url = /~https://github.com/zserge/jsmn
6 changes: 3 additions & 3 deletions MXChip/AZ3166/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
set(CMAKE_C_STANDARD 99)

set(GSG_BASE_DIR ${CMAKE_SOURCE_DIR}/../..)
set(CORE_SRC_DIR ${GSG_BASE_DIR}/core/src)
set(CORE_LIB_DIR ${GSG_BASE_DIR}/core/lib)
set(SHARED_SRC_DIR ${GSG_BASE_DIR}/shared/src)
set(SHARED_LIB_DIR ${GSG_BASE_DIR}/shared/lib)

# use the repo version of ninja on Windows as there is no Ninja installer
if(WIN32)
Expand All @@ -29,6 +29,6 @@ project(mxchip_azure_iot C ASM)
# Disable common networking component, MXCHIP has it's own
set(DISABLE_COMMON_NETWORK true)

add_subdirectory(${CORE_SRC_DIR} core_src)
add_subdirectory(${SHARED_SRC_DIR} shared_src)
add_subdirectory(lib)
add_subdirectory(app)
112 changes: 62 additions & 50 deletions MXChip/AZ3166/app/nx_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "nx_azure_iot_provisioning_client.h"

#include "azure_iot_nx_client.h"
#include "nx_azure_iot_pnp_helpers.h"

#include "azure_config.h"
#include "azure_device_x509_cert_config.h"
Expand Down Expand Up @@ -57,7 +56,7 @@ static TX_EVENT_FLAGS_GROUP azure_iot_flags;

static int32_t telemetry_interval = 10;

static UINT append_device_info_properties(NX_AZURE_IOT_JSON_WRITER* json_writer, VOID* context)
static UINT append_device_info_properties(NX_AZURE_IOT_JSON_WRITER* json_writer)
{
if (nx_azure_iot_json_writer_append_property_with_string_value(json_writer,
(UCHAR*)DEVICE_INFO_MANUFACTURER_PROPERTY_NAME,
Expand Down Expand Up @@ -106,7 +105,7 @@ static UINT append_device_info_properties(NX_AZURE_IOT_JSON_WRITER* json_writer,
return NX_AZURE_IOT_SUCCESS;
}

static UINT append_device_telemetry(NX_AZURE_IOT_JSON_WRITER* json_writer, VOID* context)
static UINT append_device_telemetry(NX_AZURE_IOT_JSON_WRITER* json_writer)
{
lps22hb_t lps22hb_data = lps22hb_data_read();
hts221_data_t hts221_data = hts221_data_read();
Expand All @@ -127,7 +126,7 @@ static UINT append_device_telemetry(NX_AZURE_IOT_JSON_WRITER* json_writer, VOID*
return NX_AZURE_IOT_SUCCESS;
}

static UINT append_device_telemetry_magnetometer(NX_AZURE_IOT_JSON_WRITER* json_writer, VOID* context)
static UINT append_device_telemetry_magnetometer(NX_AZURE_IOT_JSON_WRITER* json_writer)
{
lis2mdl_data_t lis2mdl_data = lis2mdl_data_read();

Expand All @@ -153,7 +152,7 @@ static UINT append_device_telemetry_magnetometer(NX_AZURE_IOT_JSON_WRITER* json_
return NX_AZURE_IOT_SUCCESS;
}

static UINT append_device_telemetry_accelerometer(NX_AZURE_IOT_JSON_WRITER* json_writer, VOID* context)
static UINT append_device_telemetry_accelerometer(NX_AZURE_IOT_JSON_WRITER* json_writer)
{
lsm6dsl_data_t lsm6dsl_data = lsm6dsl_data_read();

Expand All @@ -179,7 +178,7 @@ static UINT append_device_telemetry_accelerometer(NX_AZURE_IOT_JSON_WRITER* json
return NX_AZURE_IOT_SUCCESS;
}

static UINT append_device_telemetry_gyroscope(NX_AZURE_IOT_JSON_WRITER* json_writer, VOID* context)
static UINT append_device_telemetry_gyroscope(NX_AZURE_IOT_JSON_WRITER* json_writer)
{
lsm6dsl_data_t lsm6dsl_data = lsm6dsl_data_read();

Expand Down Expand Up @@ -209,77 +208,83 @@ static void set_led_state(bool level)
{
if (level)
{
printf("LED is turned ON\r\n");
printf("\tLED is turned ON\r\n");
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
}
else
{
printf("LED is turned OFF\r\n");
printf("\tLED is turned OFF\r\n");
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
}
}

static void direct_method_cb(AZURE_IOT_NX_CONTEXT* nx_context,
static void command_received_cb(AZURE_IOT_NX_CONTEXT* nx_context_ptr,
const UCHAR* method,
USHORT method_length,
UCHAR* payload,
USHORT payload_length,
VOID* context,
VOID* context_ptr,
USHORT context_length)
{
UINT status;
UINT http_status = 501;
CHAR* http_response = "{}";

if (strncmp((CHAR*)method, SET_LED_STATE_COMMAND, method_length) == 0)
{
bool arg = (strncmp((CHAR*)payload, "true", payload_length) == 0);
set_led_state(arg);

azure_iot_nx_client_publish_bool_property(&azure_iot_nx_client, LED_STATE_PROPERTY, arg);
if ((status = nx_azure_iot_hub_client_command_message_response(
&nx_context_ptr->iothub_client, 200, context_ptr, context_length, NULL, 0, NX_WAIT_FOREVER)))
{
printf("Direct method response failed! (0x%08x)\r\n", status);
return;
}

http_status = 200;
azure_iot_nx_client_publish_bool_property(&azure_iot_nx_client, LED_STATE_PROPERTY, arg);
}

else if (strncmp((CHAR*)method, SET_DISPLAY_TEXT_COMMAND, method_length) == 0)
{
// drop the first and last character to remove the quotes
screen_printn((CHAR*)payload + 1, payload_length - 2, L0);

http_status = 200;
if ((status = nx_azure_iot_hub_client_command_message_response(
&nx_context_ptr->iothub_client, 200, context_ptr, context_length, NULL, 0, NX_WAIT_FOREVER)))
{
printf("Direct method response failed! (0x%08x)\r\n", status);
return;
}
}

if ((status = nx_azure_iot_hub_client_direct_method_message_response(&nx_context->iothub_client,
http_status,
context,
context_length,
(UCHAR*)http_response,
strlen(http_response),
NX_WAIT_FOREVER)))
else
{
printf("Direct method response failed! (0x%08x)\r\n", status);
return;
printf("Direct method is not for this device\r\n");

if ((status = nx_azure_iot_hub_client_command_message_response(
&nx_context_ptr->iothub_client, 501, context_ptr, context_length, NULL, 0, NX_WAIT_FOREVER)))
{
printf("Direct method response failed! (0x%08x)\r\n", status);
return;
}
}
}

static void device_twin_desired_property_cb(UCHAR* component_name,
static void writable_property_received_cb(AZURE_IOT_NX_CONTEXT* nx_context,
const UCHAR* component_name,
UINT component_name_len,
UCHAR* property_name,
UINT property_name_len,
NX_AZURE_IOT_JSON_READER property_value_reader,
UINT version,
VOID* userContextCallback)
NX_AZURE_IOT_JSON_READER* json_reader_ptr,
UINT version)
{
UINT status;
AZURE_IOT_NX_CONTEXT* nx_context = (AZURE_IOT_NX_CONTEXT*)userContextCallback;

if (strncmp((CHAR*)property_name, TELEMETRY_INTERVAL_PROPERTY, property_name_len) == 0)
{
status = nx_azure_iot_json_reader_token_int32_get(&property_value_reader, &telemetry_interval);
status = nx_azure_iot_json_reader_token_int32_get(json_reader_ptr, &telemetry_interval);
if (status == NX_AZURE_IOT_SUCCESS)
{
printf("\tUpdating %s to %ld\r\n", TELEMETRY_INTERVAL_PROPERTY, telemetry_interval);

// Confirm reception back to hub
azure_nx_client_respond_int_writeable_property(
azure_nx_client_respond_int_writable_property(
nx_context, TELEMETRY_INTERVAL_PROPERTY, telemetry_interval, 200, version);

// Set a telemetry event so we pick up the change immediately
Expand All @@ -288,17 +293,23 @@ static void device_twin_desired_property_cb(UCHAR* component_name,
}
}

static void device_twin_property_cb(UCHAR* component_name,
static void property_received_cb(AZURE_IOT_NX_CONTEXT* context,
const UCHAR* component_name,
UINT component_name_len,
UCHAR* property_name,
UINT property_name_len,
NX_AZURE_IOT_JSON_READER property_value_reader,
UINT version,
VOID* userContextCallback)
NX_AZURE_IOT_JSON_READER* json_reader_ptr,
UINT version)
{
UINT status;

if (strncmp((CHAR*)property_name, TELEMETRY_INTERVAL_PROPERTY, property_name_len) == 0)
{
nx_azure_iot_json_reader_token_int32_get(&property_value_reader, &telemetry_interval);
status = nx_azure_iot_json_reader_token_int32_get(json_reader_ptr, &telemetry_interval);
if (status == NX_AZURE_IOT_SUCCESS)
{
printf("\tUpdating %s to %ld\r\n", TELEMETRY_INTERVAL_PROPERTY, telemetry_interval);
}
}
}

Expand Down Expand Up @@ -350,25 +361,25 @@ UINT azure_iot_nx_client_entry(
}

// Register the callbacks
azure_iot_nx_client_register_direct_method(&azure_iot_nx_client, direct_method_cb);
azure_iot_nx_client_register_device_twin_desired_prop(&azure_iot_nx_client, device_twin_desired_property_cb);
azure_iot_nx_client_register_device_twin_prop(&azure_iot_nx_client, device_twin_property_cb);
azure_iot_nx_client_register_command_callback(&azure_iot_nx_client, command_received_cb);
azure_iot_nx_client_register_writable_property_callback(&azure_iot_nx_client, writable_property_received_cb);
azure_iot_nx_client_register_property_callback(&azure_iot_nx_client, property_received_cb);

if ((status = azure_iot_nx_client_connect(&azure_iot_nx_client)))
{
printf("ERROR: failed to connect nx client (0x%08x)\r\n", status);
return status;
}

// Request the device twin for writeable property update
if ((status = azure_iot_nx_client_device_twin_request_and_wait(&azure_iot_nx_client)))
// Request the device twin for writable property update
if ((status = azure_iot_nx_client_properties_request_and_wait(&azure_iot_nx_client)))
{
printf("ERROR: azure_iot_nx_client_device_twin_request_and_wait failed (0x%08x)\r\n", status);
printf("ERROR: azure_iot_nx_client_properties_request_and_wait failed (0x%08x)\r\n", status);
return status;
}

// Send out property updates
azure_iot_nx_client_publish_int_writeable_property(
azure_iot_nx_client_publish_int_writable_property(
&azure_iot_nx_client, TELEMETRY_INTERVAL_PROPERTY, telemetry_interval);
azure_iot_nx_client_publish_bool_property(&azure_iot_nx_client, LED_STATE_PROPERTY, false);
azure_iot_nx_client_publish_properties(
Expand All @@ -385,19 +396,20 @@ UINT azure_iot_nx_client_entry(
switch (telemetry_state)
{
case TELEMETRY_STATE_DEFAULT:
azure_iot_nx_client_publish_telemetry(&azure_iot_nx_client, append_device_telemetry);
azure_iot_nx_client_publish_telemetry(&azure_iot_nx_client, NULL, append_device_telemetry);
break;

case TELEMETRY_STATE_MAGNETOMETER:
azure_iot_nx_client_publish_telemetry(&azure_iot_nx_client, append_device_telemetry_magnetometer);
azure_iot_nx_client_publish_telemetry(&azure_iot_nx_client, NULL, append_device_telemetry_magnetometer);
break;

case TELEMETRY_STATE_ACCELEROMETER:
azure_iot_nx_client_publish_telemetry(&azure_iot_nx_client, append_device_telemetry_accelerometer);
azure_iot_nx_client_publish_telemetry(
&azure_iot_nx_client, NULL, append_device_telemetry_accelerometer);
break;

case TELEMETRY_STATE_GYROSCOPE:
azure_iot_nx_client_publish_telemetry(&azure_iot_nx_client, append_device_telemetry_gyroscope);
azure_iot_nx_client_publish_telemetry(&azure_iot_nx_client, NULL, append_device_telemetry_gyroscope);
break;

default:
Expand Down
2 changes: 1 addition & 1 deletion MXChip/AZ3166/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
scriptType: 'ps'
scriptLocation: 'scriptPath'
scriptPath: '$(Build.SourcesDirectory)\Device-Lab\generate_creds.ps1'
arguments: '$(Build.SourcesDirectory)\getting-started\core\model'
arguments: '$(Build.SourcesDirectory)\getting-started\shared\model'
useGlobalConfig: true
displayName: "Start Certification"

Expand Down
6 changes: 3 additions & 3 deletions MXChip/AZ3166/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ set(NXD_ENABLE_FILE_SERVERS OFF CACHE BOOL "Disable fileX dependency by netxduo"
set(NX_AZURE_DISABLE_IOT_SECURITY_MODULE OFF CACHE BOOL "Security Module")

# Core libraries
add_subdirectory(${CORE_LIB_DIR}/threadx threadx)
add_subdirectory(${CORE_LIB_DIR}/netxduo netxduo)
add_subdirectory(${CORE_LIB_DIR}/jsmn jsmn)
add_subdirectory(${SHARED_LIB_DIR}/threadx threadx)
add_subdirectory(${SHARED_LIB_DIR}/netxduo netxduo)
add_subdirectory(${SHARED_LIB_DIR}/jsmn jsmn)

add_subdirectory(stm32cubef4)
add_subdirectory(mxchip_bsp)
Expand Down
2 changes: 1 addition & 1 deletion MXChip/AZ3166/lib/wiced_sdk/binary_build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_STANDARD 99)

set(GSG_BASE_DIR ${CMAKE_SOURCE_DIR}/../../../../..)
set(CORE_LIB_DIR ${GSG_BASE_DIR}/core/lib)
set(SHARED_LIB_DIR ${GSG_BASE_DIR}/core/lib)

# use the repo version of ninja on Windows as there is no Ninja installer
if(WIN32)
Expand Down
6 changes: 3 additions & 3 deletions Microchip/ATSAME54-XPRO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
set(CMAKE_C_STANDARD 99)

set(GSG_BASE_DIR ${CMAKE_SOURCE_DIR}/../..)
set(CORE_SRC_DIR ${GSG_BASE_DIR}/core/src)
set(CORE_LIB_DIR ${GSG_BASE_DIR}/core/lib)
set(SHARED_SRC_DIR ${GSG_BASE_DIR}/shared/src)
set(SHARED_LIB_DIR ${GSG_BASE_DIR}/shared/lib)

# use the repo version of ninja on Windows as there is no Ninja installer
if(WIN32)
Expand All @@ -23,6 +23,6 @@ include(${GSG_BASE_DIR}/cmake/utilities.cmake)
# Define the Project
project(atsame54_azure_iot C ASM)

add_subdirectory(${CORE_SRC_DIR} core_src)
add_subdirectory(${SHARED_SRC_DIR} shared_src)
add_subdirectory(lib)
add_subdirectory(app)
Loading