diff options
author | CNLohr <charles@cnlohr.com> | 2016-12-26 22:24:10 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-26 22:24:10 -0500 |
commit | a4c008dd28d2dda226bf9f9eace1413519fd76c6 (patch) | |
tree | 8ae47cc208b2d89f6828ad5cf6fb03f0f975d4da /src/disambiguator.h | |
parent | dfed49687c361ccaae75c7389cddcfd74fbdf82e (diff) | |
parent | 1f141a4cd74c1c9b2d13a204da05ad697fa1c4bf (diff) | |
download | libsurvive-a4c008dd28d2dda226bf9f9eace1413519fd76c6.tar.gz libsurvive-a4c008dd28d2dda226bf9f9eace1413519fd76c6.tar.bz2 |
Merge pull request #13 from jpicht/disambiguate
disambiguator
Diffstat (limited to 'src/disambiguator.h')
-rw-r--r-- | src/disambiguator.h | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/src/disambiguator.h b/src/disambiguator.h index 0db19de..8258a18 100644 --- a/src/disambiguator.h +++ b/src/disambiguator.h @@ -4,35 +4,65 @@ #ifndef DISAMBIGUATOR_H #define DISAMBIGUATOR_H -#define DIS_NUM_VALUES 8 +// Determines the number of samples stored in the disambiguator struct. +// Has to be higher than the maximum number of pulses expected between sync pulses. +#define DIS_NUM_VALUES 48 +#define DIS_NUM_PULSES_BEFORE_LOCK 30 +#include <stdint.h> +/** + * internal disambiguator state + */ typedef enum { D_STATE_INVALID = 0, D_STATE_LOCKED = 1, D_STATE_UNLOCKED = -1, } dis_state; +/** + * classification result + */ typedef enum { P_UNKNOWN = 0, - P_SYNC = 1, + P_MASTER = 1, P_SWEEP = 2, + P_SLAVE = 3, } pulse_type; +/** + * internal state of the disambiguator + */ struct disambiguator { - long times[DIS_NUM_VALUES]; - int scores[DIS_NUM_VALUES]; + // the timestamps of the recorded pulses + uint32_t times[DIS_NUM_VALUES]; + // countes how many sync pulses we have seen, that match the time offset at the same offset + uint16_t scores[DIS_NUM_VALUES]; + // current state dis_state state; - long last; + // last sync pulse time + uint32_t last; + // the absolute maximum counter value int max_confidence; + // the last code type seen char code; }; -struct classified_pulse_ { - pulse_type t; - int length; -}; +/** + * Initialize a new disambiguator. calloc or memset with 0x00 will work just as well. + * + * @param d Pointer to the struct + */ void disambiguator_init( struct disambiguator * d); -pulse_type disambiguator_step( struct disambiguator * d, long time, int length); -#endif /* DISAMBIGUATOR_H */ +/** + * Feed in one pulse to have if classified. + * + * @param d Pointer to disambiguator state + * @param time Rising edge of the pulse + * @param length Length of the pulse + * @return Classification result + */ +pulse_type disambiguator_step( struct disambiguator * d, uint32_t time, int length); + +#endif /* DISAMBIGUATOR_H */
\ No newline at end of file |