Asked claude opus to make an audit of code and use coding guidelines etc. This is the fix
This commit is contained in:
@@ -26,6 +26,8 @@
|
||||
#include "mdns_service.cpp"
|
||||
// clang-format on
|
||||
|
||||
internal const char *kTagMain = "MAIN";
|
||||
|
||||
// Global Application State Definitions
|
||||
bool g_Ethernet_Initialized = false;
|
||||
bool g_Wifi_Initialized = false;
|
||||
@@ -35,9 +37,8 @@ constexpr bool kBlockUntilEthernetEstablished = false;
|
||||
|
||||
extern "C" void app_main()
|
||||
{
|
||||
printf("Hello, Calendink OTA! [V1.1]\n");
|
||||
|
||||
printf("PSRAM size: %d bytes\n", esp_psram_get_size());
|
||||
ESP_LOGI(kTagMain, "Hello, Calendink OTA! [V0.1.1]");
|
||||
ESP_LOGI(kTagMain, "PSRAM size: %d bytes", esp_psram_get_size());
|
||||
|
||||
httpd_handle_t web_server = NULL;
|
||||
|
||||
@@ -56,22 +57,22 @@ extern "C" void app_main()
|
||||
err = nvs_get_u8(my_handle, "www_part", &g_Active_WWW_Partition);
|
||||
if (err == ESP_OK)
|
||||
{
|
||||
printf("NVS: Found active www partition: %d\n", g_Active_WWW_Partition);
|
||||
ESP_LOGI(kTagMain, "NVS: Found active www partition: %d",
|
||||
g_Active_WWW_Partition);
|
||||
}
|
||||
|
||||
if (err == ESP_ERR_NVS_NOT_FOUND)
|
||||
{
|
||||
// First boot (no NVS key yet): default to www_0
|
||||
// This ensures that after a fresh USB flash (which only writes www_0),
|
||||
// we start from the correct partition.
|
||||
printf("No www_part in NVS, defaulting to 0.\n");
|
||||
ESP_LOGI(kTagMain, "No www_part in NVS, defaulting to 0.");
|
||||
g_Active_WWW_Partition = 0;
|
||||
nvs_set_u8(my_handle, "www_part", 0);
|
||||
nvs_commit(my_handle);
|
||||
}
|
||||
else if (err != ESP_OK)
|
||||
{
|
||||
printf("Error reading www_part from NVS: %s\n", esp_err_to_name(err));
|
||||
ESP_LOGE(kTagMain, "Error reading www_part from NVS: %s",
|
||||
esp_err_to_name(err));
|
||||
g_Active_WWW_Partition = 0;
|
||||
}
|
||||
|
||||
@@ -83,7 +84,7 @@ extern "C" void app_main()
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error opening NVS handle!\n");
|
||||
ESP_LOGE(kTagMain, "Error opening NVS handle!");
|
||||
}
|
||||
|
||||
// Detect if this is the first boot after a new flash (Firmware or Frontend)
|
||||
@@ -98,8 +99,8 @@ extern "C" void app_main()
|
||||
ESP_OK ||
|
||||
strcmp(last_time, current_time) != 0)
|
||||
{
|
||||
printf("New firmware detected! (Last: %s, Current: %s)\n",
|
||||
last_time[0] ? last_time : "None", current_time);
|
||||
ESP_LOGI(kTagMain, "New firmware detected! (Last: %s, Current: %s)",
|
||||
last_time[0] ? last_time : "None", current_time);
|
||||
is_new_flash = true;
|
||||
nvs_set_str(my_handle, "last_fw_time", current_time);
|
||||
}
|
||||
@@ -118,7 +119,7 @@ extern "C" void app_main()
|
||||
ESP_OK ||
|
||||
memcmp(last_sha, current_sha, 32) != 0)
|
||||
{
|
||||
printf("New frontend partition detected via SHA256!\n");
|
||||
ESP_LOGI(kTagMain, "New frontend partition detected via SHA256!");
|
||||
is_new_flash = true;
|
||||
nvs_set_blob(my_handle, "www0_sha", current_sha, 32);
|
||||
}
|
||||
@@ -141,8 +142,9 @@ extern "C" void app_main()
|
||||
{
|
||||
if (is_new_flash && g_Active_WWW_Partition != 0)
|
||||
{
|
||||
printf("FACTORY APP + NEW FLASH: Overriding www_part to 0 (was %d)\n",
|
||||
g_Active_WWW_Partition);
|
||||
ESP_LOGW(kTagMain,
|
||||
"FACTORY APP + NEW FLASH: Overriding www_part to 0 (was %d)",
|
||||
g_Active_WWW_Partition);
|
||||
g_Active_WWW_Partition = 0;
|
||||
|
||||
// Persist the override
|
||||
@@ -181,7 +183,7 @@ extern "C" void app_main()
|
||||
|
||||
if (result == ESP_ERR_INVALID_STATE)
|
||||
{
|
||||
printf("Ethernet cable not plugged in, skipping retries.\n");
|
||||
ESP_LOGW(kTagMain, "Ethernet cable not plugged in, skipping retries.");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -198,7 +200,7 @@ extern "C" void app_main()
|
||||
|
||||
if (result != ESP_OK)
|
||||
{
|
||||
printf("Ethernet failed, trying wifi\n");
|
||||
ESP_LOGW(kTagMain, "Ethernet failed, trying wifi");
|
||||
disconnect_ethernet();
|
||||
g_Ethernet_Initialized = false;
|
||||
|
||||
@@ -235,20 +237,20 @@ extern "C" void app_main()
|
||||
|
||||
if (result != ESP_OK)
|
||||
{
|
||||
printf("Wifi failed.\n");
|
||||
ESP_LOGE(kTagMain, "Wifi failed.");
|
||||
goto shutdown;
|
||||
}
|
||||
|
||||
set_led_status(led_status::ReadyWifi);
|
||||
printf("Will use Wifi!\n");
|
||||
ESP_LOGI(kTagMain, "Will use Wifi!");
|
||||
}
|
||||
else
|
||||
{
|
||||
set_led_status(led_status::ReadyEthernet);
|
||||
printf("Will use Ethernet!\n");
|
||||
ESP_LOGI(kTagMain, "Will use Ethernet!");
|
||||
}
|
||||
|
||||
printf("Connected! IP acquired.\n");
|
||||
ESP_LOGI(kTagMain, "Connected! IP acquired.");
|
||||
|
||||
// Start the webserver
|
||||
web_server = start_webserver();
|
||||
@@ -274,7 +276,7 @@ extern "C" void app_main()
|
||||
}
|
||||
|
||||
shutdown:
|
||||
printf("Shutting down.\n");
|
||||
ESP_LOGE(kTagMain, "Shutting down.");
|
||||
|
||||
if (web_server)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user