Modifying part7-bluetooth to show full/friendly device names

This commit is contained in:
Adam Greenwood-Byrne 2020-07-30 15:56:39 +01:00
parent db9b058ea9
commit 10ecd8ca76
2 changed files with 27 additions and 16 deletions

View file

@ -124,7 +124,7 @@ If you look in _kernel.c_, you'll see the main bulk of our scanning code. Exactl
There may be one or more **ad report** in each event, and each contains the 48-bit Bluetooth address of the associated device e.g. `AA:BB:CC:DD:EE:FF` (bd_addr) as well as the data. I found a great article on the [Advertising Data Format from Silicon Labs](https://www.silabs.com/community/wireless/bluetooth/knowledge-base.entry.html/2017/02/10/bluetooth_advertisin-hGsf). Reading this will help you interpret my decode routines.
Right now, I'm just printing the bd_addr (using the convenient `uart_hex` routine added to _io.c_), RSSI (an indicator of signal strength), the ad report type & length, and the manufacturer code if received (`ad_type == 0xff`).
Right now, I'm just printing the bd_addr (using the convenient `uart_hex` routine added to _io.c_), the ad report type & length, and the friendly/full device name if received (ad_type 0x08 & 0x08 respectively).
Proof of life!
--------------

View file

@ -67,9 +67,10 @@ void bt_update()
while ( (buf = poll()) ) {
if (data_len >= 2 && buf[0] == LE_ADREPORT_CODE) {
unsigned char numreports = buf[1];
unsigned int c=0;
if (numreports == 1 && data_len >= 11) {
uart_writeText("a(");
if (numreports > 0 && data_len >= 11) {
uart_writeText("\ra(");
for (int c=9;c>=4;c--) {
if (c != 9) uart_writeText(":");
uart_hex(buf[c]);
@ -78,23 +79,33 @@ void bt_update()
unsigned char buf_len = buf[10];
if ((buf_len + 11) == data_len - 1) {
if ((buf_len + 11) <= data_len - 1) {
buf += 11;
unsigned char rssi = buf[buf_len];
uart_writeText(" -> rssi("); uart_hex(rssi); uart_writeText(")");
while (c < numreports) {
unsigned char ad_len = buf[0];
unsigned char ad_type = buf[1];
buf += 2;
uart_writeText(" -> adtype("); uart_hex(ad_type); uart_writeText(":"); uart_hex(ad_len); uart_writeText(")");
if (ad_len > 2) {
if (ad_type == 0xff) {
uart_writeText(" -> "); uart_hex(buf[1] << 8); uart_writeText(":"); uart_hex(buf[0]); uart_writeText("\n");
uart_writeText(" -> adtype("); uart_hex(ad_type); uart_writeText(":"); uart_hex(ad_len); uart_writeText(")");
if (ad_type == 0x09 || ad_type == 0x08) {
unsigned int d=0;
uart_writeText(" -> ");
while (d<ad_len - 1) {
uart_writeByteBlockingActual(buf[d]);
d++;
}
uart_writeText("\n");
}
}
buf += ad_len - 1;
c++;
}
}
uart_writeText("\r");
}
}
}