Ketai Bluetooth with a HC-06

edited April 2014 in Android Mode

I'm new to JAVA and Processing, so I'm struggling with the best way to parse serial data stream. I'm using one of those inexpensive HC-06 serial Bluetooth devices to TX from an AVR. The android phone is on the RX side. The Ketai call back passes a byte array, but in this case its only a single byte. So I'm currently loading it into a string, and using the built in JAVA string functions to find the location of headers and footers. But the data in the middle are unsigned 8-bit values representing the upper and lower bytes. In C, I would grab these bytes, left shift the upper and combine with the lower. What do I do in Processing? Can I recover those individual bytes once I've converted to String? Some sample code is below, just showing what I'm doing with the incoming data and how I'm finding valid headers and footers.

//Call back method to manage data received
void onBluetoothDataEvent(String who, byte[] data)
{

  int header_location;
  int footer_location;
  infodata += new String(data);
 //clean if string to long
 if(infodata.length() > 60)
   infodata = "";

 header_location = infodata.indexOf("HEADER");
 footer_location = infodata.indexOf("FOOTER");

 if(header_location > 0)
 {
    valid_header = "YES";
    if(footer_location > 0)
    {
       if(header_location < footer_location)
       {
           valid_message = "YES";
       }
    }
  }
}

Comments

  • Off topic, but for the record the code tags wouldn't work in above post. Sorry.

Sign In or Register to comment.