How can a enable/disable particular BLE channels used for advertising/scanning or when in a connection?
The smartBASIC language provides functions for setting a specific set of channels to be used for BLE advertising/scanning or a BLE connection.
- BleChannelMap(chanMap$) enables or disables data channel usage when in a connection.
- BleAdvSetCreate(nSetId, nAdvProperties, nPriSecPhy, nFilterPolicy, peerAddr$, chanMask$) can set BLE advert channels.
- BleScanStartEx(scanTimeoutMs, nPriPhyScan, chanMask$, nFilterHandle) can set channels used for BLE scanning.
The channel map/mask has to be entered as a 5 byte long string for each of the functions and due to the little-endian architecture of the underlying ARM core its composition can be confusing. The below example will show the actual assignment of channel within that string. Furthermore the meaning of a set bit differs among the above functions.
- BleChannelMap() -> a set bit means channel is enabled!
- BleAdvSetCreate() and BleScanStartEx() -> a set bit means channel is disabled!
Now let's “visualize” the channel mapping into the five byte string:
channel number:
00000000|11111100|22221111|33222222|xxx33333 76543210|54321098|32109876|10987654|xxx65432 \byte 0/ \byte 1/ \byte 2/ \byte 3/ \byte 4/
So for enabling e.g., channels 9+10 only you would set the yellow bits:
00000000|11111100|22221111|33222222|xxx33333 76543210|54321098|32109876|10987654|xxx65432 \byte 0/ \byte 1/ \byte 2/ \byte 3/ \byte 4/ 0x00 0x06 0x00 0x00 0x00
giving “0006000000” as string.
For disabling channel only 35, i.e. active channels are 0-34 and 36, it would be:
00000000|11111100|22221111|33222222|xxx33333 76543210|54321098|32109876|10987654|xxx65432 \byte 0/ \byte 1/ \byte 2/ \byte 3/ \byte 4/ 0xFF 0xFF 0xFF 0xFF 0x17
giving “FFFFFFFF17” as string.
Further detail is given in the smartBASIC Extension Guides in the documentation section of the product page for each BLE module at Bluetooth Module Portfolio.