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();