M module-bluetooth/Bluetooth/glucode/BluetoothRunLoop.cpp => module-bluetooth/Bluetooth/glucode/BluetoothRunLoop.cpp +10 -3
@@ 14,7 14,7 @@ namespace bluetooth
QueueHandle_t RunLoop::btstack_run_loop_queue;
TaskHandle_t RunLoop::btstack_run_loop_task;
QueueHandle_t RunLoop::triggerQueue;
- TimerHandle_t RunLoop::testTimer;
+ TimerHandle_t RunLoop::testTimer = nullptr;
auto RunLoop::removeTimer(btstack_timer_source_t *ts) -> bool
{
@@ 25,6 25,11 @@ namespace bluetooth
assert(queue != nullptr);
triggerQueue = queue;
}
+ void RunLoop::deinit()
+ {
+ vQueueDelete(btstack_run_loop_queue);
+ xTimerDelete(testTimer, 0);
+ }
void RunLoop::init()
{
timers = nullptr;
@@ 125,8 130,10 @@ namespace bluetooth
}
void RunLoop::start()
{
- testTimer = xTimerCreate("TestTimer", pdMS_TO_TICKS(1000), pdTRUE, nullptr, triggerCallback);
- xTimerStart(testTimer, 0);
+ if (testTimer == nullptr) {
+ testTimer = xTimerCreate("TestTimer", pdMS_TO_TICKS(1000), pdTRUE, nullptr, triggerCallback);
+ xTimerStart(testTimer, 0);
+ }
}
auto RunLoop::process() -> bool
{
M module-bluetooth/Bluetooth/glucode/BluetoothRunLoop.hpp => module-bluetooth/Bluetooth/glucode/BluetoothRunLoop.hpp +1 -0
@@ 47,6 47,7 @@ namespace bluetooth
public:
auto process() -> bool;
+ static void deinit();
void setTriggerQueue(QueueHandle_t queue);
auto getRunLoopInstance() -> btstack_run_loop *;
};
D module-bluetooth/Bluetooth/glucode/HCITRANS.cpp => module-bluetooth/Bluetooth/glucode/HCITRANS.cpp +0 -0
M module-bluetooth/Bluetooth/interface/BluetoothDriver.cpp => module-bluetooth/Bluetooth/interface/BluetoothDriver.cpp +4 -2
@@ 72,9 72,10 @@ namespace bluetooth
#else
auto uartDriver = runLoopInitLinux(runLoop);
#endif
- const hci_transport_t *transport = hci_transport_h4_instance(uartDriver);
+ const hci_transport_t *transport = hci_transport_h4_instance(uartDriver);
hci_init(transport, (void *)&config);
+
hci_set_link_key_db(bluetooth::KeyStorage::getKeyStorage());
hci_event_callback_registration.callback = &hci_packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
@@ 185,7 186,8 @@ namespace bluetooth
if (ret != 0) {
LOG_ERROR("Can't turn off Bluetooth Stack!");
}
- hci_close();
+ bluetooth::KeyStorage::settings->setValue(bluetooth::Settings::State,
+ static_cast<int>(BluetoothStatus::State::Off));
return ret != 0 ? Error::LibraryError : Error::Success;
}
auto Driver::scan() -> Error
M module-services/service-bluetooth/ServiceBluetooth.cpp => module-services/service-bluetooth/ServiceBluetooth.cpp +0 -1
@@ 123,7 123,6 @@ sys::MessagePointer ServiceBluetooth::DataReceivedHandler(sys::DataMessage *msg,
LOG_INFO("Bluetooth request!");
switch (lmsg->req) {
case BluetoothMessage::Start:
- worker->run();
break;
case BluetoothMessage::Scan:
sendWorkerCommand(bluetooth::StartScan);
M test/pytest/service-desktop/test_bluetooth.py => test/pytest/service-desktop/test_bluetooth.py +35 -2
@@ 9,14 9,41 @@ import time
@pytest.mark.rt1051
@pytest.mark.service_desktop_test
-def test_bluetooth(harness):
-
+def test_bluetooth_on_off(harness):
body = {"state": True}
ret = harness.endpoint_request("bluetooth", "get", body)
print(ret)
assert ret["status"] == status["OK"]
if ret["body"]["state"] == 0:
+ log.info("BT turned off, turning on...")
+ body = {"state": "on"}
+ ret = harness.endpoint_request("bluetooth", "put", body)
+
+ time.sleep(5)
+ body = {"state": True}
+ ret = harness.endpoint_request("bluetooth", "get", body)
+ assert ret["status"] == status["OK"]
+
+ assert ret["body"]["state"] == 1
+
+ log.info("BT turning off...")
+ body = {"state": "off"}
+ ret = harness.endpoint_request("bluetooth", "put", body)
+
+ body = {"state": True}
+ ret = harness.endpoint_request("bluetooth", "get", body)
+ assert ret["body"]["state"] == 0
+
+
+@pytest.mark.rt1051
+@pytest.mark.service_desktop_test
+def test_bluetooth_scan(harness):
+ body = {"state": True}
+ ret = harness.endpoint_request("bluetooth", "get", body)
+ print(ret)
+ assert ret["status"] == status["OK"]
+ if ret["body"]["state"] == 0:
log.info("BT turned off, turning on...")
body = {"state": "on"}
ret = harness.endpoint_request("bluetooth", "put", body)
@@ 38,3 65,9 @@ def test_bluetooth(harness):
ret = harness.endpoint_request("bluetooth", "put", body)
assert ret["body"]["scan"] == "off"
+ body = {"state": "off"}
+ ret = harness.endpoint_request("bluetooth", "put", body)
+
+ body = {"state": True}
+ ret = harness.endpoint_request("bluetooth", "get", body)
+ assert ret["body"]["state"] == 0