better logging

This commit is contained in:
Thaddeus Hughes
2025-12-29 15:49:45 -06:00
parent 039c29a39d
commit 095a52fea7
10 changed files with 138 additions and 25 deletions

View File

@@ -13,4 +13,6 @@
<storageModule moduleId="org.eclipse.cdt.core.pathentry"> <storageModule moduleId="org.eclipse.cdt.core.pathentry">
<pathentry excluding="**/CMakeFiles/**" kind="out" path="build"/> <pathentry excluding="**/CMakeFiles/**" kind="out" path="build"/>
</storageModule> </storageModule>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
</cproject> </cproject>

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType"> <launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/> <booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/SC-F001/ota_deploy.bat}"/> <stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/SC-F001/ota_deploy.bat}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/> <stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/> <booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>

View File

@@ -0,0 +1,6 @@
doxygen/doxygen_new_line_after_brief=true
doxygen/doxygen_use_brief_tag=false
doxygen/doxygen_use_javadoc_tags=true
doxygen/doxygen_use_pre_tag=false
doxygen/doxygen_use_structural_commands=false
eclipse.preferences.version=1

View File

@@ -120,6 +120,8 @@ void app_main(void) {
send_log(); send_log();
//write_dummy_log_1();
// Check wake reasons // Check wake reasons
// If button held, we stay #woke // If button held, we stay #woke
@@ -147,9 +149,14 @@ void app_main(void) {
if (webserver_init() != ESP_OK) ESP_LOGE(TAG, "WEBSERVER FAILED"); if (webserver_init() != ESP_OK) ESP_LOGE(TAG, "WEBSERVER FAILED");
/*** MAIN LOOP ***/ /*** MAIN LOOP ***/
TickType_t xLastWakeTime = xTaskGetTickCount(); TickType_t xLastWakeTime = xTaskGetTickCount();
const TickType_t xFrequency = pdMS_TO_TICKS(100); const TickType_t xFrequency = pdMS_TO_TICKS(100);
while(true) {
ESP_LOGI(TAG, "TICK");
vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(1000));
esp_task_wdt_reset();
}
while(true) { while(true) {
vTaskDelayUntil(&xLastWakeTime, xFrequency); vTaskDelayUntil(&xLastWakeTime, xFrequency);
@@ -183,7 +190,7 @@ void app_main(void) {
break; break;
case STATE_UNDO_JACK: case STATE_UNDO_JACK:
case STATE_UNDO_JACK_START: case STATE_UNDO_JACK_START:
// assume it's running // it's running the jack, but undoing
send_log(); send_log();
driveLEDs(LED_STATE_CANCELLING); driveLEDs(LED_STATE_CANCELLING);
if (i2c_get_button_tripped(0)) { if (i2c_get_button_tripped(0)) {
@@ -193,7 +200,7 @@ void app_main(void) {
break; break;
default: default:
// assume it's running in every other case // it's running in every other case
send_log(); send_log();
driveLEDs(LED_STATE_DRIVING); driveLEDs(LED_STATE_DRIVING);
if (i2c_get_button_tripped(0)) { if (i2c_get_button_tripped(0)) {

View File

@@ -48,13 +48,19 @@ const char* parameter_names[NUM_PARAMS] = {
// Partition pointer // Partition pointer
static const esp_partition_t *storage_partition = NULL; static const esp_partition_t *storage_partition = NULL;
// Log head tracking
static uint32_t log_head_index = 0;
static bool log_initialized = false;
// Calculate offset for log area (after parameters sector) // Calculate offset for log area (after parameters sector)
#define LOG_START_OFFSET FLASH_SECTOR_SIZE #define LOG_START_OFFSET FLASH_SECTOR_SIZE
// Log head tracking
static uint32_t log_head_index = 0;
static uint32_t log_tail_index = 0;
uint32_t get_log_head() { return LOG_START_OFFSET + (log_head_index * LOG_ENTRY_SIZE); }
uint32_t get_log_tail() { return LOG_START_OFFSET + (log_tail_index * LOG_ENTRY_SIZE); }
uint32_t get_log_offset() { return LOG_START_OFFSET; }
static bool log_initialized = false;
// ============================================================================ // ============================================================================
// PARAMETER FUNCTIONS // PARAMETER FUNCTIONS
// ============================================================================ // ============================================================================
@@ -283,6 +289,14 @@ esp_err_t write_log(char* entry) {
err = esp_partition_erase_range(storage_partition, err = esp_partition_erase_range(storage_partition,
next_sector * FLASH_SECTOR_SIZE, next_sector * FLASH_SECTOR_SIZE,
FLASH_SECTOR_SIZE); FLASH_SECTOR_SIZE);
log_tail_index = (next_sector)*FLASH_SECTOR_SIZE/LOG_ENTRY_SIZE;
if (log_tail_index >= max_entries)
log_tail_index = 0;
ESP_LOGI(TAG, "Tail/Head are now %ld/%ld", (long)log_tail_index, (long)log_head_index);
if (err != ESP_OK) { if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to erase sector: %s", esp_err_to_name(err)); ESP_LOGE(TAG, "Failed to erase sector: %s", esp_err_to_name(err));
return ESP_FAIL; return ESP_FAIL;
@@ -313,6 +327,45 @@ esp_err_t write_log(char* entry) {
return ESP_OK; return ESP_OK;
} }
esp_err_t write_dummy_log_1() {
log_head_index = 0;
log_tail_index = 0;
uint32_t log_area_end = storage_partition->size;
uint32_t max_entries = (log_area_end - LOG_START_OFFSET) / LOG_ENTRY_SIZE;
for (uint32_t i=0; i<max_entries*3/2; i++) {
ESP_LOGI(TAG, "log[%ld]", (long)i);
char entry[32] = {32, i>>24,i>>16,i>>8,i>>0};
write_log(entry);
}
return ESP_OK;
}
esp_err_t write_dummy_log_2() {
log_head_index = 56;
log_tail_index = 105;
uint32_t log_area_end = storage_partition->size;
uint32_t max_entries = (log_area_end - LOG_START_OFFSET) / LOG_ENTRY_SIZE;
for (uint32_t i=0; i<max_entries*3/2; i++) {
ESP_LOGI(TAG, "log[%ld]", (long)i);
char entry[32] = {32, i>>24,i>>16,i>>8,i>>0};
write_log(entry);
}
return ESP_OK;
}
esp_err_t write_dummy_log_3() {
log_head_index = 105;
log_tail_index = 34;
uint32_t log_area_end = storage_partition->size;
uint32_t max_entries = (log_area_end - LOG_START_OFFSET) / LOG_ENTRY_SIZE;
for (uint32_t i=0; i<max_entries*3/2; i++) {
ESP_LOGI(TAG, "log[%ld]", (long)i);
char entry[32] = {32, i>>24,i>>16,i>>8,i>>0};
write_log(entry);
}
return ESP_OK;
}
void storage_deinit(void) { void storage_deinit(void) {
storage_partition = NULL; storage_partition = NULL;
log_initialized = false; log_initialized = false;

View File

@@ -131,6 +131,13 @@ param_value_t get_param_default(param_idx_t id);
esp_err_t commit_params(); esp_err_t commit_params();
uint32_t get_log_head();
uint32_t get_log_tail();
uint32_t get_log_offset();
esp_err_t write_dummy_log_1();
esp_err_t write_dummy_log_2();
esp_err_t write_dummy_log_3();
#define LOG_ENTRY_SIZE 32 #define LOG_ENTRY_SIZE 32

View File

@@ -33,7 +33,7 @@
#define HOSTNAME "sc.local" #define HOSTNAME "sc.local"
#define SOFT_AP_SSID "stockcropper" #define SOFT_AP_SSID "sc_main"
#define SOFT_AP_PASSWORD "stockcropper" #define SOFT_AP_PASSWORD "stockcropper"
#define SERVER_PORT 80 #define SERVER_PORT 80
@@ -62,29 +62,64 @@ static esp_err_t log_get_handler(httpd_req_t *req) {
ESP_LOGE(TAG, "Storage partition not found"); ESP_LOGE(TAG, "Storage partition not found");
return httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Storage partition not found"); return httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Storage partition not found");
} }
int32_t start = get_log_tail();
int32_t end = get_log_head();
int32_t total_size = end - start;
int32_t offset = start;
if (start >= end) {
total_size = storage_partition->size - start + end - get_log_offset();
}
ESP_LOGI(TAG, "start/end: %ld/%ld -> %ld", (long)start, (long)end, (long)total_size);
size_t total_size = storage_partition->size; //size_t total_size = storage_partition->size;
char len_str[16]; char len_str[16];
sprintf(len_str, "%u", (unsigned)total_size); sprintf(len_str, "%u", (unsigned)total_size);
httpd_resp_set_type(req, "application/octet-stream"); httpd_resp_set_type(req, "application/octet-stream");
httpd_resp_set_hdr(req, "Content-Disposition", "attachment; filename=\"sc_storage.bin\""); httpd_resp_set_hdr(req, "Content-Disposition", "attachment; filename=\"sc_storage.bin\"");
httpd_resp_set_hdr(req, "Content-Length", len_str); httpd_resp_set_hdr(req, "Content-Length", len_str);
uint8_t buf[1024]; if (start >= end) {
size_t offset = 0; ESP_LOGI(TAG, "STARTING");
while (offset < total_size) { while (offset < storage_partition->size) {
size_t to_read = MIN(sizeof(buf), total_size - offset); // if wrapped around, just go from the start all the way to the end of storage
esp_err_t err = esp_partition_read(storage_partition, offset, buf, to_read); // then set start = get_log_offset();
// and continue
size_t to_read = MIN(sizeof(httpBuffer), storage_partition->size - offset);
esp_err_t err = esp_partition_read(storage_partition, offset, httpBuffer, to_read);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to read partition: %s", esp_err_to_name(err));
return httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to read storage");
}
ESP_LOGI(TAG, "Sending %ld x %d", (long) offset, to_read);
if (httpd_resp_send_chunk(req, (const char *)httpBuffer, to_read) != ESP_OK) {
ESP_LOGE(TAG, "Failed to send chunk");
return ESP_FAIL;
}
offset += to_read;
}
offset = get_log_offset();
}
while (offset < end) {
ESP_LOGI(TAG, "FINISHING");
// if wrapped around, just go from the start all the way to the end of storage
// then set start = get_log_offset();
// and continue
size_t to_read = MIN(sizeof(httpBuffer), end - offset);
esp_err_t err = esp_partition_read(storage_partition, offset, httpBuffer, to_read);
if (err != ESP_OK) { if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to read partition: %s", esp_err_to_name(err)); ESP_LOGE(TAG, "Failed to read partition: %s", esp_err_to_name(err));
return httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to read storage"); return httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to read storage");
} }
if (httpd_resp_send_chunk(req, (const char *)buf, to_read) != ESP_OK) { ESP_LOGI(TAG, "Sending %ld x %d", (long) offset, to_read);
if (httpd_resp_send_chunk(req, (const char *)httpBuffer, to_read) != ESP_OK) {
ESP_LOGE(TAG, "Failed to send chunk"); ESP_LOGE(TAG, "Failed to send chunk");
return ESP_FAIL; return ESP_FAIL;
} }
offset += to_read; offset += to_read;
} }
// End chunked transfer // End chunked transfer
httpd_resp_send_chunk(req, NULL, 0); httpd_resp_send_chunk(req, NULL, 0);
@@ -244,6 +279,7 @@ static esp_err_t ota_post_handler(httpd_req_t *req) {
return ESP_OK; return ESP_OK;
} }
httpd_uri_t uris[] = {{ httpd_uri_t uris[] = {{
.uri = "/status", .uri = "/status",
.method = HTTP_GET, .method = HTTP_GET,
@@ -336,6 +372,7 @@ void launchSoftAp() {
wifi_config_t wifi_config = { wifi_config_t wifi_config = {
.ap = { .ap = {
.channel = 8,
.ssid = SOFT_AP_SSID, .ssid = SOFT_AP_SSID,
.ssid_len = strlen(SOFT_AP_SSID), .ssid_len = strlen(SOFT_AP_SSID),
.password = SOFT_AP_PASSWORD, .password = SOFT_AP_PASSWORD,

View File

@@ -3,6 +3,6 @@
nvs, data, nvs, 0x9000, 0x4000, nvs, data, nvs, 0x9000, 0x4000,
otadata, data, ota, 0xd000, 0x2000, otadata, data, ota, 0xd000, 0x2000,
phy_init, data, phy, 0xf000, 0x1000, phy_init, data, phy, 0xf000, 0x1000,
ota_0, app, ota_0, 0x10000, 2M, ota_0, app, ota_0, 0x10000, 1M,
ota_1, app, ota_1, 0x210000, 2M, ota_1, app, ota_1, 0x210000, 1M,
storage, data, 0x40, 0x410000, 4032K, storage, data, 0x40, 0x310000, 32K,
1 # ESP32 Partition Table - 8MB Flash with OTA Support
3 nvs, data, nvs, 0x9000, 0x4000,
4 otadata, data, ota, 0xd000, 0x2000,
5 phy_init, data, phy, 0xf000, 0x1000,
6 ota_0, app, ota_0, 0x10000, 2M, ota_0, app, ota_0, 0x10000, 1M,
7 ota_1, app, ota_1, 0x210000, 2M, ota_1, app, ota_1, 0x210000, 1M,
8 storage, data, 0x40, 0x410000, 4032K, storage, data, 0x40, 0x310000, 32K,

View File

@@ -354,13 +354,13 @@ CONFIG_ESPTOOLPY_FLASHFREQ_40M=y
CONFIG_ESPTOOLPY_FLASHFREQ="40m" CONFIG_ESPTOOLPY_FLASHFREQ="40m"
# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set # CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set # CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_4MB is not set CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y # CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set # CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set # CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set # CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set # CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set
CONFIG_ESPTOOLPY_FLASHSIZE="8MB" CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
# CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE is not set # CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE is not set
CONFIG_ESPTOOLPY_BEFORE_RESET=y CONFIG_ESPTOOLPY_BEFORE_RESET=y
# CONFIG_ESPTOOLPY_BEFORE_NORESET is not set # CONFIG_ESPTOOLPY_BEFORE_NORESET is not set

View File

@@ -353,14 +353,14 @@ CONFIG_ESPTOOLPY_FLASHFREQ_40M=y
# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set # CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set
CONFIG_ESPTOOLPY_FLASHFREQ="40m" CONFIG_ESPTOOLPY_FLASHFREQ="40m"
# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set # CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set
CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y # CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_4MB is not set # CONFIG_ESPTOOLPY_FLASHSIZE_4MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set # CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set # CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set # CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set
# CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set # CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set
CONFIG_ESPTOOLPY_FLASHSIZE="2MB" CONFIG_ESPTOOLPY_FLASHSIZE="8MB"
# CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE is not set # CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE is not set
CONFIG_ESPTOOLPY_BEFORE_RESET=y CONFIG_ESPTOOLPY_BEFORE_RESET=y
# CONFIG_ESPTOOLPY_BEFORE_NORESET is not set # CONFIG_ESPTOOLPY_BEFORE_NORESET is not set