Using ba2str fails - why ?
-
This is pretty simple function and compiles and works fine on X86. Same usage , with same parameters passed to it, fails on ARM. Description Resource Path Location Type cannot convert ‘sockaddr_rc’ to ‘char*’ for argument ‘2’ to ‘int ba2str(const bdaddr_t*, char*)’ CBT.cpp /RPI_BT_CLIENT_ARM_/src/MODULES/M_CBT line 286 C/C++ Problem I am at lost and could use some help to make it work. It it helps, here is the code
for (i = 0; i < num\_rsp; i++) { // convert bdaddr to array addr for print ba2str(&(ii + i)->bdaddr, addr); FAILS HERE memset(name, 0, sizeof(name)); if (hci\_read\_remote\_name(dev\_descriptor, &(ii + i)->bdaddr, sizeof(name), name, 0) < 0) strcpy(name, "\[unknown\]"); printf("remote address %s remote name %s\\n", addr, name); }
Bluetooth addresses are a 6-byte hex number similar to an Ethernet MAC address. BlueZ provides convenience functions for converting between a 6-byte string in the format 00:11:22:33:44:55 and the bdaddr_t struct. Here are the function prototypes:
int ba2str(const bdaddr\_t \*ba, char \*str); int str2ba(const char \*str, bdaddr\_t \*ba);
The function ba2str converts from the internal bdaddr_t to a zero-terminated string (the str parameter should have at least 18 bytes), and str2ba provides the opposite conversion. The first example makes use of the ba2str function.
-
This is pretty simple function and compiles and works fine on X86. Same usage , with same parameters passed to it, fails on ARM. Description Resource Path Location Type cannot convert ‘sockaddr_rc’ to ‘char*’ for argument ‘2’ to ‘int ba2str(const bdaddr_t*, char*)’ CBT.cpp /RPI_BT_CLIENT_ARM_/src/MODULES/M_CBT line 286 C/C++ Problem I am at lost and could use some help to make it work. It it helps, here is the code
for (i = 0; i < num\_rsp; i++) { // convert bdaddr to array addr for print ba2str(&(ii + i)->bdaddr, addr); FAILS HERE memset(name, 0, sizeof(name)); if (hci\_read\_remote\_name(dev\_descriptor, &(ii + i)->bdaddr, sizeof(name), name, 0) < 0) strcpy(name, "\[unknown\]"); printf("remote address %s remote name %s\\n", addr, name); }
Bluetooth addresses are a 6-byte hex number similar to an Ethernet MAC address. BlueZ provides convenience functions for converting between a 6-byte string in the format 00:11:22:33:44:55 and the bdaddr_t struct. Here are the function prototypes:
int ba2str(const bdaddr\_t \*ba, char \*str); int str2ba(const char \*str, bdaddr\_t \*ba);
The function ba2str converts from the internal bdaddr_t to a zero-terminated string (the str parameter should have at least 18 bytes), and str2ba provides the opposite conversion. The first example makes use of the ba2str function.
-
This is pretty simple function and compiles and works fine on X86. Same usage , with same parameters passed to it, fails on ARM. Description Resource Path Location Type cannot convert ‘sockaddr_rc’ to ‘char*’ for argument ‘2’ to ‘int ba2str(const bdaddr_t*, char*)’ CBT.cpp /RPI_BT_CLIENT_ARM_/src/MODULES/M_CBT line 286 C/C++ Problem I am at lost and could use some help to make it work. It it helps, here is the code
for (i = 0; i < num\_rsp; i++) { // convert bdaddr to array addr for print ba2str(&(ii + i)->bdaddr, addr); FAILS HERE memset(name, 0, sizeof(name)); if (hci\_read\_remote\_name(dev\_descriptor, &(ii + i)->bdaddr, sizeof(name), name, 0) < 0) strcpy(name, "\[unknown\]"); printf("remote address %s remote name %s\\n", addr, name); }
Bluetooth addresses are a 6-byte hex number similar to an Ethernet MAC address. BlueZ provides convenience functions for converting between a 6-byte string in the format 00:11:22:33:44:55 and the bdaddr_t struct. Here are the function prototypes:
int ba2str(const bdaddr\_t \*ba, char \*str); int str2ba(const char \*str, bdaddr\_t \*ba);
The function ba2str converts from the internal bdaddr_t to a zero-terminated string (the str parameter should have at least 18 bytes), and str2ba provides the opposite conversion. The first example makes use of the ba2str function.
There's absolutely no way to tell given what you've shown us. You have given us no details on where, when or how its failing for your use case. Nor have you told us wht "fails" means in your context. Most likely, you have a bad
baddr_t*
passed in toba2str()
, or you have passed in aconst char *
, but have cast away const-ness somewhere. Doesba2str()
produce any diagnostics (e.g. set an error code like errno, or indicate failure reason in its return code) that would help narrow down why it "fails"? -
This is pretty simple function and compiles and works fine on X86. Same usage , with same parameters passed to it, fails on ARM. Description Resource Path Location Type cannot convert ‘sockaddr_rc’ to ‘char*’ for argument ‘2’ to ‘int ba2str(const bdaddr_t*, char*)’ CBT.cpp /RPI_BT_CLIENT_ARM_/src/MODULES/M_CBT line 286 C/C++ Problem I am at lost and could use some help to make it work. It it helps, here is the code
for (i = 0; i < num\_rsp; i++) { // convert bdaddr to array addr for print ba2str(&(ii + i)->bdaddr, addr); FAILS HERE memset(name, 0, sizeof(name)); if (hci\_read\_remote\_name(dev\_descriptor, &(ii + i)->bdaddr, sizeof(name), name, 0) < 0) strcpy(name, "\[unknown\]"); printf("remote address %s remote name %s\\n", addr, name); }
Bluetooth addresses are a 6-byte hex number similar to an Ethernet MAC address. BlueZ provides convenience functions for converting between a 6-byte string in the format 00:11:22:33:44:55 and the bdaddr_t struct. Here are the function prototypes:
int ba2str(const bdaddr\_t \*ba, char \*str); int str2ba(const char \*str, bdaddr\_t \*ba);
The function ba2str converts from the internal bdaddr_t to a zero-terminated string (the str parameter should have at least 18 bytes), and str2ba provides the opposite conversion. The first example makes use of the ba2str function.
You just need to cast the addr parameter to a char* as mentioned in the error message. See also https://people.csail.mit.edu/albert/bluez-intro/c404.html[^], where addr is a char array. So you can change to
for (i = 0; i < num_rsp; i++) {
// convert bdaddr to array addr for print
ba2str(&(ii + i)->bdaddr, (char*)addr); // cast addr to a char* : but this may still be a problem
memset(name, 0, sizeof(name));
if (hci_read_remote_name(dev_descriptor, &(ii + i)->bdaddr,
sizeof(name), name, 0) < 0)
strcpy(name, "[unknown]");
printf("remote address %s remote name %s\n", addr, name);
} -
I don't see a question.
Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.
len = 8;
max_rsp = 255;
flags = IREQ_CACHE_FLUSH;
ii = (inquiry_info*) malloc(max_rsp * sizeof(inquiry_info));
cout << "TASK run hci_inquiry same as hcitoo scan - takes time @line "
<< dec << __LINE__ << endl;
num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
perror("STATUS hci_inquiry");
errno = 0; // reset !if (num\_rsp < 0) perror("FAILED (?) hci\_inquiry"); for (i = 0; i < num\_rsp; i++) { **ba2str(&(ii + i)->bdaddr, addr);** memset(name, 0, sizeof(name)); if (hci\_read\_remote\_name(dev\_descriptor, &(ii + i)->bdaddr, sizeof(name), name, 0) < 0) strcpy(name, "\[unknown\]"); printf("remote address %s remote name %s\\n", addr, name); }
the question is WHY does highlighted code throws an error
-
You just need to cast the addr parameter to a char* as mentioned in the error message. See also https://people.csail.mit.edu/albert/bluez-intro/c404.html[^], where addr is a char array. So you can change to
for (i = 0; i < num_rsp; i++) {
// convert bdaddr to array addr for print
ba2str(&(ii + i)->bdaddr, (char*)addr); // cast addr to a char* : but this may still be a problem
memset(name, 0, sizeof(name));
if (hci_read_remote_name(dev_descriptor, &(ii + i)->bdaddr,
sizeof(name), name, 0) < 0)
strcpy(name, "[unknown]");
printf("remote address %s remote name %s\n", addr, name);
}Richard, there is something else wrong here. After I cast (char*) addr it complains abut wrong type. I need to go and check the ba2str source , perhaps read the results of hci_inquiry before converting to addr. It is puzzling why it works on X86, hope it is not yet another "64 bits / 32 bits " issue.
Description Resource Path Location Type
invalid cast from type ‘sockaddr_rc’ to type ‘char*’ CBT.cpp /RPI_BT_CLIENT_ARM_/src/MODULES/M_CBT line 286 C/C++ Problem -
len = 8;
max_rsp = 255;
flags = IREQ_CACHE_FLUSH;
ii = (inquiry_info*) malloc(max_rsp * sizeof(inquiry_info));
cout << "TASK run hci_inquiry same as hcitoo scan - takes time @line "
<< dec << __LINE__ << endl;
num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
perror("STATUS hci_inquiry");
errno = 0; // reset !if (num\_rsp < 0) perror("FAILED (?) hci\_inquiry"); for (i = 0; i < num\_rsp; i++) { **ba2str(&(ii + i)->bdaddr, addr);** memset(name, 0, sizeof(name)); if (hci\_read\_remote\_name(dev\_descriptor, &(ii + i)->bdaddr, sizeof(name), name, 0) < 0) strcpy(name, "\[unknown\]"); printf("remote address %s remote name %s\\n", addr, name); }
the question is WHY does highlighted code throws an error
-
len = 8;
max_rsp = 255;
flags = IREQ_CACHE_FLUSH;
ii = (inquiry_info*) malloc(max_rsp * sizeof(inquiry_info));
cout << "TASK run hci_inquiry same as hcitoo scan - takes time @line "
<< dec << __LINE__ << endl;
num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
perror("STATUS hci_inquiry");
errno = 0; // reset !if (num\_rsp < 0) perror("FAILED (?) hci\_inquiry"); for (i = 0; i < num\_rsp; i++) { **ba2str(&(ii + i)->bdaddr, addr);** memset(name, 0, sizeof(name)); if (hci\_read\_remote\_name(dev\_descriptor, &(ii + i)->bdaddr, sizeof(name), name, 0) < 0) strcpy(name, "\[unknown\]"); printf("remote address %s remote name %s\\n", addr, name); }
the question is WHY does highlighted code throws an error
in
ba2str(&(ii + i)->bdaddr, addr);
what is the type of
addr
? It should be of typechar \*
, but your compiler is telling you its of typesockaddr_rc
. Have you managed to "shadow" the addr varialbe (e.g)char addr[18];
// ...
for( /* ... \*/ ) {
sockaddr_rc addr;
// ...
ba2str(/* ... */ );
}
// ...Maybe try adding
-Wshadow
to your compiler options to find out. -
Richard, there is something else wrong here. After I cast (char*) addr it complains abut wrong type. I need to go and check the ba2str source , perhaps read the results of hci_inquiry before converting to addr. It is puzzling why it works on X86, hope it is not yet another "64 bits / 32 bits " issue.
Description Resource Path Location Type
invalid cast from type ‘sockaddr_rc’ to type ‘char*’ CBT.cpp /RPI_BT_CLIENT_ARM_/src/MODULES/M_CBT line 286 C/C++ Problem -
This is pretty simple function and compiles and works fine on X86. Same usage , with same parameters passed to it, fails on ARM. Description Resource Path Location Type cannot convert ‘sockaddr_rc’ to ‘char*’ for argument ‘2’ to ‘int ba2str(const bdaddr_t*, char*)’ CBT.cpp /RPI_BT_CLIENT_ARM_/src/MODULES/M_CBT line 286 C/C++ Problem I am at lost and could use some help to make it work. It it helps, here is the code
for (i = 0; i < num\_rsp; i++) { // convert bdaddr to array addr for print ba2str(&(ii + i)->bdaddr, addr); FAILS HERE memset(name, 0, sizeof(name)); if (hci\_read\_remote\_name(dev\_descriptor, &(ii + i)->bdaddr, sizeof(name), name, 0) < 0) strcpy(name, "\[unknown\]"); printf("remote address %s remote name %s\\n", addr, name); }
Bluetooth addresses are a 6-byte hex number similar to an Ethernet MAC address. BlueZ provides convenience functions for converting between a 6-byte string in the format 00:11:22:33:44:55 and the bdaddr_t struct. Here are the function prototypes:
int ba2str(const bdaddr\_t \*ba, char \*str); int str2ba(const char \*str, bdaddr\_t \*ba);
The function ba2str converts from the internal bdaddr_t to a zero-terminated string (the str parameter should have at least 18 bytes), and str2ba provides the opposite conversion. The first example makes use of the ba2str function.
Mea culpa! I need to get this client / server code mess under control. Way too many "addresses" and yet another "shadow" error. Thanks to all of you it is fixed! I need to pay better attention to the complier errors - this time it pointed me to "shadows". Adding the check for it as standard complier option from now on. Cheers