From 07cd99d85dcae806773f0242526a87d7e33cbbed Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sat, 2 Jan 2016 22:54:09 -0800 Subject: [PATCH] Removing baseband MessageHandlerMap. It's a bit heavy (362 bytes smaller with switch/case implementation), hard to access to add/remove handlers, doesn't bubble events like I'd like. (I'm going to bubble events to the baseband processor shortly.) --- firmware/baseband/main.cpp | 48 +++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/firmware/baseband/main.cpp b/firmware/baseband/main.cpp index 16c8c5d3..4f019621 100755 --- a/firmware/baseband/main.cpp +++ b/firmware/baseband/main.cpp @@ -121,24 +121,7 @@ static void shutdown() { class EventDispatcher { public: - MessageHandlerMap& message_handlers() { - return message_map; - } - void run() { - message_map.register_handler(Message::ID::BasebandConfiguration, - [this](const Message* const p) { - auto message = reinterpret_cast(p); - this->baseband_thread.set_configuration(message->configuration); - } - ); - - message_map.register_handler(Message::ID::Shutdown, - [this](const Message* const) { - this->request_stop(); - } - ); - events_initialize(chThdSelf()); m0apptxevent_interrupt_enable(); @@ -159,7 +142,6 @@ public: } private: - MessageHandlerMap message_map; BasebandThread baseband_thread; RSSIThread rssi_thread; @@ -182,10 +164,38 @@ private: void handle_baseband_queue() { std::array message_buffer; while(Message* const message = shared_memory.baseband_queue.pop(message_buffer)) { - message_map.send(message); + on_message(message); } } + void on_message(const Message* const message) { + switch(message->id) { + case Message::ID::BasebandConfiguration: + on_message_baseband_configuration(*reinterpret_cast(message)); + break; + + case Message::ID::Shutdown: + on_message_shutdown(*reinterpret_cast(message)); + break; + + default: + on_message_default(message); + break; + } + } + + void on_message_baseband_configuration(const BasebandConfigurationMessage& message) { + baseband_thread.set_configuration(message.configuration); + } + + void on_message_shutdown(const ShutdownMessage&) { + request_stop(); + } + + void on_message_default(const Message* const) { + // TODO: Pass to active baseband processor. + } + void handle_spectrum() { // TODO: Send this via another message?! baseband_thread.on_update_spectrum();