From da93d5821e6da8462ff42f2c8e6e07a3cbe10740 Mon Sep 17 00:00:00 2001 From: Josh Allen Date: Sun, 12 Feb 2017 09:58:32 -0500 Subject: proper decoding of bith lighthouse ootx data --- tools/ootx_decode/ootx_decode.c | 89 +++++++++++++++++++++++++++++----------- tools/ootx_decode/ootx_decoder.c | 19 ++++++--- tools/ootx_decode/ootx_decoder.h | 2 + 3 files changed, 81 insertions(+), 29 deletions(-) (limited to 'tools') diff --git a/tools/ootx_decode/ootx_decode.c b/tools/ootx_decode/ootx_decode.c index 6365a1d..380d7b2 100644 --- a/tools/ootx_decode/ootx_decode.c +++ b/tools/ootx_decode/ootx_decode.c @@ -91,45 +91,85 @@ void raw_test() { if (lh > -1) { //pump last bit // printf("LH:%d ", current_lighthouse); - uint8_t bit = 0x01; + uint8_t bit = 0x01; //bit for debugging purposes - if (current_lighthouse==0) bit &= ootx_pump_greatest_bit(c_ctx); +// if (current_lighthouse==1) bit &= ootx_pump_greatest_bit(c_ctx); + 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; //protocol version -// fwv>>=6; //firmware version +/* + uint16_t s = *(c_ctx->payload_size); + uint16_t fwv = *(c_ctx->buffer+2); + uint16_t pv = 0x3f & fwv; //protocol version + fwv>>=6; //firmware version //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); - + 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; c_ctx = ctx+current_lighthouse; } - if (ticks>2000 && current_lighthouse==0) { - //only work with master lighthouse for now - ootx_accumulate_bit(c_ctx, ootx_decode_bit(ticks) ); +// if (ticks>2000 && current_lighthouse==1) { + if (ticks>2000) { + ootx_accumulate_bit(c_ctx, ootx_decode_bit(ticks) ); } + } +} - if (lh == -1) { -// printf("%d %d %d\n", ticks, delta, current_lighthouse); -// ootx_process_bit(ctx+current_lighthouse, ticks); +void acode_test() { + ootx_packet_clbk = my_test2; - } -// printf("%d %d %d\n", ticks, delta, current_lighthouse); -// ootx_process_bit(ctx+current_lighthouse, ticks); + char* line = NULL; + size_t line_len = 0; + char trash[100] = ""; + int32_t atime = 0x00; +// uint32_t ticks = 0x00; +// uint32_t delta = 0x00; + uint8_t acode = 0x00; + char lighthouse_code = '\0'; - //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); + int8_t current_lighthouse = 0; + ootx_decoder_context *c_ctx = ctx; + + while (getline(&line,&line_len,stdin)>0) { + //L X HMD -1842671365 18 0 175393 222 + sscanf(line,"%c %s %s %d %s %hhu %s %s", + &lighthouse_code, + trash, + trash, + &atime, + trash, + &acode, + trash, + trash); + + int8_t lh = lighthouse_code=='R'?0:1; +// printf("LH:%d bit:%d %s\n", lh, (acode & 0x02) >> 1,line); + + if (lh != current_lighthouse) { + //pump last bit + uint8_t bit = 0x01; + + if (current_lighthouse==0) bit &= ootx_pump_greatest_bit(c_ctx); +// 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; //protocol version + fwv>>=6; //firmware version + + //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; + c_ctx = ctx+current_lighthouse; } -*/ +// if (current_lighthouse==0) { + ootx_accumulate_bit(c_ctx, (acode & 0x02) >> 1); +// } } } @@ -139,6 +179,7 @@ int main(int argc, char* argv[]) ootx_init_decoder_context(ctx+1); raw_test(); +// acode_test(); // hello_world_test(); return 0; diff --git a/tools/ootx_decode/ootx_decoder.c b/tools/ootx_decode/ootx_decoder.c index c244b80..6c5031c 100644 --- a/tools/ootx_decode/ootx_decoder.c +++ b/tools/ootx_decode/ootx_decoder.c @@ -45,12 +45,21 @@ 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 (delta>100000) return 0; //master - if (delta>10000) return 1; //a slave + if (delta<18000) return -1; //sweep +// if (ticks<2000) return -1; //sweep +// printf ("%d\n", delta); + + + if (ticks>2000 && delta>100000) return 0; //master + if (delta>100000) return -1; //some kind of sweep related to the master + + /* slaves are tricky. The first few sensor readings can be confused because their tick count could be too low because of the previous master pulse? + so we have to ignore ticks completly + */ + if (delta>18000) return 1; //a slave, should be at least 20000 but there are some data issues return -1; } - +/* uint8_t decode_internal(uint32_t length) { uint16_t temp = length - 2880; // printf @@ -68,7 +77,7 @@ uint8_t decode_internal(uint32_t length) { return -1; } - +*/ uint8_t ootx_decode_bit(uint32_t length) { length = ((length/500)*500)+500; diff --git a/tools/ootx_decode/ootx_decoder.h b/tools/ootx_decode/ootx_decoder.h index 7e6af82..2a1b1d2 100644 --- a/tools/ootx_decode/ootx_decoder.h +++ b/tools/ootx_decode/ootx_decoder.h @@ -63,6 +63,8 @@ int8_t ootx_decode_lighthouse_number(uint8_t last_num, uint32_t ticks, int32_t d void ootx_accumulate_bit(ootx_decoder_context *ctx, uint8_t bit); uint8_t ootx_pump_greatest_bit(ootx_decoder_context *ctx); +uint8_t ootx_decode_bit(uint32_t length); + extern void (*ootx_packet_clbk)(ootx_packet* packet); #endif \ No newline at end of file -- cgit v1.2.3