Skip to content

Dev - #3

Merged
jonasniesner merged 3 commits into
mainfrom
dev
Oct 29, 2025
Merged

Dev#3
jonasniesner merged 3 commits into
mainfrom
dev

Conversation

@jonasniesner

Copy link
Copy Markdown
Member

No description provided.

@jonasniesner
jonasniesner merged commit 955f2d0 into main Oct 29, 2025
1 check passed
@jonasniesner
jonasniesner deleted the dev branch November 20, 2025 19:55
jonasniesner pushed a commit that referenced this pull request Jul 19, 2026
#108)

* fix(ble): defer NimBLE onConnect/onDisconnect work to loop() (race audit #1-3,6)

The Bluedroid->NimBLE migration left heavyweight, state-mutating work running
inline inside the ESP32 server callbacks on the NimBLE host task, racing the
Arduino loop() task. Make the callbacks flag-only and service the flags from
loop(), mirroring the existing bleRestartAdvertisingPending pattern.

- onDisconnect: EPD session teardown (bbepSleep/delay/SPI.end + rail cut),
  partial + pipe cleanup, and resetPipeWriteState() ran on the host task while
  loop() streamed SPI via bbepWriteData and processed pipe frames. The only
  guard (epdRefreshInProgress) covered the refresh phase, not streaming.
  Now sets bleDisconnectCleanupPending; serviced by serviceBleDisconnectCleanup()
  in loop() (preserving the epdRefreshInProgress deferral), run before the
  advertising restart. (#1 critical, #2 high, #6 medium)
- onConnect: updatemsdata() polled I2C and mutated the shared advertisement
  vector that loop() also drives on its 60s cadence -> heap corruption. Now
  sets msdUpdatePending; loop() calls updatemsdata(). (#3 high)
- updatemsdata(): drop the connected-branch that rebuilt *advertisementData
  but never pushed it via setAdvertisementData() -- dead work, no behavior
  change.

All ESP32-guarded; nRF/Bluefruit path untouched. Builds clean on
esp32-s3-N16R8, esp32-c3-N16, nrf52840custom.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* Replace protocol magic numbers with canonical named constants

Follow-up to the header vendoring (3f09f6d): sweep the remaining
hand-coded protocol literals across the BLE command handlers and use
the constants from the vendored opendisplay_protocol.h. Value-for-value,
no wire-behavior change; all CI envs build clean.

- encryption.cpp: auth-status frames -> RESP_ACK/RESP_AUTHENTICATE +
  AUTH_STATUS_*; CCM envelope sizes -> BLE_CMD_HEADER_SIZE/
  ENCRYPTION_NONCE_SIZE/ENCRYPTION_TAG_SIZE (handshake nonces left as-is).
- communication.cpp: handler response codes -> RESP_* (incl.
  RESP_AUTH_REQUIRED); config limits -> CONFIG_CHUNK_SIZE*/
  MAX_CONFIG_CHUNKS/MAX_RESPONSE_DATA_SIZE; envelope sizes.
- device_control.cpp / buzzer_control.cpp: LED, deep-sleep, and buzzer
  ack/nack frames -> RESP_*.
- display_service.cpp: direct-write/refresh frames -> RESP_DIRECT_WRITE_*;
  pipe-start errors -> OD_ERR_PIPE_START_*; deleted the local ERR_*
  shadow copies of OD_ERR_PARTIAL_* in favor of the canonical names.

Pipe/partial-write opcode-echo bytes (0x76/0x80/0x81/0x82), the pipe
data-phase error codes, and the START response-flags bit stay raw with
TODO(protocol) markers: the canonical header defines no RESP_* mirror or
data-phase error namespace for them yet.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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