move scan report parser to Scanner

This commit is contained in:
hathach committed 2017-07-13 16:48:45 +07:00
1 parent c2991de3cd
commit c84236b2f9
7 files changed
+90 -87

No files matched your search

@@ -50,82 +50,6 @@ void BLECentral::begin(void)
Bluefruit.Discovery.begin();
}
/*------------------------------------------------------------------*/
/* Scan and Parser
*------------------------------------------------------------------*/
uint8_t* BLECentral::extractScanData(uint8_t const* scandata, uint8_t scanlen, uint8_t type, uint8_t* result_len)
{
*result_len = 0;
// len (1+data), type, data
while ( scanlen )
{
if ( scandata[1] == type )
{
*result_len = scandata[0]-1;
return (uint8_t*) (scandata + 2);
}
else
{
scanlen -= (scandata[0] + 1);
scandata += (scandata[0] + 1);
}
}
return NULL;
}
uint8_t* BLECentral::extractScanData(const ble_gap_evt_adv_report_t* report, uint8_t type, uint8_t* result_len)
{
return extractScanData(report->data, report->dlen, type, result_len);
}
bool BLECentral::checkUuidInScan(const ble_gap_evt_adv_report_t* report, BLEUuid ble_uuid)
{
const uint8_t* uuid;
uint8_t uuid_len = ble_uuid.size();
uint8_t type_arr[2];
// Check both UUID16 more available and complete list
if ( uuid_len == 16)
{
type_arr[0] = BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE;
type_arr[1] = BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE;
uuid = (uint8_t*) &ble_uuid._uuid.uuid;
}else
{
type_arr[0] = BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE;
type_arr[1] = BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE;
uuid = ble_uuid._uuid128;
}
uuid_len /= 8; // convert uuid_len to number of bytes
for (int i=0; i<2; i++)
{
uint8_t len = 0;
uint8_t const* data = extractScanData(report, type_arr[i] , &len);
while( len )
{
// found matched
if ( !memcmp(data, uuid, uuid_len) )
{
return true;
}else
{
data += uuid_len;
len -= uuid_len;
}
}
}
return false;
}
/*------------------------------------------------------------------*/
/*
*------------------------------------------------------------------*/