forked from zjwhitehead/eppg-controller
-
-
Notifications
You must be signed in to change notification settings - Fork 13
ESP-IDF + BLE OTA #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
b6e0b41
Add OTA BLE service and device settings support
zjwhitehead 2bf9acf
Update BLE OTA service to Espressif standard
zjwhitehead dd8cc21
Enable OTA rollback and confirm firmware validity
zjwhitehead 4833b13
Refactor BLE OTA service to Espressif sector/CRC protocol
zjwhitehead a9a2b10
Update ota_service.cpp
zjwhitehead cd1304f
Enhance OTA service with image size tracking and validation
zjwhitehead faeb2ca
Update BLE OTA service UUIDs and protocol
zjwhitehead 756d6fb
linting
zjwhitehead 17f3d00
Remove extra internal logging
zjwhitehead d2fbb5b
Switch OTA CRC to CRC16-CCITT for compatibility
zjwhitehead 8dcd3f5
Improve OTA BLE service and LVGL display handling
zjwhitehead 266f5ec
Update main.cpp
zjwhitehead fa65b02
Remove unused alt_wire parameter from setupAltimeter
zjwhitehead f0b0b5a
Defer BLE advertising until after splash screen
zjwhitehead e77322e
Refactor boot sequence and RTOS setup for clarity
zjwhitehead 5638fc0
linting and cleanup
zjwhitehead 3e8a503
Enable app rollback and improve OTA validation logic
zjwhitehead eb8ab17
tweak LED ram usage
zjwhitehead 5de7963
Refactor altimeter sensor handling to dedicated task
zjwhitehead fd40868
Refactor altimeter data sharing using FreeRTOS queue
zjwhitehead 0e70ac1
Improve BLE OTA timeout and conn params
zjwhitehead b5cd41e
Merge branch 'master' into esp-idf
zjwhitehead b613c50
Merge remote-tracking branch 'origin/master' into esp-idf
zjwhitehead da81624
Rename parse_serial_commands to poll_serial_commands
zjwhitehead 6fd4eda
Pin CI Python version + format source comments
zjwhitehead 517e75d
Skip fastlink/controls during OTA and log stats
zjwhitehead be721b1
Fix OTA CRC log, image parse and write abort
zjwhitehead 2d5aa78
Remove altimeter globals, reset OTA, tweak BLE
zjwhitehead f339065
Refactor OTA state, handlers, and abort flow
zjwhitehead dabda44
Update sdkconfig.OpenPPG-CESP32S3-CAN-SP140
zjwhitehead e39f027
Initial plan
Copilot ab89131
Use ESP_PWR_LVL_P9 enum for BLE TX power instead of raw integer
Copilot 6e1491c
Merge pull request #99 from openppg/copilot/sub-pr-89
zjwhitehead 177c7a6
Update build configs, remove altimeter & fixes
zjwhitehead f1b5ce5
lint
zjwhitehead File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| cmake_minimum_required(VERSION 3.16.0) | ||
| include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
| project(openppg_controller) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Name, Type, SubType, Offset, Size, Flags | ||
| nvs, data, nvs, 0x9000, 0x5000, | ||
| otadata, data, ota, 0xe000, 0x2000, | ||
| app0, app, ota_0, 0x10000, 0x330000, | ||
| app1, app, ota_1, 0x340000,0x330000, | ||
| spiffs, data, spiffs, 0x670000,0x180000, | ||
| coredump, data, coredump,0x7F0000,0x10000, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,32 @@ | ||
| #ifndef INC_SP140_ALTIMETER_H_ | ||
| #define INC_SP140_ALTIMETER_H_ | ||
| #include "sp140/shared-config.h" | ||
| #include "sp140/structs.h" | ||
| #include <Arduino.h> | ||
| #include <CircularBuffer.hpp> | ||
| #include <freertos/semphr.h> | ||
| #ifndef INC_SP140_ALTIMETER_H_ | ||
| #define INC_SP140_ALTIMETER_H_ | ||
|
|
||
| #include "sp140/shared-config.h" | ||
| #include "sp140/structs.h" | ||
| #include <Arduino.h> | ||
| #include <CircularBuffer.hpp> | ||
| #include <freertos/semphr.h> | ||
|
|
||
| // Constants | ||
| #define VARIO_BUFFER_SIZE 50 // Number of samples to average for vertical speed | ||
| #define MAX_VERTICAL_SPEED 250.0f // Maximum vertical speed to display (m/s) | ||
| // Set up the barometer | ||
| bool setupAltimeter(); | ||
| // Get the altitude (in meters) | ||
| float getAltitude(const STR_DEVICE_DATA_140_V1 &deviceData); | ||
| // Get the vertical speed in meters per second | ||
| float getVerticalSpeed(); | ||
| // Set the ground altitude to the current altitude to compute AGL | ||
| void setGroundAltitude(const STR_DEVICE_DATA_140_V1 &deviceData); | ||
| // Get the temperature in degrees Celsius | ||
| float getBaroTemperature(); | ||
| // Get the pressure in hPa | ||
| float getBaroPressure(); | ||
|
|
||
| // Set up the barometer | ||
| bool setupAltimeter(); | ||
|
|
||
| // Get the altitude (in meters) | ||
| float getAltitude(const STR_DEVICE_DATA_140_V1 &deviceData); | ||
|
|
||
| // Get the vertical speed in meters per second | ||
| float getVerticalSpeed(); | ||
|
|
||
| // Set the ground altitude to the current altitude to compute AGL | ||
| void setGroundAltitude(const STR_DEVICE_DATA_140_V1 &deviceData); | ||
|
|
||
| // Get the temperature in degrees Celsius | ||
| float getBaroTemperature(); | ||
|
|
||
| // Get the pressure in hPa | ||
| float getBaroPressure(); | ||
|
|
||
| #endif // INC_SP140_ALTIMETER_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #ifndef INC_SP140_BLE_OTA_SERVICE_H_ | ||
| #define INC_SP140_BLE_OTA_SERVICE_H_ | ||
|
|
||
| #include <NimBLEDevice.h> | ||
|
|
||
| /** | ||
| * Initialize the OTA BLE service. | ||
| * @param pServer Pointer to the NimBLEServer instance. | ||
| */ | ||
| void initOtaBleService(NimBLEServer* pServer); | ||
|
|
||
| /** | ||
| * Check if an OTA update is currently in progress. | ||
| * @return true if OTA is active (should pause other tasks) | ||
| */ | ||
| bool isOtaInProgress(); | ||
|
|
||
| /** | ||
| * Abort any in-progress OTA update and reset state. | ||
| * Safe to call even if no OTA is in progress. | ||
| */ | ||
| void abortOta(); | ||
|
|
||
| /** | ||
| * Check if OTA has been idle too long and abort if so. | ||
| * Call periodically (e.g. from a monitoring task). | ||
| */ | ||
| void checkOtaTimeout(); | ||
|
|
||
| #endif // INC_SP140_BLE_OTA_SERVICE_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #ifndef INC_SP140_DEVICE_SETTINGS_H_ | ||
| #define INC_SP140_DEVICE_SETTINGS_H_ | ||
|
|
||
| #include "structs.h" | ||
| #include "esp32s3-config.h" | ||
|
|
||
| // Constants | ||
| extern const unsigned int DEFAULT_SCREEN_ROTATION; | ||
| void refreshDeviceData(); | ||
| void writeDeviceData(); | ||
| void resetDeviceData(); | ||
| void poll_serial_commands(); | ||
| void send_device_data(); | ||
| bool sanitizeDeviceData(); | ||
| void debugHardwareConfig(const HardwareConfig& config); | ||
|
|
||
| #endif // INC_SP140_DEVICE_SETTINGS_H_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,68 +1,68 @@ | ||
| #ifndef INC_SP140_ESC_H_ | ||
| #define INC_SP140_ESC_H_ | ||
| #include <Arduino.h> | ||
| // Motor temp validity range (disconnected/invalid readings are represented as NaN) | ||
| constexpr float MOTOR_TEMP_VALID_MIN_C = -20.0f; | ||
| constexpr float MOTOR_TEMP_VALID_MAX_C = 140.0f; | ||
| inline bool isMotorTempValidC(float tempC) { | ||
| return tempC > MOTOR_TEMP_VALID_MIN_C && tempC <= MOTOR_TEMP_VALID_MAX_C; | ||
| } | ||
| #include "sp140/structs.h" | ||
| #include "../../inc/sp140/esp32s3-config.h" | ||
| #include <SineEsc.h> | ||
| #include <CanardAdapter.h> | ||
| void initESC(); | ||
| void setESCThrottle(int throttlePWM); | ||
| void readESCTelemetry(); | ||
| bool setupTWAI(); | ||
| // Request ESC hardware info (HW ID, FW version, bootloader, serial number). | ||
| // Thread-safe: sets a flag consumed by readESCTelemetry() on its next tick. | ||
| // Also called automatically the first time the ESC connects. | ||
| void requestEscHardwareInfo(); | ||
| // ESC Error Decoding Functions | ||
| String decodeRunningError(uint16_t errorCode); | ||
| String decodeSelfCheckError(uint16_t errorCode); | ||
| bool hasRunningError(uint16_t errorCode); | ||
| bool hasSelfCheckError(uint16_t errorCode); | ||
| bool hasCriticalRunningError(uint16_t errorCode); | ||
| bool hasWarningRunningError(uint16_t errorCode); | ||
| bool hasCriticalSelfCheckError(uint16_t errorCode); | ||
| // Individual running error bit checkers | ||
| bool hasOverCurrentError(uint16_t errorCode); | ||
| bool hasLockedRotorError(uint16_t errorCode); | ||
| bool hasOverTempError(uint16_t errorCode); | ||
| bool hasOverVoltError(uint16_t errorCode); | ||
| bool hasVoltagDropError(uint16_t errorCode); | ||
| bool hasThrottleSatWarning(uint16_t errorCode); | ||
| // Individual self-check error bit checkers | ||
| bool hasMotorCurrentOutError(uint16_t errorCode); | ||
| bool hasTotalCurrentOutError(uint16_t errorCode); | ||
| bool hasMotorVoltageOutError(uint16_t errorCode); | ||
| bool hasCapNTCError(uint16_t errorCode); | ||
| bool hasMosNTCError(uint16_t errorCode); | ||
| bool hasBusVoltRangeError(uint16_t errorCode); | ||
| bool hasBusVoltSampleError(uint16_t errorCode); | ||
| bool hasMotorZLowError(uint16_t errorCode); | ||
| bool hasMotorZHighError(uint16_t errorCode); | ||
| bool hasMotorVDet1Error(uint16_t errorCode); | ||
| bool hasMotorVDet2Error(uint16_t errorCode); | ||
| bool hasMotorIDet2Error(uint16_t errorCode); | ||
| bool hasSwHwIncompatError(uint16_t errorCode); | ||
| bool hasBootloaderBadError(uint16_t errorCode); | ||
| // for debugging | ||
| void dumpThrottleResponse(const sine_esc_SetThrottleSettings2Response *res); | ||
| void dumpESCMessages(); // dumps all messages to USBSerial | ||
| // External declaration of telemetry data structure | ||
| extern STR_ESC_TELEMETRY_140 escTelemetryData; | ||
| #endif // INC_SP140_ESC_H_ | ||
| #ifndef INC_SP140_ESC_H_ | ||
| #define INC_SP140_ESC_H_ | ||
|
|
||
| #include <Arduino.h> | ||
|
|
||
| // Motor temp validity range (disconnected/invalid readings are represented as NaN) | ||
| constexpr float MOTOR_TEMP_VALID_MIN_C = -20.0f; | ||
| constexpr float MOTOR_TEMP_VALID_MAX_C = 140.0f; | ||
|
|
||
| inline bool isMotorTempValidC(float tempC) { | ||
| return tempC > MOTOR_TEMP_VALID_MIN_C && tempC <= MOTOR_TEMP_VALID_MAX_C; | ||
| } | ||
| #include "sp140/structs.h" | ||
| #include "../../inc/sp140/esp32s3-config.h" | ||
| #include <SineEsc.h> | ||
| #include <CanardAdapter.h> | ||
|
|
||
| void initESC(); | ||
| void setESCThrottle(int throttlePWM); | ||
| void readESCTelemetry(); | ||
| bool setupTWAI(); | ||
|
|
||
| // Request ESC hardware info (HW ID, FW version, bootloader, serial number). | ||
| // Thread-safe: sets a flag consumed by readESCTelemetry() on its next tick. | ||
| // Also called automatically the first time the ESC connects. | ||
| void requestEscHardwareInfo(); | ||
|
|
||
| // ESC Error Decoding Functions | ||
| String decodeRunningError(uint16_t errorCode); | ||
| String decodeSelfCheckError(uint16_t errorCode); | ||
| bool hasRunningError(uint16_t errorCode); | ||
| bool hasSelfCheckError(uint16_t errorCode); | ||
| bool hasCriticalRunningError(uint16_t errorCode); | ||
| bool hasWarningRunningError(uint16_t errorCode); | ||
| bool hasCriticalSelfCheckError(uint16_t errorCode); | ||
|
|
||
| // Individual running error bit checkers | ||
| bool hasOverCurrentError(uint16_t errorCode); | ||
| bool hasLockedRotorError(uint16_t errorCode); | ||
| bool hasOverTempError(uint16_t errorCode); | ||
| bool hasOverVoltError(uint16_t errorCode); | ||
| bool hasVoltagDropError(uint16_t errorCode); | ||
| bool hasThrottleSatWarning(uint16_t errorCode); | ||
|
|
||
| // Individual self-check error bit checkers | ||
| bool hasMotorCurrentOutError(uint16_t errorCode); | ||
| bool hasTotalCurrentOutError(uint16_t errorCode); | ||
| bool hasMotorVoltageOutError(uint16_t errorCode); | ||
| bool hasCapNTCError(uint16_t errorCode); | ||
| bool hasMosNTCError(uint16_t errorCode); | ||
| bool hasBusVoltRangeError(uint16_t errorCode); | ||
| bool hasBusVoltSampleError(uint16_t errorCode); | ||
| bool hasMotorZLowError(uint16_t errorCode); | ||
| bool hasMotorZHighError(uint16_t errorCode); | ||
| bool hasMotorVDet1Error(uint16_t errorCode); | ||
| bool hasMotorVDet2Error(uint16_t errorCode); | ||
| bool hasMotorIDet2Error(uint16_t errorCode); | ||
| bool hasSwHwIncompatError(uint16_t errorCode); | ||
| bool hasBootloaderBadError(uint16_t errorCode); | ||
|
|
||
| // for debugging | ||
| void dumpThrottleResponse(const sine_esc_SetThrottleSettings2Response *res); | ||
| void dumpESCMessages(); // dumps all messages to USBSerial | ||
|
|
||
| // External declaration of telemetry data structure | ||
| extern STR_ESC_TELEMETRY_140 escTelemetryData; | ||
|
|
||
| #endif // INC_SP140_ESC_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Name, Type, SubType, Offset, Size, Flags | ||
| nvs, data, nvs, , 0x4000, | ||
| otadata, data, ota, , 0x2000, | ||
| app0, app, ota_0, , 3M, | ||
| app1, app, ota_1, , 3M, | ||
| spiffs, data, spiffs, , 1500K, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
device_settings.hincludes"structs.h"and"esp32s3-config.h"without thesp140/prefix. With the current include path setup (e.g.include_dir = inc), these headers won’t be found (there is noinc/structs.h), which will break compilation for any TU including this header. Update the includes to the correct paths (e.g.sp140/structs.handsp140/esp32s3-config.h) or adjust the build include directories consistently.