Skip to content

feat: add auto-save for SD card every 2s in sync mode - #9954

Merged
mdmohsin7 merged 1 commit into
BasedHardware:mainfrom
TuEmb:sd_auto_save
Jul 18, 2026
Merged

mdmohsin7 merged 1 commit into
BasedHardware:mainfrom
TuEmb:sd_auto_save

Conversation

@TuEmb

@TuEmb TuEmb commented Jul 18, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Today the device only advances the SD ring read pointer after the entire sync
finishes
(after NOTIFY_DONE — the app advances only on completion, by design,
for data safety). Two consequences:

  • Nothing is freed until the very end. The on-device ring can hold hundreds of
    MB, and a full sync takes hours. Free space on the device stays flat the whole
    time and only jumps at the end.
  • A mid-sync disconnect loses all progress. BLE drops are common (weak signal,
    app backgrounded, etc.). Since read_seq wasn't advanced, on reconnect the app
    re-reads from the original pointer and the whole sync restarts from the
    beginning
    — potentially re-sending hundreds of MB.

Change

Advance + persist the ring read_seq incrementally, as data is confirmed
delivered to the phone
(counted in the BLE TX-completion callback), checkpointed
every ~2 s and once more on DONE / disconnect.

  • Only data the phone has actually received (TX-confirmed at the link layer) is
    ever freed → safe, no over-advance / data loss.
  • On reconnect the app reads from the now-advanced read_seq, so a dropped sync
    resumes near where it stopped instead of restarting from scratch.
  • Free space grows live during the sync.

Compatible with the current app: it still reads from read_seq and still sends
CMD_RING_ADVANCE after DONE (now a no-op since we've already advanced).

Implementation

  • storage.c — accumulate TX-confirmed bytes; sync_checkpoint_advance() advances
    read_seq to the confirmed seq (throttled 2 s, forced on DONE/disconnect) and
    updates the cached used/free/unread counters without touching the SD.
  • sd_card.c / sd_card.h — sd_ring_advance_async(): fire-and-forget ring advance
    on the SD worker.

Review in cubic

@TuEmb

TuEmb commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator Author

Connect to the phone app and leave it for a while:
image

Disconnect and connect to the device again:
image

@mdmohsin7
mdmohsin7 merged commit f125e86 into BasedHardware:main Jul 18, 2026
22 of 25 checks passed
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.

2 participants