Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue of writing 13 bytes sendSerialMessage with causes error Received message of unknown type 0x0001 #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

loune
Copy link

@loune loune commented Apr 17, 2017

I came across an issue where the Bean with become unresponsive after writing 13 bytes. I also get the logcat message Received message of unknown type 0x0001 when that happens. Googling seems to show a similar instance of this reported, but with scratch data ( http://beantalk.punchthrough.com/t/is-bean-still-supported-by-punchthrough/4056/2 ).

This only happens with 13 bytes, 12 bytes and 14 bytes are fine, indicating that this is possibly a boundary issue. I looked through the code, and found an issue in GattSerialTransportProfile.sendMessage

int packets = (int) (message.size() / PACKET_TX_MAX_PAYLOAD_LENGTH);

int packets = (int) (message.size() / PACKET_TX_MAX_PAYLOAD_LENGTH);
PACKET_TX_MAX_PAYLOAD_LENGTH is 19

  • when message.size() is 18, packets is 0
  • when message.size() is 19, packets is 1, when it should be 0.
  • when message.size() is 20, packets is 1.

I've refactored packets to indicate the number of total packets, such that:

  • when message.size() is 18, packets is 1
  • when message.size() is 19, packets is 1
  • when message.size() is 20, packets is 2

and changed the following new GattSerialPacket logic to use pre-decrement on packets

I've also added a test case to illustrate the issue.

@kdjani
Copy link

kdjani commented Apr 17, 2017

Nice find loune. We had have been hitting issues with sendSerial and my intuition tells me that this what we have been hitting. In general, I have found the Bean Android SDK to be buggy and lacking in so many ways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants