My app interfaces with a bluetooth device, which sends data up in packets, usually 6 bytes but up to hundreds of bytes. In most cases the data arrives OK, but once in a while I get unexpected data, which could be a result of either a lost chunk of data, or two subsequent chunks of data arriving in the wrong order. The situation is much worse in DEBUG than in RELEASE mode.
I am testing with only 6 byte long packets at the moment. In my Asynchstreams_NewData function, I read out the number of bytes received and stick it in a fifo, buffering it up until I have at least 6 bytes and then I call my packet handler. The packet handler extracts the packet and removes the relevant data from the fifo, reporting on what is left in the fifo upon exit.
got 1
got 5
left in buf 0
got 3
got 3
left in buf 0
got 1
got 5
left in buf 0
got 1
got 5
left in buf 0
got 1
got 5
left in buf 0
got 1
got 1
got 5
So, in the case of the last NewData events, I got 7 bytes and experienced the unexpected data problem. Examining the data, if the last and second last packets were swapped around, the data would have made sense. This could be co-incidental due to the repetitive nature of the packets I am testing with.
Anyway, to cut to the chase: I was under the impression that since I cannot use Prefix mode, using a fifo to buffer the incoming data until I had enough data to decrypt a packet was all I needed to do. I need to find out why I am getting unexpected data, and I suspect that the Astream_NewData function sometimes returns chunks of data in the incorrect order.
Is this a possiblity, or am I barking up the wrong tree?
The product normally interfaces to a PC with a bluetooth dongle of my own design, I've sold hundreds of systems and worked with further development of the system every day for over 3 years and I've never once experienced a communication error, so the issue is on the android side of things, that much I know.
I am testing with only 6 byte long packets at the moment. In my Asynchstreams_NewData function, I read out the number of bytes received and stick it in a fifo, buffering it up until I have at least 6 bytes and then I call my packet handler. The packet handler extracts the packet and removes the relevant data from the fifo, reporting on what is left in the fifo upon exit.
got 1
got 5
left in buf 0
got 3
got 3
left in buf 0
got 1
got 5
left in buf 0
got 1
got 5
left in buf 0
got 1
got 5
left in buf 0
got 1
got 1
got 5
So, in the case of the last NewData events, I got 7 bytes and experienced the unexpected data problem. Examining the data, if the last and second last packets were swapped around, the data would have made sense. This could be co-incidental due to the repetitive nature of the packets I am testing with.
Anyway, to cut to the chase: I was under the impression that since I cannot use Prefix mode, using a fifo to buffer the incoming data until I had enough data to decrypt a packet was all I needed to do. I need to find out why I am getting unexpected data, and I suspect that the Astream_NewData function sometimes returns chunks of data in the incorrect order.
Is this a possiblity, or am I barking up the wrong tree?
The product normally interfaces to a PC with a bluetooth dongle of my own design, I've sold hundreds of systems and worked with further development of the system every day for over 3 years and I've never once experienced a communication error, so the issue is on the android side of things, that much I know.