aboutsummaryrefslogtreecommitdiff
path: root/tools/ootx_decode/ootx_decoder.c
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/ootx_decode/ootx_decoder.c
parent5c54917eaed3e1c6777e16baec65e63dffa215ce (diff)
downloadlibsurvive-aab9f4f1db0dd752a00f3ae67531f1d58b9e2980.tar.gz
libsurvive-aab9f4f1db0dd752a00f3ae67531f1d58b9e2980.tar.bz2
correctly decodes lighthouse 1 ootx frames
Diffstat (limited to 'tools/ootx_decode/ootx_decoder.c')
-rw-r--r--tools/ootx_decode/ootx_decoder.c32
1 files changed, 28 insertions, 4 deletions
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);