Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Flipper-Zero/STM32CubeWB.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Projects/P-NUCLEO-WB55.Nucleo/Applications/Zigbee/Zigbee_MeterId_Server_Coord/STM32_WPAN/App/app_zigbee.c')
-rw-r--r--Projects/P-NUCLEO-WB55.Nucleo/Applications/Zigbee/Zigbee_MeterId_Server_Coord/STM32_WPAN/App/app_zigbee.c225
1 files changed, 136 insertions, 89 deletions
diff --git a/Projects/P-NUCLEO-WB55.Nucleo/Applications/Zigbee/Zigbee_MeterId_Server_Coord/STM32_WPAN/App/app_zigbee.c b/Projects/P-NUCLEO-WB55.Nucleo/Applications/Zigbee/Zigbee_MeterId_Server_Coord/STM32_WPAN/App/app_zigbee.c
index d1f0a6b74..12351884a 100644
--- a/Projects/P-NUCLEO-WB55.Nucleo/Applications/Zigbee/Zigbee_MeterId_Server_Coord/STM32_WPAN/App/app_zigbee.c
+++ b/Projects/P-NUCLEO-WB55.Nucleo/Applications/Zigbee/Zigbee_MeterId_Server_Coord/STM32_WPAN/App/app_zigbee.c
@@ -1,20 +1,22 @@
+/* USER CODE BEGIN Header */
/**
******************************************************************************
- * File Name : App/app_zigbee.c
- * Description : Zigbee Application.
- ******************************************************************************
- * @attention
- *
- * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
- * All rights reserved.</center></h2>
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * www.st.com/SLA0044
- *
- ******************************************************************************
- */
+ * File Name : App/app_zigbee.c
+ * Description : Zigbee Application.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
+ * All rights reserved.</center></h2>
+ *
+ * This software component is licensed by ST under Ultimate Liberty license
+ * SLA0044, the "License"; You may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at:
+ * www.st.com/SLA0044
+ *
+ ******************************************************************************
+ */
+/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "app_common.h"
@@ -29,31 +31,47 @@
#include "zigbee_types.h"
#include "stm32_seq.h"
+/* Private includes -----------------------------------------------------------*/
#include <assert.h>
#include "zcl/zcl.h"
#include "zcl/zcl.meter.id.h"
-/* external definition */
-enum ZbStatusCodeT ZbStartupWait(struct ZigBeeT *zb, struct ZbStartupT *config);
+/* USER CODE BEGIN Includes */
+/* USER CODE END Includes */
+
+/* Private typedef -----------------------------------------------------------*/
+/* USER CODE BEGIN PTD */
+/* USER CODE END PTD */
/* Private defines -----------------------------------------------------------*/
#define APP_ZIGBEE_STARTUP_FAIL_DELAY 500U
-#define SW1_ENDPOINT 17
#define CHANNEL 19
+
+#define SW1_ENDPOINT 17
+
+/* USER CODE BEGIN PD */
#define NB_MAX_STRING 10
-/* Meter Identification specific defines -------------------------------------------------*/
+/* Meter Identification specific defines -------------------------------------*/
#define GENERIC_METER_TYPE 0x0110
#define COMPANY_NAME "ST"
#define METER_TYPE_ID GENERIC_METER_TYPE
+/* USER CODE END PD */
+
+/* Private macros ------------------------------------------------------------*/
+/* USER CODE BEGIN PM */
+/* USER CODE END PM */
+
+/* External definition -------------------------------------------------------*/
+enum ZbStatusCodeT ZbStartupWait(struct ZigBeeT *zb, struct ZbStartupT *config);
+
+/* USER CODE BEGIN ED */
+/* USER CODE END ED */
/* Private function prototypes -----------------------------------------------*/
static void APP_ZIGBEE_StackLayersInit(void);
static void APP_ZIGBEE_ConfigEndpoints(void);
static void APP_ZIGBEE_NwkForm(void);
-static void APP_ZIGBEE_App_Init(void);
-
-static void APP_ZIGBEE_MeterId_Server_Init(void);
static void APP_ZIGBEE_TraceError(const char *pMess, uint32_t ErrCode);
static void APP_ZIGBEE_CheckWirelessFirmwareInfo(void);
@@ -62,7 +80,12 @@ static void Wait_Getting_Ack_From_M0(void);
static void Receive_Ack_From_M0(void);
static void Receive_Notification_From_M0(void);
-/* Private variables -----------------------------------------------*/
+/* USER CODE BEGIN PFP */
+static void APP_ZIGBEE_App_Init(void);
+static void APP_ZIGBEE_MeterId_Server_Init(void);
+/* USER CODE END PFP */
+
+/* Private variables ---------------------------------------------------------*/
static TL_CmdPacket_t *p_ZIGBEE_otcmdbuffer;
static TL_EvtPacket_t *p_ZIGBEE_notif_M0_to_M4;
static TL_EvtPacket_t *p_ZIGBEE_request_M0_to_M4;
@@ -77,13 +100,17 @@ PLACE_IN_SECTION("MB_MEM2") ALIGN(4) static uint8_t ZigbeeNotifRequestBuffer[siz
struct zigbee_app_info {
bool has_init;
struct ZigBeeT *zb;
+ enum ZbStartType startupControl;
enum ZbStatusCodeT join_status;
uint32_t join_delay;
+ bool init_after_join;
- struct ZbZclClusterT *meterid_server_1;
+ struct ZbZclClusterT *meter_id_server_1;
};
static struct zigbee_app_info zigbee_app_info;
+/* USER CODE BEGIN PV */
+/* USER CODE END PV */
/* Functions Definition ------------------------------------------------------*/
/**
@@ -91,54 +118,6 @@ static struct zigbee_app_info zigbee_app_info;
* @param None
* @retval None
*/
-static void APP_ZIGBEE_App_Init(void){
- /* Initialize Zigbee Meter Identification Server parameters */
- APP_ZIGBEE_MeterId_Server_Init();
-}
-
-/**
- * @brief Meter Identification server initialization
- * @param None
- * @retval None
- */
-static void APP_ZIGBEE_MeterId_Server_Init(void){
- enum ZclStatusCodeT status;
-
- /* Compute company name string in ZCL string format */
-
- uint8_t ZCL_company_mame_string_size = sizeof(COMPANY_NAME)/sizeof(uint8_t)+1;
- uint8_t buf[NB_MAX_STRING] = COMPANY_NAME;
- uint8_t ZCL_company_mame_string[NB_MAX_STRING+1];
- memset(ZCL_company_mame_string, 0, ZCL_company_mame_string_size);
-
- ZCL_company_mame_string[0] = ZCL_company_mame_string_size;
- memcpy(&ZCL_company_mame_string[1], &buf, ZCL_company_mame_string_size);
- ZCL_company_mame_string[ZCL_company_mame_string_size+1] = '\0';
-
- /* ZCL_METER_ID_ATTR_COMPANY_NAME attribute init */
- APP_DBG("[METER ID] Writing Company Name attribute.");
- status = ZbZclAttrStringWriteShort(zigbee_app_info.meterid_server_1, ZCL_METER_ID_ATTR_COMPANY_NAME, (const uint8_t*)&ZCL_company_mame_string);
- if(status != ZCL_STATUS_SUCCESS){
- APP_DBG("[METER ID] Error writting local attribute.");
- assert(0);
- }
-
- /* ZCL_METER_ID_ATTR_METER_TYPE_ID attribute init */
- APP_DBG("[METER ID] Writing Meter Type ID attribute.");
- status = ZbZclAttrIntegerWrite(zigbee_app_info.meterid_server_1, ZCL_METER_ID_ATTR_METER_TYPE_ID, METER_TYPE_ID);
- if(status != ZCL_STATUS_SUCCESS){
- APP_DBG("[METER ID] Error writting local attribute.");
- assert(0);
- }
-
- APP_DBG("[METER ID] Meter Identification server init done!\n");
-} /* APP_ZIGBEE_MeterId_Server_Init */
-
-/**
- * @brief Zigbee application initialization
- * @param None
- * @retval None
- */
void APP_ZIGBEE_Init(void)
{
SHCI_CmdStatus_t ZigbeeInitStatus;
@@ -163,8 +142,11 @@ void APP_ZIGBEE_Init(void)
/* Task associated with network creation process */
UTIL_SEQ_RegTask(1U << CFG_TASK_ZIGBEE_NETWORK_FORM, UTIL_SEQ_RFU, APP_ZIGBEE_NwkForm);
- /* Task associated with application init */
+ /* USER CODE BEGIN APP_ZIGBEE_INIT */
+ /* Task associated with application init */
UTIL_SEQ_RegTask(1U << CFG_TASK_ZIGBEE_APP_START, UTIL_SEQ_RFU, APP_ZIGBEE_App_Init);
+ /* USER CODE END APP_ZIGBEE_INIT */
+
/* Start the Zigbee on the CPU2 side */
ZigbeeInitStatus = SHCI_C2_ZIGBEE_Init();
/* Prevent unused argument(s) compilation warning */
@@ -172,8 +154,6 @@ void APP_ZIGBEE_Init(void)
/* Initialize Zigbee stack layers */
APP_ZIGBEE_StackLayersInit();
-
-
} /* APP_ZIGBEE_Init */
@@ -192,13 +172,16 @@ static void APP_ZIGBEE_StackLayersInit(void)
/* Create the endpoint and cluster(s) */
APP_ZIGBEE_ConfigEndpoints();
+ /* USER CODE BEGIN APP_ZIGBEE_StackLayersInit */
BSP_LED_Off(LED_RED);
BSP_LED_Off(LED_GREEN);
BSP_LED_Off(LED_BLUE);
+ /* USER CODE END APP_ZIGBEE_StackLayersInit */
/* Configure the joining parameters */
zigbee_app_info.join_status = (enum ZbStatusCodeT) 0x01; /* init to error status */
zigbee_app_info.join_delay = HAL_GetTick(); /* now */
+ zigbee_app_info.startupControl = ZbStartTypeForm;
/* Initialization Complete */
zigbee_app_info.has_init = true;
@@ -218,18 +201,21 @@ static void APP_ZIGBEE_ConfigEndpoints(void)
ZbApsmeAddEndpointConfT conf;
memset(&req, 0, sizeof(req));
- req.profileId = ZCL_PROFILE_HOME_AUTOMATION;
- req.deviceId = ZCL_DEVICE_METER_INTERFACE;
/* Endpoint: SW1_ENDPOINT */
+ req.profileId = ZCL_PROFILE_HOME_AUTOMATION;
+ req.deviceId = ZCL_DEVICE_ONOFF_SWITCH;
req.endpoint = SW1_ENDPOINT;
ZbZclAddEndpoint(zigbee_app_info.zb, &req, &conf);
assert(conf.status == ZB_STATUS_SUCCESS);
- /* Meter Identification Server */
- zigbee_app_info.meterid_server_1 = ZbZclMeterIdServerAlloc(zigbee_app_info.zb, SW1_ENDPOINT);
- assert(zigbee_app_info.meterid_server_1 != NULL);
- ZbZclClusterEndpointRegister(zigbee_app_info.meterid_server_1);
+ /* Meter id server */
+ zigbee_app_info.meter_id_server_1 = ZbZclMeterIdServerAlloc(zigbee_app_info.zb, SW1_ENDPOINT);
+ assert(zigbee_app_info.meter_id_server_1 != NULL);
+ ZbZclClusterEndpointRegister(zigbee_app_info.meter_id_server_1);
+
+ /* USER CODE BEGIN CONFIG_ENDPOINT */
+ /* USER CODE END CONFIG_ENDPOINT */
} /* APP_ZIGBEE_ConfigEndpoints */
/**
@@ -244,15 +230,15 @@ static void APP_ZIGBEE_NwkForm(void)
struct ZbStartupT config;
enum ZbStatusCodeT status;
- /* Configure Zigbee Logging (only need to do this once, but this is a good place to put it) */
+ /* Configure Zigbee Logging */
ZbSetLogging(zigbee_app_info.zb, ZB_LOG_MASK_LEVEL_5, NULL);
/* Attempt to join a zigbee network */
ZbStartupConfigGetProDefaults(&config);
/* Set the centralized network */
- APP_DBG("Network config : APP_STARTUP_CENTRALIZED_COORD");
- config.startupControl = ZbStartTypeForm;
+ APP_DBG("Network config : APP_STARTUP_CENTRALIZED_COORDINATOR");
+ config.startupControl = zigbee_app_info.startupControl;
/* Using the default HA preconfigured Link Key */
memcpy(config.security.preconfiguredLinkKey, sec_key_ha, ZB_SEC_KEYSIZE);
@@ -261,20 +247,22 @@ static void APP_ZIGBEE_NwkForm(void)
config.channelList.list[0].page = 0;
config.channelList.list[0].channelMask = 1 << CHANNEL; /*Channel in use */
- /* Using ZbStartupWait (blocking) here instead of ZbStartup, in order to demonstrate how to do
- * a blocking call on the M4. */
+ /* Using ZbStartupWait (blocking) */
status = ZbStartupWait(zigbee_app_info.zb, &config);
APP_DBG("ZbStartup Callback (status = 0x%02x)", status);
zigbee_app_info.join_status = status;
if (status == ZB_STATUS_SUCCESS) {
+ /* USER CODE BEGIN 0 */
zigbee_app_info.join_delay = 0U;
+ zigbee_app_info.init_after_join = true;
BSP_LED_On(LED_BLUE);
}
else
{
- APP_DBG("Startup failed, re-attempting to form a network after a short delay (%d ms)", APP_ZIGBEE_STARTUP_FAIL_DELAY);
+ /* USER CODE END 0 */
+ APP_DBG("Startup failed, attempting again after a short delay (%d ms)", APP_ZIGBEE_STARTUP_FAIL_DELAY);
zigbee_app_info.join_delay = HAL_GetTick() + APP_ZIGBEE_STARTUP_FAIL_DELAY;
}
}
@@ -284,8 +272,11 @@ static void APP_ZIGBEE_NwkForm(void)
{
UTIL_SEQ_SetTask(1U << CFG_TASK_ZIGBEE_NETWORK_FORM, CFG_SCH_PRIO_0);
}
+
+ /* USER CODE BEGIN NW_FORM */
else
{
+ zigbee_app_info.init_after_join = false;
/* Since we're using group addressing (broadcast), shorten the broadcast timeout */
uint32_t bcast_timeout = 3;
@@ -294,6 +285,7 @@ static void APP_ZIGBEE_NwkForm(void)
/* Starting application init task */
UTIL_SEQ_SetTask(1U << CFG_TASK_ZIGBEE_APP_START, CFG_SCH_PRIO_0);
+ /* USER CODE END NW_FORM */
} /* APP_ZIGBEE_NwkForm */
/*************************************************************
@@ -358,8 +350,7 @@ void APP_ZIGBEE_Error(uint32_t ErrId, uint32_t ErrCode)
*************************************************************/
/**
- * @brief Warn the user that an error has occurred.In this case,
- * the LEDs on the Board will start blinking.
+ * @brief Warn the user that an error has occurred.
*
* @param pMess : Message associated to the error.
* @param ErrCode: Error code associated to the module (Zigbee or other module if any)
@@ -368,6 +359,7 @@ void APP_ZIGBEE_Error(uint32_t ErrId, uint32_t ErrCode)
static void APP_ZIGBEE_TraceError(const char *pMess, uint32_t ErrCode)
{
APP_DBG("**** Fatal error = %s (Err = %d)", pMess, ErrCode);
+ /* USER CODE BEGIN TRACE_ERROR */
while (1U == 1U) {
BSP_LED_Toggle(LED1);
HAL_Delay(500U);
@@ -376,6 +368,8 @@ static void APP_ZIGBEE_TraceError(const char *pMess, uint32_t ErrCode)
BSP_LED_Toggle(LED3);
HAL_Delay(500U);
}
+ /* USER CODE END TRACE_ERROR */
+
} /* APP_ZIGBEE_TraceError */
/**
@@ -602,5 +596,58 @@ void APP_ZIGBEE_ProcessRequestM0ToM4(void)
CptReceiveRequestFromM0 = 0;
}
}
+/* USER CODE BEGIN FD_LOCAL_FUNCTIONS */
+
+/**
+ * @brief Zigbee application initialization
+ * @param None
+ * @retval None
+ */
+static void APP_ZIGBEE_App_Init(void){
+ /* Initialize Zigbee Meter Identification Server parameters */
+ APP_ZIGBEE_MeterId_Server_Init();
+}
+
+/**
+ * @brief Meter Identification server initialization
+ * @param None
+ * @retval None
+ */
+static void APP_ZIGBEE_MeterId_Server_Init(void){
+ enum ZclStatusCodeT status;
+
+ /* Compute company name string in ZCL string format */
+
+ uint8_t ZCL_company_mame_string_size = sizeof(COMPANY_NAME)/sizeof(uint8_t)+1;
+ uint8_t buf[NB_MAX_STRING] = COMPANY_NAME;
+ uint8_t ZCL_company_mame_string[NB_MAX_STRING+1];
+ memset(ZCL_company_mame_string, 0, ZCL_company_mame_string_size);
+
+ ZCL_company_mame_string[0] = ZCL_company_mame_string_size;
+ memcpy(&ZCL_company_mame_string[1], &buf, ZCL_company_mame_string_size);
+ ZCL_company_mame_string[ZCL_company_mame_string_size+1] = '\0';
+
+ /* ZCL_METER_ID_ATTR_COMPANY_NAME attribute init */
+ APP_DBG("[METER ID] Writing Company Name attribute.");
+ status = ZbZclAttrStringWriteShort(zigbee_app_info.meter_id_server_1, ZCL_METER_ID_ATTR_COMPANY_NAME, (const uint8_t*)&ZCL_company_mame_string);
+ if(status != ZCL_STATUS_SUCCESS){
+ APP_DBG("[METER ID] Error writting local attribute.");
+ assert(0);
+ }
+
+ /* ZCL_METER_ID_ATTR_METER_TYPE_ID attribute init */
+ APP_DBG("[METER ID] Writing Meter Type ID attribute.");
+ status = ZbZclAttrIntegerWrite(zigbee_app_info.meter_id_server_1, ZCL_METER_ID_ATTR_METER_TYPE_ID, METER_TYPE_ID);
+ if(status != ZCL_STATUS_SUCCESS){
+ APP_DBG("[METER ID] Error writting local attribute.");
+ assert(0);
+ }
+
+ APP_DBG("[METER ID] Meter Identification server init done!\n");
+} /* APP_ZIGBEE_MeterId_Server_Init */
+
+
+/* USER CODE END FD_LOCAL_FUNCTIONS */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+