From cf3bff3b03f3eca6cba5b96e028ebd6fe551dd04 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Mon, 28 Sep 2015 12:46:44 -0700 Subject: [PATCH] Decouple PacketBuilder PayloadHandler function from method type. --- firmware/baseband/packet_builder.hpp | 18 ++++++++++++++---- firmware/baseband/proc_fsk.cpp | 12 +----------- firmware/baseband/proc_fsk.hpp | 6 +++++- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/firmware/baseband/packet_builder.hpp b/firmware/baseband/packet_builder.hpp index 973c79d1..16678c10 100644 --- a/firmware/baseband/packet_builder.hpp +++ b/firmware/baseband/packet_builder.hpp @@ -25,21 +25,29 @@ #include #include #include +#include #include "bit_pattern.hpp" class PacketBuilder { public: + using PayloadType = std::bitset<256>; + using PayloadHandlerFunc = std::function; + + PacketBuilder( + const PayloadHandlerFunc payload_handler + ) : payload_handler { payload_handler } + { + } + void configure( const BitPattern preamble, const BitPattern unstuffing, size_t new_payload_length ); - template void execute( - const uint_fast8_t symbol, - PayloadHandler payload_handler + const uint_fast8_t symbol ) { bit_history.add(symbol); @@ -89,6 +97,8 @@ private: return bit_history.matches(end_flag_pattern); } + const PayloadHandlerFunc payload_handler; + BitHistory bit_history; BitPattern preamble_pattern { 0b01010101010101010101111110, 26, 1 }; BitPattern unstuff_pattern { 0b111110, 6 }; @@ -97,7 +107,7 @@ private: size_t payload_length { 0 }; size_t bits_received { 0 }; State state { State::Preamble }; - std::bitset<256> payload; + PayloadType payload; void reset_state(); }; diff --git a/firmware/baseband/proc_fsk.cpp b/firmware/baseband/proc_fsk.cpp index d169906c..c9f2c403 100644 --- a/firmware/baseband/proc_fsk.cpp +++ b/firmware/baseband/proc_fsk.cpp @@ -103,20 +103,10 @@ void FSKProcessor::execute(buffer_c8_t buffer) { void FSKProcessor::consume_symbol( const float raw_symbol ) { - const auto payload_handler_fn = [this]( - const std::bitset<256>& payload, - const size_t bits_received - ) { - this->payload_handler(payload, bits_received); - }; - const uint_fast8_t sliced_symbol = (raw_symbol >= 0.0f) ? 1 : 0; const auto decoded_symbol = nrzi_decode(sliced_symbol); - packet_builder.execute( - decoded_symbol, - payload_handler_fn - ); + packet_builder.execute(decoded_symbol); } void FSKProcessor::payload_handler( diff --git a/firmware/baseband/proc_fsk.hpp b/firmware/baseband/proc_fsk.hpp index b6b2da89..e2f4d8ed 100644 --- a/firmware/baseband/proc_fsk.hpp +++ b/firmware/baseband/proc_fsk.hpp @@ -84,7 +84,11 @@ private: [this](const float symbol) { this->consume_symbol(symbol); } }; symbol_coding::NRZIDecoder nrzi_decode; - PacketBuilder packet_builder; + PacketBuilder packet_builder { + [this](const PacketBuilder::PayloadType& payload, const size_t bits_received) { + this->payload_handler(payload, bits_received); + } + }; MessageHandlerMap& message_handlers;