Android Question SOLVED BT, AsyncStreams, and asymmetric prefix mode

johnf2013

Member
Licensed User
Longtime User
I have an app that is to communicate with an STM32 sending short, usually single byte, commands and receiving large packets of sensor data over BT, frequently (50Hz or so).

The app and the firmware are both written and run happily in simulation mode. They are just waiting for me to finish the communications code.

I like the prefix mode and the large data packets arrive safely to Android in this mode. The problem is sending the commands back to RTOS. The RTOS in the STM32 fires off an event when a byte arrives. When this happens, and when I am ready, I check the input buffer for a valid first byte, maybe an argument, and a cr/lf, then do something, or maybe not.

This is really simple and works well from a serial console. It gets more complicated if the command arrives with a prefix from Android. It would be nice to avoid this.

To do this I would need an asymmetric prefix mode. I tried, without much hope of success, setting up two streams on the same serial device, one for input with prefix and the other for output without prefix. Not unexpectedly, it did not work.

Does anyone have any ideas how I may go about this or will I just have to "bite the bullet" and code the input prefix handling into the RTOS?

Thanks.
 
Last edited:

johnf2013

Member
Licensed User
Longtime User
Solved it. Setting up two streams does work. I just got it wrong the first time. One stream is a prefix stream and the other is standard. Works perfectly. So now I have asymmetric prefix mode AsyncStreams.
I am currently testing it with the sample chat program and a PC running Realterm. Prefix mode strings go to the PC which Realterm can display in hex to show the prefix bytes. Strings from the PC to Android are sent without prefix and display correctly in the chat window.
 
Upvote 0
Top