Jump to content
Android Forum - A Community For Android Users and Enthusiasts

Noob question on receiving and parsing binary data


hackster84
 Share

Recommended Posts

Hi,

 

I am a noob in the Java/Android development world.  I primarily do hardware and firmware design, but a new product my company is developing has the need for an Android app and since I have the most Android programming experience (which is extremely limited) that leaves the task to me.  I need a little guidance figuring out how to do a few things so that I can get this app up and running.  I already have a simple GUI to display some stuff, but what I need is a way to handle data.  

 

I am trying to receive a 148 byte stream of data over a serial connection, parse it into a structure and display certain values from that structure.  The data is packed in a struct that is sent from a micro controller and due to that it has a very specific layout (i.e. the first 8 bytes mean this, the next 16 bytes are this... ).  In C, I can just declare a struct with those values and use the #pragma pack function to eliminate any extra spacing the compiler would otherwise inject for alignment purposes, receive the data and do a memcpy into the struct to write the data.  It's not the safest or cleanest way to do it, but it takes very little time and if you do CRC tests to make sure the data received is valid it works like a charm.

 

Now to the root of the problem: How do I declare structs in Java?  Is there a way to pack them tightly like you can using C? Once I've received the binary data, is there a way to parse it into the structure easily?  These are the issues we hardware programmers face when dealing with Java... 

 

Any help would be greatly appreciated, thank you.

 

-Chris

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...