diff --git a/armsrc/pcf7931.c b/armsrc/pcf7931.c index a39fa7065..54d4c6f74 100644 --- a/armsrc/pcf7931.c +++ b/armsrc/pcf7931.c @@ -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;