better logging
This commit is contained in:
@@ -13,4 +13,6 @@
|
||||
<storageModule moduleId="org.eclipse.cdt.core.pathentry">
|
||||
<pathentry excluding="**/CMakeFiles/**" kind="out" path="build"/>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
|
||||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
|
||||
</cproject>
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
|
||||
<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_RUN_BUILD_KINDS" value="full,incremental,"/>
|
||||
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
|
||||
|
||||
6
.settings/org.eclipse.cdt.core.prefs
Normal file
6
.settings/org.eclipse.cdt.core.prefs
Normal 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
|
||||
13
main/main.c
13
main/main.c
@@ -121,6 +121,8 @@ void app_main(void) {
|
||||
|
||||
send_log();
|
||||
|
||||
//write_dummy_log_1();
|
||||
|
||||
// Check wake reasons
|
||||
// If button held, we stay #woke
|
||||
// If not it must've been the RTC - check alarms
|
||||
@@ -147,10 +149,15 @@ void app_main(void) {
|
||||
if (webserver_init() != ESP_OK) ESP_LOGE(TAG, "WEBSERVER FAILED");
|
||||
|
||||
/*** MAIN LOOP ***/
|
||||
|
||||
TickType_t xLastWakeTime = xTaskGetTickCount();
|
||||
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) {
|
||||
vTaskDelayUntil(&xLastWakeTime, xFrequency);
|
||||
|
||||
@@ -183,7 +190,7 @@ void app_main(void) {
|
||||
break;
|
||||
case STATE_UNDO_JACK:
|
||||
case STATE_UNDO_JACK_START:
|
||||
// assume it's running
|
||||
// it's running the jack, but undoing
|
||||
send_log();
|
||||
driveLEDs(LED_STATE_CANCELLING);
|
||||
if (i2c_get_button_tripped(0)) {
|
||||
@@ -193,7 +200,7 @@ void app_main(void) {
|
||||
break;
|
||||
|
||||
default:
|
||||
// assume it's running in every other case
|
||||
// it's running in every other case
|
||||
send_log();
|
||||
driveLEDs(LED_STATE_DRIVING);
|
||||
if (i2c_get_button_tripped(0)) {
|
||||
|
||||
@@ -48,13 +48,19 @@ const char* parameter_names[NUM_PARAMS] = {
|
||||
// Partition pointer
|
||||
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)
|
||||
#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
|
||||
// ============================================================================
|
||||
@@ -283,6 +289,14 @@ esp_err_t write_log(char* entry) {
|
||||
err = esp_partition_erase_range(storage_partition,
|
||||
next_sector * 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) {
|
||||
ESP_LOGE(TAG, "Failed to erase sector: %s", esp_err_to_name(err));
|
||||
return ESP_FAIL;
|
||||
@@ -313,6 +327,45 @@ esp_err_t write_log(char* entry) {
|
||||
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) {
|
||||
storage_partition = NULL;
|
||||
log_initialized = false;
|
||||
|
||||
@@ -131,6 +131,13 @@ param_value_t get_param_default(param_idx_t id);
|
||||
|
||||
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
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
|
||||
#define HOSTNAME "sc.local"
|
||||
#define SOFT_AP_SSID "stockcropper"
|
||||
#define SOFT_AP_SSID "sc_main"
|
||||
#define SOFT_AP_PASSWORD "stockcropper"
|
||||
#define SERVER_PORT 80
|
||||
|
||||
@@ -63,23 +63,58 @@ static esp_err_t log_get_handler(httpd_req_t *req) {
|
||||
return httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Storage partition not found");
|
||||
}
|
||||
|
||||
size_t total_size = storage_partition->size;
|
||||
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;
|
||||
char len_str[16];
|
||||
sprintf(len_str, "%u", (unsigned)total_size);
|
||||
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-Length", len_str);
|
||||
|
||||
uint8_t buf[1024];
|
||||
size_t offset = 0;
|
||||
while (offset < total_size) {
|
||||
size_t to_read = MIN(sizeof(buf), total_size - offset);
|
||||
esp_err_t err = esp_partition_read(storage_partition, offset, buf, to_read);
|
||||
if (start >= end) {
|
||||
ESP_LOGI(TAG, "STARTING");
|
||||
while (offset < storage_partition->size) {
|
||||
// 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), 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");
|
||||
}
|
||||
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");
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
@@ -244,6 +279,7 @@ static esp_err_t ota_post_handler(httpd_req_t *req) {
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
httpd_uri_t uris[] = {{
|
||||
.uri = "/status",
|
||||
.method = HTTP_GET,
|
||||
@@ -336,6 +372,7 @@ void launchSoftAp() {
|
||||
|
||||
wifi_config_t wifi_config = {
|
||||
.ap = {
|
||||
.channel = 8,
|
||||
.ssid = SOFT_AP_SSID,
|
||||
.ssid_len = strlen(SOFT_AP_SSID),
|
||||
.password = SOFT_AP_PASSWORD,
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
nvs, data, nvs, 0x9000, 0x4000,
|
||||
otadata, data, ota, 0xd000, 0x2000,
|
||||
phy_init, data, phy, 0xf000, 0x1000,
|
||||
ota_0, app, ota_0, 0x10000, 2M,
|
||||
ota_1, app, ota_1, 0x210000, 2M,
|
||||
storage, data, 0x40, 0x410000, 4032K,
|
||||
ota_0, app, ota_0, 0x10000, 1M,
|
||||
ota_1, app, ota_1, 0x210000, 1M,
|
||||
storage, data, 0x40, 0x310000, 32K,
|
||||
|
@@ -354,13 +354,13 @@ CONFIG_ESPTOOLPY_FLASHFREQ_40M=y
|
||||
CONFIG_ESPTOOLPY_FLASHFREQ="40m"
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_4MB is not set
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_64MB 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_BEFORE_RESET=y
|
||||
# CONFIG_ESPTOOLPY_BEFORE_NORESET is not set
|
||||
|
||||
@@ -353,14 +353,14 @@ CONFIG_ESPTOOLPY_FLASHFREQ_40M=y
|
||||
# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set
|
||||
CONFIG_ESPTOOLPY_FLASHFREQ="40m"
|
||||
# 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_8MB is not set
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_64MB 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_BEFORE_RESET=y
|
||||
# CONFIG_ESPTOOLPY_BEFORE_NORESET is not set
|
||||
|
||||
Reference in New Issue
Block a user