Search code examples
c++linuxbluetoothbufferrfcomm

Check state of buffer in Bluetooth socket


I created a socket to receive data from a rfcomm socket in bluetooth.

The packages if received in one piece have 10 numbers, but sometimes I receive separate parts. It depends on the frequency I choose to acquire data. For example, if I choose 1000Hz I get all the information. I'm using a QTimer and as it gets a int as interval 1000 ms / 1000 Hz is equal an int, which is OK. But if the division is not an int so the QTimer will round it and it does not restart the function in time to get all the package as it desynchronizes.

I use this,

sock = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);

numb = read (sock, buf, 10);

If numb is equal 10 the package was OK, so I process it. If not, a part only was received. Then that part is lost.

Is there a way to only check if the buffer is full instead of reading it already? I.e. If the state if full read it, if not, leave it to the next iteration.

I'm not really an expert in this matter, but would the flag MSG_EOR help me? My data cames in packages.

Should I change readto recv? recv gets a socket as parameter.

Any help would be very appreciated.


Solution

  • Well I worked it out my self.

    Being each package 10 bytes, I changed the buffer size to have the size of frequency * 10 bytes so it can receive a second of acquisition and so I can have the QTimer with an interval of one second.