Skip to content

Commit 905bb3b

Browse files
committed
correct scanner when using filter. Tested all central example
1 parent 6062aaa commit 905bb3b

File tree

10 files changed

+169
-70
lines changed

10 files changed

+169
-70
lines changed

.project

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Adafruit_nRF52_Arduino</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
10+
<triggers>clean,full,incremental,</triggers>
11+
<arguments>
12+
</arguments>
13+
</buildCommand>
14+
<buildCommand>
15+
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
16+
<triggers>full,incremental,</triggers>
17+
<arguments>
18+
</arguments>
19+
</buildCommand>
20+
</buildSpec>
21+
<natures>
22+
<nature>org.eclipse.cdt.core.cnature</nature>
23+
<nature>org.eclipse.cdt.core.ccnature</nature>
24+
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
25+
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
26+
</natures>
27+
<linkedResources>
28+
<link>
29+
<name>arduino-libraries</name>
30+
<type>2</type>
31+
<location>/home/hathach/Arduino/libraries</location>
32+
</link>
33+
</linkedResources>
34+
<filteredResources>
35+
<filter>
36+
<id>1498710934502</id>
37+
<name></name>
38+
<type>22</type>
39+
<matcher>
40+
<id>org.eclipse.ui.ide.multiFilter</id>
41+
<arguments>1.0-name-matches-false-false-*.o</arguments>
42+
</matcher>
43+
</filter>
44+
<filter>
45+
<id>1498710934507</id>
46+
<name></name>
47+
<type>22</type>
48+
<matcher>
49+
<id>org.eclipse.ui.ide.multiFilter</id>
50+
<arguments>1.0-name-matches-false-false-*.d</arguments>
51+
</matcher>
52+
</filter>
53+
<filter>
54+
<id>1498710934515</id>
55+
<name></name>
56+
<type>6</type>
57+
<matcher>
58+
<id>org.eclipse.ui.ide.multiFilter</id>
59+
<arguments>1.0-name-matches-false-false-*.pyc</arguments>
60+
</matcher>
61+
</filter>
62+
<filter>
63+
<id>1498710934520</id>
64+
<name></name>
65+
<type>22</type>
66+
<matcher>
67+
<id>org.eclipse.ui.ide.multiFilter</id>
68+
<arguments>1.0-name-matches-false-false-*.so</arguments>
69+
</matcher>
70+
</filter>
71+
</filteredResources>
72+
</projectDescription>

libraries/Bluefruit52Lib/examples/Central/central_bleuart/central_bleuart.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ void scan_callback(ble_gap_evt_adv_report_t* report)
7575

7676
// Connect to device with bleuart service in advertising
7777
Bluefruit.Central.connect(report);
78+
}else
79+
{
80+
// For Softdevice v6: after received a report, scanner will be paused
81+
// We need to call Scanner start() to resume scanning
82+
Bluefruit.Scanner.start();
7883
}
7984
}
8085

@@ -181,4 +186,3 @@ void loop()
181186
}
182187
}
183188
}
184-

libraries/Bluefruit52Lib/examples/Central/central_bleuart_multi/central_bleuart_multi.ino

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ void setup()
117117
/* Start Central Scanning
118118
* - Enable auto scan if disconnected
119119
* - Interval = 100 ms, window = 80 ms
120+
* - Filter only accept bleuart service in advertising
120121
* - Don't use active scan (used to retrieve the optional scan response adv packet)
121122
* - Start(0) = will scan forever since no timeout is given
122123
*/
123124
Bluefruit.Scanner.setRxCallback(scan_callback);
124125
Bluefruit.Scanner.restartOnDisconnect(true);
125126
Bluefruit.Scanner.setInterval(160, 80); // in units of 0.625 ms
127+
Bluefruit.Scanner.filterUuid(BLEUART_UUID_SERVICE);
126128
Bluefruit.Scanner.useActiveScan(false); // Don't request scan response data
127129
Bluefruit.Scanner.start(0); // 0 = Don't stop scanning after n seconds
128130
}
@@ -133,14 +135,10 @@ void setup()
133135
*/
134136
void scan_callback(ble_gap_evt_adv_report_t* report)
135137
{
136-
// Check if advertising data contains the BleUart service UUID
137-
if ( Bluefruit.Scanner.checkReportForUuid(report, BLEUART_UUID_SERVICE) )
138-
{
139-
Serial.print("BLE UART service detected. Connecting ... ");
140-
141-
// Connect to the device with bleuart service in advertising packet
142-
Bluefruit.Central.connect(report);
143-
}
138+
// Since we configure the scanner with filterUuid()
139+
// Scan callback only invoked for device with bleuart service advertised
140+
// Connect to the device with bleuart service in advertising packet
141+
Bluefruit.Central.connect(report);
144142
}
145143

146144
/**

libraries/Bluefruit52Lib/examples/Central/central_custom_hrm/central_custom_hrm.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ void loop()
9090
*/
9191
void scan_callback(ble_gap_evt_adv_report_t* report)
9292
{
93+
// Since we configure the scanner with filterUuid()
94+
// Scan callback only invoked for device with hrm service advertised
9395
// Connect to device with HRM service in advertising
9496
Bluefruit.Central.connect(report);
9597
}

libraries/Bluefruit52Lib/examples/Central/central_hid/central_hid.ino

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ void setup()
5959
* - Enable auto scan if disconnected
6060
* - Interval = 100 ms, window = 80 ms
6161
* - Don't use active scan
62+
* - Filter only accept HID service in advertising
6263
* - Start(timeout) with timeout = 0 will scan forever (until connected)
6364
*/
6465
Bluefruit.Scanner.setRxCallback(scan_callback);
6566
Bluefruit.Scanner.restartOnDisconnect(true);
6667
Bluefruit.Scanner.setInterval(160, 80); // in unit of 0.625 ms
68+
Bluefruit.Scanner.filterService(hid); // only report HID service
6769
Bluefruit.Scanner.useActiveScan(false);
6870
Bluefruit.Scanner.start(0); // 0 = Don't stop scanning after n seconds
69-
70-
Bluefruit.Scanner.filterService(hid); // only report HID service
7171
}
7272

7373
/**
@@ -76,7 +76,9 @@ void setup()
7676
*/
7777
void scan_callback(ble_gap_evt_adv_report_t* report)
7878
{
79-
// Connect to device
79+
// Since we configure the scanner with filterUuid()
80+
// Scan callback only invoked for device with hid service advertised
81+
// Connect to the device with hid service in advertising packet
8082
Bluefruit.Central.connect(report);
8183
}
8284

@@ -221,4 +223,3 @@ void processKeyboardReport(hid_keyboard_report_t* report)
221223
// update last report
222224
memcpy(&last_kbd_report, report, sizeof(hid_keyboard_report_t));
223225
}
224-

libraries/Bluefruit52Lib/examples/Central/central_scan_advanced/central_scan_advanced.ino

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ void setup()
5959

6060
void scan_callback(ble_gap_evt_adv_report_t* report)
6161
{
62+
PRINT_LOCATION();
6263
uint8_t len = 0;
6364
uint8_t buffer[32];
6465
memset(buffer, 0, sizeof(buffer));
6566

6667
/* Display the timestamp and device address */
67-
if (report->scan_rsp)
68+
if (report->type.scan_response)
6869
{
6970
Serial.printf("[SR%10d] Packet received from ", millis());
7071
}
@@ -77,11 +78,11 @@ void scan_callback(ble_gap_evt_adv_report_t* report)
7778
Serial.print("\n");
7879

7980
/* Raw buffer contents */
80-
Serial.printf("%14s %d bytes\n", "PAYLOAD", report->dlen);
81-
if (report->dlen)
81+
Serial.printf("%14s %d bytes\n", "PAYLOAD", report->data.len);
82+
if (report->data.len)
8283
{
8384
Serial.printf("%15s", " ");
84-
Serial.printBuffer(report->data, report->dlen, '-');
85+
Serial.printBuffer(report->data.p_data, report->data.len, '-');
8586
Serial.println();
8687
}
8788

@@ -90,20 +91,20 @@ void scan_callback(ble_gap_evt_adv_report_t* report)
9091

9192
/* Adv Type */
9293
Serial.printf("%14s ", "ADV TYPE");
93-
switch (report->type)
94-
{
95-
case BLE_GAP_ADV_TYPE_ADV_IND:
96-
Serial.printf("Connectable undirected\n");
97-
break;
98-
case BLE_GAP_ADV_TYPE_ADV_DIRECT_IND:
99-
Serial.printf("Connectable directed\n");
100-
break;
101-
case BLE_GAP_ADV_TYPE_ADV_SCAN_IND:
102-
Serial.printf("Scannable undirected\n");
103-
break;
104-
case BLE_GAP_ADV_TYPE_ADV_NONCONN_IND:
105-
Serial.printf("Non-connectable undirected\n");
106-
break;
94+
if ( report->type.connectable )
95+
{
96+
Serial.print("Connectable ");
97+
}else
98+
{
99+
Serial.print("Non-connectable ");
100+
}
101+
102+
if ( report->type.directed )
103+
{
104+
Serial.println("directed");
105+
}else
106+
{
107+
Serial.println("undirected");
107108
}
108109

109110
/* Shortened Local Name */
@@ -178,6 +179,10 @@ void scan_callback(ble_gap_evt_adv_report_t* report)
178179
}
179180

180181
Serial.println();
182+
183+
// For Softdevice v6: after received a report, scanner will be paused
184+
// We need to call Scanner start() to resume scanning
185+
Bluefruit.Scanner.start();
181186
}
182187

183188
void printUuid16List(uint8_t* buffer, uint8_t len)
@@ -209,9 +214,5 @@ void printUuid128List(uint8_t* buffer, uint8_t len)
209214

210215
void loop()
211216
{
212-
// Toggle both LEDs every 1 second
213-
digitalToggle(LED_RED);
214-
215-
delay(1000);
217+
// nothing to do
216218
}
217-

libraries/Bluefruit52Lib/examples/Central/central_ti_sensortag_optical/central_ti_sensortag_optical.ino

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void scan_callback(ble_gap_evt_adv_report_t* report)
122122

123123
/* Choose a peripheral to connect with by searching for an advertisement packet with a
124124
Complete Local Name matching our target device*/
125-
uint8_t buffer[BLE_GAP_ADV_MAX_SIZE] = { 0 };
125+
uint8_t buffer[BLE_GAP_ADV_SET_DATA_SIZE_MAX] = { 0 };
126126

127127
Serial.print("Parsing report for Local Name ... ");
128128
if(Bluefruit.Scanner.parseReportByType(report, BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME, buffer, sizeof(buffer)))
@@ -131,7 +131,7 @@ void scan_callback(ble_gap_evt_adv_report_t* report)
131131
Serial.printf("%14s %s\n", "Local Name:", buffer);
132132

133133
Serial.print(" Local Name data: ");
134-
printHexList(buffer, BLE_GAP_ADV_MAX_SIZE );
134+
printHexList(buffer, BLE_GAP_ADV_SET_DATA_SIZE_MAX );
135135

136136
Serial.print("Determining Local Name Match ... ");
137137
if ( !memcmp( buffer, SENSORTAG_ADV_COMPLETE_LOCAL_NAME, sizeof(SENSORTAG_ADV_COMPLETE_LOCAL_NAME)) )
@@ -144,11 +144,16 @@ void scan_callback(ble_gap_evt_adv_report_t* report)
144144
else
145145
{
146146
Serial.println("No Match");
147+
Bluefruit.Scanner.start(); // continue scanning
147148
}
148149
}
149150
else
150151
{
151-
Serial.println("Failed");
152+
Serial.println("Failed");
153+
154+
// For Softdevice v6: after received a report, scanner will be paused
155+
// We need to call Scanner start() to resume scanning
156+
Bluefruit.Scanner.start();
152157
}
153158
}
154159

@@ -163,7 +168,7 @@ void connect_callback(uint16_t conn_handle)
163168
Serial.println( conn_handle );
164169

165170
/* Complete Local Name */
166-
uint8_t buffer[BLE_GAP_ADV_MAX_SIZE] = { 0 };
171+
uint8_t buffer[BLE_GAP_ADV_SET_DATA_SIZE_MAX] = { 0 };
167172

168173
// If Service is not found, disconnect and return
169174
Serial.print("Discovering Optical Service ... ");
@@ -289,15 +294,15 @@ void printReport( const ble_gap_evt_adv_report_t* report )
289294
Serial.print( " rssi: " );
290295
Serial.println( report->rssi );
291296
Serial.print( " scan_rsp: " );
292-
Serial.println( report->scan_rsp );
293-
Serial.print( " type: " );
294-
Serial.println( report->type );
297+
Serial.println( report->type.scan_response );
298+
// Serial.print( " type: " );
299+
// Serial.println( report->type );
295300
Serial.print( " dlen: " );
296-
Serial.println( report->dlen );
301+
Serial.println( report->data.len );
297302
Serial.print( " data: " );
298-
for( int i = 0; i < report->dlen; i+= sizeof(uint8_t) )
303+
for( int i = 0; i < report->data.len; i+= sizeof(uint8_t) )
299304
{
300-
Serial.printf( "%02X-", report->data[ i ] );
305+
Serial.printf( "%02X-", report->data.p_data[ i ] );
301306
}
302307
Serial.println("");
303308
}

libraries/Bluefruit52Lib/keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ setIntervalMS KEYWORD2
220220
filterRssi KEYWORD2
221221
filterMSD KEYWORD2
222222
filterUuid KEYWORD2
223+
filterService KEYWORD2
223224
clearFilters KEYWORD2
224225

225226
restartOnDisconnect KEYWORD2

0 commit comments

Comments
 (0)