Defer the discovery of services using the system task.
This commit is contained in:
parent
56b527925c
commit
87c6556ad0
|
@ -42,10 +42,6 @@ bool AlertNotificationClient::OnDiscoveryEvent(uint16_t connectionHandle, const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlertNotificationClient::Init() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int AlertNotificationClient::OnCharacteristicsDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error,
|
int AlertNotificationClient::OnCharacteristicsDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error,
|
||||||
const ble_gatt_chr *characteristic) {
|
const ble_gatt_chr *characteristic) {
|
||||||
if(error->status != 0 && error->status != BLE_HS_EDONE) {
|
if(error->status != 0 && error->status != BLE_HS_EDONE) {
|
||||||
|
|
|
@ -16,7 +16,6 @@ namespace Pinetime {
|
||||||
public:
|
public:
|
||||||
explicit AlertNotificationClient(Pinetime::System::SystemTask &systemTask,
|
explicit AlertNotificationClient(Pinetime::System::SystemTask &systemTask,
|
||||||
Pinetime::Controllers::NotificationManager ¬ificationManager);
|
Pinetime::Controllers::NotificationManager ¬ificationManager);
|
||||||
void Init();
|
|
||||||
|
|
||||||
bool OnDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error, const ble_gatt_svc *service);
|
bool OnDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error, const ble_gatt_svc *service);
|
||||||
int OnCharacteristicsDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error,
|
int OnCharacteristicsDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error,
|
||||||
|
|
|
@ -10,10 +10,6 @@ CurrentTimeClient::CurrentTimeClient(DateTime& dateTimeController) : dateTimeCon
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CurrentTimeClient::Init() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CurrentTimeClient::OnDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error, const ble_gatt_svc *service) {
|
bool CurrentTimeClient::OnDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error, const ble_gatt_svc *service) {
|
||||||
if(service == nullptr && error->status == BLE_HS_EDONE) {
|
if(service == nullptr && error->status == BLE_HS_EDONE) {
|
||||||
NRF_LOG_INFO("CTS Discovery complete");
|
NRF_LOG_INFO("CTS Discovery complete");
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace Pinetime {
|
||||||
class CurrentTimeClient {
|
class CurrentTimeClient {
|
||||||
public:
|
public:
|
||||||
explicit CurrentTimeClient(DateTime& dateTimeController);
|
explicit CurrentTimeClient(DateTime& dateTimeController);
|
||||||
void Init();
|
|
||||||
bool OnDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error, const ble_gatt_svc *service);
|
bool OnDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error, const ble_gatt_svc *service);
|
||||||
int OnCharacteristicDiscoveryEvent(uint16_t conn_handle, const ble_gatt_error *error,
|
int OnCharacteristicDiscoveryEvent(uint16_t conn_handle, const ble_gatt_error *error,
|
||||||
const ble_gatt_chr *characteristic);
|
const ble_gatt_chr *characteristic);
|
||||||
|
|
|
@ -73,7 +73,6 @@ void NimbleController::Init() {
|
||||||
ble_svc_gatt_init();
|
ble_svc_gatt_init();
|
||||||
|
|
||||||
deviceInformationService.Init();
|
deviceInformationService.Init();
|
||||||
// currentTimeClient.Init();
|
|
||||||
dfuService.Init();
|
dfuService.Init();
|
||||||
int res;
|
int res;
|
||||||
res = ble_hs_util_ensure_addr(0);
|
res = ble_hs_util_ensure_addr(0);
|
||||||
|
@ -156,8 +155,9 @@ int NimbleController::OnGAPEvent(ble_gap_event *event) {
|
||||||
bleController.Disconnect();
|
bleController.Disconnect();
|
||||||
} else {
|
} else {
|
||||||
bleController.Connect();
|
bleController.Connect();
|
||||||
|
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::BleConnected);
|
||||||
connectionHandle = event->connect.conn_handle;
|
connectionHandle = event->connect.conn_handle;
|
||||||
// ble_gattc_disc_all_svcs(connectionHandle, OnAllSvrDisco, this);
|
// Service discovery is deffered via systemtask
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -166,6 +166,7 @@ int NimbleController::OnGAPEvent(ble_gap_event *event) {
|
||||||
NRF_LOG_INFO("disconnect; reason=%d ", event->disconnect.reason);
|
NRF_LOG_INFO("disconnect; reason=%d ", event->disconnect.reason);
|
||||||
|
|
||||||
/* Connection terminated; resume advertising. */
|
/* Connection terminated; resume advertising. */
|
||||||
|
connectionHandle = BLE_HS_CONN_HANDLE_NONE;
|
||||||
bleController.Disconnect();
|
bleController.Disconnect();
|
||||||
StartAdvertising();
|
StartAdvertising();
|
||||||
break;
|
break;
|
||||||
|
@ -248,7 +249,6 @@ int NimbleController::OnDiscoveryEvent(uint16_t i, const ble_gatt_error *error,
|
||||||
ble_gattc_disc_all_chrs(connectionHandle, alertNotificationClient.StartHandle(), alertNotificationClient.EndHandle(),
|
ble_gattc_disc_all_chrs(connectionHandle, alertNotificationClient.StartHandle(), alertNotificationClient.EndHandle(),
|
||||||
AlertNotificationCharacteristicDiscoveredCallback, this);
|
AlertNotificationCharacteristicDiscoveredCallback, this);
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
alertNotificationClient.OnDiscoveryEvent(i, error, service);
|
alertNotificationClient.OnDiscoveryEvent(i, error, service);
|
||||||
|
@ -295,6 +295,10 @@ int NimbleController::OnANSDescriptorDiscoveryEventCallback(uint16_t connectionH
|
||||||
return alertNotificationClient.OnDescriptorDiscoveryEventCallback(connectionHandle, error, characteristicValueHandle, descriptor);
|
return alertNotificationClient.OnDescriptorDiscoveryEventCallback(connectionHandle, error, characteristicValueHandle, descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NimbleController::StartDiscovery() {
|
||||||
|
ble_gattc_disc_all_svcs(connectionHandle, OnAllSvrDisco, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace Pinetime {
|
||||||
int OnCurrentTimeReadResult(uint16_t connectionHandle, const ble_gatt_error *error, ble_gatt_attr *attribute);
|
int OnCurrentTimeReadResult(uint16_t connectionHandle, const ble_gatt_error *error, ble_gatt_attr *attribute);
|
||||||
int OnANSDescriptorDiscoveryEventCallback(uint16_t connectionHandle, const ble_gatt_error *error,
|
int OnANSDescriptorDiscoveryEventCallback(uint16_t connectionHandle, const ble_gatt_error *error,
|
||||||
uint16_t characteristicValueHandle, const ble_gatt_dsc *descriptor);
|
uint16_t characteristicValueHandle, const ble_gatt_dsc *descriptor);
|
||||||
|
|
||||||
|
void StartDiscovery();
|
||||||
private:
|
private:
|
||||||
static constexpr char* deviceName = "Pinetime-JF";
|
static constexpr char* deviceName = "Pinetime-JF";
|
||||||
Pinetime::System::SystemTask& systemTask;
|
Pinetime::System::SystemTask& systemTask;
|
||||||
|
|
|
@ -100,9 +100,25 @@ void SystemTask::Work() {
|
||||||
case Messages::OnNewNotification:
|
case Messages::OnNewNotification:
|
||||||
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::NewNotification);
|
displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::NewNotification);
|
||||||
break;
|
break;
|
||||||
|
case Messages::BleConnected:
|
||||||
|
isBleDiscoveryTimerRunning = true;
|
||||||
|
bleDiscoveryTimer = 5;
|
||||||
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isBleDiscoveryTimerRunning) {
|
||||||
|
if(bleDiscoveryTimer == 0) {
|
||||||
|
isBleDiscoveryTimerRunning = false;
|
||||||
|
// Services discovery is deffered from 3 seconds to avoid the conflicts between the host communicating with the
|
||||||
|
// tharget and vice-versa. I'm not sure if this is the right way to handle this...
|
||||||
|
nimbleController.StartDiscovery();
|
||||||
|
} else {
|
||||||
|
bleDiscoveryTimer--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG);
|
uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG);
|
||||||
dateTimeController.UpdateTime(systick_counter);
|
dateTimeController.UpdateTime(systick_counter);
|
||||||
batteryController.Update();
|
batteryController.Update();
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace Pinetime {
|
||||||
namespace System {
|
namespace System {
|
||||||
class SystemTask {
|
class SystemTask {
|
||||||
public:
|
public:
|
||||||
enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification
|
enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification, BleConnected
|
||||||
};
|
};
|
||||||
|
|
||||||
SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd, Drivers::Cst816S &touchPanel,
|
SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd, Drivers::Cst816S &touchPanel,
|
||||||
|
@ -58,7 +58,8 @@ namespace Pinetime {
|
||||||
|
|
||||||
static void Process(void* instance);
|
static void Process(void* instance);
|
||||||
void Work();
|
void Work();
|
||||||
|
bool isBleDiscoveryTimerRunning = false;
|
||||||
|
uint8_t bleDiscoveryTimer = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user