|
The "in progress" status is telling you that the local device is trying to complete some operation. If you then try to use it again it may well be returning "busy" because it is unable to accept your request.
The perror() function has been around for years and has always been fairly succinct in its output. The important information is the actual errno value. It is a fairly simple matter to write your own function to display the value and the error message (see strerror(3) - Linux manual page[^]).
What you really should do is get hold of the RFC documents for TCP/IP and Bluetooth, and study the protocol details. They should give you the exact sequence of events that are supposed to happen when the two endpoints try to communicate.
|
|
|
|
|
Richard MacCutchan wrote: The perror() function has been around for years and has always been fairly succinct in its output. The important information is the actual errno value. It is a fairly simple matter to write your own function to display the value and the error message (see strerror(3) - Linux manual page[^]).
Even old dogs learn something new occasionally. I was certain that perror() would be locale aware, but it seems not (which could be an issue if you are depending on exact text matches in your output). While researching that, I came across the GNU error() function, which might help the OP. See about half-way down this page: Error Messages (The GNU C Library)
|
|
|
|
|
Thanks, this is very good reference.
Error Messages (The GNU C Library)[^]
So far I am getting used to perror , it mostly gives good description of the state.
I am still unsure how to recover from some of those related to socket and bluetooth.
The moral of the story
check the return value first , then let perror describe the state.
perror does not always tells error, but state.
BTW the original error was due to my mistake not checking the remote bluetooth device address.
I was passing the device name and not the address!
Live and learn...
Cheers
|
|
|
|
|
Vaclav_ wrote: check the return value first , then let perror describe the state. No, don't rely on perror alone. The most important piece of information is the actual error code. And, as I already suggested, you should study the RFC documents to get a thorough understanding of the protocols you are trying to use.
|
|
|
|
|
Quote: The important information is the actual errno value. It is a fairly simple matter to write your own function to display the value and the error message (see strerror(3) - Linux manual page[^]).
You don't need to, on GNU systems simply use '%m' in the printf format string. The '%m' is replaced with the actual error message in the language that the system is set to.
|
|
|
|
|
I think this question was well answered 9 months ago.
|
|
|
|
|
Quote: perror posts “operation now in progress “ which is great to know
BUT connect return “status “ is -1 .
To whom do I trust ?
They're both saying the same thing. Why are you confused? The return from connect() means "Unable to connect, check errno for why". The errno you are getting for "why I can't connect" is "operation in progress (EINPROGRESS)".
Seems pretty clear.
|
|
|
|
|
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++) {
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.
|
|
|
|
|
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;
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
|
|
|
|
|
No idea, because you have not told us what the error is.
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.
|
|
|
|
|
in
ba2str(&(ii + i)->bdaddr, addr); what is the type of addr ? It should be of type char * , but your compiler is telling you its of type sockaddr_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.
|
|
|
|
|
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 to ba2str() , or you have passed in a const char * , but have cast away const-ness somewhere. Does ba2str() 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"?
|
|
|
|
|
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++) {
ba2str(&(ii + i)->bdaddr, (char*)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);
}
|
|
|
|
|
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
|
|
|
|
|
Sorry, I missed the fact that addr is not a pointer (as shown in that link I gave you). Try:
ba2str(&(ii + i)->bdaddr, (char*)&addr);
Or better still use a char array as in the example.
|
|
|
|
|
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
|
|
|
|
|
I have been writing code using crosscomplier for ARM architecture.
Works as expected. No "cast looses precision " errors.
Now I optioned IDE to change the architecture to X86.
Compiler now complains about
"cast looses precision " .
The complains (too many) are in class I am currently NOT editing.
Is there a option I can set GCC to temporary ignore
"cast looses precision " errors ?
Since the
"cast looses precision " was not present while compiling for ARM it would not hurt to know WHY it fails in X86.
Here is the IDE "error"
Description Resource Path Location Type
cast from ‘uint32_t* {aka unsigned int*}’ to ‘uint32_t {aka unsigned int}’ loses precision [-fpermissive] CBCM2835SPITFT.cpp /RPI_BT_SERVER_X86_/src/MODULES/M_BCM2835_SPI_TFT line 21264 C/C++ Problem
And here ONE of the offending code
bcm2835_peripherals = (uint32_t*) mapmem(
NULL, bcm2835_peripherals_size, _memfd, (uint32_t) bcm2835_peripherals_base);
Cheers
PS I think wholesale "search and replace " is too risky.
PPS Does the architecture - 64 bits on X86 and 32 on ARM matter? - both Linux OS.
|
|
|
|
|
That is because you are trying to cast a pointer to a unint32_t (i.e. a memory address) to an actual uint32_t (i.e. an integer variable). And the pointer may well be larger than 32 bits, so the compiler is warning you that the resulting value may not be what you expect.
|
|
|
|
|
The compiler is complaining that you are casting a pointer to uint32_t (which is 64 bits on Linux built for x86_64) to uint32_t (which is 32 bits). You are losing half of the pointer, which is guaranteed not to end well.
The ARM code was compiled for a 32-bit ARM. If you wish to compile the code for a 64-bit processor, you will have to go carefully through the code, examining each cast and ensuring that it is still valid.
One way to make this (slightly...) less painful would be to use the C99 type uintptr_t (defined in stdint.h) or the C++ type std::uintptr_t (defined in cstdint), which gives you an integer type guaranteed to hold a pointer. You must then ensure that your structures are correctly defined.
All in all, converting a program from 32-bit to 64-bit is a non-trivial task...
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
As Richard and Daniel have pointed out, you get this when trying to convert a pointer to a 32-bit integer in a 64 bit context. You should see the same issue when compiling for 64-bit windows or aarch-64, or indeed any 64-bit architecture.
I would take a look at the definition/implementation of mapmem() . That does not seem to be a linux standard library function, so I can only assume that it is something you have written yourself, or gleaned from the internet. That being the case, in any context, assigning a pointer to an integer is, in general, a sign that you are abusing the language type system. Pointers should remain pointers and ints should remain ints. If you do need to assign a pointer to an int, at least use intptr_t , which will work for most systems. It should certainly work for X86, X86-64, ARM32 and ARM64.
You could add -fpermissive to your complier flags, which will turn the errors intow warnings , but you still have the problem that you are assigning a 64 bit pointer to a 32 bit integer, and are almost certainly going to have serious execution problems.
If you absolutely need to stick with uint32_t for mapmem, then maybe you should compile your X86 code in 32 bit mode, by adding -m32 to the compiler flags. If you do that, you will need to install 32-bit versions, and development versions, of all of the system libraries you are using (libc, bluetooth, etc), and, of course, you will need to recompile your project and all its dependencies in 32 bit mode, too.
|
|
|
|
|
Well that were unexpectedly speedy replies.
I suppose next time I'll sleep on the problem before I post it.
I did find out my mistake - it was actually posted as LAST sentence!
Yes, it is a FFT code I used successfully long time ago and since I am currently not using it , but it is a part of "MY package", I obviously did not pay attention it was written for 32 bits.
After getting about 20 of these error I panic a little, fixing them would keep me from doing the main task. Hence I was looking for a hack.
But it is all fixed and I feel I need to apology for letting the forum to spent much time explaining such "minor" detail as "switching from 32 bits to 64 " in middle of development.
Sorry.
|
|
|
|
|
Well, that's nice. But it bears mentioning that int <-> pointer conversions fail the "smell test". 99.999% of the time integer to pointer conversions are not needed, and point to a misunderstanding of pointers, integers and the relationship between them.
Let me further point out that Raspberry Pi3 and Pi4 are both 64bit chips, and there are various 64-bit Linux distributions available for them. Its not inconceivable that when the Pi5 arrives, it might support 8G RAM (or other features that will only be availble in 64-bit mode), and the default OS will move up to 64 bits. If and/or when that happens, you are going to be back to dealing with "cast looses precision" issues. At least use intptr_t , which is what you should be using in the first place.
|
|
|
|
|
At least use intptr_t, which is what you should be using in the first place. And that is what I am using now.
There is still unanswered question - the inherited ( OK cut and paste) FFT code used 32 bit casts and Rpi 3B HAD no issue with it. I'll go back to that when I am done with code for 64 bit X86.
As far as "8GB ram" - that is little too late for me, but I did learn few tricks cross-compiling.
|
|
|
|
|
I am looking for somebody who can help me to resolve this bluetooth issue.
( I'll ignore any replies NOT discussing / leading to resolution , including insults and RTFM comments )
Included is "bare bones " bluetooth code , I have not included any necessary #includes / library , but if it will help I can add them later if necessary.
I am still having an issue with "address already in use" , BUT my question for now is
why I cannot close and successfully reallocate "socket" ?
I understand that some functions DO NOT generate valid "errno" hence "invalid argument" is really somewhat bogus perror message, however SECOND call to socket should generate "Success" .
Again please concentrate on that for now.
Code output
RPI_BT_SERVER _X86
date version Feb 28 2020
test time 10:17:50
BRAEK @line 333
STATUS allocate socket : Success
STATUS close socket : Invalid argument
STATUS reallocate socket : Invalid argument this is the issue
STATUS bind : Address already in use
STATUS listen : File descriptor in bad state
STATUS accept : File descriptor in bad state
accepted connection from 00:00:00:00:00:00
Code snippet:
<pre> struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 };
char buf[1024] = { 0 };
int socket_fd, client_fd, bytes_read;
socklen_t opt = sizeof(rem_addr);
socket_fd= socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
perror("STATUS allocate socket ");
close(socket_fd);
perror("STATUS close socket ");
socket_fd = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
perror("STATUS reallocate socket ");
loc_addr.rc_family = AF_BLUETOOTH;
struct hci_dev_info device_info;
hci_devinfo(0, &device_info);
loc_addr.rc_bdaddr = device_info.bdaddr; loc_addr.rc_channel = (uint8_t) 1;
bind(socket_fd, (struct sockaddr*) &loc_addr, sizeof(loc_addr));
perror("STATUS bind ");
listen(socket_fd, 1);
perror("STATUS listen ");
client_fd = accept(socket_fd, (struct sockaddr*) &rem_addr, &opt);
perror("STATUS accept ");
ba2str(&rem_addr.rc_bdaddr, buf);
fprintf(stderr, "accepted connection from %s\n", buf);
memset(buf, 0, sizeof(buf));
bytes_read = read(client_fd, buf, sizeof(buf));
if (bytes_read > 0) {
printf("received [%s]\n", buf);
}
close(client_fd);
close(socket_fd);
|
|
|
|
|