This commit is contained in:
Thaddeus Hughes
2026-03-04 17:41:58 -06:00
parent 6ce5dae3a4
commit e2451fce78
21 changed files with 9013 additions and 7 deletions

View File

@@ -42,8 +42,12 @@ typedef enum {
STATE_CALIBRATE_DRIVE_DELAY,
STATE_CALIBRATE_DRIVE_MOVE
} fsm_state_t;
#define LOG_TYPE_BAT 100
#define LOG_TYPE_CRASH 101
#define LOG_TYPE_BAT 100
#define LOG_TYPE_CRASH 101
#define LOG_TYPE_BOOT 102 // Every boot: [ts_ms u64][boot_info u8]
// boot_info bits[3:0] = esp_reset_reason_t
// boot_info bits[7:4] = esp_sleep_wakeup_cause_t (non-zero only when reset=DEEPSLEEP)
#define LOG_TYPE_TIME_SET 103 // Time sync: [ts_ms u64]
typedef enum {
RELAY_SENSORS = 0,

View File

@@ -174,8 +174,19 @@ void app_main(void) {esp_task_wdt_add(NULL);
if (storage_init() != ESP_OK) ESP_LOGE(TAG, "STORAGE FAILED");
if (log_init() != ESP_OK) ESP_LOGE(TAG, "LOG FAILED");
// Write a crash log entry if we rebooted unexpectedly
esp_reset_reason_t reset_reason = esp_reset_reason();
esp_sleep_wakeup_cause_t wake_cause = esp_sleep_get_wakeup_cause();
// Log every boot: boot_info = wake_cause[7:4] | reset_reason[3:0]
{
uint8_t boot_entry[9] = {};
uint64_t ts = rtc_get_ms();
memcpy(&boot_entry[0], &ts, 8);
boot_entry[8] = ((uint8_t)wake_cause << 4) | ((uint8_t)reset_reason & 0x0F);
log_write(boot_entry, sizeof(boot_entry), LOG_TYPE_BOOT);
}
// Write a crash log entry if we rebooted unexpectedly
if (reset_reason == ESP_RST_PANIC ||
reset_reason == ESP_RST_INT_WDT ||
reset_reason == ESP_RST_TASK_WDT ||

View File

@@ -100,6 +100,9 @@ void rtc_set_s(int64_t tv_sec)
rtc_backup_s = tv_sec;
solar_reset_fsm();
rtc_schedule_next_alarm();
uint64_t ts_ms = (uint64_t)tv_sec * 1000ULL;
log_write((uint8_t*)&ts_ms, sizeof(ts_ms), LOG_TYPE_TIME_SET);
}
void rtc_save_time(void)