From 9317538667e6f54661949fee1c1f300ba89d185c Mon Sep 17 00:00:00 2001 From: Joshua Allen Date: Fri, 10 Feb 2017 20:09:33 -0500 Subject: don't write to buffer until preamble is found --- tools/ootx_decode/ootx_decoder.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/ootx_decode/ootx_decoder.c b/tools/ootx_decode/ootx_decoder.c index f5ab7e5..5a14113 100644 --- a/tools/ootx_decode/ootx_decoder.c +++ b/tools/ootx_decode/ootx_decoder.c @@ -62,11 +62,15 @@ void ootx_reset_buffer(ootx_decoder_context *ctx) { void ootx_inc_buffer_offset(ootx_decoder_context *ctx) { ++(ctx->buf_offset); -// if (buf_offset>=MAX_BUFF_SIZE) buf_offset = 0; + +// assert(ctx->buf_offsetbuf_offset>=MAX_BUFF_SIZE) { + ctx->buf_offset = 0; ctx->found_preamble = 0; } - assert(ctx->buf_offsetbuffer[ctx->buf_offset] = 0; } @@ -99,12 +103,17 @@ void ootx_process_bit(ootx_decoder_context *ctx, uint32_t length) { ctx->found_preamble = 1; } else if(ctx->bits_processed>16) { - //every 17th bit needs to be dropped + //every 17th bit needs to be dropped (sync bit) // printf("drop %d\n", dbit); ctx->bits_processed = 0; } - else + else if (ctx->found_preamble > 0) { + /* only write to buffer if the preamble is found. + if the buffer overflows, found_preamble will be cleared + and writing will stop. data would be corrupted, so there is no point in continuing + */ + ootx_write_to_buffer(ctx, dbit); if (ctx->buf_offset >= (*(ctx->payload_size)+6)) { -- cgit v1.2.3