javaos74 / btstack

Automatically exported from code.google.com/p/btstack
0 stars 0 forks source link

Help: understanding the binary representation of a Bluetooth address #449

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
As per the specification ,Bluetooth Device Address as 6 Byte, and Bluetooth 
device Addresses looks like this "12:45:78:01:34:67".
I observed the code, 
#define BD_ADDR_LEN 6
typedef uint8_t bd_addr_t[BD_ADDR_LEN];

As per the code, it supports only the Device address up to 6 characters. 
"12:45:" 
Modified the Code to support complete Bluetooth Device Address of 18 Characters 
as code given below. 

#define BD_ADDR_LEN 18
typedef uint8_t bd_addr_t[BD_ADDR_LEN];

Original issue reported on code.google.com by svrajas...@gmail.com on 21 Feb 2015 at 5:23

Attachments:

GoogleCodeExporter commented 9 years ago
The bluetooth address is similar to the MAC addresses. In BTstack, it's binary 
representation of 6 bytes ist stored in bt_addr_t. If needed, this can be 
converted to a human readable string.

Original comment by matthias.ringwald@gmail.com on 21 Feb 2015 at 7:09

GoogleCodeExporter commented 9 years ago
How many bytes we require to store this Bluetooth Address("12:45:78:01:34:67")?
As per my understanding, uint8_t bd_addr_t[6] buffer capable enough to store 
the Bluetooth address of 6 bytes that to "12:45.

I didn't understand, how uint8_t bd_addr_t[6] is capable enough to store 18 
Bytes of Bluetooth address.
if we want to store the Bluetooth address of 18 bytes, we require the buffer of 
uint8_t bd_addr_t[18].

Original comment by svrajas...@gmail.com on 23 Feb 2015 at 4:31

GoogleCodeExporter commented 9 years ago
A Bluetooth address has exactly 6 bytes of information. 

How many bytes do you need to store the value 100? It's one byte and not 3-4 if 
you look at the string representation "100".

Asides from that: BTstack is working and tested against the official Bluetooth 
tests. If it couldn't store the Bluetooth address, it wouldn't work at all.

Please stop adding issues on this tracker for questions. Please try to figure 
out how to find a string in a set of files using either "grep" or the search 
functionality of a text editor (if it can handle projects).

You may post on the mailing list for help.

Original comment by matthias.ringwald@gmail.com on 23 Feb 2015 at 8:43

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
There is one small index error on comment #5, you can refer comment #6

Code Snippet to support Comment #2
if we want to store string "Hello", we require the msg array of size6.

uint8_t msg[6] = "Hello";
msg[0] = 'H'; msg[1] = 'e'; msg[2] = 'l'; msg[3] = 'l'; msg[4] = 'o'; msg[5] = 
'\0';

As per the comment #2,
uint8_t bd_addr_t[18] = "12:45:78:01:34:67" requires 18 ,as the size of the 
array to store complete Bluetooth Device Address.

bd_addr_t[0] = '1';
bd_addr_t[1] = '2';
bd_addr_t[2] = ':';
bd_addr_t[3] = '4';
bd_addr_t[4] = '5';
bd_addr_t[5] = ':';
bd_addr_t[6] = '7';
bd_addr_t[7] = '8';
bd_addr_t[8] = ':';
bd_addr_t[9] = '0';
bd_addr_t[10] = '1';
bd_addr_t[11] = ':';
bd_addr_t[12] = '3';
bd_addr_t[13] = '4';
bd_addr_t[14] = ':';
bd_addr_t[15] = '6';
bd_addr_t[16] = '7';
bd_addr_t[17] = ':';

Original comment by svrajas...@gmail.com on 23 Feb 2015 at 1:23

GoogleCodeExporter commented 9 years ago
The example for storing "hello" is correct. it requires 6 bytes with the final 
\0.
Each character is stored as a single byte.
However, a byte has 8 bits, and you can have 256 different values in a single 
byte. The Bluetooth address is given as 6 hex values with ':' in between. The 
':' isn't stored.

So,  "12:45:78:01:34:67" is stored in memory as { 0x12, 0x45, 0x78, 0x01, 0x34, 
0x67 } taking up 6 bytes of memory.

That's not the same as storing the same characters as string, which would take 
18 bytes. 

Original comment by matthias.ringwald@gmail.com on 23 Feb 2015 at 9:05

GoogleCodeExporter commented 9 years ago
Please confirm the below mentioned C programming statements, From your point of 
you 
we understand that these both statements are either similar or same.

uint8_t bd_addr_t[6] = "12:45:78:01:34:67";
uint8_t bd_addr_t[6] = {0x12, 0x45, 0x78, 0x01, 0x34, 0x67 };

Original comment by svrajas...@gmail.com on 24 Feb 2015 at 5:32

GoogleCodeExporter commented 9 years ago
Hi

these statements are different. The first one is also incorrect, it would be 
uint8_t bd_addr_t[18] = "12:45:78:01:34:67" (as you've used before)

Anyway, this one stores a C string of len 17 in memory. This string is the 
human readable representation of a 6 byte Bluetooth address.

bd_addr_t (or uint8_t[6]) stores these directly in memory.

... a I see where I might have confused you. BTstack doesn't store 
"12:45:78:01:34:67" in memory. It stores the 6 byte representation of the same 
address.

Original comment by matthias.ringwald@gmail.com on 26 Feb 2015 at 9:30