From 5c54917eaed3e1c6777e16baec65e63dffa215ce Mon Sep 17 00:00:00 2001 From: Josh Allen Date: Sat, 11 Feb 2017 15:45:10 -0500 Subject: end of frame detection corrected --- tools/ootx_decode/ootx_decode.c | 14 ++++++++++---- tools/ootx_decode/ootx_decoder.c | 22 ++++++++++++---------- tools/ootx_decode/ootx_decoder.h | 2 +- 3 files changed, 23 insertions(+), 15 deletions(-) (limited to 'tools/ootx_decode') diff --git a/tools/ootx_decode/ootx_decode.c b/tools/ootx_decode/ootx_decode.c index aabf1e8..d3c1c0f 100644 --- a/tools/ootx_decode/ootx_decode.c +++ b/tools/ootx_decode/ootx_decode.c @@ -86,14 +86,19 @@ void raw_test() { if (lh > -1) { //pump last bit - ootx_pump_greatest_bit(c_ctx); +// printf("LH:%d ", current_lighthouse); + uint8_t bit = 0x01; + + if (current_lighthouse==0) bit &= ootx_pump_greatest_bit(c_ctx); uint16_t s = *(c_ctx->payload_size); uint16_t fwv = *(c_ctx->buffer+2); - uint16_t pv = 0x3f & fwv; - fwv>>=6; + uint16_t pv = 0x3f & fwv; //protocol version + fwv>>=6; //firmware version // uint16_t ss = (s>>8) | (s<<8); - if (c_ctx->found_preamble) printf("LH:%d s:%d 0x%x fw:%d pv:%d %d\t%s", current_lighthouse, s, s, fwv, pv, c_ctx->buf_offset, line); + + //this will print after any messages from ootx_pump + if (c_ctx->found_preamble>0) printf("LH:%d s:%d 0x%x fw:%d pv:%d bo:%d bit:%d\t%s", current_lighthouse, s, s, fwv, pv, c_ctx->buf_offset, bit, line); //change to newly found lighthouse current_lighthouse = lh; @@ -101,6 +106,7 @@ void raw_test() { } if (ticks>2000 && current_lighthouse==0) { + //only work with master lighthouse for now ootx_log_bit(c_ctx, ticks); } diff --git a/tools/ootx_decode/ootx_decoder.c b/tools/ootx_decode/ootx_decoder.c index 6ec0857..8c7f28c 100644 --- a/tools/ootx_decode/ootx_decoder.c +++ b/tools/ootx_decode/ootx_decoder.c @@ -92,24 +92,23 @@ void ootx_log_bit(ootx_decoder_context *ctx, uint32_t ticks) { // printf("%d %d %d\n", dbit, ctx->bit_count[0], ctx->bit_count[1]); } -void ootx_pump_greatest_bit(ootx_decoder_context *ctx) { +uint8_t ootx_pump_greatest_bit(ootx_decoder_context *ctx) { //pump the bit - if (ctx->bit_count[0] > ctx->bit_count[1]) { -// printf("Pump 0x00\n"); - ootx_pump_bit( ctx, 0x00 ); - } else { -// printf("Pump 0xFF\n"); - ootx_pump_bit( ctx, 0xFF ); - } + uint8_t bit = 0x00; + if (ctx->bit_count[0] < ctx->bit_count[1]) bit = 0xFF; + + ootx_pump_bit( ctx, bit ); ctx->bit_count[0] = 0; ctx->bit_count[1] = 0; + + return bit; } uint8_t ootx_detect_preamble(ootx_decoder_context *ctx, uint8_t dbit) { ctx->preamble <<= 1; ctx->preamble |= (0x01 & dbit); - if ((ctx->preamble & 0x0001ffff) == 0x00000001) return 1; + if ((ctx->preamble & 0x0003ffff) == 0x00000001) return 1; return 0; } @@ -183,7 +182,10 @@ void ootx_pump_bit(ootx_decoder_context *ctx, uint8_t dbit) { ootx_write_to_buffer(ctx, dbit); - if (ctx->buf_offset >= (*(ctx->payload_size)+6)) { + uint16_t padded_length = *(ctx->payload_size); + padded_length += (padded_length&0x01); //extra null byte if odd + + if (ctx->buf_offset >= (padded_length+6)) { /* once we have a complete ootx packet, send it out in the callback */ ootx_packet op; diff --git a/tools/ootx_decode/ootx_decoder.h b/tools/ootx_decode/ootx_decoder.h index 6b181ee..13f14d6 100644 --- a/tools/ootx_decode/ootx_decoder.h +++ b/tools/ootx_decode/ootx_decoder.h @@ -34,7 +34,7 @@ void ootx_init_decoder_context(ootx_decoder_context *ctx); int8_t ootx_decode_lighthouse_number(uint8_t last_num, uint32_t ticks, int32_t delta); void ootx_log_bit(ootx_decoder_context *ctx, uint32_t length); -void ootx_pump_greatest_bit(ootx_decoder_context *ctx); +uint8_t ootx_pump_greatest_bit(ootx_decoder_context *ctx); extern void (*ootx_packet_clbk)(ootx_packet* packet); -- cgit v1.2.3