aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJosh Allen <axlecrusher@gmail.com>2017-02-11 16:27:57 -0500
committerJosh Allen <axlecrusher@gmail.com>2017-02-11 16:27:57 -0500
commitaab9f4f1db0dd752a00f3ae67531f1d58b9e2980 (patch)
tree35aa71e054316871ac59dd1146f614c9a9f6727e /tools
parent5c54917eaed3e1c6777e16baec65e63dffa215ce (diff)
downloadlibsurvive-aab9f4f1db0dd752a00f3ae67531f1d58b9e2980.tar.gz
libsurvive-aab9f4f1db0dd752a00f3ae67531f1d58b9e2980.tar.bz2
correctly decodes lighthouse 1 ootx frames
Diffstat (limited to 'tools')
-rw-r--r--tools/ootx_decode/Makefile4
-rw-r--r--tools/ootx_decode/ootx_decode.c2
-rw-r--r--tools/ootx_decode/ootx_decoder.c32
3 files changed, 31 insertions, 7 deletions
diff --git a/tools/ootx_decode/Makefile b/tools/ootx_decode/Makefile
index 2c0d01a..8be8618 100644
--- a/tools/ootx_decode/Makefile
+++ b/tools/ootx_decode/Makefile
@@ -3,5 +3,5 @@ all: ootx_decode hmd_datagen
hmd_datagen: HMD_Datagen.c crc32.c crc32.h
gcc -Wall HMD_Datagen.c crc32.c -o hmd_datagen
-ootx_decode: ootx_decode.c ootx_decoder.c ootx_decoder.h crc32.c crc32.h
- gcc -Wall ootx_decode.c ootx_decoder.c crc32.c -o ootx_decode \ No newline at end of file
+ootx_decode: ootx_decode.c ootx_decoder.c ootx_decoder.h
+ gcc -Wall ootx_decode.c ootx_decoder.c -lz -o ootx_decode \ No newline at end of file
diff --git a/tools/ootx_decode/ootx_decode.c b/tools/ootx_decode/ootx_decode.c
index d3c1c0f..19d6574 100644
--- a/tools/ootx_decode/ootx_decode.c
+++ b/tools/ootx_decode/ootx_decode.c
@@ -98,7 +98,7 @@ void raw_test() {
// uint16_t ss = (s>>8) | (s<<8);
//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;
diff --git a/tools/ootx_decode/ootx_decoder.c b/tools/ootx_decode/ootx_decoder.c
index 8c7f28c..72ce87c 100644
--- a/tools/ootx_decode/ootx_decoder.c
+++ b/tools/ootx_decode/ootx_decoder.c
@@ -6,10 +6,10 @@
#include <stdio.h>
#include <stdlib.h>
-
+#include <zlib.h>
#include <assert.h>
#include "ootx_decoder.h"
-#include "crc32.h"
+//#include "crc32.h"
//char* fmt_str = "L Y HMD %d 5 1 206230 %d\n";
@@ -153,6 +153,19 @@ void ootx_process_bit(ootx_decoder_context *ctx, uint32_t length) {
ootx_pump_bit( ctx, dbit );
}
+void print_crc32(uint32_t crc) {
+// uint8_t* p = (uint32_t*)&crc;
+// uint8_t i = 0;
+
+ printf("%X\n", crc);
+}
+
+void write_to_file(uint8_t *d, uint16_t length){
+ FILE *fp = fopen("binary.data","w");
+ fwrite(d, length, 1, fp);
+ fclose(fp);
+}
+
void ootx_pump_bit(ootx_decoder_context *ctx, uint8_t dbit) {
// uint8_t dbit = ootx_decode_bit(length);
++(ctx->bits_processed);
@@ -191,12 +204,23 @@ void ootx_pump_bit(ootx_decoder_context *ctx, uint8_t dbit) {
op.length = *(ctx->payload_size);
op.data = ctx->buffer+2;
- op.crc32 = *(uint32_t*)(ctx->buffer+2+op.length);
+ op.crc32 = *(uint32_t*)(op.data+padded_length);
+
+ uint32_t crc = crc32( 0L, Z_NULL, 0 );
+ crc = crc32( crc, op.data,op.length);
+// uint32_t crc = crc32(0xffffffff,op.data,op.length);
- uint32_t crc = crc32(0xffffffff,op.data,op.length);
if (crc != op.crc32) {
printf("CRC mismatch\n");
+/*
+ printf("r:");
+ print_crc32(op.crc32);
+
+ printf("c:");
+ print_crc32(crc);
+// write_to_file(op.data,op.length);
+*/
}
if ((crc == op.crc32) && ootx_packet_clbk) ootx_packet_clbk(&op);