From 6be93bef430159995acbbcbcddb9009863532b5b Mon Sep 17 00:00:00 2001 From: Jakub Pyszczak Date: Fri, 16 Apr 2021 13:04:17 +0200 Subject: [PATCH] [EGD-6166] HSP ringing Added HSP ring sound on incoming call event while there's bluetooth connection active and HSP is selected as the current profile. Possibility of pick up/decline the call using BT device buttons added. Slightly changed HSP initialization according to the UML-s added. Changed call hangup handler in service cellular. --- module-bluetooth/Bluetooth/CommandHandler.cpp | 6 ++ module-bluetooth/Bluetooth/CommandHandler.hpp | 3 + .../interface/profiles/A2DP/A2DP.cpp | 15 +++++ .../interface/profiles/A2DP/A2DP.hpp | 6 ++ .../Bluetooth/interface/profiles/HSP/HSP.cpp | 62 ++++++++++++++++++- .../Bluetooth/interface/profiles/HSP/HSP.hpp | 25 +++++++- .../interface/profiles/HSP/HSPImpl.hpp | 7 ++- .../Bluetooth/interface/profiles/Profile.hpp | 9 +++ .../interface/profiles/ProfileManager.cpp | 15 +++++ .../interface/profiles/ProfileManager.hpp | 3 + ...hsp_incoming_connection_establishment.puml | 15 +++++ ..._hsp_incoming_connection_establishment.svg | 28 +++++++++ module-bluetooth/bt_hsp_ring_handler.puml | 15 +++++ module-bluetooth/bt_hsp_ring_handler.svg | 28 +++++++++ module-bluetooth/bt_hsp_ring_trigger.puml | 14 +++++ module-bluetooth/bt_hsp_ring_trigger.svg | 27 ++++++++ .../service-audio/ServiceAudio.cpp | 19 +++++- .../service-bluetooth/ServiceBluetooth.cpp | 18 ++++++ .../service-bluetooth/ServiceBluetooth.hpp | 5 +- .../messages/AudioRouting.hpp | 12 ++++ .../service-bluetooth/messages/Ring.hpp | 32 ++++++++++ .../service-cellular/ServiceCellular.cpp | 15 +++-- .../service-cellular/ServiceCellular.hpp | 2 +- module-utils/log/Logger.cpp | 1 + 24 files changed, 366 insertions(+), 16 deletions(-) create mode 100644 module-bluetooth/bt_hsp_incoming_connection_establishment.puml create mode 100644 module-bluetooth/bt_hsp_incoming_connection_establishment.svg create mode 100644 module-bluetooth/bt_hsp_ring_handler.puml create mode 100644 module-bluetooth/bt_hsp_ring_handler.svg create mode 100644 module-bluetooth/bt_hsp_ring_trigger.puml create mode 100644 module-bluetooth/bt_hsp_ring_trigger.svg create mode 100644 module-services/service-bluetooth/service-bluetooth/messages/AudioRouting.hpp create mode 100644 module-services/service-bluetooth/service-bluetooth/messages/Ring.hpp diff --git a/module-bluetooth/Bluetooth/CommandHandler.cpp b/module-bluetooth/Bluetooth/CommandHandler.cpp index 27acbf05f996cc4f1b7ad0c7555a30d4877f53e1..55c594366199a8e54f1ea50b58796373055a5f7b 100644 --- a/module-bluetooth/Bluetooth/CommandHandler.cpp +++ b/module-bluetooth/Bluetooth/CommandHandler.cpp @@ -69,6 +69,12 @@ namespace bluetooth return switchAudioProfile(); case bluetooth::Command::None: return Error::Success; + case Command::StartRinging: + return profileManager->startRinging(); + case Command::StopRinging: + return profileManager->stopRinging(); + case Command::StartRouting: + return profileManager->initializeCall(); case Command::StartStream: profileManager->start(); return Error::Success; diff --git a/module-bluetooth/Bluetooth/CommandHandler.hpp b/module-bluetooth/Bluetooth/CommandHandler.hpp index cf71639ea5a29fad43e186958575b90a82428fac..ff11a512c40c4440c059ed0a34936903ef9dc18b 100644 --- a/module-bluetooth/Bluetooth/CommandHandler.hpp +++ b/module-bluetooth/Bluetooth/CommandHandler.hpp @@ -35,6 +35,9 @@ namespace bluetooth PowerOff, Pair, Unpair, + StartRinging, + StopRinging, + StartRouting, StartStream, StopStream, SwitchProfile, diff --git a/module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DP.cpp b/module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DP.cpp index d182ee6c64eec6e6cf26153e597b4e4e3086f6e1..c4f18ad987f811c0bcc25600f30756d0d08e22bb 100644 --- a/module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DP.cpp +++ b/module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DP.cpp @@ -95,6 +95,21 @@ namespace bluetooth pimpl->stop(); } + auto A2DP::startRinging() const noexcept -> Error::Code + { + return Error::SystemError; + } + + auto A2DP::stopRinging() const noexcept -> Error::Code + { + return Error::SystemError; + } + + auto A2DP::initializeCall() const noexcept -> Error::Code + { + return Error::SystemError; + } + void A2DP::setAudioDevice(std::shared_ptr audioDevice) { pimpl->setAudioDevice(std::move(audioDevice)); diff --git a/module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DP.hpp b/module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DP.hpp index 8e98cf2ba31b101a85544baa03f58ffb338dbf63..45978771312cd0fa458e06f773e4babe157840ab 100644 --- a/module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DP.hpp +++ b/module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DP.hpp @@ -30,6 +30,12 @@ namespace bluetooth void disconnect() override; void start() override; void stop() override; + /// @return SystemError - it's not posible to start ringing while there's A2DP active + [[nodiscard]] auto startRinging() const noexcept -> Error::Code override; + /// @return SystemError - it's not posible to stop ringing while there's A2DP active + [[nodiscard]] auto stopRinging() const noexcept -> Error::Code override; + /// @return SystemError - it's not posible to start routing while there's A2DP active + [[nodiscard]] auto initializeCall() const noexcept -> Error::Code override; void setAudioDevice(std::shared_ptr audioDevice) override; diff --git a/module-bluetooth/Bluetooth/interface/profiles/HSP/HSP.cpp b/module-bluetooth/Bluetooth/interface/profiles/HSP/HSP.cpp index dd27c13248e1e753f940837c07104418a4e603a4..f4db01516c91992e1db3f3efe9dc044b5ae76f17 100644 --- a/module-bluetooth/Bluetooth/interface/profiles/HSP/HSP.cpp +++ b/module-bluetooth/Bluetooth/interface/profiles/HSP/HSP.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include extern "C" @@ -20,6 +21,16 @@ extern "C" namespace bluetooth { + bool CellularInterfaceImpl::answerIncomingCall(sys::Service *service) + { + return CellularServiceAPI::AnswerIncomingCall(service); + } + + bool CellularInterfaceImpl::hangupCall(sys::Service *service) + { + return CellularServiceAPI::HangupCall(service); + } + HSP::HSP() : pimpl(std::make_unique(HSPImpl())) {} @@ -71,6 +82,24 @@ namespace bluetooth pimpl->stop(); } + auto HSP::startRinging() const noexcept -> Error::Code + { + pimpl->startRinging(); + return Error::Success; + } + + auto HSP::stopRinging() const noexcept -> Error::Code + { + pimpl->stopRinging(); + return Error::Success; + } + + auto HSP::initializeCall() const noexcept -> Error::Code + { + pimpl->initializeCall(); + return Error::Success; + } + HSP::~HSP() = default; uint16_t HSP::HSPImpl::scoHandle = HCI_CON_HANDLE_INVALID; @@ -78,6 +107,7 @@ namespace bluetooth std::array HSP::HSPImpl::ATcommandBuffer; std::array HSP::HSPImpl::serviceBuffer; std::unique_ptr HSP::HSPImpl::sco; + std::unique_ptr HSP::HSPImpl::cellularInterface = nullptr; const sys::Service *HSP::HSPImpl::ownerService; std::string HSP::HSPImpl::agServiceName = "PurePhone HSP"; bool HSP::HSPImpl::isConnected = false; @@ -153,6 +183,7 @@ namespace bluetooth else { scoHandle = hsp_subevent_audio_connection_complete_get_handle(event); LOG_DEBUG("Audio connection established with SCO handle 0x%04x.\n", scoHandle); + cellularInterface->answerIncomingCall(const_cast(ownerService)); hci_request_sco_can_send_now_event(); RunLoop::trigger(); } @@ -160,6 +191,7 @@ namespace bluetooth case HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE: LOG_DEBUG("Audio connection released.\n\n"); sendAudioEvent(audio::EventType::BlutoothHSPDeviceState, audio::Event::DeviceState::Disconnected); + cellularInterface->hangupCall(const_cast(ownerService)); scoHandle = HCI_CON_HANDLE_INVALID; isConnected = false; break; @@ -185,12 +217,20 @@ namespace bluetooth } } + void HSP::HSPImpl::establishAudioConnection() + { + LOG_DEBUG("Establish Audio connection to %s...\n", bd_addr_to_str(deviceAddr)); + hsp_ag_establish_audio_connection(); + } + auto HSP::HSPImpl::init() -> Error::Code { sco = std::make_unique(); sco->setOwnerService(ownerService); sco->init(); + cellularInterface = std::make_unique(); + Profile::initL2cap(); Profile::initSdp(); @@ -233,7 +273,7 @@ namespace bluetooth void HSP::HSPImpl::setDeviceAddress(bd_addr_t addr) { bd_addr_copy(deviceAddr, addr); - LOG_INFO("Address set!"); + LOG_DEBUG("Address set!"); } void HSP::HSPImpl::setOwnerService(const sys::Service *service) @@ -250,12 +290,28 @@ namespace bluetooth if (!isConnected) { connect(); } - LOG_DEBUG("Establish Audio connection to %s...\n", bd_addr_to_str(deviceAddr)); - hsp_ag_establish_audio_connection(); } void HSP::HSPImpl::stop() { + stopRinging(); hsp_ag_release_audio_connection(); } + void HSP::HSPImpl::startRinging() const noexcept + { + LOG_DEBUG("Bluetooth ring started"); + hsp_ag_start_ringing(); + } + + void HSP::HSPImpl::stopRinging() const noexcept + { + LOG_DEBUG("Bluetooth ring stopped"); + hsp_ag_stop_ringing(); + } + + void HSP::HSPImpl::initializeCall() const noexcept + { + stopRinging(); + establishAudioConnection(); + } } // namespace bluetooth diff --git a/module-bluetooth/Bluetooth/interface/profiles/HSP/HSP.hpp b/module-bluetooth/Bluetooth/interface/profiles/HSP/HSP.hpp index e160f64263c7002db0976a1f241e6c3bcd4ed7ba..9e861d611b569a87152faed75b355d0aa7fbbbcc 100644 --- a/module-bluetooth/Bluetooth/interface/profiles/HSP/HSP.hpp +++ b/module-bluetooth/Bluetooth/interface/profiles/HSP/HSP.hpp @@ -9,7 +9,19 @@ namespace bluetooth { - + class CellularInterface + { + public: + virtual ~CellularInterface() = default; + virtual bool answerIncomingCall(sys::Service *service) = 0; + virtual bool hangupCall(sys::Service *service) = 0; + }; + class CellularInterfaceImpl : public CellularInterface + { + public: + bool answerIncomingCall(sys::Service *service) override; + bool hangupCall(sys::Service *service) override; + }; class HSP : public Profile { static constexpr auto CLASS_OF_DEVICE = 0x400204; @@ -31,6 +43,17 @@ namespace bluetooth void disconnect() override; void start() override; void stop() override; + /// @brief Starts ring + /// @return Success + [[nodiscard]] auto startRinging() const noexcept -> Error::Code override; + /// @brief Stops ring + /// @return Success + [[nodiscard]] auto stopRinging() const noexcept -> Error::Code override; + /// @brief Initializes bluetooth audio call which is divided into two parts: + /// - Ring stop + /// - SCO link establishment + /// @return Success + [[nodiscard]] auto initializeCall() const noexcept -> Error::Code override; void setAudioDevice(std::shared_ptr audioDevice) override {} diff --git a/module-bluetooth/Bluetooth/interface/profiles/HSP/HSPImpl.hpp b/module-bluetooth/Bluetooth/interface/profiles/HSP/HSPImpl.hpp index 3f9c168df7820c1945e26b677b0106c7bebc40d9..bbd362e2feca0e7593dd75d9309bc9e59c3e203f 100644 --- a/module-bluetooth/Bluetooth/interface/profiles/HSP/HSPImpl.hpp +++ b/module-bluetooth/Bluetooth/interface/profiles/HSP/HSPImpl.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -19,6 +19,9 @@ namespace bluetooth auto init() -> Error::Code; void start(); void stop(); + void startRinging() const noexcept; + void stopRinging() const noexcept; + void initializeCall() const noexcept; void connect(); void disconnect(); void setDeviceAddress(bd_addr_t addr); @@ -29,11 +32,13 @@ namespace bluetooth static void sendAudioEvent(audio::EventType event, audio::Event::DeviceState state); static void processHCIEvent(uint8_t *event); static void processHSPEvent(uint8_t *event); + static void establishAudioConnection(); static std::array serviceBuffer; static constexpr uint8_t rfcommChannelNr = 1; static std::string agServiceName; static uint16_t scoHandle; static std::unique_ptr sco; + static std::unique_ptr cellularInterface; static std::array ATcommandBuffer; static bd_addr_t deviceAddr; static const sys::Service *ownerService; diff --git a/module-bluetooth/Bluetooth/interface/profiles/Profile.hpp b/module-bluetooth/Bluetooth/interface/profiles/Profile.hpp index f16eb59c6981abfb07fdaac6e8378be4af6b84b6..02e2b062ae94b41c335ab549add91b89ea30a530 100644 --- a/module-bluetooth/Bluetooth/interface/profiles/Profile.hpp +++ b/module-bluetooth/Bluetooth/interface/profiles/Profile.hpp @@ -24,6 +24,15 @@ namespace bluetooth virtual void stop() = 0; virtual void disconnect() = 0; virtual void setAudioDevice(std::shared_ptr audioDevice) = 0; + /// Starts ringing + /// @return Error code that determines, whether operation was successful or not + [[nodiscard]] virtual auto startRinging() const noexcept -> Error::Code = 0; + /// Stops ringing + /// @return Error code that determines, whether operation was successful or not + [[nodiscard]] virtual auto stopRinging() const noexcept -> Error::Code = 0; + /// Initializes call + /// @return Error code that determines, whether operation was successful or not + [[nodiscard]] virtual auto initializeCall() const noexcept -> Error::Code = 0; protected: static void initSdp(); diff --git a/module-bluetooth/Bluetooth/interface/profiles/ProfileManager.cpp b/module-bluetooth/Bluetooth/interface/profiles/ProfileManager.cpp index 6ec94bb3ca3b9abfb3a68ddae0c32ea11fbad0f6..23267ce335bbbc3f7a4058255efa7938bf0d20d2 100644 --- a/module-bluetooth/Bluetooth/interface/profiles/ProfileManager.cpp +++ b/module-bluetooth/Bluetooth/interface/profiles/ProfileManager.cpp @@ -95,6 +95,21 @@ namespace bluetooth return Error::Success; } + auto ProfileManager::startRinging() -> Error::Code + { + return currentProfilePtr->startRinging(); + } + + auto ProfileManager::stopRinging() -> Error::Code + { + return currentProfilePtr->stopRinging(); + } + + auto ProfileManager::initializeCall() -> Error::Code + { + return currentProfilePtr->initializeCall(); + } + auto ProfileManager::setAudioDevice(std::shared_ptr device) -> Error::Code { if (currentProfilePtr == nullptr) { diff --git a/module-bluetooth/Bluetooth/interface/profiles/ProfileManager.hpp b/module-bluetooth/Bluetooth/interface/profiles/ProfileManager.hpp index 56c441a777838606dfbb67405c03d0394aa04b6f..cd282085b5d9009fdd05973a200587ae428660cd 100644 --- a/module-bluetooth/Bluetooth/interface/profiles/ProfileManager.hpp +++ b/module-bluetooth/Bluetooth/interface/profiles/ProfileManager.hpp @@ -46,6 +46,9 @@ namespace bluetooth auto start() -> Error::Code; auto stop() -> Error::Code; + auto startRinging() -> Error::Code; + auto stopRinging() -> Error::Code; + auto initializeCall() -> Error::Code; auto setAudioDevice(std::shared_ptr device) -> Error::Code; diff --git a/module-bluetooth/bt_hsp_incoming_connection_establishment.puml b/module-bluetooth/bt_hsp_incoming_connection_establishment.puml new file mode 100644 index 0000000000000000000000000000000000000000..e5357658f26eea685ffe645b3695192faafbe830 --- /dev/null +++ b/module-bluetooth/bt_hsp_incoming_connection_establishment.puml @@ -0,0 +1,15 @@ +@startuml + +participant "Bluetooth Headset" as HS +participant "Pure Phone" as AG + + activate HS + activate AG + AG -> HS : Connection establishment + AG -> HS : Ring + ... + -> HS : User initiated action + HS -> AG : AT+CKPD=200 + AG -> HS : OK + AG -> HS : SCO link establishment +@enduml \ No newline at end of file diff --git a/module-bluetooth/bt_hsp_incoming_connection_establishment.svg b/module-bluetooth/bt_hsp_incoming_connection_establishment.svg new file mode 100644 index 0000000000000000000000000000000000000000..eb4bd8cf78ca192b59231bf7a9c7fa76ad5ccd32 --- /dev/null +++ b/module-bluetooth/bt_hsp_incoming_connection_establishment.svg @@ -0,0 +1,28 @@ +Bluetooth HeadsetBluetooth HeadsetPure PhonePure PhoneConnection establishmentRingUser initiated actionAT+CKPD=200OKSCO link establishment \ No newline at end of file diff --git a/module-bluetooth/bt_hsp_ring_handler.puml b/module-bluetooth/bt_hsp_ring_handler.puml new file mode 100644 index 0000000000000000000000000000000000000000..0ad2fa91edd5350a864a0e7133a81aaebe77e7e4 --- /dev/null +++ b/module-bluetooth/bt_hsp_ring_handler.puml @@ -0,0 +1,15 @@ +@startuml +start +note right + Ringing +end note +while (Call terminated) is (no) + if (Answer a call) then (no) + else (yes) + :SCO link established; + break; + endif +endwhile +:Stop Ringing; +stop +@enduml diff --git a/module-bluetooth/bt_hsp_ring_handler.svg b/module-bluetooth/bt_hsp_ring_handler.svg new file mode 100644 index 0000000000000000000000000000000000000000..f6c41b1b9e66c7e31f4cabe9cae1ce7791e79ea9 --- /dev/null +++ b/module-bluetooth/bt_hsp_ring_handler.svg @@ -0,0 +1,28 @@ +RingingSCO link establishedyesAnswer a callnonoCall terminatedStop Ringing \ No newline at end of file diff --git a/module-bluetooth/bt_hsp_ring_trigger.puml b/module-bluetooth/bt_hsp_ring_trigger.puml new file mode 100644 index 0000000000000000000000000000000000000000..bc2dedea07fd417d2a2b84b9570769c8cdf92ba7 --- /dev/null +++ b/module-bluetooth/bt_hsp_ring_trigger.puml @@ -0,0 +1,14 @@ +@startuml +start +note right + Call incoming +end note +:Service Cellular; +:Application call; +:Service Audio; +:Service Bluetooth; +if (Current profile allows ringing) then (yes) + :Ring; +endif +stop +@enduml diff --git a/module-bluetooth/bt_hsp_ring_trigger.svg b/module-bluetooth/bt_hsp_ring_trigger.svg new file mode 100644 index 0000000000000000000000000000000000000000..d33698908048033ced7f55041835c7b4b982a232 --- /dev/null +++ b/module-bluetooth/bt_hsp_ring_trigger.svg @@ -0,0 +1,27 @@ +Call incomingService CellularApplication callService AudioService BluetoothRingyesCurrent profile allows ringing \ No newline at end of file diff --git a/module-services/service-audio/ServiceAudio.cpp b/module-services/service-audio/ServiceAudio.cpp index bfe6e25b6ec8ccccfce5f1ecc67768ead51ef35e..747bdf57d4ec8d7fe4704ac6a85ed42131f06137 100644 --- a/module-services/service-audio/ServiceAudio.cpp +++ b/module-services/service-audio/ServiceAudio.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include @@ -319,9 +321,16 @@ std::unique_ptr ServiceAudio::HandleStart(const Operation: auto input = audioMux.GetPlaybackInput(playbackType); // stop bluetooth stream if available if (bluetoothConnected) { - LOG_DEBUG("Sending Bluetooth start stream request"); - bus.sendUnicast(std::make_shared(BluetoothMessage::Request::Play), - service::name::bluetooth); + if (playbackType == audio::PlaybackType::CallRingtone) { + LOG_DEBUG("Sending Bluetooth start ringing"); + bus.sendUnicast(std::make_shared(message::bluetooth::Ring::State::Enable), + service::name::bluetooth); + } + else { + LOG_DEBUG("Sending Bluetooth start stream request"); + bus.sendUnicast(std::make_shared(BluetoothMessage::Request::Play), + service::name::bluetooth); + } } AudioStart(input); @@ -334,6 +343,10 @@ std::unique_ptr ServiceAudio::HandleStart(const Operation: } else if (opType == Operation::Type::Router) { auto input = audioMux.GetRoutingInput(true); + if (bluetoothConnected) { + LOG_DEBUG("Sending Bluetooth start routing"); + bus.sendUnicast(std::make_shared(), service::name::bluetooth); + } AudioStart(input); return std::make_unique(retCode, retToken); } diff --git a/module-services/service-bluetooth/ServiceBluetooth.cpp b/module-services/service-bluetooth/ServiceBluetooth.cpp index a7a409e1bc425614337031c8abdc871557f36fe5..4e709c5c679a7e1a4c6f0abf7e9c2e248a0c4b39 100644 --- a/module-services/service-bluetooth/ServiceBluetooth.cpp +++ b/module-services/service-bluetooth/ServiceBluetooth.cpp @@ -11,6 +11,7 @@ #include #include #include "service-bluetooth/messages/AudioVolume.hpp" +#include "service-bluetooth/messages/AudioRouting.hpp" #include "service-bluetooth/messages/Connect.hpp" #include "service-bluetooth/messages/Disconnect.hpp" #include "service-bluetooth/messages/Status.hpp" @@ -18,6 +19,7 @@ #include "service-bluetooth/messages/BondedDevices.hpp" #include "service-bluetooth/messages/Unpair.hpp" #include "service-bluetooth/messages/SetDeviceName.hpp" +#include "service-bluetooth/messages/Ring.hpp" #include "SystemManager/messages/SentinelRegistrationMessage.hpp" @@ -76,6 +78,8 @@ sys::ReturnCodes ServiceBluetooth::InitHandler() connectHandler(); connectHandler(); connectHandler(); + connectHandler(); + connectHandler(); connectHandler(); connectHandler(); connectHandler(); @@ -319,6 +323,20 @@ auto ServiceBluetooth::handle(message::bluetooth::AudioVolume *msg) -> std::shar return sys::MessageNone{}; } +auto ServiceBluetooth::handle(message::bluetooth::Ring *msg) -> std::shared_ptr +{ + const auto enableRing = msg->enabled(); + sendWorkerCommand(bluetooth::Command(enableRing ? bluetooth::Command::Type::StartRinging + : bluetooth::Command::Type::StopRinging)); + return std::make_shared(); +} + +auto ServiceBluetooth::handle(message::bluetooth::StartAudioRouting *msg) -> std::shared_ptr +{ + sendWorkerCommand(bluetooth::Command(bluetooth::Command::Type::StartRouting)); + return std::make_shared(); +} + void ServiceBluetooth::startTimeoutTimer() { if (connectionTimeoutTimer.isValid()) { diff --git a/module-services/service-bluetooth/service-bluetooth/ServiceBluetooth.hpp b/module-services/service-bluetooth/service-bluetooth/ServiceBluetooth.hpp index d6886c2effd5c18217f64e63334dfc1bbbffcc43..bb75c80eb153521d92c5d26648721ca06cdfa995 100644 --- a/module-services/service-bluetooth/service-bluetooth/ServiceBluetooth.hpp +++ b/module-services/service-bluetooth/service-bluetooth/ServiceBluetooth.hpp @@ -45,7 +45,8 @@ namespace message::bluetooth class Disconnect; class DisconnectResult; class AudioVolume; - + class Ring; + class StartAudioRouting; } // namespace message::bluetooth class ServiceBluetooth : public sys::Service @@ -93,6 +94,8 @@ class ServiceBluetooth : public sys::Service [[nodiscard]] auto handle(sdesktop::developerMode::DeveloperModeRequest *msg) -> std::shared_ptr; [[nodiscard]] auto handle(BluetoothAudioStartMessage *msg) -> std::shared_ptr; [[nodiscard]] auto handle(message::bluetooth::AudioVolume *msg) -> std::shared_ptr; + [[nodiscard]] auto handle(message::bluetooth::Ring *msg) -> std::shared_ptr; + [[nodiscard]] auto handle(message::bluetooth::StartAudioRouting *msg) -> std::shared_ptr; }; namespace sys diff --git a/module-services/service-bluetooth/service-bluetooth/messages/AudioRouting.hpp b/module-services/service-bluetooth/service-bluetooth/messages/AudioRouting.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1c9232fb93c638376b1a059b3b82679482f25a58 --- /dev/null +++ b/module-services/service-bluetooth/service-bluetooth/messages/AudioRouting.hpp @@ -0,0 +1,12 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include "service-bluetooth/BluetoothMessage.hpp" + +namespace message::bluetooth +{ + class StartAudioRouting : public BluetoothMessage + {}; +} // namespace message::bluetooth diff --git a/module-services/service-bluetooth/service-bluetooth/messages/Ring.hpp b/module-services/service-bluetooth/service-bluetooth/messages/Ring.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5683cfced5b6a44ffe3e5f8e84148863cdc658bc --- /dev/null +++ b/module-services/service-bluetooth/service-bluetooth/messages/Ring.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include "service-bluetooth/BluetoothMessage.hpp" + +namespace message::bluetooth +{ + /// @brief Message that indicates whether to enable or disable bluetooth ring + class Ring : public BluetoothMessage + { + public: + enum class State : bool + { + Enable, + Disable + }; + + explicit Ring(State state) : state{state} + {} + + /// @return True if bluetooth should ring, false otherwise + [[nodiscard]] auto enabled() const noexcept -> bool + { + return state == State::Enable; + } + + private: + const State state; + }; +} // namespace message::bluetooth diff --git a/module-services/service-cellular/ServiceCellular.cpp b/module-services/service-cellular/ServiceCellular.cpp index 8d5b5e24668d81ace397921644f3eec9ce92ff12..0df57ad630add34bf4ad2139e93fc7a8ae917aeb 100644 --- a/module-services/service-cellular/ServiceCellular.cpp +++ b/module-services/service-cellular/ServiceCellular.cpp @@ -500,7 +500,8 @@ void ServiceCellular::registerMessageHandlers() connect(typeid(CellularHangupCallMessage), [&](sys::Message *request) -> sys::MessagePointer { auto msg = static_cast(request); - return handleCellularHangupCallMessage(msg); + handleCellularHangupCallMessage(msg); + return sys::MessageNone{}; }); connect(typeid(db::QueryResponse), [&](sys::Message *request) -> sys::MessagePointer { @@ -2291,8 +2292,7 @@ auto ServiceCellular::handleCellularCallRequestMessage(CellularCallRequestMessag return std::make_shared(request->isHandled()); } -auto ServiceCellular::handleCellularHangupCallMessage(CellularHangupCallMessage *msg) - -> std::shared_ptr +void ServiceCellular::handleCellularHangupCallMessage(CellularHangupCallMessage *msg) { auto channel = cmux->get(TS0710::Channel::Commands); LOG_INFO("CellularHangupCall"); @@ -2303,14 +2303,17 @@ auto ServiceCellular::handleCellularHangupCallMessage(CellularHangupCallMessage if (!ongoingCall.endCall(CellularCall::Forced::True)) { LOG_ERROR("Failed to end ongoing call"); } - return std::make_shared(true, msg->messageType); + bus.sendMulticast(std::make_shared(true, msg->messageType), + sys::BusChannel::ServiceCellularNotifications); } else { LOG_ERROR("Call not aborted"); - return std::make_shared(false, msg->messageType); + bus.sendMulticast(std::make_shared(false, msg->messageType), + sys::BusChannel::ServiceCellularNotifications); } } - return std::make_shared(false, msg->messageType); + bus.sendMulticast(std::make_shared(false, msg->messageType), + sys::BusChannel::ServiceCellularNotifications); } auto ServiceCellular::handleDBQueryResponseMessage(db::QueryResponse *msg) -> std::shared_ptr diff --git a/module-services/service-cellular/service-cellular/ServiceCellular.hpp b/module-services/service-cellular/service-cellular/ServiceCellular.hpp index e398a8dfc0acf92a1ad5128843e39c14b82e6057..640bb5ae101363d9ed32d736e288c6cdd35709a7 100644 --- a/module-services/service-cellular/service-cellular/ServiceCellular.hpp +++ b/module-services/service-cellular/service-cellular/ServiceCellular.hpp @@ -341,7 +341,7 @@ class ServiceCellular : public sys::Service auto handleCellularAnswerIncomingCallMessage(CellularMessage *msg) -> std::shared_ptr; auto handleCellularCallRequestMessage(CellularCallRequestMessage *msg) -> std::shared_ptr; - auto handleCellularHangupCallMessage(CellularHangupCallMessage *msg) -> std::shared_ptr; + void handleCellularHangupCallMessage(CellularHangupCallMessage *msg); auto handleDBQueryResponseMessage(db::QueryResponse *msg) -> std::shared_ptr; auto handleCellularListCallsMessage(CellularMessage *msg) -> std::shared_ptr; auto handleDBNotificatioMessage(db::NotificationMessage *msg) -> std::shared_ptr; diff --git a/module-utils/log/Logger.cpp b/module-utils/log/Logger.cpp index 220b055427c17a416ff330d7aad8c09e9b5df3b7..5b9f1be1b5ba284868f7c195ecd8607b83df8ba6 100644 --- a/module-utils/log/Logger.cpp +++ b/module-utils/log/Logger.cpp @@ -15,6 +15,7 @@ namespace Log {"ServiceCellular", logger_level::LOGINFO}, {"ServiceAntenna", logger_level::LOGINFO}, {"ServiceAudio", logger_level::LOGINFO}, + {"ServiceBluetooth", logger_level::LOGINFO}, {"ServiceFota", logger_level::LOGINFO}, {"ServiceEink", logger_level::LOGINFO}, {"ServiceDB", logger_level::LOGINFO},