From acf367aab41e13b047df6670ffbb27cea8afe2d9 Mon Sep 17 00:00:00 2001 From: Joshua Allen Date: Fri, 10 Feb 2017 21:09:14 -0500 Subject: add code to try to deal with lighthouse data. need to decode which lighthouse is sending the sync pulse. I could not get the disambiguator to work. --- tools/ootx_decode/ootx_decode.c | 66 +++++++++++++++++++++++++++++++++++++--- tools/ootx_decode/ootx_decoder.c | 29 +++++++++++++----- tools/ootx_decode/ootx_decoder.h | 2 ++ 3 files changed, 85 insertions(+), 12 deletions(-) (limited to 'tools') diff --git a/tools/ootx_decode/ootx_decode.c b/tools/ootx_decode/ootx_decode.c index 030b31b..735b5fc 100644 --- a/tools/ootx_decode/ootx_decode.c +++ b/tools/ootx_decode/ootx_decode.c @@ -20,10 +20,15 @@ void my_test(ootx_packet* packet) { printf("%d %s 0x%X\n", packet->length, packet->data, packet->crc32); } -int main(int argc, char* argv[]) -{ - ootx_decoder_context ctx; - ootx_init_decoder_context(&ctx); +void my_test2(ootx_packet* packet) { + printf("completed ootx packet\n"); +// packet->data[packet->length] = 0; +// printf("%d %s 0x%X\n", packet->length, packet->data, packet->crc32); +} + +ootx_decoder_context ctx[2]; + +void hello_world_test() { // ootx_init_buffer(); ootx_packet_clbk = my_test; @@ -45,8 +50,59 @@ int main(int argc, char* argv[]) &ticks); // printf("%d\n", ticks); - ootx_process_bit(&ctx, ticks); + ootx_process_bit(ctx, ticks); } +} + +void raw_test() { + ootx_packet_clbk = my_test2; + + char* line = NULL; + size_t line_len = 0; + char trash[100] = ""; + int32_t atime = 0x00; + uint32_t ticks = 0x00; + uint32_t delta = 0x00; + + int8_t current_lighthouse = 0; + + while (getline(&line,&line_len,stdin)>0) { +// printf("%s\n", line); + + //HMD 20 0 5881 765645903 -5 + sscanf(line,"%s %s %s %d %d %d", + trash, + trash, + trash, + &ticks, + &atime, + &delta); +// printf("%d\n", ticks); + + int8_t lh = ootx_decode_lighthouse_number(current_lighthouse, ticks, delta); + + if (lh > -1) { + //change to newly found lighthouse + current_lighthouse = lh; +// 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); + } +/* + if (current_lighthouse >= 0) { + ootx_process_bit(ctx+current_lighthouse, ticks); + } + +*/ + } +} + +int main(int argc, char* argv[]) +{ + ootx_init_decoder_context(ctx); + ootx_init_decoder_context(ctx+1); + + raw_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 5a14113..b386132 100644 --- a/tools/ootx_decode/ootx_decoder.c +++ b/tools/ootx_decode/ootx_decoder.c @@ -21,7 +21,7 @@ void ootx_init_decoder_context(ootx_decoder_context *ctx) { ctx->buf_offset = 0; ctx->bits_written = 0; - ctx->preamble = 0x00; + ctx->preamble = 0XFFFFFFFF; ctx->bits_processed = 0; ctx->found_preamble = 0; @@ -36,12 +36,27 @@ void ootx_init_buffer() { *payload_size = 0; } */ -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; } +/* + how to decode pulses + ticks>2000 && delta>100000== master lighthouse + ticks>2000 && delta>10000 == slave lighthouse +*/ + +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 + return -1; +} + + +uint8_t ootx_decode_bit(uint32_t ticks) { + ticks = ((ticks/500)*500)+500; + + ticks-=3000; + if (ticks>=2000) { ticks-=2000; } + if (ticks>=1000) { return 0xFF; } return 0x00; } @@ -97,7 +112,7 @@ void ootx_process_bit(ootx_decoder_context *ctx, uint32_t length) { if ( ootx_detect_preamble(ctx, dbit) ) { /* data stream can start over at any time so we must always look for preamble bits */ -// printf("Preamble found\n"); + printf("Preamble found\n"); ootx_reset_buffer(ctx); ctx->bits_processed = 0; ctx->found_preamble = 1; diff --git a/tools/ootx_decode/ootx_decoder.h b/tools/ootx_decode/ootx_decoder.h index 2c0ee63..696fecb 100644 --- a/tools/ootx_decode/ootx_decoder.h +++ b/tools/ootx_decode/ootx_decoder.h @@ -29,6 +29,8 @@ typedef struct { //void ootx_init_buffer(); 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); + extern void (*ootx_packet_clbk)(ootx_packet* packet); -- cgit v1.2.3