aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCNLohr <charles@cnlohr.com>2018-02-24 12:26:32 -0500
committerGitHub <noreply@github.com>2018-02-24 12:26:32 -0500
commit3fbd36f71cfe168ada14b8f58f023bb05e4d322b (patch)
tree0d830ad923f207d74cc8493e35757f22fc02369a
parent4da907623f5ce8a71ab9f5ec60112df45060b2aa (diff)
parentdabb0764a080ad219e1bb477e8cf7386a1a4dc7c (diff)
downloadlibsurvive-3fbd36f71cfe168ada14b8f58f023bb05e4d322b.tar.gz
libsurvive-3fbd36f71cfe168ada14b8f58f023bb05e4d322b.tar.bz2
Merge pull request #99 from jdavidberger/misc-bugfix
Fixed two minor / potential bugs
-rw-r--r--src/ootx_decoder.c7
-rwxr-xr-xsrc/survive_cal.c1
-rw-r--r--src/survive_cal.h6
-rwxr-xr-xsrc/survive_vive.c18
4 files changed, 23 insertions, 9 deletions
diff --git a/src/ootx_decoder.c b/src/ootx_decoder.c
index 7bf7d7e..ad55f5b 100644
--- a/src/ootx_decoder.c
+++ b/src/ootx_decoder.c
@@ -182,8 +182,13 @@ union iFloat {
float f;
};
+
+struct __attribute__((__packed__)) unaligned_16_t {
+ uint16_t v;
+};
+
float _half_to_float(uint8_t* data) {
- uint16_t x = *(uint16_t*)data;
+ uint16_t x = ((struct unaligned_16_t*)data)->v;
union iFloat fnum;
fnum.f = 0;
diff --git a/src/survive_cal.c b/src/survive_cal.c
index 87d8c0b..f3a682a 100755
--- a/src/survive_cal.c
+++ b/src/survive_cal.c
@@ -15,6 +15,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <linmath.h>
+#include <assert.h>
#include "survive_config.h"
diff --git a/src/survive_cal.h b/src/survive_cal.h
index ae644d1..f5ef6dc 100644
--- a/src/survive_cal.h
+++ b/src/survive_cal.h
@@ -51,14 +51,14 @@ struct SurviveCalData
ootx_decoder_context ootx_decoders[NUM_LIGHTHOUSES];
//For statistics-gathering phase. (Stage 2/3)
- FLT all_lengths[MAX_SENSORS_TO_CAL][NUM_LIGHTHOUSES][2][DRPTS];
- FLT all_angles[MAX_SENSORS_TO_CAL][NUM_LIGHTHOUSES][2][DRPTS];
+ FLT all_lengths[MAX_SENSORS_TO_CAL][NUM_LIGHTHOUSES][2][DRPTS + 1];
+ FLT all_angles[MAX_SENSORS_TO_CAL][NUM_LIGHTHOUSES][2][DRPTS + 1];
int16_t all_counts[MAX_SENSORS_TO_CAL][NUM_LIGHTHOUSES][2];
int16_t peak_counts;
int8_t found_common;
int8_t times_found_common;
- FLT all_sync_times[MAX_SENSORS_TO_CAL][NUM_LIGHTHOUSES][DRPTS];
+ FLT all_sync_times[MAX_SENSORS_TO_CAL][NUM_LIGHTHOUSES][DRPTS + 1];
int16_t all_sync_counts[MAX_SENSORS_TO_CAL][NUM_LIGHTHOUSES];
//For camfind (4+)
diff --git a/src/survive_vive.c b/src/survive_vive.c
index 843482a..5be2d03 100755
--- a/src/survive_vive.c
+++ b/src/survive_vive.c
@@ -902,8 +902,16 @@ int survive_get_config( char ** config, SurviveViveData * sv, int devno, int ifa
///////////////////////////////////////////////////////////////////////////////
#define POP1 (*(readdata++))
-#define POP2 (*(((uint16_t*)((readdata+=2)-2))))
-#define POP4 (*(((uint32_t*)((readdata+=4)-4))))
+
+
+struct __attribute__((__packed__)) unaligned_16_t {
+ uint16_t v;
+};
+struct __attribute__((__packed__)) unaligned_32_t {
+ uint32_t v;
+};
+#define POP2 ((((( struct unaligned_16_t*)((readdata+=2)-2))))->v)
+#define POP4 ((((( struct unaligned_32_t*)((readdata+=4)-4))))->v)
void calibrate_acc(SurviveObject* so, FLT* agm) {
if (so->acc_bias != NULL) {
@@ -1431,7 +1439,7 @@ void survive_data_cb( SurviveUSBInterface * si )
//printf( "%d -> ", size );
for( i = 0; i < 3; i++ )
{
- int16_t * acceldata = (int16_t*)readdata;
+ struct unaligned_16_t * acceldata = (struct unaligned_16_t *)readdata;
readdata += 12;
uint32_t timecode = POP4;
uint8_t code = POP1;
@@ -1443,8 +1451,8 @@ void survive_data_cb( SurviveUSBInterface * si )
obj->oldcode = code;
//XXX XXX BIG TODO!!! Actually recal gyro data.
- FLT agm[9] = { acceldata[0], acceldata[1], acceldata[2],
- acceldata[3], acceldata[4], acceldata[5],
+ FLT agm[9] = { acceldata[0].v, acceldata[1].v, acceldata[2].v,
+ acceldata[3].v, acceldata[4].v, acceldata[5].v,
0,0,0 };
agm[0]*=(float)(1./8192.0);