Fixed issue of writing 13 bytes sendSerialMessage with causes error Received message of unknown type 0x0001 #37
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
bean-sdk-android/sdk/src/main/java/com/punchthrough/bean/sdk/internal/serial/GattSerialTransportProfile.java
Line 207 in dc33e8c
int packets = (int) (message.size() / PACKET_TX_MAX_PAYLOAD_LENGTH);
PACKET_TX_MAX_PAYLOAD_LENGTH
is19
message.size()
is 18, packets is0
message.size()
is 19, packets is1
, when it should be0
.message.size()
is 20, packets is1
.I've refactored packets to indicate the number of total packets, such that:
message.size()
is 18, packets is1
message.size()
is 19, packets is1
message.size()
is 20, packets is2
and changed the following
new GattSerialPacket
logic to use pre-decrement onpackets
I've also added a test case to illustrate the issue.