aboutsummaryrefslogtreecommitdiff
path: root/src/survive_data.c
diff options
context:
space:
mode:
authormwturvey <michael.w.turvey@intel.com>2017-03-17 16:32:18 -0700
committermwturvey <michael.w.turvey@intel.com>2017-03-17 16:32:18 -0700
commite1818d84e1ab0ae217d8035f8a12398f06508059 (patch)
tree08ad309ac2e299fbc19ec01371ee2fa62c29a71c /src/survive_data.c
parent7f62d016ff5fe45e9cae0ff29c189b64ed1bb315 (diff)
downloadlibsurvive-e1818d84e1ab0ae217d8035f8a12398f06508059.tar.gz
libsurvive-e1818d84e1ab0ae217d8035f8a12398f06508059.tar.bz2
Alternate disambiguator and calibration updates
Diffstat (limited to 'src/survive_data.c')
-rw-r--r--src/survive_data.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/survive_data.c b/src/survive_data.c
index 5c5a5e9..e6538d1 100644
--- a/src/survive_data.c
+++ b/src/survive_data.c
@@ -5,9 +5,87 @@
#include <stdint.h>
#include <string.h>
+int getAcodeFromSyncPulse(int pulseLen)
+{
+ if (pulseLen < 3125) return 0;
+ if (pulseLen < 3625) return 1;
+ if (pulseLen < 4125) return 2;
+ if (pulseLen < 4625) return 3;
+ if (pulseLen < 5125) return 4;
+ if (pulseLen < 5625) return 5;
+ if (pulseLen < 6125) return 6;
+ return 7;
+}
+void handle_lightcap2_sync(SurviveObject * so, LightcapElement * le )
+{
+ fprintf(stderr, "%d\n", le->length);
+
+ if (le->timestamp - so->recent_sync_time < 24000)
+ {
+ // I do believe we are lighthouse B
+ so->last_sync_time[1] = so->recent_sync_time = le->timestamp;
+ so->last_sync_length[1] = le->length;
+ if (le->length < 4625) // max non-skip pulse + 1/4 the difference in time between pulses.
+ {
+ so->sync_set_number = 1;
+ so->ctx->lightproc(so, -2, getAcodeFromSyncPulse(le->length), le->length, le->timestamp, le->length); // Don't think I got this quite right.
+ }
+ }
+ else
+ {
+ // looks like this is the first sync pulse. Cool!
+ if (le->length < 4625) // max non-skip pulse + 1/4 the difference in time between pulses.
+ {
+ so->sync_set_number = 1;
+ so->ctx->lightproc(so, -1, getAcodeFromSyncPulse(le->length), le->length, le->timestamp, le->length); // Don't think I got this quite right.
+ }
+ }
+
+
+// ctx->lightproc( so, -2, acode_array[1], delta2, so->last_sync_time[1], so->last_sync_length[1] );
+
+
+// typedef void (*light_process_func)( SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length );
+
+}
+
+void handle_lightcap2_sweep(SurviveObject * so, LightcapElement * le )
+{
+
+}
+
+void handle_lightcap2( SurviveObject * so, LightcapElement * le )
+{
+ SurviveContext * ctx = so->ctx;
+
+ if( le->sensor_id > SENSORS_PER_OBJECT )
+ {
+ return;
+ }
+
+ if (le->length > 6750)
+ {
+ // Should never get a reading so high. Odd.
+ return;
+ }
+ if (le->length >= 2750)
+ {
+ // Looks like a sync pulse, process it!
+ handle_lightcap2_sync(so, le);
+ }
+
+ // must be a sweep pulse, process it!
+ handle_lightcap2_sweep(so, le);
+
+}
+
+
//This is the disambiguator function, for taking light timing and figuring out place-in-sweep for a given photodiode.
void handle_lightcap( SurviveObject * so, LightcapElement * le )
{
+ handle_lightcap2(so,le);
+ return;
+
SurviveContext * ctx = so->ctx;
//int32_t deltat = (uint32_t)le->timestamp - (uint32_t)so->last_master_time;