aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorCNLohr <charles@cnlohr.com>2017-02-14 10:06:23 -0500
committerGitHub <noreply@github.com>2017-02-14 10:06:23 -0500
commit23a202f50fc0f9eb9127bebaf34c48d45776a25c (patch)
treed99f9611314c7a565190570e2c337f8ffc6ae9c3 /tools
parentf782146df94b3b54965c2aed696d49e86870046d (diff)
parent119a205619632076c7b258eaa6c28dd7bcd2c294 (diff)
downloadlibsurvive-23a202f50fc0f9eb9127bebaf34c48d45776a25c.tar.gz
libsurvive-23a202f50fc0f9eb9127bebaf34c48d45776a25c.tar.bz2
Merge pull request #27 from cnlohr/cal_with_ootx
Cal with ootx
Diffstat (limited to 'tools')
-rw-r--r--tools/ootx_decode/HMD_Datagen.c103
-rw-r--r--tools/ootx_decode/Makefile7
-rw-r--r--tools/ootx_decode/ootx_decode.c120
3 files changed, 230 insertions, 0 deletions
diff --git a/tools/ootx_decode/HMD_Datagen.c b/tools/ootx_decode/HMD_Datagen.c
new file mode 100644
index 0000000..15ed62c
--- /dev/null
+++ b/tools/ootx_decode/HMD_Datagen.c
@@ -0,0 +1,103 @@
+// (C) 2017 Joshua Allen, MIT/x11 License.
+//
+//All MIT/x11 Licensed Code in this file may be relicensed freely under the GPL or LGPL licenses.
+
+/* generate data to test ootx decoding */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <time.h>
+#include <stdlib.h>
+#include <zlib.h>
+
+//this program is broken and does not produce useable data.
+
+uint32_t time_stamp = -525198892;
+
+char* fmt_str = "L Y HMD %d 5 1 206230 %d\n";
+
+void print_bit(uint8_t data);
+void print_preamble();
+void print_uint16(uint16_t d);
+void print_uint32(uint32_t d);
+void print_payload(char* data, uint16_t length);
+
+
+int main(int argc, char* argv[])
+{
+ char* str = "Hello World!";
+// printf("%s\n", str);
+
+ srand(time(NULL));
+
+ print_preamble();
+
+ uint16_t payload_lenth = strlen(str);
+ uint32_t crc = crc32( 0L, Z_NULL, 0 );
+ crc = crc32( crc, (uint8_t*)str,payload_lenth);
+
+ print_uint16(payload_lenth);
+ print_payload(str,payload_lenth);
+ print_uint32(crc);
+
+ return 0;
+}
+
+void print_preamble() {
+ int i;
+ for (i=0;i<17;++i) print_bit(0);
+ print_bit(1);
+}
+
+void print_uint16(uint16_t d) {
+ int i;
+ for (i=0;i<16;++i) {
+ print_bit(d & 0x0001);
+ d>>=1;
+ }
+ print_bit(1);
+}
+
+void print_uint32(uint32_t d) {
+ int i = 0;
+ for (;i<16;++i) {
+ print_bit(d & 0x01);
+ d>>=1;
+ }
+ print_bit(1);
+
+ for (;i<32;++i) {
+ print_bit(d & 0x01);
+ d>>=1;
+ }
+ print_bit(1);
+}
+
+void print_payload(char* data, uint16_t length) {
+ int i;
+ for(i=0;i<length;i+=2) {
+ uint16_t d = *((uint16_t*)(data+i));
+// printf("%d\n", d);
+ print_uint16(d);
+ }
+}
+
+void print_bit(uint8_t data) {
+ uint32_t length = 3000 + (rand()%2)*500 + data*1000 + (rand()%2)*2000;
+ length -= rand()%500;
+ printf(fmt_str, time_stamp, length);
+
+ time_stamp++;
+
+ /*
+ //to decode
+ // 3000 + x*500 + dbit*1000 + y*2000
+ length -= 3000;
+ if (length>=2000) { length-=2000; y = 0x01; }
+ if (length>=1000) { length-=1000; dbit = 0x01; }
+ if (length>=500) { x = 0x01; }
+ */
+
+ //fire off a callback when a full OOTX packet is received
+}
diff --git a/tools/ootx_decode/Makefile b/tools/ootx_decode/Makefile
new file mode 100644
index 0000000..9170ac4
--- /dev/null
+++ b/tools/ootx_decode/Makefile
@@ -0,0 +1,7 @@
+all: ootx_decode hmd_datagen
+
+hmd_datagen: HMD_Datagen.c
+ gcc -Wall HMD_Datagen.c -lz -o hmd_datagen
+
+ootx_decode: ootx_decode.c ootx_decoder.c ootx_decoder.h
+ gcc -Wall ootx_decode.c ootx_decoder.c -lz -o ootx_decode
diff --git a/tools/ootx_decode/ootx_decode.c b/tools/ootx_decode/ootx_decode.c
new file mode 100644
index 0000000..1074698
--- /dev/null
+++ b/tools/ootx_decode/ootx_decode.c
@@ -0,0 +1,120 @@
+// (C) 2017 Joshua Allen, MIT/x11 License.
+//
+//All MIT/x11 Licensed Code in this file may be relicensed freely under the GPL or LGPL licenses.
+
+/* ootx data decoder test*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <assert.h>
+
+#include "ootx_decoder.h"
+
+void my_test(ootx_packet* packet) {
+ packet->data[packet->length] = 0;
+ printf("%d %s 0x%X\n", packet->length, packet->data, packet->crc32);
+}
+
+void my_test2(ootx_packet* packet) {
+ printf("completed ootx packet\n");
+
+ lighthouse_info_v6 lhi;
+ init_lighthouse_info_v6(&lhi,packet->data);
+ print_lighthouse_info_v6(&lhi);
+// packet->data[packet->length] = 0;
+// printf("%d %s 0x%X\n", packet->length, packet->data, packet->crc32);
+}
+
+
+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 bad_crc(ootx_packet* packet, uint32_t crc) {
+ printf("CRC mismatch\n");
+
+ printf("r:");
+ print_crc32(packet->crc32);
+
+ printf("c:");
+ print_crc32(crc);
+ write_to_file(packet->data,packet->length);
+}
+
+ootx_decoder_context ctx[2];
+
+void cnlohr_code_test() {
+ ootx_packet_clbk = my_test2;
+ ootx_bad_crc_clbk = bad_crc;
+
+ char* line = NULL;
+ size_t line_len = 0;
+ char trash[100] = "";
+ int8_t lh_id = 0x00;
+ uint32_t ticks = 0x00;
+ int32_t delta = 0x00;
+
+ ootx_decoder_context *c_ctx = ctx;
+
+ while (getline(&line,&line_len,stdin)>0) {
+ //R Y HMD -1575410734 -2 7 19714 6485
+ sscanf(line,"%s %s %s %s %hhd %s %d %d",
+ trash,
+ trash,
+ trash,
+ trash,
+ &lh_id,
+ trash, //sensor id?
+ &delta,
+ &ticks);
+
+// int8_t lh = lighthouse_code=='R'?0:1;
+// printf("LH:%d %s\n", lh_id, line);
+ int8_t lh = (lh_id*-1)-1;
+ if (lh_id < 0) {
+// uint8_t bit = 0x01; //bit for debugging purposes
+
+ //change to newly found lighthouse
+ c_ctx = ctx+lh;
+
+// uint8_t dbit = ootx_decode_bit(ticks);
+// printf("LH:%d ticks:%d bit:%X %s", lh, ticks, dbit, line);
+
+ ootx_process_bit(c_ctx, ticks);
+
+/*
+ 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);
+*/
+ }
+ }
+}
+
+int main(int argc, char* argv[])
+{
+ ootx_init_decoder_context(ctx);
+ ootx_init_decoder_context(ctx+1);
+
+ cnlohr_code_test();
+
+ ootx_free_decoder_context(ctx);
+ ootx_free_decoder_context(ctx+1);
+
+ return 0;
+} \ No newline at end of file