From 7eb1feba7c7a64910cb17f741f2349254a34fddd Mon Sep 17 00:00:00 2001 From: Josh Allen Date: Sat, 11 Feb 2017 10:08:16 -0500 Subject: ootx payload length for lighthouse 1 seems to be decoding correctly at 0x21. the payload length seems to be oscillating between 0x21 and a much larger number. the larger number 0xc8ec I have no idea why. 0xc8ec does not last long before a new preamble is found --- tools/ootx_decode/ootx_decode.c | 29 ++++++++++++++-- tools/ootx_decode/ootx_decoder.c | 74 ++++++++++++++++++++++++++++++++++------ tools/ootx_decode/ootx_decoder.h | 4 +++ 3 files changed, 94 insertions(+), 13 deletions(-) (limited to 'tools/ootx_decode') diff --git a/tools/ootx_decode/ootx_decode.c b/tools/ootx_decode/ootx_decode.c index 735b5fc..26e0028 100644 --- a/tools/ootx_decode/ootx_decode.c +++ b/tools/ootx_decode/ootx_decode.c @@ -65,6 +65,7 @@ void raw_test() { uint32_t delta = 0x00; int8_t current_lighthouse = 0; + ootx_decoder_context *c_ctx = ctx; while (getline(&line,&line_len,stdin)>0) { // printf("%s\n", line); @@ -80,14 +81,37 @@ void raw_test() { // printf("%d\n", ticks); int8_t lh = ootx_decode_lighthouse_number(current_lighthouse, ticks, delta); +// printf("lh:%d %s\n", lh, line); +// if (lh>0) continue; if (lh > -1) { + //pump last bit + ootx_pump_greatest_bit(c_ctx); + + uint16_t s = *(c_ctx->payload_size); +// uint16_t ss = (s>>8) | (s<<8); + if (c_ctx->found_preamble) printf("LH:%d s:%d 0x%x\t%s", current_lighthouse, s, s, line); + //change to newly found lighthouse current_lighthouse = lh; + c_ctx = ctx+current_lighthouse; + } + + if (ticks>2000 && current_lighthouse==0) { + ootx_log_bit(c_ctx, ticks); + } + + if (lh == -1) { // printf("%d %d %d\n", ticks, delta, current_lighthouse); - ootx_process_bit(ctx+current_lighthouse, ticks); - printf("%d %d %d\n", current_lighthouse, *(ctx->payload_size), ctx->found_preamble); +// ootx_process_bit(ctx+current_lighthouse, ticks); + } +// printf("%d %d %d\n", ticks, delta, current_lighthouse); +// ootx_process_bit(ctx+current_lighthouse, ticks); + + //we would expect a length of 40 bytes +// printf("%d %d %d\t%s\n", current_lighthouse, *(ctx->payload_size), ctx->found_preamble, line); +// } /* if (current_lighthouse >= 0) { ootx_process_bit(ctx+current_lighthouse, ticks); @@ -103,6 +127,7 @@ int main(int argc, char* argv[]) ootx_init_decoder_context(ctx+1); raw_test(); +// hello_world_test(); return 0; } \ No newline at end of file diff --git a/tools/ootx_decode/ootx_decoder.c b/tools/ootx_decode/ootx_decoder.c index b386132..6ec0857 100644 --- a/tools/ootx_decode/ootx_decoder.c +++ b/tools/ootx_decode/ootx_decoder.c @@ -16,6 +16,7 @@ #define MAX_BUFF_SIZE 1024 void (*ootx_packet_clbk)(ootx_packet* packet) = NULL; +void ootx_pump_bit(ootx_decoder_context *ctx, uint8_t dbit); void ootx_init_decoder_context(ootx_decoder_context *ctx) { ctx->buf_offset = 0; @@ -45,26 +46,70 @@ void ootx_init_buffer() { int8_t ootx_decode_lighthouse_number(uint8_t last_num, uint32_t ticks, int32_t delta) { if (ticks<2000) return -1; //sweep - if ((ticks > 2000) & (delta>100000)) return 0; //master - if ((ticks > 2000) & (delta>10000)) return last_num+1; //a slave + if (delta>100000) return 0; //master + if (delta>10000) return 1; //a slave return -1; } +uint8_t decode_internal(uint32_t length) { + uint16_t temp = length - 2880; +// printf -uint8_t ootx_decode_bit(uint32_t ticks) { - ticks = ((ticks/500)*500)+500; +#if BETTER_SAFE_THAN_FAST + if (temp < 0 || length > 6525) { + return -1; + } +#endif + + if ((temp % 500) < 150) { + return temp / 500; + } - ticks-=3000; - if (ticks>=2000) { ticks-=2000; } - if (ticks>=1000) { return 0xFF; } + return -1; + +} + +uint8_t ootx_decode_bit(uint32_t length) { + length = ((length/500)*500)+500; + + length-=3000; + if (length>=2000) { length-=2000; } + if (length>=1000) { return 0xFF; } return 0x00; } +/* +uint8_t ootx_decode_bit(uint32_t ticks) { + int8_t bits = decode_internal(ticks); + return bits&0x02; +} +*/ + +void ootx_log_bit(ootx_decoder_context *ctx, uint32_t ticks) { + int8_t dbit = ootx_decode_bit(ticks); +// printf("%d\n\n", dbit); + ctx->bit_count[(dbit&0x01)]++; +// printf("%d %d %d\n", dbit, ctx->bit_count[0], ctx->bit_count[1]); +} + +void 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 ); + } + + ctx->bit_count[0] = 0; + ctx->bit_count[1] = 0; +} uint8_t ootx_detect_preamble(ootx_decoder_context *ctx, uint8_t dbit) { ctx->preamble <<= 1; ctx->preamble |= (0x01 & dbit); - if ((ctx->preamble & 0x0001ffff) == 0x01) return 1; + if ((ctx->preamble & 0x0001ffff) == 0x00000001) return 1; return 0; } @@ -92,8 +137,10 @@ void ootx_inc_buffer_offset(ootx_decoder_context *ctx) { void ootx_write_to_buffer(ootx_decoder_context *ctx, uint8_t dbit) { uint8_t *current_byte = ctx->buffer + ctx->buf_offset; // printf("%d\n", dbit); - *current_byte >>= 1; - *current_byte |= (0x80 & dbit); +// *current_byte >>= 1; +// *current_byte |= (0x80 & dbit); + *current_byte <<= 1; + *current_byte |= (0x01 & dbit); ++(ctx->bits_written); if (ctx->bits_written>7) { ctx->bits_written=0; @@ -103,7 +150,12 @@ void ootx_write_to_buffer(ootx_decoder_context *ctx, uint8_t dbit) { } void ootx_process_bit(ootx_decoder_context *ctx, uint32_t length) { - uint8_t dbit = ootx_decode_bit(length); + int8_t dbit = ootx_decode_bit(length); + ootx_pump_bit( ctx, dbit ); +} + +void ootx_pump_bit(ootx_decoder_context *ctx, uint8_t dbit) { +// uint8_t dbit = ootx_decode_bit(length); ++(ctx->bits_processed); // printf("z %d %d\n", bits_processed,dbit); diff --git a/tools/ootx_decode/ootx_decoder.h b/tools/ootx_decode/ootx_decoder.h index 696fecb..6b181ee 100644 --- a/tools/ootx_decode/ootx_decoder.h +++ b/tools/ootx_decode/ootx_decoder.h @@ -23,6 +23,8 @@ typedef struct { uint32_t preamble; uint8_t bits_processed; uint8_t found_preamble; + + uint8_t bit_count[2]; } ootx_decoder_context; @@ -31,6 +33,8 @@ void ootx_process_bit(ootx_decoder_context *ctx, uint32_t length); 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); extern void (*ootx_packet_clbk)(ootx_packet* packet); -- cgit v1.2.3