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:
5
Provider/.agents/rules/how-to-work-with-user.md
Normal file
5
Provider/.agents/rules/how-to-work-with-user.md
Normal 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.
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <cstddef>
|
||||
|
||||
// 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);
|
||||
|
||||
8
Provider/main/utils.hpp
Normal file
8
Provider/main/utils.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <types.hpp>
|
||||
|
||||
template <typename T, size_t N> constexpr size_t ArrayCount(T (&)[N])
|
||||
{
|
||||
return N;
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
|
Reference in New Issue
Block a user