feat(#430): report chunk count in caplog truncation error

Adds the received CHUNK-frame count to CaplogTruncatedException and the
on-screen error ("received X of Y bytes in N chunks"). This diagnostic
pinpointed the near-full BLE truncation: 94 chunks (all frames arrived) but
each full frame 3 bytes short = BLE MTU clipping 176-byte caplog frames to
173. Firmware chunk-size cap for BLE tracked with TopazHill.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
fix/395-dm-channel-send-wedge
Strycher 2 months ago
parent fc119b1832
commit 1021f9770d

@ -77,10 +77,17 @@ class CaplogTruncatedException implements Exception {
const CaplogTruncatedException({
required this.received,
required this.expected,
this.chunks,
});
final int received;
final int expected;
/// Number of CHUNK frames the client accumulated before END — a diagnostic to
/// tell client/transport frame loss apart from the firmware streaming short.
final int? chunks;
@override
String toString() =>
'CaplogTruncatedException: received $received of $expected bytes';
'CaplogTruncatedException: received $received of $expected bytes'
'${chunks != null ? ' in $chunks chunks' : ''}';
}

@ -290,6 +290,7 @@ class MeshCoreConnector extends ChangeNotifier {
bool _caplogAwaitingStart = false;
Completer<CaplogAck>? _caplogAckCompleter;
Completer<CaplogDeviceStatus>? _caplogStatusCompleter;
int _caplogChunks = 0; // CHUNK frames in the active download (diagnostic)
String? _firmwareVersion;
String? _deviceModel;
int? _offbandCaps;
@ -4354,10 +4355,15 @@ class MeshCoreConnector extends ChangeNotifier {
switch (event.status) {
case CaplogStatus.started:
_caplogAwaitingStart = false;
_caplogChunks = 0;
break;
case CaplogStatus.chunk:
_caplogChunks++;
break;
case CaplogStatus.completed:
_appDebugLogService?.info(
'Caplog download complete: ${event.bytes!.length} bytes',
'Caplog download complete: ${event.bytes!.length} bytes in '
'$_caplogChunks chunks',
tag: 'Caplog',
);
completer.complete(event.bytes);
@ -4365,17 +4371,17 @@ class MeshCoreConnector extends ChangeNotifier {
case CaplogStatus.truncated:
_appDebugLogService?.warn(
'Caplog download truncated: ${event.bytes!.length} of '
'${event.expected} bytes',
'${event.expected} bytes in $_caplogChunks chunks',
tag: 'Caplog',
);
completer.completeError(
CaplogTruncatedException(
received: event.bytes!.length,
expected: event.expected!,
chunks: _caplogChunks,
),
);
break;
case CaplogStatus.chunk:
case CaplogStatus.ignored:
break;
}

Loading…
Cancel
Save

Powered by TurnKey Linux.