-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Paul D.Smith
committed
Jan 4, 2024
1 parent
b56d423
commit 96ccf10
Showing
15 changed files
with
224 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
* Copyright (c) 2023 Paul D.Smith ([email protected]). | ||
* License: Free to copy providing the author is acknowledged. | ||
*/ | ||
#pragma once | ||
|
||
/** | ||
* The T-ZigBee board has a reset key (which just cuts power when pressed) and | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
* Copyright (c) 2023 Paul D.Smith ([email protected]). | ||
* License: Free to copy providing the author is acknowledged. | ||
*/ | ||
#pragma once | ||
|
||
#include "nvs.h" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
* Copyright (c) 2023 Paul D.Smith ([email protected]). | ||
* License: Free to copy providing the author is acknowledged. | ||
*/ | ||
#pragma once | ||
|
||
typedef enum { | ||
CS_FLASH_EVENT_FLASH_TIMER, /* Event from the timer callback. */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
* Copyright (c) 2023 Paul D.Smith ([email protected]). | ||
* License: Free to copy providing the author is acknowledged. | ||
*/ | ||
#pragma once | ||
|
||
/** | ||
* There are three ESP32c3 GPIO lines used by the T-Zigbee | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
* Copyright (c) 2023 Paul D.Smith ([email protected]). | ||
* License: Free to copy providing the author is acknowledged. | ||
*/ | ||
#pragma once | ||
|
||
typedef struct | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
/* | ||
* Copyright (c) 2023 Paul D.Smith ([email protected]). | ||
* License: Free to copy providing the author is acknowledged. | ||
* | ||
* Configuration store using ESP-IDF no-volatile storage. | ||
* https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/storage/nvs_flash.html?highlight=non%20volatile | ||
*/ | ||
*/ | ||
#include <stdio.h> | ||
#include "freertos/FreeRTOS.h" | ||
#include "freertos/task.h" | ||
|
@@ -33,7 +30,7 @@ | |
#define TAG cs_ota_task_name | ||
|
||
/** | ||
* Define the ZIGBEE events base. | ||
* Define the OTA events base. | ||
*/ | ||
ESP_EVENT_DEFINE_BASE(CS_OTA_EVENT); | ||
|
||
|
@@ -42,15 +39,12 @@ ESP_EVENT_DEFINE_BASE(CS_OTA_EVENT); | |
#define SEMVER_FORMAT_NO_DEV "%hu.%hu.%hu" | ||
|
||
// Task config. | ||
// TODO: Use this everywhere! | ||
#define CS_TASK_TICKS_TO_WAIT CONFIG_CS_TASK_TICKS_TO_WAIT | ||
|
||
static esp_event_loop_handle_t ota_event_loop_handle; | ||
|
||
esp_timer_handle_t ota_retry_timer_handle; | ||
esp_timer_handle_t ota_acceptance_timer_handle; | ||
|
||
static void ota_acceptance(void); | ||
|
||
// TODO: move this out into a header file? | ||
typedef struct | ||
{ | ||
uint16_t major; | ||
|
@@ -59,13 +53,6 @@ typedef struct | |
uint16_t dev; | ||
} ota_version_t; | ||
|
||
typedef struct | ||
{ | ||
int tag; | ||
bool allow_dev; | ||
ota_version_t *version; | ||
} xml_user_data_t; | ||
|
||
static esp_err_t http_event_handler(esp_http_client_event_t *evt) | ||
{ | ||
ota_version_t *version; | ||
|
@@ -368,7 +355,7 @@ bool do_we_upgrade(ota_version_t *version, bool *upgrade) | |
* TODO: What is ower outage trashes the image? Will it get downloaded again | ||
* and retried? | ||
*/ | ||
static void start_ota() | ||
static void start_ota(esp_timer_handle_t ota_retry_timer_handle) | ||
{ | ||
bool success = true; | ||
bool do_upgrade; | ||
|
@@ -422,12 +409,17 @@ static void start_ota() | |
static void default_event_handler(void *arg, esp_event_base_t event_base, | ||
int32_t event_id, void *event_data) | ||
{ | ||
esp_event_loop_handle_t ota_event_loop_handle = (esp_event_loop_handle_t)arg; | ||
|
||
esp_event_post_to(ota_event_loop_handle, event_base, event_id, NULL, 0, 0); | ||
} | ||
|
||
static void event_handler(void *arg, esp_event_base_t event_base, | ||
int32_t event_id, void *event_data) | ||
{ | ||
esp_timer_handle_t ota_retry_timer_handle = (esp_timer_handle_t)arg; | ||
|
||
|
||
if (event_base == CS_OTA_EVENT) | ||
{ | ||
switch (event_id) | ||
|
@@ -437,7 +429,7 @@ static void event_handler(void *arg, esp_event_base_t event_base, | |
break; | ||
|
||
case CS_OTA_EVENT_START_OTA_TIMER: | ||
start_ota(); | ||
start_ota(ota_retry_timer_handle); | ||
break; | ||
|
||
default: | ||
|
@@ -453,7 +445,7 @@ static void event_handler(void *arg, esp_event_base_t event_base, | |
/** | ||
* We are connected so check for OTA update. | ||
*/ | ||
start_ota(); | ||
start_ota(ota_retry_timer_handle); | ||
break; | ||
|
||
case WIFI_EVENT_STA_DISCONNECTED: | ||
|
@@ -487,6 +479,8 @@ static void event_handler(void *arg, esp_event_base_t event_base, | |
// TODO: Use local function prototypes so can order code nicely. | ||
void ota_retry_timer_cb(void *arg) | ||
{ | ||
esp_event_loop_handle_t ota_event_loop_handle = (esp_event_loop_handle_t)arg; | ||
|
||
// (Re)Start the OTA process. | ||
esp_event_post_to(ota_event_loop_handle, CS_OTA_EVENT, CS_OTA_EVENT_START_OTA_TIMER, NULL, 0, 10); | ||
} | ||
|
@@ -504,21 +498,17 @@ static void ota_acceptance(void) | |
|
||
static void ota_acceptance_timer_cb(void *arg) | ||
{ | ||
esp_event_loop_handle_t ota_event_loop_handle = (esp_event_loop_handle_t)arg; | ||
|
||
esp_event_post_to(ota_event_loop_handle, CS_OTA_EVENT, CS_OTA_EVENT_ACCEPTANCE_TIMER, NULL, 0, 10); | ||
} | ||
|
||
static esp_timer_create_args_t esp_ota_timer_create_args = { | ||
.callback = ota_retry_timer_cb, | ||
.name = "OTA timer" | ||
}; | ||
|
||
static esp_timer_create_args_t esp_acceptance_timer_create_args = { | ||
.callback = ota_acceptance_timer_cb, | ||
.name = "OTA acceptance" | ||
}; | ||
|
||
void cs_ota_task(cs_ota_create_parms_t *create_parms) | ||
{ | ||
esp_event_loop_handle_t ota_event_loop_handle = NULL; | ||
esp_timer_handle_t ota_retry_timer_handle; | ||
esp_timer_handle_t ota_acceptance_timer_handle; | ||
|
||
// TODO: Remove this. | ||
esp_log_level_set(TAG, ESP_LOG_VERBOSE); | ||
|
||
|
@@ -537,30 +527,42 @@ void cs_ota_task(cs_ota_create_parms_t *create_parms) | |
WIFI_EVENT, | ||
ESP_EVENT_ANY_ID, | ||
default_event_handler, | ||
NULL, | ||
ota_event_loop_handle, | ||
NULL)); | ||
ESP_ERROR_CHECK(esp_event_handler_instance_register_with( | ||
ota_event_loop_handle, | ||
WIFI_EVENT, | ||
ESP_EVENT_ANY_ID, | ||
event_handler, | ||
NULL, | ||
ota_retry_timer_handle, | ||
NULL)); | ||
ESP_ERROR_CHECK(esp_event_handler_instance_register_with( | ||
ota_event_loop_handle, | ||
CS_CONFIG_EVENT, | ||
CS_CONFIG_CHANGE, | ||
event_handler, | ||
NULL, | ||
ota_retry_timer_handle, | ||
NULL)); | ||
ESP_ERROR_CHECK(esp_event_handler_instance_register_with( | ||
ota_event_loop_handle, | ||
CS_OTA_EVENT, | ||
ESP_EVENT_ANY_ID, | ||
event_handler, | ||
NULL, | ||
ota_retry_timer_handle, | ||
NULL)); | ||
|
||
esp_timer_create_args_t esp_ota_timer_create_args = { | ||
.callback = ota_retry_timer_cb, | ||
.name = "OTA timer", | ||
.arg = ota_event_loop_handle | ||
}; | ||
|
||
esp_timer_create_args_t esp_acceptance_timer_create_args = { | ||
.callback = ota_acceptance_timer_cb, | ||
.name = "OTA acceptance", | ||
.arg = ota_event_loop_handle | ||
}; | ||
|
||
// Create the acceptance timer and callback. | ||
ESP_ERROR_CHECK(esp_timer_create(&esp_acceptance_timer_create_args, &ota_acceptance_timer_handle)); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
ESP_EVENT_DECLARE_BASE(CS_OTA_EVENT); | ||
/* | ||
* Copyright (c) 2023 Paul D.Smith ([email protected]). | ||
* License: Free to copy providing the author is acknowledged. | ||
*/ | ||
#pragma once | ||
|
||
/** Time event declarations */ | ||
typedef enum { | ||
CS_OTA_EVENT_ACCEPTANCE_TIMER = 0, /**< Attributes. */ | ||
CS_OTA_EVENT_START_OTA_TIMER, /**< Attributes. */ | ||
} ota_event_t; | ||
|
||
ESP_EVENT_DECLARE_BASE(CS_OTA_EVENT); | ||
|
||
typedef struct | ||
{ | ||
esp_event_loop_handle_t ota_event_loop_handle; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
/* | ||
* Copyright (c) 2023 Paul D.Smith ([email protected]). | ||
* License: Free to copy providing the author is acknowledged. | ||
* | ||
* Configuration store using ESP-IDF no-volatile storage. | ||
* https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/storage/nvs_flash.html?highlight=non%20volatile | ||
* | ||
* Note that this API operates on the default NVRAM partition. | ||
*/ | ||
#include "esp_event.h" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
/* | ||
* Copyright (c) 2023 Paul D.Smith ([email protected]). | ||
* License: Free to copy providing the author is acknowledged. | ||
* | ||
* Configuration store using ESP-IDF no-volatile storage. | ||
* https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/storage/nvs_flash.html?highlight=non%20volatile | ||
* | ||
* Note that this API operates on the default NVRAM partition. | ||
*/ | ||
#pragma once | ||
|
||
#include "esp_event.h" | ||
|
||
ESP_EVENT_DECLARE_BASE(CS_TIME_EVENT); | ||
|
Oops, something went wrong.