Skip to content

Feat: Implement enhanced logging and config validation (Phase 1)#3

Open
leontappe wants to merge 2 commits into
mainfrom
fix-state-loading-and-crash
Open

Feat: Implement enhanced logging and config validation (Phase 1)#3
leontappe wants to merge 2 commits into
mainfrom
fix-state-loading-and-crash

Conversation

@leontappe

Copy link
Copy Markdown
Owner

This commit introduces Phase 1 of robustness improvements:

  1. Enhanced Logging for State Management:

    • Added logs for state enable/disable actions (OBDState::setEnabled).
    • Added logs for changes to state update intervals (OBDState::setUpdateInterval).
    • Added logs when lastUpdate timestamps are set (TypedOBDState::readValue, TypedOBDState::calcValue).
    • Added detailed, conditional (via DEBUG_STATE_FILTERING macro) logging in OBDStates::nextState to show reasons for state filtering.
  2. Configuration Validation for states.json:

    • Added OBDClass::validateStates() method, called after states are loaded.
    • Logs INFO for very short update intervals.
    • Logs WARNING for enabled CALC states without calculation expressions.
  3. Basic Configuration Validation for settings.json:

    • Added SettingsClass::validateSettings() method, called after settings load/parse.
    • Validates and logs INFO/WARNINGs for general, WiFi, and OBD2 settings (e.g., sleep duration, empty AP SSID, OBD2 adapter name/MAC, protocol character validity).

This commit introduces Phase 1 of robustness improvements:

1.  **Enhanced Logging for State Management:**
    *   Added logs for state enable/disable actions (`OBDState::setEnabled`).
    *   Added logs for changes to state update intervals (`OBDState::setUpdateInterval`).
    *   Added logs when `lastUpdate` timestamps are set (`TypedOBDState::readValue`, `TypedOBDState::calcValue`).
    *   Added detailed, conditional (via `DEBUG_STATE_FILTERING` macro) logging in `OBDStates::nextState` to show reasons for state filtering.

2.  **Configuration Validation for `states.json`:**
    *   Added `OBDClass::validateStates()` method, called after states are loaded.
    *   Logs INFO for very short update intervals.
    *   Logs WARNING for enabled CALC states without calculation expressions.

3.  **Basic Configuration Validation for `settings.json`:**
    *   Added `SettingsClass::validateSettings()` method, called after settings load/parse.
    *   Validates and logs INFO/WARNINGs for general, WiFi, and OBD2 settings (e.g., sleep duration, empty AP SSID, OBD2 adapter name/MAC, protocol character validity).
This commit introduces Phase 2 of robustness improvements:

1.  **Improved Error Reporting in `OBDState::readValue()`:**
    *   Added `consecutiveReadFailures` member to `OBDState`.
    *   Implemented `getRxStateString` for readable ELM status logging.
    *   `TypedOBDState<T>::readValue()` now:
        *   Resets `consecutiveReadFailures` on success/no_data.
        *   Increments failure count and logs detailed errors (status string, raw status, count) on read failures.
        *   Auto-disables states via `setEnabled(false)` after `MAX_CONSECUTIVE_READ_FAILURES` (5) are reached.
        *   Avoids updating `lastUpdate` on errors.

2.  **Enhanced PID Support Check Logic:**
    *   Corrected `supported` and `init` flag logic in `TypedOBDState<T>::readValue()` for accurate one-time PID support checking when `checkPidSupport` is enabled.
    *   Logs results of PID support checks (supported, not supported, or check failed).
    *   If a support check fails, PID is assumed supported to allow data queries, but failure is logged.
    *   `readValue` now returns early if a PID is definitively known as unsupported, preventing data queries.
    *   Updated `OBDStates::nextState()` predicate to correctly filter out `READ` states where `isSupported()` is false.
    *   Improved `DEBUG_STATE_FILTERING` logs for unsupported states.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant