Sunday, April 11, 2021

Setup Progress #4 Moving on to Development

 

I solved my last problem.  It was fairly complex and was directly tied to how RAD studio implemented the Bluetooth GATT characteristic writing.  Originally all of the BT communications was done as 4 bytes.  Only the Heartbeat notification was done as 2 bytes.  As the API documentation showed, all of the payload formatting was in a 32 bit format.  It has become obvious that this was no longer going to work with 10 LEDs and the expanded script commands.  However, I wanted the Android APP to control both the Brick Buddy I and II.  Also some commands did not need to go to 64 bits.  Thus some 32 bit payloads were going to remain.

When I started testing the 64 bit transfers, I noticed that once I made a 64 bit transfer, all subsequent transfers for that BT GATT Characteristic would be 64 bits, even though I may have requested a 32 bit transfer.  After tracing it down into the system libraries, I found the function that was causing the problem.  The payload value was a dynamic array of bytes, meaning the length had to be set programmatically.  The library function did not set the payload value arbitrarily, it appeared to take the last payload value sent and determine its length.  Then it would look at the length of the new payload value and expand the dynamic array if needed, but it would never shrink the dynamic array.  Thus while the first 4 bytes in a 32 bit transfer would be correct, there would be 4 more bytes and they would be the same as the last 64 bit transfer.  This was causing issues with the PIC32 code, since it was expecting 32 bits and getting 64 bits and not knowing which 32 bits it was supposed to use.  I solved this by always setting the length of the dynamic array to 1, prior to setting the new payload value.  This forced the system library function to always expand the dynamic array to the correct size, since every payload transmission I do is great than 1 byte.

We move on to development.  Here is the general path I will follow.

  1. All 10 LEDs working in Android and PC software
  2. Verify Motor Functionality in Android and PC software
  3. New MP3 functionality
  4. Script Functionality, especially in Android
  5. Package it all up

One Note, I will be working on the MOCs also, so it is not 100% coding.

Should be fun!!😅

 

No comments:

Post a Comment