M .gitmodules => .gitmodules +2 -2
@@ 35,10 35,10 @@
url = https://github.com/catchorg/Catch2
[submodule "module-utils/date"]
path = module-utils/date
- url = git@github.com:mudita/date.git
+ url = ../date.git
[submodule "module-audio/Audio/decoder/minimp3"]
path = module-audio/Audio/decoder/minimp3
- url = git@github.com:mudita/minimp3.git
+ url = ../minimp3.git
branch = RT1051
[submodule "module-audio/Audio/decoder/taglib"]
path = module-audio/Audio/decoder/taglib
M module-apps/application-settings/ApplicationSettings.cpp => module-apps/application-settings/ApplicationSettings.cpp +16 -1
@@ 12,6 12,7 @@
#include "windows/SettingsMainWindow.hpp"
#include "windows/LanguageWindow.hpp"
#include "windows/BtWindow.hpp"
+#include "windows/BtScanWindow.hpp"
#include "windows/DateTimeWindow.hpp"
#include "windows/FotaWindow.hpp"
#include "windows/Info.hpp"
@@ 31,7 32,7 @@
#include "windows/SettingsChange.hpp"
#include <module-services/service-evtmgr/api/EventManagerServiceAPI.hpp>
-
+#include <service-bluetooth/messages/BluetoothMessage.hpp>
#include <i18/i18.hpp>
namespace app
@@ 53,7 54,17 @@ namespace app
if (reinterpret_cast<sys::ResponseMessage *>(retMsg.get())->retCode == sys::ReturnCodes::Success) {
return retMsg;
}
+ if (auto btmsg = dynamic_cast<BluetoothScanMessage *>(msgl); btmsg != nullptr) {
+ auto devices = btmsg->devices;
+ LOG_INFO("received BT Scan message!");
+ auto window = new gui::BtScanWindow(this, devices);
+ windows.erase(gui::name::window::name_btscan);
+ windows.insert(std::pair<std::string, gui::AppWindow *>(window->getName(), window));
+ setActiveWindow(gui::name::window::name_btscan);
+ // this->switchWindow("BT_SCAN",nullptr);
+ render(gui::RefreshModes::GUI_REFRESH_FAST);
+ }
// this variable defines whether message was processed.
bool handled = true;
@@ 99,6 110,10 @@ namespace app
window = new gui::BtWindow(this);
windows.insert(std::pair<std::string, gui::AppWindow *>(window->getName(), window));
+ window = new gui::BtScanWindow(this, std::vector<Devicei>());
+ window->setVisible(false);
+ windows.insert(std::pair<std::string, gui::AppWindow *>(window->getName(), window));
+
window = new gui::UiTestWindow(this);
windows.insert(std::pair<std::string, gui::AppWindow *>(window->getName(), window));
M module-apps/application-settings/CMakeLists.txt => module-apps/application-settings/CMakeLists.txt +1 -0
@@ 18,6 18,7 @@ target_sources( ${PROJECT_NAME}
windows/SettingsMainWindow.cpp
windows/LanguageWindow.cpp
windows/BtWindow.cpp
+ windows/BtScanWindow.cpp
windows/UITestWindow.cpp
windows/Info.cpp
A module-apps/application-settings/windows/BtScanWindow.cpp => module-apps/application-settings/windows/BtScanWindow.cpp +106 -0
@@ 0,0 1,106 @@
+#include <functional>
+#include <memory>
+
+#include "service-appmgr/ApplicationManager.hpp"
+
+#include "../ApplicationSettings.hpp"
+
+#include "i18/i18.hpp"
+
+#include "BtScanWindow.hpp"
+#include "Label.hpp"
+#include "Margins.hpp"
+
+#include <Style.hpp>
+
+namespace gui
+{
+
+ BtScanWindow::BtScanWindow(app::Application *app, std::vector<Devicei> devices)
+ : AppWindow(app, name::window::name_btscan), devices(devices)
+ {
+ buildInterface();
+ }
+
+ void BtScanWindow::rebuild()
+ {
+ destroyInterface();
+ buildInterface();
+ }
+
+ void add_box_label2(VBox *layout, UTF8 name, std::function<bool(Item &)> foo)
+ {
+ auto el = new gui::Label(nullptr, 0, 0, layout->getWidth(), style::window::label::default_h);
+ style::window::decorateOption(el);
+ el->setText(name);
+ el->activatedCallback = std::move(foo);
+ layout->addWidget(el);
+ }
+
+ sys::ReturnCodes message_bt2(app::Application *app, BluetoothMessage::Request req)
+ {
+ std::shared_ptr<BluetoothMessage> msg = std::make_shared<BluetoothMessage>(req);
+ auto ret = sys::Bus::SendUnicast(msg, "ServiceBluetooth", app);
+ if (!ret) {
+ LOG_ERROR("err: %d", static_cast<int>(ret));
+ }
+ return ret ? sys::ReturnCodes::Success : sys::ReturnCodes::Failure;
+ }
+
+ void BtScanWindow::buildInterface()
+ {
+ AppWindow::buildInterface();
+ bottomBar->setActive(BottomBar::Side::CENTER, true);
+ bottomBar->setActive(BottomBar::Side::RIGHT, true);
+ bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::select));
+ bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back));
+ topBar->setActive(TopBar::Elements::SIGNAL, true);
+ topBar->setActive(TopBar::Elements::BATTERY, true);
+
+ setTitle(utils::localize.get("BT_scan_results"));
+
+ box = new gui::VBox(this, 0, title->offset_h(), style::window_width, 7 * style::window::label::default_h);
+
+ for (auto device : devices) {
+ add_box_label2(box, device.name, [=](Item &) {
+ LOG_DEBUG("Device: %s", device.name.c_str());
+
+ std::shared_ptr<BluetoothAddrMessage> msg =
+ std::make_shared<BluetoothAddrMessage>(bd_addr_to_str(device.address));
+ sys::Bus::SendUnicast(msg, "ServiceBluetooth", application, 5000);
+
+ message_bt2(application, BluetoothMessage::Request::StopScan);
+ // message_bt2(application, BluetoothMessage::Request::Start);
+
+ return true;
+ });
+ }
+ for (auto &el : box->children) {
+ el->visible = true;
+ }
+ box->setPenWidth(style::window::default_border_no_focus_w);
+ box->setVisible(true);
+ setFocusItem(box);
+ application->render(gui::RefreshModes::GUI_REFRESH_FAST);
+ }
+
+ bool BtScanWindow::onInput(const InputEvent &inputEvent)
+ {
+ return AppWindow::onInput(inputEvent);
+ }
+
+ void BtScanWindow::destroyInterface()
+ {
+ erase();
+ invalidate();
+ }
+
+ void BtScanWindow::invalidate() noexcept
+ {
+ box = nullptr;
+ }
+
+ void BtScanWindow::onBeforeShow(ShowMode mode, SwitchData *data)
+ {}
+
+} // namespace gui
A module-apps/application-settings/windows/BtScanWindow.hpp => module-apps/application-settings/windows/BtScanWindow.hpp +39 -0
@@ 0,0 1,39 @@
+#pragma once
+
+#include <functional>
+#include <string>
+
+#include "AppWindow.hpp"
+#include "gui/widgets/Image.hpp"
+#include "gui/widgets/Label.hpp"
+#include "gui/widgets/Window.hpp"
+#include <memory>
+#include <BoxLayout.hpp>
+#include <service-bluetooth/messages/BluetoothMessage.hpp>
+
+namespace gui
+{
+ namespace name::window
+ {
+ inline const std::string name_btscan = "BT_SCAN";
+ }
+
+ class BtScanWindow : public AppWindow
+ {
+ protected:
+ VBox *box;
+
+ public:
+ BtScanWindow(app::Application *app, std::vector<Devicei> devices);
+
+ void onBeforeShow(ShowMode mode, SwitchData *data) override;
+ void rebuild() override;
+ void buildInterface() override;
+ auto onInput(const InputEvent &inputEvent) -> bool override;
+ void destroyInterface() override;
+
+ private:
+ void invalidate() noexcept;
+ std::vector<Devicei> devices;
+ };
+} // namespace gui
M module-apps/application-settings/windows/BtWindow.cpp => module-apps/application-settings/windows/BtWindow.cpp +6 -4
@@ 4,6 4,7 @@
#include "service-appmgr/ApplicationManager.hpp"
#include "../ApplicationSettings.hpp"
+#include "../windows/BtScanWindow.hpp"
#include "i18/i18.hpp"
@@ 41,11 42,11 @@ namespace gui
sys::ReturnCodes message_bt(app::Application *app, BluetoothMessage::Request req)
{
std::shared_ptr<BluetoothMessage> msg = std::make_shared<BluetoothMessage>(req);
- auto ret = sys::Bus::SendUnicast(msg, "ServiceBluetooth", app, 5000);
- if (ret.first != sys::ReturnCodes::Success) {
- LOG_ERROR("err: %d", static_cast<int>(ret.first));
+ auto ret = sys::Bus::SendUnicast(msg, "ServiceBluetooth", app);
+ if (!ret) {
+ LOG_ERROR("err: %d", static_cast<int>(ret));
}
- return ret.first;
+ return ret ? sys::ReturnCodes::Success : sys::ReturnCodes::Failure;
}
void BtWindow::buildInterface()
@@ 80,6 81,7 @@ namespace gui
add_box_label(box, " -> All devices", [=](Item &) {
LOG_DEBUG("Callback all devices");
message_bt(application, BluetoothMessage::Request::Scan);
+ application->setActiveWindow(gui::name::window::name_btscan);
return true;
});
M module-bluetooth/Bluetooth/BluetoothWorker.cpp => module-bluetooth/Bluetooth/BluetoothWorker.cpp +24 -7
@@ 2,13 2,18 @@
#include "log/log.hpp"
#include "BtCommand.hpp"
+extern "C"
+{
+#include "module-bluetooth/lib/btstack/src/btstack_util.h"
+};
+
using namespace bsp;
const char *c_str(Bt::Error::Code code)
{
switch (code) {
- case Bt::Error::Code::Succes:
- return "Succes";
+ case Bt::Error::Code::Success:
+ return "Success";
case Bt::Error::Code::NotReady:
return "NotReady";
case Bt::Error::Code::SystemError:
@@ 49,7 54,7 @@ bool BluetoothWorker::run()
std::string name = "PurePhone";
Bt::set_name(name);
// set local namne
- // set discoverable (on)
+ Bt::GAP::set_visibility(true);
// Bt::GAP::
Bt::run_stack(&this->bt_worker_task);
return true;
@@ 62,21 67,29 @@ bool BluetoothWorker::run()
bool BluetoothWorker::scan()
{
std::vector<Device> empty;
-
+ Bt::GAP::setOwnerService(service);
auto ret = Bt::GAP::scan();
- if (ret.err != Bt::Error::Succes) {
+ if (ret.err != Bt::Error::Success) {
LOG_ERROR("Cant start scan!: %s %" PRIu32 "", c_str(ret.err), ret.lib_code);
return false;
}
else {
LOG_INFO("Scan started!");
+ // open new scan window
return true;
}
}
+void BluetoothWorker::stop_scan()
+{
+ Bt::GAP::stop_scan();
+}
+
bool BluetoothWorker::set_visible()
{
- LOG_ERROR("TODO");
+ static bool visibility = true;
+ Bt::GAP::set_visibility(visibility);
+ visibility = !visibility;
return false;
}
@@ 85,7 98,7 @@ bool BluetoothWorker::start_pan()
{
Bt::PAN::bnep_setup();
auto err = Bt::PAN::bnep_start();
- if (err.err != Bt::Error::Succes) {
+ if (err.err != Bt::Error::Success) {
LOG_ERROR("PAN setup error: %s %" PRIu32, c_str(err.err), err.lib_code);
}
return false;
@@ 169,3 182,7 @@ bool BluetoothWorker::handleMessage(uint32_t queueID)
return true;
}
+void BluetoothWorker::set_addr(uint8_t *addr)
+{
+ LOG_INFO("ADDRESS %s SET!", bd_addr_to_str(addr));
+}
M module-bluetooth/Bluetooth/BluetoothWorker.hpp => module-bluetooth/Bluetooth/BluetoothWorker.hpp +2 -0
@@ 95,4 95,6 @@ class BluetoothWorker : private sys::Worker
Error aud_init();
/// bluetooth stack id in use
unsigned long active_features;
+ void stop_scan();
+ void set_addr(uint8_t *);
};
M module-bluetooth/Bluetooth/BtCommand.hpp => module-bluetooth/Bluetooth/BtCommand.hpp +11 -8
@@ 8,19 8,22 @@
namespace Bt
{
- Error initialize_stack();
- Error register_hw_error_callback(std::function<void(uint8_t)> new_callback = nullptr);
- Error set_name(std::string &name);
- Error run_stack(TaskHandle_t *handle);
+ auto initialize_stack() -> Error;
+ auto register_hw_error_callback(std::function<void(uint8_t)> new_callback = nullptr) -> Error;
+ auto set_name(std::string &name) -> Error;
+ auto run_stack(TaskHandle_t *handle) -> Error;
namespace GAP
{
/// THIS have to be called prior to Bt system start!
- Error register_scan();
- Error scan();
+ auto register_scan() -> Error;
+ auto scan() -> Error;
+ void stop_scan();
+ auto set_visibility(bool visibility) -> Error;
+ void setOwnerService(sys::Service *service);
}; // namespace GAP
namespace PAN
{
- Error bnep_start();
- Error bnep_setup();
+ auto bnep_start() -> Error;
+ auto bnep_setup() -> Error;
} // namespace PAN
}; // namespace Bt
M module-bluetooth/Bluetooth/Device.hpp => module-bluetooth/Bluetooth/Device.hpp +29 -2
@@ 1,11 1,38 @@
#pragma once
#include <string>
+#include <cstring>
+#include <utility>
+#include <module-bluetooth/lib/btstack/src/bluetooth.h>
struct Device
{
public:
- Device(std::string name = "") : name(name)
+ explicit Device(std::string name = "") : name(std::move(name))
{}
- virtual ~Device(){};
+ virtual ~Device() = default;
std::string name;
};
+
+enum DEVICE_STATE
+{
+ REMOTE_NAME_REQUEST,
+ REMOTE_NAME_INQUIRED,
+ REMOTE_NAME_FETCHED
+};
+
+struct Devicei : public Device
+{
+ public:
+ bd_addr_t address;
+ uint8_t pageScanRepetitionMode;
+ uint16_t clockOffset;
+ DEVICE_STATE state;
+
+ Devicei(std::string name = "") : Device(std::move(name))
+ {}
+ ~Devicei() override = default;
+ void address_set(bd_addr_t *addr)
+ {
+ memcpy(&address, addr, sizeof address);
+ }
+};
M module-bluetooth/Bluetooth/Error.hpp => module-bluetooth/Bluetooth/Error.hpp +3 -3
@@ 11,13 11,13 @@ namespace Bt
{
enum Code
{
- Succes,
+ Success,
NotReady,
SystemError,
LibraryError,
- } err = Succes;
+ } err = Success;
uint32_t lib_code = 0;
- Error(enum Code err = Succes, int lib_code = Succes) : err(err), lib_code(0)
+ Error(enum Code err = Success, int lib_code = Success) : err(err), lib_code(0)
{}
};
R module-bluetooth/Bluetooth/interface/bluekitchen/GAP.cpp => module-bluetooth/Bluetooth/interface/profiles/GAP.cpp +88 -81
@@ 1,43 1,26 @@
#include <Bluetooth/Device.hpp>
#include <log/log.hpp>
+#include "Service/Bus.hpp"
#include <vector>
#include <Bluetooth/Error.hpp>
+#include <module-services/service-bluetooth/messages/BluetoothMessage.hpp>
+#include "BluetoothWorker.hpp"
+#include "Device.hpp"
extern "C"
{
#include "btstack.h"
+#include "hci.h"
};
btstack_packet_callback_registration_t cb_handler;
-enum DEVICE_STATE
-{
- REMOTE_NAME_REQUEST,
- REMOTE_NAME_INQUIRED,
- REMOTE_NAME_FETCHED
-};
-
-struct Devicei : public Device
-{
- public:
- bd_addr_t address;
- uint8_t pageScanRepetitionMode;
- uint16_t clockOffset;
- enum DEVICE_STATE state;
-
- Devicei(std::string name = "") : name(name)
- {}
- virtual ~Devicei()
- {}
- void address_set(bd_addr_t *addr)
- {
- memcpy(&address, addr, sizeof address);
- }
- std::string name;
-};
std::vector<Devicei> devices;
-static int getDeviceIndexForAddress(std::vector<Devicei> &devs, bd_addr_t addr)
+static auto start_scan() -> int;
+static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
+
+static auto getDeviceIndexForAddress(std::vector<Devicei> &devs, bd_addr_t addr) -> int
{
int j;
for (j = 0; j < devs.size(); j++) {
@@ 56,24 39,73 @@ enum STATE
};
enum STATE state = INIT;
+namespace Bt::GAP
+{
+ static sys::Service *ownerService = nullptr;
+
+ void setOwnerService(sys::Service *service)
+ {
+ ownerService = service;
+ }
+
+ auto register_scan() -> Error
+ {
+ LOG_INFO("GAP register scan!");
+ /// -> this have to be called prior to power on!
+ hci_set_inquiry_mode(INQUIRY_MODE_RSSI_AND_EIR);
+ cb_handler.callback = &packet_handler;
+ hci_add_event_handler(&cb_handler);
+ return Error();
+ }
+
+ auto scan() -> Error
+ {
+ LOG_INFO("Start scan if active: %d: %d", hci_get_state(), state);
+ if (hci_get_state() == HCI_STATE_WORKING) {
+ if (int ret = start_scan(); ret != 0) {
+ LOG_ERROR("Start scan error!: 0x%X", ret);
+ return Error(Error::LibraryError, ret);
+ }
+ }
+ else {
+ return Error(Error::NotReady);
+ }
+ return Error();
+ }
+
+ void stop_scan()
+ {
+ gap_inquiry_force_stop();
+ LOG_INFO("Scan stopped!");
+ }
+
+ auto set_visibility(bool visibility) -> Error
+ {
+ gap_discoverable_control(static_cast<uint8_t>(visibility));
+ LOG_INFO("Visibility: %s", visibility ? "true" : "false");
+ return Error();
+ }
+} // namespace Bt::GAP
+
#define INQUIRY_INTERVAL 5
-static int start_scan(void)
+static auto start_scan() -> int
{
LOG_INFO("Starting inquiry scan..");
return gap_inquiry_start(INQUIRY_INTERVAL);
}
-static int has_more_remote_name_requests(void)
+static auto has_more_remote_name_requests() -> int
{
int i;
for (i = 0; i < devices.size(); i++) {
- if (devices[i].state == REMOTE_NAME_REQUEST)
+ if (devices[i].state == REMOTE_NAME_REQUEST) {
return 1;
+ }
}
return 0;
}
-static void do_next_remote_name_request(void)
+static void do_next_remote_name_request()
{
int i;
for (i = 0; i < devices.size(); i++) {
@@ 88,9 120,9 @@ static void do_next_remote_name_request(void)
}
}
-static void continue_remote_names(void)
+static void continue_remote_names()
{
- if (has_more_remote_name_requests()) {
+ if (has_more_remote_name_requests() != 0) {
do_next_remote_name_request();
return;
}
@@ 106,15 138,16 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
int i;
int index;
- if (packet_type != HCI_EVENT_PACKET)
+ if (packet_type != HCI_EVENT_PACKET) {
return;
+ }
uint8_t event = hci_event_packet_get_type(packet);
switch (state) {
- /* @text In INIT, an inquiry scan is started, and the application transits to
- * ACTIVE state.
- */
+ /* @text In INIT, an inquiry scan is started, and the application transits to
+ * ACTIVE state.
+ */
case INIT:
switch (event) {
case BTSTACK_EVENT_STATE:
@@ 127,23 160,24 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
}
break;
- /* @text In ACTIVE, the following events are processed:
- * - GAP Inquiry result event: BTstack provides a unified inquiry result that contain
- * Class of Device (CoD), page scan mode, clock offset. RSSI and name (from EIR) are optional.
- * - Inquiry complete event: the remote name is requested for devices without a fetched
- * name. The state of a remote name can be one of the following:
- * REMOTE_NAME_REQUEST, REMOTE_NAME_INQUIRED, or REMOTE_NAME_FETCHED.
- * - Remote name request complete event: the remote name is stored in the table and the
- * state is updated to REMOTE_NAME_FETCHED. The query of remote names is continued.
- */
+ /* @text In ACTIVE, the following events are processed:
+ * - GAP Inquiry result event: BTstack provides a unified inquiry result that contain
+ * Class of Device (CoD), page scan mode, clock offset. RSSI and name (from EIR) are optional.
+ * - Inquiry complete event: the remote name is requested for devices without a fetched
+ * name. The state of a remote name can be one of the following:
+ * REMOTE_NAME_REQUEST, REMOTE_NAME_INQUIRED, or REMOTE_NAME_FETCHED.
+ * - Remote name request complete event: the remote name is stored in the table and the
+ * state is updated to REMOTE_NAME_FETCHED. The query of remote names is continued.
+ */
case ACTIVE:
switch (event) {
case GAP_EVENT_INQUIRY_RESULT: {
gap_event_inquiry_result_get_bd_addr(packet, addr);
index = getDeviceIndexForAddress(devices, addr);
- if (index >= 0)
+ if (index >= 0) {
break; // already in our list
+ }
Devicei dev;
dev.address_set(&addr);
@@ 154,22 188,25 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
LOG_INFO("with COD: 0x%06x, ", (unsigned int)gap_event_inquiry_result_get_class_of_device(packet));
LOG_INFO("pageScan %d, ", dev.pageScanRepetitionMode);
LOG_INFO("clock offset 0x%04x", dev.clockOffset);
- if (gap_event_inquiry_result_get_rssi_available(packet)) {
+ if (gap_event_inquiry_result_get_rssi_available(packet) != 0u) {
LOG_INFO(", rssi %d dBm", (int8_t)gap_event_inquiry_result_get_rssi(packet));
}
- if (gap_event_inquiry_result_get_name_available(packet)) {
+ if (gap_event_inquiry_result_get_name_available(packet) != 0u) {
char name_buffer[240];
int name_len = gap_event_inquiry_result_get_name_len(packet);
memcpy(name_buffer, gap_event_inquiry_result_get_name(packet), name_len);
name_buffer[name_len] = 0;
LOG_INFO(", name '%s'", name_buffer);
+ dev.name = std::string{name_buffer};
dev.state = REMOTE_NAME_FETCHED;
- ;
}
else {
dev.state = REMOTE_NAME_REQUEST;
}
devices.push_back(dev);
+ auto msg = std::make_shared<BluetoothScanMessage>(devices);
+ auto ret = sys::Bus::SendUnicast(msg, "ApplicationSettings", Bt::GAP::ownerService, 5000);
+
} break;
case GAP_EVENT_INQUIRY_COMPLETE:
@@ 197,6 234,8 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
if (index + 1 == devices.size()) {
LOG_INFO("Scanned all");
state = DONE;
+ gap_inquiry_stop();
+ break;
}
continue_remote_names();
} break;
@@ 210,35 249,3 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
break;
}
}
-
-namespace Bt
-{
- namespace GAP
- {
-
- Error register_scan()
- {
- LOG_INFO("GAP register scan!");
- /// -> this have to be called prior to power on!
- hci_set_inquiry_mode(INQUIRY_MODE_RSSI_AND_EIR);
- cb_handler.callback = &packet_handler;
- hci_add_event_handler(&cb_handler);
- return Error();
- }
-
- Error scan()
- {
- LOG_INFO("Start scan if active: %d: %d", hci_get_state(), state);
- if (hci_get_state() == HCI_STATE_WORKING) {
- if (int ret = start_scan() != 0) {
- LOG_ERROR("Start scan error!: 0x%X", ret);
- return Error(Error::LibraryError, ret);
- }
- }
- else {
- return Error(Error::NotReady);
- }
- return Error();
- }
- } // namespace GAP
-} // namespace Bt
R module-bluetooth/Bluetooth/interface/bluekitchen/PAN.cpp => module-bluetooth/Bluetooth/interface/profiles/PAN.cpp +0 -0
R module-bluetooth/Bluetooth/interface/bluekitchen/Worker.cpp => module-bluetooth/Bluetooth/interface/profiles/Worker.cpp +0 -0
R module-bluetooth/Bluetooth/interface/bluekitchen/btstack_config.h => module-bluetooth/Bluetooth/interface/profiles/btstack_config.h +0 -0
M module-bluetooth/CMakeLists.txt => module-bluetooth/CMakeLists.txt +1 -1
@@ 11,7 11,7 @@ set(SOURCES
message("Build with BlueKitchen")
include(lib/btstack.cmake)
-
+message(${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
message("Sources: " ${SOURCES})
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${BOARD_DIR_SOURCES})
M module-bluetooth/lib/btstack => module-bluetooth/lib/btstack +1 -1
@@ 1,1 1,1 @@
-Subproject commit a652416846deeab67f1d4c9295d746db0f19a911
+Subproject commit 725ab2bc2adc415a0f50c5f34d85e24f5e22922d
M module-bluetooth/lib/btstack.cmake => module-bluetooth/lib/btstack.cmake +1 -1
@@ 1,5 1,5 @@
set(BT_GLU "${CMAKE_CURRENT_SOURCE_DIR}/Bluetooth/glucode/")
-set(BT_INT "${CMAKE_CURRENT_SOURCE_DIR}/Bluetooth/interface/bluekitchen/")
+set(BT_INT "${CMAKE_CURRENT_SOURCE_DIR}/Bluetooth/interface/profiles/")
set(BT_STACK_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/lib/btstack")
M module-bsp/bsp/bluetooth/Bluetooth.hpp => module-bsp/bsp/bluetooth/Bluetooth.hpp +1 -1
@@ 100,7 100,7 @@ namespace bsp {
// uart specyfic
};
- // Common stuff for Bluetopia and bluekitchen +clean listing for overrrides
+ // Common stuff for Bluetopia and profiles +clean listing for overrrides
class BluetoothCommon : public BTdev
{
public:
M module-services/service-bluetooth/ServiceBluetooth.cpp => module-services/service-bluetooth/ServiceBluetooth.cpp +6 -1
@@ 58,8 58,9 @@ sys::Message_t ServiceBluetooth::DataReceivedHandler(sys::DataMessage *msg, sys:
else {
return std::make_shared<sys::ResponseMessage>(sys::ReturnCodes::Failure);
}
+ case BluetoothMessage::StopScan:
+ worker->stop_scan();
break;
-
case BluetoothMessage::PAN: {
/// TODO request lwip first...
/// because TODO blocking message - wrecks system
@@ 91,6 92,10 @@ sys::Message_t ServiceBluetooth::DataReceivedHandler(sys::DataMessage *msg, sys:
catch (std::exception &ex) {
LOG_ERROR("Exception on BtService!: %s", ex.what());
}
+ if (dynamic_cast<BluetoothAddrMessage *>(msg) != nullptr) {
+ auto addrMsg = static_cast<BluetoothAddrMessage *>(msg);
+ worker->set_addr(addrMsg->addr);
+ }
return std::make_shared<sys::ResponseMessage>();
}
M module-services/service-bluetooth/messages/BluetoothMessage.hpp => module-services/service-bluetooth/messages/BluetoothMessage.hpp +30 -1
@@ 1,7 1,15 @@
#pragma once
#include "Service/Message.hpp"
+
+#include <utility>
#include "MessageType.hpp"
+#include "Bluetooth/Device.hpp"
+
+extern "C"
+{
+#include "module-bluetooth/lib/btstack/src/btstack_util.h"
+};
class BluetoothMessage : public sys::DataMessage
{
@@ 11,10 19,31 @@ class BluetoothMessage : public sys::DataMessage
None,
Start,
Scan,
+ StopScan,
PAN,
Visible,
};
enum Request req = Request::None;
BluetoothMessage(enum Request req = None) : sys::DataMessage(MessageType::BluetoothRequest), req(req){};
- virtual ~BluetoothMessage() = default;
+ ~BluetoothMessage() override = default;
+};
+
+class BluetoothScanMessage : public sys::DataMessage
+{
+ public:
+ std::vector<Devicei> devices;
+ BluetoothScanMessage(std::vector<Devicei> devices)
+ : sys::DataMessage(MessageType::BluetoothScanResult), devices(std::move(devices)){};
+ ~BluetoothScanMessage() override = default;
+};
+
+class BluetoothAddrMessage : public sys::DataMessage
+{
+ public:
+ bd_addr_t addr;
+ BluetoothAddrMessage(std::string addr) : sys::DataMessage(MessageType::BluetoothAddrResult)
+ {
+ sscanf_bd_addr(addr.c_str(), this->addr);
+ };
+ ~BluetoothAddrMessage() override = default;
};
M source/MessageType.hpp => source/MessageType.hpp +2 -0
@@ 192,6 192,8 @@ enum class MessageType
// bluetooth messages
BluetoothRequest,
+ BluetoothScanResult,
+ BluetoothAddrResult,
LwIP_request,
EVM_GPIO,