aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJoshua Allen <axlecrusher@gmail.com>2017-02-10 20:09:33 -0500
committerJoshua Allen <axlecrusher@gmail.com>2017-02-10 20:09:33 -0500
commit9317538667e6f54661949fee1c1f300ba89d185c (patch)
tree31cd071e9ce6f17bdf32715cce19eaa07a29dbdc /tools
parenta4b9d6de0673f16c82b295ffc4778f6361e81fe8 (diff)
downloadlibsurvive-9317538667e6f54661949fee1c1f300ba89d185c.tar.gz
libsurvive-9317538667e6f54661949fee1c1f300ba89d185c.tar.bz2
don't write to buffer until preamble is found
Diffstat (limited to 'tools')
-rw-r--r--tools/ootx_decode/ootx_decoder.c17
1 files changed, 13 insertions, 4 deletions
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_offset<MAX_BUFF_SIZE);
+
+ /* the buffer is going to overflow, wrap the buffer and don't write more data until the preamble is found again */
if(ctx->buf_offset>=MAX_BUFF_SIZE) {
+ ctx->buf_offset = 0;
ctx->found_preamble = 0;
}
- assert(ctx->buf_offset<MAX_BUFF_SIZE);
+
ctx->buffer[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)) {