feat: Implement OTA status API with partition information, define ESP32 partition layout, add ArrayCount utility, and include agent interaction rules.

This commit is contained in:
2026-03-03 21:38:52 -05:00
parent ad65bf520b
commit 849d126ce0
4 changed files with 28 additions and 7 deletions

View File

@@ -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.

View File

@@ -1,3 +1,5 @@
#include <cstddef>
// SDK // SDK
#include "cJSON.h" #include "cJSON.h"
#include "esp_http_server.h" #include "esp_http_server.h"
@@ -7,6 +9,7 @@
// Project // Project
#include "appstate.hpp" #include "appstate.hpp"
#include "types.hpp" #include "types.hpp"
#include "utils.hpp"
internal esp_err_t api_ota_status_handler(httpd_req_t *req) 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); 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"); 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 *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( 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) if (p)
{ {
cJSON_AddNumberToObject(p_obj, "size", p->size); cJSON_AddNumberToObject(p_obj, "size", p->size);
size_t total = 0, used = 0; 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, "used", used);
cJSON_AddNumberToObject(p_obj, "free", total - used); cJSON_AddNumberToObject(p_obj, "free", total - used);

8
Provider/main/utils.hpp Normal file
View File

@@ -0,0 +1,8 @@
#pragma once
#include <types.hpp>
template <typename T, size_t N> constexpr size_t ArrayCount(T (&)[N])
{
return N;
}

View File

@@ -1,6 +1,9 @@
# Name, Type, SubType, Offset, Size, Flags # Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x6000, nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000, otadata, data, ota, , 0x2000,
factory, app, factory, 0x10000, 1M, 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_0, data, littlefs, , 1M,
www_1, data, littlefs, , 1M, www_1, data, littlefs, , 1M,
1 # Name Type SubType Offset Size Flags
2 nvs data nvs 0x9000 0x6000
3 phy_init otadata data phy ota 0xf000 0x1000 0x2000
4 factory phy_init app data factory phy 0x10000 1M 0x1000
5 factory app factory 2M
6 ota_0 app ota_0 2M
7 ota_1 app ota_1 2M
8 www_0 data littlefs 1M
9 www_1 data littlefs 1M