summaryrefslogtreecommitdiff
path: root/include/decoder.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/decoder.h')
-rw-r--r--include/decoder.h29
1 files changed, 26 insertions, 3 deletions
diff --git a/include/decoder.h b/include/decoder.h
index 9aee34d..4ae723c 100644
--- a/include/decoder.h
+++ b/include/decoder.h
@@ -2,6 +2,7 @@
#include <cstdint>
#include <mcu/init.h>
+#include <cstdio>
namespace radio_controller {
@@ -10,6 +11,26 @@ struct sample {
uint16_t pulse_us;
};
+namespace decoder_ns {
+
+inline static
+bool between(uint16_t smallest, uint16_t biggest, uint16_t value)
+{
+ return smallest <= value && value <= biggest;
+}
+
+inline static
+bool check_pulse(sample s, uint16_t period_time, uint16_t pulse_time)
+{
+ printf("check_pulse: between(%d, %d, %d) && between(%d, %d, %d)\n",
+ uint16_t(period_time * 0.8), uint16_t(period_time * 1.2), s.period_us,
+ uint16_t(pulse_time * 0.8), uint16_t(pulse_time * 1.2), s.pulse_us);
+
+ return between(uint16_t(period_time * 0.8), uint16_t(period_time * 1.2), s.period_us) &&
+ between(uint16_t(pulse_time * 0.8), uint16_t(pulse_time * 1.2), s.pulse_us);
+}
+} // namespace decoder_ns
+
class sample_iterator {
public:
virtual int size() = 0;
@@ -77,9 +98,11 @@ public:
enum class decoding_state {
OK,
- TOO_SHORT,
- BAD_START,
- SHORT_BODY
+ FAIL,
+// TOO_SHORT,
+// BAD_START,
+// SHORT_BODY,
+// UNKNOWN_TOKEN,
};
class decoding_result {