aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulian Picht <julian.picht@gmail.com>2016-12-27 00:15:33 +0100
committerJulian Picht <julian.picht@gmail.com>2016-12-27 01:11:10 +0100
commit37e6524203b7a974bddede2f2631015d74ea31b1 (patch)
tree85f4047f19a104554a6846e5a4a58bb025fe3225 /src
parent8688f251051fd0e12453f513b248f1c3e4f4dc7b (diff)
downloadlibsurvive-37e6524203b7a974bddede2f2631015d74ea31b1.tar.gz
libsurvive-37e6524203b7a974bddede2f2631015d74ea31b1.tar.bz2
implement slave sync pulses
Diffstat (limited to 'src')
-rw-r--r--src/disambiguator.c40
-rw-r--r--src/disambiguator.h3
2 files changed, 27 insertions, 16 deletions
diff --git a/src/disambiguator.c b/src/disambiguator.c
index b93639f..645b15e 100644
--- a/src/disambiguator.c
+++ b/src/disambiguator.c
@@ -83,55 +83,60 @@ void disambiguator_discard( struct disambiguator * d, uint32_t age )
/**
* Find the index that has the best likelyhood too match up with the timestamp given
- * @param time Rising edge time, where we expect to find the last sync pulse
+ * @param t1 Rising edge time, where we expect to find the last sync pulse, if this is a master pulse
+ * @param t2 Rising edge time, where we expect to find the last sync pulse, if this is a slave pulse
* @param max_diff Maximum difference we are prepared to accept
* @return index inside d->times, if we found something, -1 otherwise
*/
-inline int disambiguator_find_nearest( struct disambiguator * d, uint32_t time, int max_diff );
+inline int disambiguator_find_nearest( struct disambiguator * d, uint32_t t1, uint32_t t2, int max_diff );
-int disambiguator_find_nearest( struct disambiguator * d, uint32_t time, int max_diff )
+int disambiguator_find_nearest( struct disambiguator * d, uint32_t t1, uint32_t t2, int max_diff )
{
int diff = max_diff; // max allowed diff for a match
int idx = -1;
for (unsigned int i = 0; i < DIS_NUM_VALUES; ++i) {
if (d->times[i] == 0) continue;
- int a = abs(d->times[i] - time);
+ int a_1 = abs(d->times[i] - t1);
+ int a_2 = abs(d->times[i] - t2);
// printf("T %d %d %d\n", time, i, a);
- if (a < diff) {
+ if (a_1 < diff) {
idx = i;
- diff = a;
+ diff = a_1;
+ } else if (a_2 < diff) {
+ idx = i;
+ diff = a_2;
}
}
- if (idx != -1) {
-// printf("R %d %d %d\n", time, idx, d->scores[idx]);
- }
+// if (idx != -1) {
+// printf("R %d %d %d\n", idx, d->scores[idx], diff);
+// }
+
return idx;
}
pulse_type disambiguator_step( struct disambiguator * d, uint32_t time, int length)
{
+ uint32_t diff = time - d->last;
+
// all smaller pulses are most probably sweeps
// TODO: check we are inside the time window of actual sweeps
if (length < 2750) {
return d->state == D_STATE_LOCKED ? P_SWEEP : P_UNKNOWN;
}
- // where to expect the corresponding pulse
- uint32_t expected_diff = 400000;
-
// we expected to see a sync pulse earlier ...
if (time - d->last > 401000) {
d->state = D_STATE_UNLOCKED;
}
-
+
// discard all data, that is so old, we don't care about it anymore
disambiguator_discard(d, time - 10000000);
// find the best match for our timestamp and presumed offset
- int idx = disambiguator_find_nearest(d, time - expected_diff, 100);
+ int idx = disambiguator_find_nearest(d, time - 400000, time - 20000, 100);
// We did not find a matching pulse, so try find a place to record the current
// one's time of arrival.
@@ -150,10 +155,15 @@ pulse_type disambiguator_step( struct disambiguator * d, uint32_t time, int leng
d->state = D_STATE_LOCKED;
}
+ if (diff < 21000) {
+ return d->state == D_STATE_LOCKED ? P_SLAVE : P_UNKNOWN;
+ }
+
d->times[idx] = time;
d->last = time;
+
return d->state == D_STATE_LOCKED ? (
- d->scores[idx] >= d->max_confidence ? P_SYNC : P_SWEEP
+ d->scores[idx] >= d->max_confidence ? P_MASTER : P_SWEEP
) : P_UNKNOWN;
}
diff --git a/src/disambiguator.h b/src/disambiguator.h
index dbd4921..8258a18 100644
--- a/src/disambiguator.h
+++ b/src/disambiguator.h
@@ -24,8 +24,9 @@ typedef enum {
*/
typedef enum {
P_UNKNOWN = 0,
- P_SYNC = 1,
+ P_MASTER = 1,
P_SWEEP = 2,
+ P_SLAVE = 3,
} pulse_type;
/**