PCF7931: bound the capture length instead of filling the whole BigBuf
DemodPCF7931 called DoAcquisition with sample_size 0 and no trigger, so every capture filled all of BigBuf and only the button could stop it: ~1s on RDV4 (~32 KB), ~13s on PM5 (~405 KB). The decoder then stored every whole block into an 8-entry stack array and copied them into ReadPCF7931's 4-entry buffer, both unbounded - a PM5 capture holds ~190. Capture 4.5 blocks (~0.3s on every platform), decode only the samples taken and stop storing at the 4 blocks the caller has room for. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
065a4c5eb8
commit
39145ce3e7
1 file changed
+16
-5
+16
-5
@@ -56,11 +56,18 @@
|
||||
// theshold for recognition of positive/negative slope
|
||||
#define THRESHOLD 80
|
||||
|
||||
// whole blocks one capture can hold, ReadPCF7931 buffers this many
|
||||
#define PCF7931_CAPTURE_BLOCKS 4
|
||||
// block + PMC (8576T0) in decimated samples
|
||||
#define PCF7931_BLOCK_SAMPLES ((8192 + 384) / DECIMATION)
|
||||
// bounded capture, a whole BigBuf takes ~13s on PM5. 4.5 blocks always hold 3-4 whole ones
|
||||
#define PCF7931_CAPTURE_SAMPLES ((PCF7931_CAPTURE_BLOCKS * PCF7931_BLOCK_SAMPLES) + (PCF7931_BLOCK_SAMPLES / 2))
|
||||
|
||||
size_t DemodPCF7931(uint8_t **outBlocks, bool ledcontrol) {
|
||||
uint8_t bits[256] = {0x00};
|
||||
uint8_t blocks[8][16];
|
||||
uint8_t *dest = BigBuf_get_addr();
|
||||
uint32_t g_GraphTraceLen = BigBuf_max_traceLen();
|
||||
uint32_t g_GraphTraceLen;
|
||||
// limit g_GraphTraceLen to a little more than 2 data frames.
|
||||
// To make sure a complete dataframe is in the dataset.
|
||||
// 1 Frame is 16 Byte -> 128byte. at a T0 of 64 -> 8129 Samples per frame.
|
||||
@@ -73,7 +80,11 @@ size_t DemodPCF7931(uint8_t **outBlocks, bool ledcontrol) {
|
||||
|
||||
BigBuf_Clear_keep_EM();
|
||||
LFSetupFPGAForADC(LF_DIVISOR_125, true);
|
||||
DoAcquisition(DECIMATION, 8, 0, 0, false, 0, 0, 0, ledcontrol);
|
||||
// returns bits, 8 per sample
|
||||
g_GraphTraceLen = DoAcquisition(DECIMATION, 8, 0, 0, false, PCF7931_CAPTURE_SAMPLES, 0, 0, ledcontrol) >> 3;
|
||||
if (g_GraphTraceLen < 5) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t j;
|
||||
uint8_t half_switch;
|
||||
@@ -179,7 +190,7 @@ size_t DemodPCF7931(uint8_t **outBlocks, bool ledcontrol) {
|
||||
// check if it is a complete block. If bitpos <128, it means that we did not receive
|
||||
// a complete block. E.g. at the first start of a transmission.
|
||||
// only save if a complete block is being received.
|
||||
if (bitPos == 128) {
|
||||
if (bitPos == 128 && num_blocks < PCF7931_CAPTURE_BLOCKS) {
|
||||
for (j = 0; j < 16; ++j) {
|
||||
blocks[num_blocks][j] =
|
||||
128 * bits[j * 8 + 7] +
|
||||
@@ -265,7 +276,7 @@ void ReadPCF7931(bool ledcontrol) {
|
||||
// TODO: Why 17 byte len? 16 should be good.
|
||||
uint8_t memory_blocks[maxBlocks][17]; // PCF content
|
||||
uint8_t single_blocks[maxBlocks][17]; // PFC blocks with unknown position
|
||||
uint8_t tmp_blocks[4][16]; // temporary read buffer
|
||||
uint8_t tmp_blocks[PCF7931_CAPTURE_BLOCKS][16]; // temporary read buffer
|
||||
|
||||
int single_blocks_cnt = 0;
|
||||
|
||||
@@ -286,7 +297,7 @@ void ReadPCF7931(bool ledcontrol) {
|
||||
Dbprintf("ReadPCF7931() -- Reading Loop ==========");
|
||||
i = 0;
|
||||
|
||||
memset(tmp_blocks, 0, 4 * 16 * sizeof(uint8_t));
|
||||
memset(tmp_blocks, 0, sizeof(tmp_blocks));
|
||||
n = DemodPCF7931((uint8_t **)tmp_blocks, ledcontrol);
|
||||
if (!n)
|
||||
++errors;
|
||||
|
||||
Reference in new issue
Block a user