I have a third party Android application which connects to my target using Bluetooth SPP. Application sends JSON data, but number of data bytes sent are not known, also data received at my target is inconsistent (sometimes in chunks), there are no line endings to detect the end of data sent.
I have a thread running in my code to read the data over serial port.
int fd = open(rfcommDevice, O_RDWR | O_NOCTTY | O_SYNC);
void readData(int fd)
{
while (1)
{
nbytes = read(fd, buf, buflen);
if (nbytes < 0)
{
break;
}
else if (nbytes > 0)
{
showCompleteData();
}
else
{
close(fd);
break;
}
}
}
Now showCompleteData() first parses the data and if found incomplete it fails. As data is received in chunks, so I am not able to understand how to accumulate the complete data and then call showCompleteData().
Also read() does not return 0, as its a blocking call.
Please suggest.