fix(#430): accept 176-byte frames (caplog chunks were being rejected)

The frame decoder capped companion frames at 172, but the firmware's real
MAX_FRAME_SIZE is 176 (BaseSerialInterface.h, "+4 for transport codes").
Full-size caplog CHUNK frames (176 B) were silently rejected; only the final
sub-172 partial chunk survived, so a download reassembled just the last chunk
(e.g. "received 95 of 5141"). Caplog is the first feature to use full frames,
so nothing exposed this before.

- usb_serial_frame_codec.dart: usbSerialMaxPayloadLength 172 -> 176.
- serial_capture_screen.dart: erase-on-start (Start / Start&Reboot) for a clean
  session ("didn't start at 0").
- 3 decoder regression tests; 113 tests total green; analyze clean.

Root cause confirmed with firmware (TopazHill): firmware streams the full
buffer correctly (wire trace 5175/5175); the client decoder dropped oversized
chunks. My earlier firmware-ring hypothesis was wrong.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
fix/395-dm-channel-send-wedge
Strycher 4 months ago
parent 7d03a43bb7
commit ed8bfdf503

@ -136,6 +136,7 @@ class _SerialCaptureScreenState extends State<SerialCaptureScreen> {
_error = null;
});
try {
await _connector?.eraseDeviceCaplog(); // clean session: start from 0
await _setEnabled(true);
if (!mounted) return;
_startedAt = DateTime.now();
@ -207,6 +208,7 @@ class _SerialCaptureScreenState extends State<SerialCaptureScreen> {
_error = null;
});
try {
await c.eraseDeviceCaplog(); // fresh boot log from power-on
await _setEnabled(true); // no timer: runs until Stop
_startedAt = DateTime.now();
_timedWindowMinutes = null;

@ -3,7 +3,11 @@ import 'dart:typed_data';
const int usbSerialTxFrameStart = 0x3c;
const int usbSerialRxFrameStart = 0x3e;
const int usbSerialHeaderLength = 3;
const int usbSerialMaxPayloadLength = 172;
// Max companion frame the decoder will accept, matching the firmware's
// MAX_FRAME_SIZE (BaseSerialInterface.h = 176, "+4 for transport codes"). This
// was 172, which silently rejected full-size frames — exposed by caplog chunks
// (176 B), the first feature to use the full frame. Normal traffic stays <=172.
const int usbSerialMaxPayloadLength = 176;
Uint8List wrapUsbSerialTxFrame(Uint8List payload) {
if (payload.length > usbSerialMaxPayloadLength) {

@ -0,0 +1,39 @@
import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/services/usb_serial_frame_codec.dart';
/// Wrap [payload] as an inbound (RX) transport frame: [0x3e, len_lo, len_hi, …].
Uint8List _rxFrame(Uint8List payload) => Uint8List.fromList([
usbSerialRxFrameStart,
payload.length & 0xff,
(payload.length >> 8) & 0xff,
...payload,
]);
void main() {
group('UsbSerialFrameDecoder frame-size boundary (#430)', () {
test('accepts a full 176-byte companion frame (caplog chunk)', () {
// Regression: 172 used to reject this, dropping every full caplog chunk.
final payload = Uint8List(176)..fillRange(0, 176, 0xAB);
final packets = UsbSerialFrameDecoder().ingest(_rxFrame(payload));
expect(packets, hasLength(1));
expect(packets.single.payload.length, 176);
});
test('decodes 30 full chunks batched into one read (caplog stream)', () {
final buf = <int>[];
for (var i = 0; i < 30; i++) {
buf.addAll(_rxFrame(Uint8List(176)..fillRange(0, 176, i)));
}
final packets = UsbSerialFrameDecoder().ingest(Uint8List.fromList(buf));
expect(packets, hasLength(30));
expect(packets.every((p) => p.payload.length == 176), isTrue);
});
test('still rejects an over-max (177-byte) frame', () {
final packets = UsbSerialFrameDecoder().ingest(_rxFrame(Uint8List(177)));
expect(packets, isEmpty);
});
});
}
Loading…
Cancel
Save

Powered by TurnKey Linux.