Skip to content

Commit f9a47de

Browse files
ci(pre-commit): Apply automatic fixes
1 parent 5c06561 commit f9a47de

File tree

4 files changed

+111
-114
lines changed

4 files changed

+111
-114
lines changed

libraries/Zigbee/examples/Zigbee_OTA_Client/Zigbee_OTA_Client.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ uint8_t led = RGB_BUILTIN;
3838
uint8_t button = BOOT_PIN;
3939

4040
/* Zigbee OTA configuration */
41-
#define OTA_UPGRADE_RUNNING_FILE_VERSION 0x01010100 // Increment this value when the running image is updated
42-
#define OTA_UPGRADE_DOWNLOADED_FILE_VERSION 0x01010101 // Increment this value when the downloaded image is updated
43-
#define OTA_UPGRADE_HW_VERSION 0x0101 // The hardware version, this can be used to differentiate between different hardware versions
41+
#define OTA_UPGRADE_RUNNING_FILE_VERSION 0x01010100 // Increment this value when the running image is updated
42+
#define OTA_UPGRADE_DOWNLOADED_FILE_VERSION 0x01010101 // Increment this value when the downloaded image is updated
43+
#define OTA_UPGRADE_HW_VERSION 0x0101 // The hardware version, this can be used to differentiate between different hardware versions
4444

4545
ZigbeeLight zbLight = ZigbeeLight(ZIGBEE_LIGHT_ENDPOINT);
4646

libraries/Zigbee/src/ZigbeeEP.cpp

+30-28
Original file line numberDiff line numberDiff line change
@@ -376,57 +376,59 @@ void ZigbeeEP::zbReadTimeCluster(const esp_zb_zcl_attribute_t *attribute) {
376376
// uint8_t max_data_size; /*!< The maximum size of OTA data */
377377
// } esp_zb_zcl_ota_upgrade_client_variable_t;
378378

379-
void ZigbeeEP::addOTAClient(uint32_t file_version, uint32_t downloaded_file_ver, uint16_t hw_version, uint16_t manufacturer, uint16_t image_type, uint8_t max_data_size) {
379+
void ZigbeeEP::addOTAClient(
380+
uint32_t file_version, uint32_t downloaded_file_ver, uint16_t hw_version, uint16_t manufacturer, uint16_t image_type, uint8_t max_data_size
381+
) {
380382

381383
esp_zb_ota_cluster_cfg_t ota_cluster_cfg = {};
382-
ota_cluster_cfg.ota_upgrade_file_version = file_version;//OTA_UPGRADE_RUNNING_FILE_VERSION;
383-
ota_cluster_cfg.ota_upgrade_downloaded_file_ver = downloaded_file_ver;//OTA_UPGRADE_DOWNLOADED_FILE_VERSION;
384-
ota_cluster_cfg.ota_upgrade_manufacturer = manufacturer;//OTA_UPGRADE_MANUFACTURER;
385-
ota_cluster_cfg.ota_upgrade_image_type = image_type;//OTA_UPGRADE_IMAGE_TYPE;
386-
384+
ota_cluster_cfg.ota_upgrade_file_version = file_version; //OTA_UPGRADE_RUNNING_FILE_VERSION;
385+
ota_cluster_cfg.ota_upgrade_downloaded_file_ver = downloaded_file_ver; //OTA_UPGRADE_DOWNLOADED_FILE_VERSION;
386+
ota_cluster_cfg.ota_upgrade_manufacturer = manufacturer; //OTA_UPGRADE_MANUFACTURER;
387+
ota_cluster_cfg.ota_upgrade_image_type = image_type; //OTA_UPGRADE_IMAGE_TYPE;
388+
387389
esp_zb_attribute_list_t *ota_cluster = esp_zb_ota_cluster_create(&ota_cluster_cfg);
388390

389391
esp_zb_zcl_ota_upgrade_client_variable_t variable_config = {};
390392
variable_config.timer_query = ESP_ZB_ZCL_OTA_UPGRADE_QUERY_TIMER_COUNT_DEF;
391-
variable_config.hw_version = hw_version;//OTA_UPGRADE_HW_VERSION;
392-
variable_config.max_data_size = max_data_size;//OTA_UPGRADE_MAX_DATA_SIZE;
393+
variable_config.hw_version = hw_version; //OTA_UPGRADE_HW_VERSION;
394+
variable_config.max_data_size = max_data_size; //OTA_UPGRADE_MAX_DATA_SIZE;
393395

394396
uint16_t ota_upgrade_server_addr = 0xffff;
395397
uint8_t ota_upgrade_server_ep = 0xff;
396398

397399
ESP_ERROR_CHECK(esp_zb_ota_cluster_add_attr(ota_cluster, ESP_ZB_ZCL_ATTR_OTA_UPGRADE_CLIENT_DATA_ID, (void *)&variable_config));
398400
ESP_ERROR_CHECK(esp_zb_ota_cluster_add_attr(ota_cluster, ESP_ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ADDR_ID, (void *)&ota_upgrade_server_addr));
399401
ESP_ERROR_CHECK(esp_zb_ota_cluster_add_attr(ota_cluster, ESP_ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ENDPOINT_ID, (void *)&ota_upgrade_server_ep));
400-
402+
401403
ESP_ERROR_CHECK(esp_zb_cluster_list_add_ota_cluster(_cluster_list, ota_cluster, ESP_ZB_ZCL_CLUSTER_CLIENT_ROLE));
402404
}
403405

404406
static void findOTAServer(esp_zb_zdp_status_t zdo_status, uint16_t addr, uint8_t endpoint, void *user_ctx) {
405407
if (zdo_status == ESP_ZB_ZDP_STATUS_SUCCESS) {
406-
esp_zb_ota_upgrade_client_query_interval_set(*((uint8_t *)user_ctx), OTA_UPGRADE_QUERY_INTERVAL);
407-
esp_zb_ota_upgrade_client_query_image_req(addr, endpoint);
408-
log_i("Query OTA upgrade from server endpoint: %d after %d seconds", endpoint, OTA_UPGRADE_QUERY_INTERVAL);
408+
esp_zb_ota_upgrade_client_query_interval_set(*((uint8_t *)user_ctx), OTA_UPGRADE_QUERY_INTERVAL);
409+
esp_zb_ota_upgrade_client_query_image_req(addr, endpoint);
410+
log_i("Query OTA upgrade from server endpoint: %d after %d seconds", endpoint, OTA_UPGRADE_QUERY_INTERVAL);
409411
} else {
410-
log_w("No OTA Server found");
412+
log_w("No OTA Server found");
411413
}
412414
}
413415

414416
void ZigbeeEP::requestOTAUpdate() {
415-
esp_zb_zdo_match_desc_req_param_t req;
416-
uint16_t cluster_list[] = {ESP_ZB_ZCL_CLUSTER_ID_OTA_UPGRADE};
417-
418-
/* Match the OTA server of coordinator */
419-
req.addr_of_interest = 0x0000;
420-
req.dst_nwk_addr = 0x0000;
421-
req.num_in_clusters = 1;
422-
req.num_out_clusters = 0;
423-
req.profile_id = ESP_ZB_AF_HA_PROFILE_ID;
424-
req.cluster_list = cluster_list;
425-
esp_zb_lock_acquire(portMAX_DELAY);
426-
if (esp_zb_bdb_dev_joined()) {
427-
esp_zb_zdo_match_cluster(&req, findOTAServer, &_endpoint);
428-
}
429-
esp_zb_lock_release();
417+
esp_zb_zdo_match_desc_req_param_t req;
418+
uint16_t cluster_list[] = {ESP_ZB_ZCL_CLUSTER_ID_OTA_UPGRADE};
419+
420+
/* Match the OTA server of coordinator */
421+
req.addr_of_interest = 0x0000;
422+
req.dst_nwk_addr = 0x0000;
423+
req.num_in_clusters = 1;
424+
req.num_out_clusters = 0;
425+
req.profile_id = ESP_ZB_AF_HA_PROFILE_ID;
426+
req.cluster_list = cluster_list;
427+
esp_zb_lock_acquire(portMAX_DELAY);
428+
if (esp_zb_bdb_dev_joined()) {
429+
esp_zb_zdo_match_cluster(&req, findOTAServer, &_endpoint);
430+
}
431+
esp_zb_lock_release();
430432
}
431433

432434
#endif //SOC_IEEE802154_SUPPORTED && CONFIG_ZB_ENABLED

libraries/Zigbee/src/ZigbeeEP.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#include <Arduino.h>
99

1010
/* Useful defines */
11-
#define ZB_CMD_TIMEOUT 10000 // 10 seconds
12-
#define OTA_UPGRADE_QUERY_INTERVAL (1 * 60) // 1 hour = 60 minutes
11+
#define ZB_CMD_TIMEOUT 10000 // 10 seconds
12+
#define OTA_UPGRADE_QUERY_INTERVAL (1 * 60) // 1 hour = 60 minutes
1313

1414
#define ZB_ARRAY_LENTH(arr) (sizeof(arr) / sizeof(arr[0]))
1515
#define XYZ_TO_RGB(X, Y, Z, r, g, b) \
@@ -119,8 +119,11 @@ class ZigbeeEP {
119119
* @param image_type The image type code (default: 0x1011).
120120
* @param max_data_size The maximum data size for OTA transfer (default and recommended: 223).
121121
*/
122-
void addOTAClient(uint32_t file_version, uint32_t downloaded_file_ver, uint16_t hw_version, uint16_t manufacturer = 0x1001, uint16_t image_type = 0x1011, uint8_t max_data_size = 223);
123-
/**
122+
void addOTAClient(
123+
uint32_t file_version, uint32_t downloaded_file_ver, uint16_t hw_version, uint16_t manufacturer = 0x1001, uint16_t image_type = 0x1011,
124+
uint8_t max_data_size = 223
125+
);
126+
/**
124127
* @brief Request OTA update from the server, first request is within a minute and the next requests are sent every hour automatically.
125128
*/
126129
void requestOTAUpdate();

libraries/Zigbee/src/ZigbeeHandlers.cpp

+71-79
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
#if SOC_IEEE802154_SUPPORTED && CONFIG_ZB_ENABLED
66

77
#include "esp_ota_ops.h"
8-
#if CONFIG_ZB_DELTA_OTA // Delta OTA, code is prepared for this feature but not enabled by default
8+
#if CONFIG_ZB_DELTA_OTA // Delta OTA, code is prepared for this feature but not enabled by default
99
#include "esp_delta_ota_ops.h"
1010
#endif
1111

1212
//OTA Upgrade defines and variables
13-
#define OTA_ELEMENT_HEADER_LEN 6 /* OTA element format header size include tag identifier and length field */
13+
#define OTA_ELEMENT_HEADER_LEN 6 /* OTA element format header size include tag identifier and length field */
1414

1515
/**
1616
* @name Enumeration for the tag identifier denotes the type and format of the data within the element
1717
* @anchor esp_ota_element_tag_id_t
1818
*/
1919
typedef enum esp_ota_element_tag_id_e {
20-
UPGRADE_IMAGE = 0x0000, /*!< Upgrade image */
20+
UPGRADE_IMAGE = 0x0000, /*!< Upgrade image */
2121
} esp_ota_element_tag_id_t;
2222

2323
static const esp_partition_t *s_ota_partition = NULL;
@@ -36,7 +36,6 @@ static esp_err_t zb_window_covering_movement_resp_handler(const esp_zb_zcl_windo
3636
static esp_err_t zb_ota_upgrade_status_handler(const esp_zb_zcl_ota_upgrade_value_message_t *message);
3737
static esp_err_t zb_ota_upgrade_query_image_resp_handler(const esp_zb_zcl_ota_upgrade_query_image_resp_message_t *message);
3838

39-
4039
// Zigbee action handlers
4140
[[maybe_unused]]
4241
static esp_err_t zb_action_handler(esp_zb_core_action_callback_id_t callback_id, const void *message) {
@@ -55,9 +54,7 @@ static esp_err_t zb_action_handler(esp_zb_core_action_callback_id_t callback_id,
5554
case ESP_ZB_CORE_WINDOW_COVERING_MOVEMENT_CB_ID:
5655
ret = zb_window_covering_movement_resp_handler((esp_zb_zcl_window_covering_movement_message_t *)message);
5756
break;
58-
case ESP_ZB_CORE_OTA_UPGRADE_VALUE_CB_ID:
59-
ret = zb_ota_upgrade_status_handler((esp_zb_zcl_ota_upgrade_value_message_t *)message);
60-
break;
57+
case ESP_ZB_CORE_OTA_UPGRADE_VALUE_CB_ID: ret = zb_ota_upgrade_status_handler((esp_zb_zcl_ota_upgrade_value_message_t *)message); break;
6158
case ESP_ZB_CORE_OTA_UPGRADE_QUERY_IMAGE_RESP_CB_ID:
6259
ret = zb_ota_upgrade_query_image_resp_handler((esp_zb_zcl_ota_upgrade_query_image_resp_message_t *)message);
6360
break;
@@ -237,21 +234,20 @@ static esp_err_t zb_window_covering_movement_resp_handler(const esp_zb_zcl_windo
237234
return ESP_OK;
238235
}
239236

240-
static esp_err_t esp_element_ota_data(uint32_t total_size, const void *payload, uint16_t payload_size, void **outbuf, uint16_t *outlen)
241-
{
237+
static esp_err_t esp_element_ota_data(uint32_t total_size, const void *payload, uint16_t payload_size, void **outbuf, uint16_t *outlen) {
242238
static uint16_t tagid = 0;
243239
void *data_buf = NULL;
244240
uint16_t data_len;
245241

246242
if (!s_tagid_received) {
247243
uint32_t length = 0;
248244
if (!payload || payload_size <= OTA_ELEMENT_HEADER_LEN) {
249-
log_e("Invalid element format");
250-
return ESP_ERR_INVALID_ARG;
245+
log_e("Invalid element format");
246+
return ESP_ERR_INVALID_ARG;
251247
}
252248

253249
const uint8_t *payload_ptr = (const uint8_t *)payload;
254-
tagid = *(const uint16_t *)payload_ptr;
250+
tagid = *(const uint16_t *)payload_ptr;
255251
length = *(const uint32_t *)(payload_ptr + sizeof(tagid));
256252
if ((length + OTA_ELEMENT_HEADER_LEN) != total_size) {
257253
log_e("Invalid element length [%ld/%ld]", length, total_size);
@@ -281,8 +277,7 @@ static esp_err_t esp_element_ota_data(uint32_t total_size, const void *payload,
281277
return ESP_OK;
282278
}
283279

284-
static esp_err_t zb_ota_upgrade_status_handler(const esp_zb_zcl_ota_upgrade_value_message_t *message)
285-
{
280+
static esp_err_t zb_ota_upgrade_status_handler(const esp_zb_zcl_ota_upgrade_value_message_t *message) {
286281
static uint32_t total_size = 0;
287282
static uint32_t offset = 0;
288283
[[maybe_unused]]
@@ -291,94 +286,91 @@ static esp_err_t zb_ota_upgrade_status_handler(const esp_zb_zcl_ota_upgrade_valu
291286

292287
if (message->info.status == ESP_ZB_ZCL_STATUS_SUCCESS) {
293288
switch (message->upgrade_status) {
294-
case ESP_ZB_ZCL_OTA_UPGRADE_STATUS_START:
295-
log_i("Zigbee - OTA upgrade start");
296-
start_time = esp_timer_get_time();
297-
s_ota_partition = esp_ota_get_next_update_partition(NULL);
298-
assert(s_ota_partition);
289+
case ESP_ZB_ZCL_OTA_UPGRADE_STATUS_START:
290+
log_i("Zigbee - OTA upgrade start");
291+
start_time = esp_timer_get_time();
292+
s_ota_partition = esp_ota_get_next_update_partition(NULL);
293+
assert(s_ota_partition);
299294
#if CONFIG_ZB_DELTA_OTA
300-
ret = esp_delta_ota_begin(s_ota_partition, 0, &s_ota_handle);
295+
ret = esp_delta_ota_begin(s_ota_partition, 0, &s_ota_handle);
301296
#else
302-
ret = esp_ota_begin(s_ota_partition, 0, &s_ota_handle);
297+
ret = esp_ota_begin(s_ota_partition, 0, &s_ota_handle);
303298
#endif
304-
if(ret != ESP_OK) {
305-
log_e("Zigbee - Failed to begin OTA partition, status: %s", esp_err_to_name(ret));
306-
return ret;
307-
}
308-
break;
309-
case ESP_ZB_ZCL_OTA_UPGRADE_STATUS_RECEIVE:
310-
total_size = message->ota_header.image_size;
311-
offset += message->payload_size;
312-
log_i("Zigbee - OTA Client receives data: progress [%ld/%ld]", offset, total_size);
313-
if (message->payload_size && message->payload) {
314-
uint16_t payload_size = 0;
315-
void *payload = NULL;
316-
ret = esp_element_ota_data(total_size, message->payload, message->payload_size, &payload, &payload_size);
317-
if(ret != ESP_OK) {
318-
log_e("Zigbee - Failed to element OTA data, status: %s", esp_err_to_name(ret));
299+
if (ret != ESP_OK) {
300+
log_e("Zigbee - Failed to begin OTA partition, status: %s", esp_err_to_name(ret));
319301
return ret;
320302
}
303+
break;
304+
case ESP_ZB_ZCL_OTA_UPGRADE_STATUS_RECEIVE:
305+
total_size = message->ota_header.image_size;
306+
offset += message->payload_size;
307+
log_i("Zigbee - OTA Client receives data: progress [%ld/%ld]", offset, total_size);
308+
if (message->payload_size && message->payload) {
309+
uint16_t payload_size = 0;
310+
void *payload = NULL;
311+
ret = esp_element_ota_data(total_size, message->payload, message->payload_size, &payload, &payload_size);
312+
if (ret != ESP_OK) {
313+
log_e("Zigbee - Failed to element OTA data, status: %s", esp_err_to_name(ret));
314+
return ret;
315+
}
321316
#if CONFIG_ZB_DELTA_OTA
322-
ret = esp_delta_ota_write(s_ota_handle, payload, payload_size);
317+
ret = esp_delta_ota_write(s_ota_handle, payload, payload_size);
323318
#else
324-
ret = esp_ota_write(s_ota_handle, (const void *)payload, payload_size);
319+
ret = esp_ota_write(s_ota_handle, (const void *)payload, payload_size);
325320
#endif
326-
if(ret != ESP_OK) {
327-
log_e("Zigbee - Failed to write OTA data to partition, status: %s", esp_err_to_name(ret));
328-
return ret;
321+
if (ret != ESP_OK) {
322+
log_e("Zigbee - Failed to write OTA data to partition, status: %s", esp_err_to_name(ret));
323+
return ret;
324+
}
329325
}
330-
}
331-
break;
332-
case ESP_ZB_ZCL_OTA_UPGRADE_STATUS_APPLY:
333-
log_i("Zigbee - OTA upgrade apply");
334-
break;
335-
case ESP_ZB_ZCL_OTA_UPGRADE_STATUS_CHECK:
336-
ret = offset == total_size ? ESP_OK : ESP_FAIL;
337-
offset = 0;
338-
total_size = 0;
339-
s_tagid_received = false;
340-
log_i("Zigbee - OTA upgrade check status: %s", esp_err_to_name(ret));
341-
break;
342-
case ESP_ZB_ZCL_OTA_UPGRADE_STATUS_FINISH:
343-
log_i("Zigbee - OTA Finish");
344-
log_i("Zigbee - OTA Information: version: 0x%lx, manufacturer code: 0x%x, image type: 0x%x, total size: %ld bytes, cost time: %lld ms,",
345-
message->ota_header.file_version, message->ota_header.manufacturer_code, message->ota_header.image_type,
346-
message->ota_header.image_size, (esp_timer_get_time() - start_time) / 1000);
326+
break;
327+
case ESP_ZB_ZCL_OTA_UPGRADE_STATUS_APPLY: log_i("Zigbee - OTA upgrade apply"); break;
328+
case ESP_ZB_ZCL_OTA_UPGRADE_STATUS_CHECK:
329+
ret = offset == total_size ? ESP_OK : ESP_FAIL;
330+
offset = 0;
331+
total_size = 0;
332+
s_tagid_received = false;
333+
log_i("Zigbee - OTA upgrade check status: %s", esp_err_to_name(ret));
334+
break;
335+
case ESP_ZB_ZCL_OTA_UPGRADE_STATUS_FINISH:
336+
log_i("Zigbee - OTA Finish");
337+
log_i(
338+
"Zigbee - OTA Information: version: 0x%lx, manufacturer code: 0x%x, image type: 0x%x, total size: %ld bytes, cost time: %lld ms,",
339+
message->ota_header.file_version, message->ota_header.manufacturer_code, message->ota_header.image_type, message->ota_header.image_size,
340+
(esp_timer_get_time() - start_time) / 1000
341+
);
347342
#if CONFIG_ZB_DELTA_OTA
348-
ret = esp_delta_ota_end(s_ota_handle);
343+
ret = esp_delta_ota_end(s_ota_handle);
349344
#else
350-
ret = esp_ota_end(s_ota_handle);
345+
ret = esp_ota_end(s_ota_handle);
351346
#endif
352-
if(ret != ESP_OK) {
353-
log_e("Zigbee - Failed to end OTA partition, status: %s", esp_err_to_name(ret));
354-
return ret;
355-
}
356-
ret = esp_ota_set_boot_partition(s_ota_partition);
357-
if(ret != ESP_OK) {
358-
log_e("Zigbee - Failed to set OTA boot partition, status: %s", esp_err_to_name(ret));
359-
return ret;
360-
}
361-
log_w("Zigbee - Prepare to restart system");
362-
esp_restart();
363-
break;
364-
default:
365-
log_i("Zigbee - OTA status: %d", message->upgrade_status);
366-
break;
347+
if (ret != ESP_OK) {
348+
log_e("Zigbee - Failed to end OTA partition, status: %s", esp_err_to_name(ret));
349+
return ret;
350+
}
351+
ret = esp_ota_set_boot_partition(s_ota_partition);
352+
if (ret != ESP_OK) {
353+
log_e("Zigbee - Failed to set OTA boot partition, status: %s", esp_err_to_name(ret));
354+
return ret;
355+
}
356+
log_w("Zigbee - Prepare to restart system");
357+
esp_restart();
358+
break;
359+
default: log_i("Zigbee - OTA status: %d", message->upgrade_status); break;
367360
}
368361
}
369362
return ret;
370363
}
371364

372-
static esp_err_t zb_ota_upgrade_query_image_resp_handler(const esp_zb_zcl_ota_upgrade_query_image_resp_message_t *message)
373-
{
365+
static esp_err_t zb_ota_upgrade_query_image_resp_handler(const esp_zb_zcl_ota_upgrade_query_image_resp_message_t *message) {
374366
if (message->info.status == ESP_ZB_ZCL_STATUS_SUCCESS) {
375367
log_i("Zigbee - Queried OTA image from address: 0x%04hx, endpoint: %d", message->server_addr.u.short_addr, message->server_endpoint);
376368
log_i("Zigbee - Image version: 0x%lx, manufacturer code: 0x%x, image size: %ld", message->file_version, message->manufacturer_code, message->image_size);
377-
if(message->image_size == 0) {
369+
if (message->image_size == 0) {
378370
log_i("Zigbee - Rejecting OTA image upgrade, image size is 0");
379371
return ESP_FAIL;
380372
}
381-
if(message->file_version == 0) {
373+
if (message->file_version == 0) {
382374
log_i("Zigbee - Rejecting OTA image upgrade, file version is 0");
383375
return ESP_FAIL;
384376
}

0 commit comments

Comments
 (0)