Files
swiftcontrol/lib/bluetooth/support_log_buffer.dart
Jonas Bark beb11b9717 feat(support): separate the wire trace from the app log buffer
Beta bundles routed the verbose DirCon/trainer wire trace and the high-level
app events (shifts, ERG targets, control writes, errors) into one bounded
buffer, so a few dozen trace frames per second evicted every event a support
bundle needs -- a ThinkRider XX Pro bundle arrived as 2000/2000 wire frames
with zero app entries, undiagnosable.

Give the trace its own SupportLogBuffer, keep the app log in its own, and
render a separate "Wire trace:" bundle section. The app log can no longer be
flooded out.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-01 09:29:59 +02:00

29 lines
1.1 KiB
Dart

/// A bounded, newest-kept ring of timestamped log lines for the support bundle.
///
/// [Connection] keeps two of these: one for app-level events (shifts, ERG
/// targets, errors) and one for the verbose DirCon/trainer wire trace. Keeping
/// them separate means a high-rate trace can never evict the high-level events
/// a support bundle needs — the ThinkRider XX Pro beta bundle arrived as
/// 2000/2000 wire-trace frames with zero app entries because both shared one
/// buffer, which made every trainer-control issue undiagnosable.
class SupportLogBuffer {
SupportLogBuffer(this.cap) : assert(cap > 0);
/// Maximum number of entries retained; older entries are dropped first.
final int cap;
var _entries = <({DateTime date, String entry})>[];
/// Oldest-to-newest view of the retained entries.
List<({DateTime date, String entry})> get entries => _entries;
void add(String entry, {DateTime? at}) {
_entries.add((date: at ?? DateTime.now(), entry: entry));
if (_entries.length > cap) {
_entries = _entries.sublist(_entries.length - cap);
}
}
void clear() => _entries = [];
}