From cbb6d0b53319a7e0124fff6ce7ffb12cfe94fa3f Mon Sep 17 00:00:00 2001 From: Josh Allen Date: Mon, 13 Feb 2017 15:44:39 -0500 Subject: remove unused code --- tools/ootx_decode/ootx_decode.c | 153 --------------------------------------- tools/ootx_decode/ootx_decoder.c | 60 +++------------ tools/ootx_decode/ootx_decoder.h | 6 +- 3 files changed, 10 insertions(+), 209 deletions(-) (limited to 'tools') diff --git a/tools/ootx_decode/ootx_decode.c b/tools/ootx_decode/ootx_decode.c index a97bc8d..1074698 100644 --- a/tools/ootx_decode/ootx_decode.c +++ b/tools/ootx_decode/ootx_decode.c @@ -12,9 +12,6 @@ #include "ootx_decoder.h" -//char* fmt_str = "L Y HMD %d 5 1 206230 %d\n"; -//extern std::istream cin; - void my_test(ootx_packet* packet) { packet->data[packet->length] = 0; printf("%d %s 0x%X\n", packet->length, packet->data, packet->crc32); @@ -57,149 +54,6 @@ void bad_crc(ootx_packet* packet, uint32_t crc) { ootx_decoder_context ctx[2]; -void hello_world_test() { -// ootx_init_buffer(); - ootx_packet_clbk = my_test; - - char* line = NULL; - size_t line_len = 0; - char trash[100] = ""; - uint32_t ticks = 0x00; - - while (getline(&line,&line_len,stdin)>0) { -// printf("%s\n", line); - sscanf(line,"%s %s %s %s %s %s %s %d", - trash, - trash, - trash, - trash, - trash, - trash, - trash, - &ticks); -// printf("%d\n", ticks); - - ootx_process_bit(ctx, ticks); - } -} - -void raw_test() { - ootx_packet_clbk = my_test2; - ootx_bad_crc_clbk = bad_crc; - - 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; - ootx_decoder_context *c_ctx = ctx; - - 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); -// printf("lh:%d %s\n", lh, line); -// if (lh>0) continue; - - if (lh > -1) { - //pump last bit -// printf("LH:%d ", current_lighthouse); - uint8_t bit = 0x01; //bit for debugging purposes - -// 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 - - //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 (ticks>2000 && current_lighthouse==1) { - if (ticks>2000) { - ootx_accumulate_bit(c_ctx, ootx_decode_bit(ticks) ); - } - } -} - -void acode_test() { - ootx_packet_clbk = my_test2; - ootx_bad_crc_clbk = bad_crc; - - 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'; - - 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); -// } - } -} - void cnlohr_code_test() { ootx_packet_clbk = my_test2; ootx_bad_crc_clbk = bad_crc; @@ -207,14 +61,10 @@ void cnlohr_code_test() { char* line = NULL; size_t line_len = 0; char trash[100] = ""; -// int32_t atime = 0x00; int8_t lh_id = 0x00; uint32_t ticks = 0x00; int32_t delta = 0x00; -// uint8_t acode = 0x00; -// char lighthouse_code = '\0'; -// int8_t current_lighthouse = 0; ootx_decoder_context *c_ctx = ctx; while (getline(&line,&line_len,stdin)>0) { @@ -262,9 +112,6 @@ int main(int argc, char* argv[]) ootx_init_decoder_context(ctx+1); cnlohr_code_test(); -// raw_test(); -// acode_test(); -// hello_world_test(); ootx_free_decoder_context(ctx); ootx_free_decoder_context(ctx+1); diff --git a/tools/ootx_decode/ootx_decoder.c b/tools/ootx_decode/ootx_decoder.c index 510fadb..5c64898 100644 --- a/tools/ootx_decode/ootx_decoder.c +++ b/tools/ootx_decode/ootx_decoder.c @@ -39,55 +39,16 @@ void ootx_free_decoder_context(ootx_decoder_context *ctx) { ctx->payload_size = NULL; } -/* - 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 (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 ootx_decode_bit(uint32_t length) { uint8_t t = (length - 2750) / 500; //why 2750? -// return ((t & 0x02)>0)?0xFF:0x00; +// return ((t & 0x02)>0)?0xFF:0x00; //easier if we need to bitshift right return ((t & 0x02)>>1); } -void ootx_accumulate_bit(ootx_decoder_context *ctx, uint8_t bit) { - ctx->bit_count[bit&0x01]++; -} - -uint8_t ootx_pump_greatest_bit(ootx_decoder_context *ctx) { - //pump the bit - uint8_t bit = 0x00; - if (ctx->bit_count[0] < ctx->bit_count[1]) bit = 0xFF; - -// printf("pump %d\n", bit); - 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); +// ctx->preamble |= (0x01 & dbit); + ctx->preamble |= dbit; if ((ctx->preamble & 0x0003ffff) == 0x00000001) return 1; return 0; } @@ -115,11 +76,11 @@ 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 |= (0x01 & dbit); +// *current_byte |= (0x01 & dbit); + *current_byte |= dbit; + ++(ctx->bits_written); if (ctx->bits_written>7) { ctx->bits_written=0; @@ -128,19 +89,16 @@ 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 ootx_process_bit(ootx_decoder_context *ctx, uint32_t length) { uint8_t dbit = ootx_decode_bit(length); - ootx_pump_bit( ctx, dbit ); + return 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); -// printf("d %d\n", bits_processed,dbit); - if ( ootx_detect_preamble(ctx, dbit) ) { /* data stream can start over at any time so we must always look for preamble bits */ diff --git a/tools/ootx_decode/ootx_decoder.h b/tools/ootx_decode/ootx_decoder.h index 4ec1fd1..c707159 100644 --- a/tools/ootx_decode/ootx_decoder.h +++ b/tools/ootx_decode/ootx_decoder.h @@ -55,14 +55,10 @@ typedef struct { void init_lighthouse_info_v6(lighthouse_info_v6* lhi, uint8_t* data); void print_lighthouse_info_v6(lighthouse_info_v6* lhi); -//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); void ootx_free_decoder_context(ootx_decoder_context *ctx); -void ootx_accumulate_bit(ootx_decoder_context *ctx, uint8_t bit); -uint8_t ootx_pump_greatest_bit(ootx_decoder_context *ctx); +uint8_t ootx_process_bit(ootx_decoder_context *ctx, uint32_t length); uint8_t ootx_decode_bit(uint32_t length); -- cgit v1.2.3