Commit 240a5fc
committed
pbio/drv/bluetooth: Broadcast on the Move Hub while connected.
The BlueNRG-MS GAP layer refuses to enter any advertising mode while a
computer is connected, so aci_gap_set_non_connectable() answered
BLE_STATUS_FAILED and nothing was broadcast. The driver mapped that one
error to success so that programs using broadcasting could at least run.
Drive the link layer directly instead, with the set advertising
parameters, set advertising data and set advertise enable sequence from
UM1865 section 3.3. The chip is already configured for role mode 4,
which supports advertising alongside connections and scanning, and it
accepts all three commands while a computer is connected. Asking the
chip first was no help: HCI_LE_Read_Supported_States answers with bit 20
clear, but it also claims not to support advertising while scanning and
not to support scanning while a slave, both of which demonstrably work,
so its answer understates what this stack can do.
Advertising is now enabled behind the GAP layer's back, so stopping has
to disable it the same way, and the discoverable mode has to be left
before the parameters can be set. The link layer advertises exactly the
payload it is given, so the service UUID and TX power AD types left over
from discovery no longer have to be deleted to make room. Broadcasts
therefore no longer carry the Flags AD type, which is what the BTstack
hubs already send.
The advertising interval has to be requested as a range. The chip fits a
new activity to the anchor period it is already running for the
connection and for any scanning, and answers 0x85
BLE_STATUS_INTERVAL_TOO_LARGE when no multiple of that period falls
between the requested minimum and maximum. A fixed 100ms therefore
failed the moment the hub was also observing or connected, which is
precisely the case being fixed here. The GAP layer picked its own range
internally and so never ran into it. 100ms is the fastest this Bluetooth
4.1 controller allows for non-connectable advertising and is the bottom
of the range; 200ms at the top measures the same as the GAP layer
managed, 2.45 against 2.53 broadcasts a second reaching a third hub,
which is inside the run to run spread.
Drop the note about broadcasting interfering with observing as well.
Measured on a Move Hub with the 50% scan duty cycle, reception is
unchanged by broadcasting at the same time: 13.4 advertisements a second
from a reference transmitter either way, with the same distribution of
gaps. That measurement depends on the duty cycle, so this belongs after
that change.
Fixes pybricks/support#28261 parent 8c861c1 commit 240a5fc
3 files changed
Lines changed: 88 additions & 36 deletions
File tree
- lib/pbio/drv/bluetooth
- pybricks/messaging
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
239 | 258 | | |
240 | 259 | | |
241 | 260 | | |
| |||
292 | 311 | | |
293 | 312 | | |
294 | 313 | | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
299 | 329 | | |
300 | 330 | | |
301 | 331 | | |
| |||
599 | 629 | | |
600 | 630 | | |
601 | 631 | | |
| 632 | + | |
| 633 | + | |
602 | 634 | | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | 635 | | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
616 | | - | |
617 | | - | |
618 | | - | |
619 | | - | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
620 | 643 | | |
621 | 644 | | |
622 | | - | |
623 | | - | |
624 | | - | |
625 | 645 | | |
626 | | - | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
627 | 664 | | |
| 665 | + | |
628 | 666 | | |
629 | | - | |
630 | | - | |
631 | | - | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
632 | 671 | | |
633 | | - | |
634 | | - | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
635 | 677 | | |
636 | | - | |
| 678 | + | |
| 679 | + | |
637 | 680 | | |
638 | 681 | | |
639 | | - | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
640 | 686 | | |
641 | 687 | | |
642 | | - | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
643 | 692 | | |
644 | | - | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
645 | 698 | | |
646 | 699 | | |
647 | 700 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | 278 | | |
282 | 279 | | |
283 | 280 | | |
| |||
0 commit comments