aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJoshua Allen <axlecrusher@gmail.com>2017-02-10 18:12:32 -0500
committerJoshua Allen <axlecrusher@gmail.com>2017-02-10 18:12:32 -0500
commita4b9d6de0673f16c82b295ffc4778f6361e81fe8 (patch)
treeeb14534593e5db1bc5a5fc3b6c07d068bb90f653 /tools
parent9ac3cddf749366f81540aac549ac7583602b7170 (diff)
downloadlibsurvive-a4b9d6de0673f16c82b295ffc4778f6361e81fe8.tar.gz
libsurvive-a4b9d6de0673f16c82b295ffc4778f6361e81fe8.tar.bz2
use decoding contexts to separate simultaneous lighthouse ootx decoding.
Diffstat (limited to 'tools')
-rw-r--r--tools/ootx_decode/ootx_decode.c6
-rw-r--r--tools/ootx_decode/ootx_decoder.c94
-rw-r--r--tools/ootx_decode/ootx_decoder.h17
3 files changed, 71 insertions, 46 deletions
diff --git a/tools/ootx_decode/ootx_decode.c b/tools/ootx_decode/ootx_decode.c
index 803b39e..030b31b 100644
--- a/tools/ootx_decode/ootx_decode.c
+++ b/tools/ootx_decode/ootx_decode.c
@@ -22,7 +22,9 @@ void my_test(ootx_packet* packet) {
int main(int argc, char* argv[])
{
- ootx_init_buffer();
+ ootx_decoder_context ctx;
+ ootx_init_decoder_context(&ctx);
+// ootx_init_buffer();
ootx_packet_clbk = my_test;
char* line = NULL;
@@ -43,7 +45,7 @@ int main(int argc, char* argv[])
&ticks);
// printf("%d\n", ticks);
- ootx_process_bit(ticks);
+ ootx_process_bit(&ctx, ticks);
}
return 0;
diff --git a/tools/ootx_decode/ootx_decoder.c b/tools/ootx_decode/ootx_decoder.c
index 2bd818f..f5ab7e5 100644
--- a/tools/ootx_decode/ootx_decoder.c
+++ b/tools/ootx_decode/ootx_decoder.c
@@ -14,96 +14,106 @@
//char* fmt_str = "L Y HMD %d 5 1 206230 %d\n";
#define MAX_BUFF_SIZE 1024
-uint8_t* buffer = NULL;
-uint16_t buf_offset = 0;
-uint8_t bits_written = 0;
-uint16_t* payload_size = NULL;
void (*ootx_packet_clbk)(ootx_packet* packet) = NULL;
+void ootx_init_decoder_context(ootx_decoder_context *ctx) {
+ ctx->buf_offset = 0;
+ ctx->bits_written = 0;
+
+ ctx->preamble = 0x00;
+ ctx->bits_processed = 0;
+ ctx->found_preamble = 0;
+
+ ctx->buffer = (uint8_t*)malloc(MAX_BUFF_SIZE);
+ ctx->payload_size = (uint16_t*)ctx->buffer;
+ *(ctx->payload_size) = 0;
+}
+/*
void ootx_init_buffer() {
buffer = (uint8_t*)malloc(MAX_BUFF_SIZE);
payload_size = (uint16_t*)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 0x01; }
+ if (length>=1000) { return 0xFF; }
return 0x00;
}
-uint8_t ootx_detect_preamble(uint8_t dbit) {
- static uint32_t preamble = 0x00;
- preamble <<= 1;
- preamble |= dbit;
- if ((preamble & 0x0001ffff) == 0x01) return 1;
+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;
return 0;
}
-void ootx_reset_buffer() {
- buf_offset = 0;
- buffer[buf_offset] = 0;
- bits_written = 0;
- *payload_size = 0;
+void ootx_reset_buffer(ootx_decoder_context *ctx) {
+ ctx->buf_offset = 0;
+ ctx->buffer[ctx->buf_offset] = 0;
+ ctx->bits_written = 0;
+ *(ctx->payload_size) = 0;
}
-void ootx_inc_buffer_offset() {
- ++buf_offset;
+void ootx_inc_buffer_offset(ootx_decoder_context *ctx) {
+ ++(ctx->buf_offset);
// if (buf_offset>=MAX_BUFF_SIZE) buf_offset = 0;
- assert(buf_offset<MAX_BUFF_SIZE);
- buffer[buf_offset] = 0;
+ if(ctx->buf_offset>=MAX_BUFF_SIZE) {
+ ctx->found_preamble = 0;
+ }
+ assert(ctx->buf_offset<MAX_BUFF_SIZE);
+ ctx->buffer[ctx->buf_offset] = 0;
}
-void ootx_write_to_buffer(uint8_t dbit) {
- uint8_t *current_byte = buffer+buf_offset;
+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);
- ++bits_written;
- if (bits_written>7) {
- bits_written=0;
+ *current_byte |= (0x80 & dbit);
+ ++(ctx->bits_written);
+ if (ctx->bits_written>7) {
+ ctx->bits_written=0;
// printf("%d\n", *current_byte);
- ootx_inc_buffer_offset();
+ ootx_inc_buffer_offset(ctx);
}
}
-void ootx_process_bit(uint32_t length) {
- static uint8_t bits_processed = 0;
-
+void ootx_process_bit(ootx_decoder_context *ctx, uint32_t length) {
uint8_t dbit = ootx_decode_bit(length);
- ++bits_processed;
+ ++(ctx->bits_processed);
// printf("z %d %d\n", bits_processed,dbit);
// printf("d %d\n", bits_processed,dbit);
- if ( ootx_detect_preamble(dbit) ) {
+ 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");
- ootx_reset_buffer();
- bits_processed = 0;
+ ootx_reset_buffer(ctx);
+ ctx->bits_processed = 0;
+ ctx->found_preamble = 1;
}
- else if(bits_processed>16) {
+ else if(ctx->bits_processed>16) {
//every 17th bit needs to be dropped
// printf("drop %d\n", dbit);
- bits_processed = 0;
+ ctx->bits_processed = 0;
}
else
{
- ootx_write_to_buffer(dbit);
+ ootx_write_to_buffer(ctx, dbit);
- if (buf_offset >= (*payload_size+6)) {
+ if (ctx->buf_offset >= (*(ctx->payload_size)+6)) {
/* once we have a complete ootx packet, send it out in the callback */
ootx_packet op;
- op.length = *(uint16_t*)buffer;
- op.data = buffer+2;
- op.crc32 = *(uint32_t*)(buffer+2+op.length);
+ op.length = *(ctx->payload_size);
+ op.data = ctx->buffer+2;
+ op.crc32 = *(uint32_t*)(ctx->buffer+2+op.length);
uint32_t crc = crc32(0xffffffff,op.data,op.length);
@@ -113,7 +123,7 @@ void ootx_process_bit(uint32_t length) {
if ((crc == op.crc32) && ootx_packet_clbk) ootx_packet_clbk(&op);
- ootx_reset_buffer();
+ ootx_reset_buffer(ctx);
}
}
}
diff --git a/tools/ootx_decode/ootx_decoder.h b/tools/ootx_decode/ootx_decoder.h
index 3a14f74..2c0ee63 100644
--- a/tools/ootx_decode/ootx_decoder.h
+++ b/tools/ootx_decode/ootx_decoder.h
@@ -14,8 +14,21 @@ typedef struct {
uint32_t crc32;
} ootx_packet;
-void ootx_init_buffer();
-void ootx_process_bit(uint32_t length);
+typedef struct {
+ uint8_t* buffer;
+ uint16_t buf_offset;
+ uint8_t bits_written;
+ uint16_t* payload_size;
+
+ uint32_t preamble;
+ uint8_t bits_processed;
+ uint8_t found_preamble;
+} ootx_decoder_context;
+
+
+//void ootx_init_buffer();
+void ootx_process_bit(ootx_decoder_context *ctx, uint32_t length);
+void ootx_init_decoder_context(ootx_decoder_context *ctx);
extern void (*ootx_packet_clbk)(ootx_packet* packet);