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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user