Android Question SOLVED BT, AsyncStreams, and asymmetric prefix mode

Discussion in 'Android Questions' started by johnf2013, Sep 2, 2018.

  1. johnf2013

    johnf2013 Member Licensed 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: Sep 2, 2018
  2. johnf2013

    johnf2013 Member Licensed 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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice