lf: restore the graph buffer length along with its contents

restore_bufferS32() returns the length it put back and every graph-buffer
caller dropped it, so g_GraphTraceLen kept whatever value the code between
save and restore had left.

In try_detect_modulation() that is the 160 sample psk antenna-settle trim:
`data modulation` gave the buffer's samples back but left it 160 short, and
a following demod lost round(160 / clk) bits off the end. check_chiptype()
loses the same way through the acquisitions its detections make, on the
`lf search` path, and for g_DemodBuffer too. demodTI() loses convLen + 16
on its error path.

save_graphbuffer() / restore_graphbuffer() pair the length and grid offset
with the contents so no call site has to remember them. The visa2000 and
zx8211 sites do not change the length, so converting them is a no-op today
and keeps the next one from being a bug.

Regression test in tools/pm3_tests.sh: `data modulation` on a saved psk1
trace must leave all 20000 samples.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Matthew CarrollandClaude Opus 5 committed 2026-09-10 10:33:17 -07:00
1 parent 0884083530
commit 782d28932c
9 files changed
+39 -29

No files matched your search

+4 -5
View File
@@ -1609,8 +1609,7 @@ static bool check_chiptype(bool getDeviceData) {
}
//Save the state of the Graph and Demod Buffers
buffer_savestate_t saveState_gb = save_bufferS32(g_GraphBuffer, g_GraphTraceLen);
saveState_gb.offset = g_GridOffset;
buffer_savestate_t saveState_gb = save_graphbuffer();
buffer_savestate_t saveState_db = save_buffer8(g_DemodBuffer, g_DemodBufferLen);
saveState_db.clock = g_DemodClock;
saveState_db.offset = g_DemodStartIdx;
@@ -1683,12 +1682,12 @@ static bool check_chiptype(bool getDeviceData) {
PrintAndLogEx(INFO, "Couldn't identify a chipset");
out:
restore_buffer8(saveState_db, g_DemodBuffer);
// the detections above demodulate, so the length comes back with the contents
g_DemodBufferLen = restore_buffer8(saveState_db, g_DemodBuffer);
g_DemodClock = saveState_db.clock;
g_DemodStartIdx = saveState_db.offset;
restore_bufferS32(saveState_gb, g_GraphBuffer);
g_GridOffset = saveState_gb.offset;
restore_graphbuffer(saveState_gb);
return retval;
}