This commit is contained in:
hathach committed 2017-03-31 14:57:59 +07:00
1 parent 041a42d904
commit 9afb42694a
2 files changed
+11 -11

No files matched your search

+10 -10
View File
@@ -43,22 +43,22 @@ BLEDiscovery::BLEDiscovery(void)
_hdl_range.start_handle = 1;
_hdl_range.end_handle = 0xffff;
_evt_sem = NULL;
_sem = NULL;
_evt_buf = NULL;
_evt_bufsize = 0;
}
void BLEDiscovery::begin(void)
{
if (_evt_sem == NULL)
if (_sem == NULL)
{
_evt_sem = xSemaphoreCreateBinary();
_sem = xSemaphoreCreateBinary();
}
}
bool BLEDiscovery::begun(void)
{
return (_evt_sem != NULL);
return (_sem != NULL);
}
bool BLEDiscovery::_discoverService(uint16_t conn_handle, BLECentralService& svc, uint16_t start_handle)
@@ -71,7 +71,7 @@ bool BLEDiscovery::_discoverService(uint16_t conn_handle, BLECentralService& svc
VERIFY_STATUS( sd_ble_gattc_primary_services_discover(conn_handle, start_handle, &svc.uuid._uuid), false );
// wait for discovery event: timeout or has no data
if ( !xSemaphoreTake(_evt_sem, BLE_CENTRAL_TIMEOUT) || (_evt_bufsize == 0) ) return false;
if ( !xSemaphoreTake(_sem, BLE_CENTRAL_TIMEOUT) || (_evt_bufsize == 0) ) return false;
// Check the discovered UUID with input one
if ( (disc_svc.count == 1) && (svc.uuid == disc_svc.services[0].uuid) )
@@ -103,7 +103,7 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLECentralCha
// wait for discovery event: timeout or has no data
// Assume only 1 characteristic discovered each
if ( !xSemaphoreTake(_evt_sem, BLE_CENTRAL_TIMEOUT) || (_evt_bufsize == 0) || (disc_chr.count == 0) ) break;
if ( !xSemaphoreTake(_sem, BLE_CENTRAL_TIMEOUT) || (_evt_bufsize == 0) || (disc_chr.count == 0) ) break;
// increase handle range for next discovery
_hdl_range.start_handle = disc_chr.chars[0].handle_value + 1;
@@ -142,7 +142,7 @@ uint16_t BLEDiscovery::_discoverDescriptor(uint16_t conn_handle, ble_gattc_evt_d
VERIFY_STATUS( sd_ble_gattc_descriptors_discover(conn_handle, &_hdl_range), 0 );
// wait for discovery event: timeout or has no data
if ( !xSemaphoreTake(_evt_sem, BLE_CENTRAL_TIMEOUT) || (_evt_bufsize == 0) ) return 0;
if ( !xSemaphoreTake(_sem, BLE_CENTRAL_TIMEOUT) || (_evt_bufsize == 0) ) return 0;
result = min16(disc_desc->count, max_count);
if (result)
@@ -184,7 +184,7 @@ void BLEDiscovery::_event_handler(ble_evt_t* evt)
_evt_bufsize = 0; // no data
}
xSemaphoreGive(_evt_sem);
xSemaphoreGive(_sem);
}
break;
@@ -205,7 +205,7 @@ void BLEDiscovery::_event_handler(ble_evt_t* evt)
_evt_bufsize = 0; // no data
}
xSemaphoreGive(_evt_sem);
xSemaphoreGive(_sem);
}
break;
@@ -228,7 +228,7 @@ void BLEDiscovery::_event_handler(ble_evt_t* evt)
_evt_bufsize = 0; // no data
}
xSemaphoreGive(_evt_sem);
xSemaphoreGive(_sem);
}
break;
+1 -1
View File
@@ -50,7 +50,7 @@ class BLEDiscovery
void* _evt_buf;
uint16_t _evt_bufsize;
SemaphoreHandle_t _evt_sem;
SemaphoreHandle_t _sem;
void _event_handler(ble_evt_t* evt);