From 849d126ce08482d51a5a72cfe2dce3a371181bf6 Mon Sep 17 00:00:00 2001 From: Patedam Date: Tue, 3 Mar 2026 21:38:52 -0500 Subject: [PATCH] feat: Implement OTA status API with partition information, define ESP32 partition layout, add `ArrayCount` utility, and include agent interaction rules. --- Provider/.agents/rules/how-to-work-with-user.md | 5 +++++ Provider/main/api/ota/status.cpp | 15 ++++++++++----- Provider/main/utils.hpp | 8 ++++++++ Provider/partitions.csv | 7 +++++-- 4 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 Provider/.agents/rules/how-to-work-with-user.md create mode 100644 Provider/main/utils.hpp diff --git a/Provider/.agents/rules/how-to-work-with-user.md b/Provider/.agents/rules/how-to-work-with-user.md new file mode 100644 index 0000000..35bdc9e --- /dev/null +++ b/Provider/.agents/rules/how-to-work-with-user.md @@ -0,0 +1,5 @@ +--- +trigger: always_on +--- + +The way you must work with the human user is simple. When you finish a task, tell him what you did, what you think you should do next and ask for review and confirmation. Never go rogue. \ No newline at end of file diff --git a/Provider/main/api/ota/status.cpp b/Provider/main/api/ota/status.cpp index 8da18b0..dda8fe7 100644 --- a/Provider/main/api/ota/status.cpp +++ b/Provider/main/api/ota/status.cpp @@ -1,3 +1,5 @@ +#include + // SDK #include "cJSON.h" #include "esp_http_server.h" @@ -7,6 +9,7 @@ // Project #include "appstate.hpp" #include "types.hpp" +#include "utils.hpp" internal esp_err_t api_ota_status_handler(httpd_req_t *req) { @@ -17,22 +20,24 @@ internal esp_err_t api_ota_status_handler(httpd_req_t *req) cJSON_AddNumberToObject(root, "active_slot", g_Active_WWW_Partition); - const char *partitions[] = {"www_0", "www_1"}; + constexpr const char *kPartitions[] = {"www_0", "www_1", "ota_0", "ota_1", + "factory"}; + constexpr size_t kPartitionCount = ArrayCount(kPartitions); cJSON *parts_arr = cJSON_AddArrayToObject(root, "partitions"); - for (int i = 0; i < 2; i++) + for (size_t i = 0; i < kPartitionCount; i++) { cJSON *p_obj = cJSON_CreateObject(); - cJSON_AddStringToObject(p_obj, "label", partitions[i]); + cJSON_AddStringToObject(p_obj, "label", kPartitions[i]); const esp_partition_t *p = esp_partition_find_first( - ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, partitions[i]); + ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, kPartitions[i]); if (p) { cJSON_AddNumberToObject(p_obj, "size", p->size); size_t total = 0, used = 0; - if (esp_littlefs_info(partitions[i], &total, &used) == ESP_OK) + if (esp_littlefs_info(kPartitions[i], &total, &used) == ESP_OK) { cJSON_AddNumberToObject(p_obj, "used", used); cJSON_AddNumberToObject(p_obj, "free", total - used); diff --git a/Provider/main/utils.hpp b/Provider/main/utils.hpp new file mode 100644 index 0000000..111975f --- /dev/null +++ b/Provider/main/utils.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include + +template constexpr size_t ArrayCount(T (&)[N]) +{ + return N; +} \ No newline at end of file diff --git a/Provider/partitions.csv b/Provider/partitions.csv index 9c44e65..5039963 100644 --- a/Provider/partitions.csv +++ b/Provider/partitions.csv @@ -1,6 +1,9 @@ # Name, Type, SubType, Offset, Size, Flags nvs, data, nvs, 0x9000, 0x6000, -phy_init, data, phy, 0xf000, 0x1000, -factory, app, factory, 0x10000, 1M, +otadata, data, ota, , 0x2000, +phy_init, data, phy, , 0x1000, +factory, app, factory, , 2M, +ota_0, app, ota_0, , 2M, +ota_1, app, ota_1, , 2M, www_0, data, littlefs, , 1M, www_1, data, littlefs, , 1M,