How To Parse Binary Data Into Structures

May 15, 2014

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...

how to parse binary data into structures


Parse Binary Data Received Through Bluetooth

Sep 22, 2011

I have an application that receives data in binary form through bluetooth. I read the data using bluetoothsocket to an byte[]. But i must parse all messages, because they must have an given format and they are in binary.

My solution was to convert byte[] to a string and then split the string and parse all received messages.

An example of the data to parse:
0000000010000001

I should know that the first 8 zeros are the header and 10000001 the real data.

My idea was to create a string that represents -> 0000000010000001 and then split the whole string in one byte and check the value, like:

string1 had 00000000
string2 had 10000001

I know that 8 zeros are the header, therefore string2 has the representation of the data.

View 1 Replies View Related

Android :: Static Data Structures On Embedded Devices

May 2, 2010

I've started working on some Android applications and have a question regarding how people normally deal with situations where you have a static data set and have an application where that data is needed in memory as one of the standard java collections or as an array.

In my current specific issue i have a spreadsheet with some pre-calculated data. It consists of ~100 rows and 3 columns. 1 Column is a string, 1 column is a float, 1 column is an integer. I need access to this data as an array in java.

It seems like i could:

1) Encode in XML - This would be cpu intensive to decode in my experience.

2) build into SQLite database - seems like a lot of overhead for static access to data i only need array style access to in ram.

3) Build into binary blob and read in. (never done this in java, i miss void *)

4) Build a python script to take the CSV version of my data and spit out a java function that adds the values to my desired structure with hard coded values.

5) Store a string array via androids resource mechanism and compute the other 2 columns on application load. In my case the computation would require a lot of calls to Math.log, Math.pow and Math.floor which i'd rather not have to do for load time and battery usage reasons.

I mostly work in low power embedded applications in C and as such #4 is what i'm used to doing in these situations.

It just seems like it should be far easier to gain access to static data structures in java/android.

Perhaps I'm just being too battery usage conscious and in my single case i imagine the answer is that it doesn't matter much, but if every application took that stance it could begin to matter.

View 3 Replies View Related

Android :: How To Pass Complex Data Structures Between Service And Remote Binder?

Feb 17, 2010

The object passing between an Android service and the remote binder is happening through serialization of the object. If the service needs to return a very large collection, it seems very inefficient to use this. What is the recommended way to deal with this?

View 1 Replies View Related

Android :: Save Data Structures In Android?

Sep 24, 2009

I want to store some data from structures like this:

...........................

I want to save it to an external file on the sdcard of my device so that other apps can read it (and users can open/copy it). I thought I should use a DOM parser because my data structures are not very big, but I find no tutorials or anything like that. Is there a better way to store this information? how to use the parsers in android?

View 1 Replies View Related

Android :: Fast Way To Compress Binary Data?

Nov 2, 2010

I have some binary data (pixel values) in a int[] (or a byte[] if you prefer) that I want to write to disk in an Android app. I only want to use a small amount of processing time but want as much compression as I can for this. What are my options?In many cases the array will contain lots of consecutive zeros so something simple and fast like RLE compression would probably work well. I can't see any Android API functions for this though. If I have to loop over the array in Java, this will be very slow as there is no JIT on most Android devices. I could use the NDK but I'd rather avoid this if I can.

View 4 Replies View Related

Android :: Sending Binary Data Via POST

Jun 15, 2010

Android supports a limited version of apache's http client(v4). typically if I want to send binary data using content type= application/octet-stream via POST,

I do the following:

CODE:.........................

However ByteArrayRequestEntity is not supported on android. what can I do?

View 1 Replies View Related

Android :: Way To Get Binary Data From External Device To Droid?

Jul 8, 2010

I'm looking for some input on how to go about a problem I have. We have a device that has binary data that it needs to send out (they are mainly just symbols, but in a custom binary format) over ethernet. I need to intercept this data on the phone and display the symbols over google maps. I'm just wondering the best way to go about this, I have a few ideas but am not sure if they are possible or feasable: 1. Is it possible for the phone to connect directly to the device if the device had some sort of server running on it, then poll for new data? If so, what is the protocol needed to be able to direct connect like that? 2. Perhaps modify the device software to send data to the phone(s) in SMS data message format? Im not sure if it is possible for software to "spoof" an SMS to a phone when it is not a phone itself? 3. Have the device software upload all its binary data to a ftp/http server that is sitting out there somewhere, have the phone(s) connect to that server and poll for new data periodically? I'm brand new to android development, basically all I want to do is grab this binary data from the device on my phone and parse/display it over google maps. How do any of those ideas sound, or is there a much easier way I am overlooking?

View 2 Replies View Related

Android :: Convert Binary Data (ISO-8859-1) To String?

Oct 6, 2010

I have created an android app. It sends a data message on a port for communicating with the same app on some other phone. While sending the message, i have encoded it into binary data using ISO8859_1 encoding.

byte[] b1=payload.getbytes();

I am able to receive the data message at the receiving end. But the problem is that after receving it in binary format , My app needs to decode the message back to string or human read-able format. But i am not able to do the same.

I have tried to convert it into String using 'toString()' but string contains binary character .

View 1 Replies View Related

Android :: Converting Binary JPEG Data To Bitmap

Sep 8, 2010

My app will have an SQLite database with some embedded JPEG images -- basically the binary contents of a JPEG file stored as a Blob in the database. Can someone point me in the general direction of where to start to figure out how to convert this "array of bytes" into a Bitmap object that can be further manipulated and displayed in an ImageView?

View 2 Replies View Related

Android :: Code To Parse Xml Data?

Sep 26, 2010

How to parse xml data.. file is php file and Soap is used in xml..
i am going to use this in a android application.
please provide me proper codes

View 1 Replies View Related

How To Obtain And Parse Data From A Website

Feb 28, 2012

I want to create an app that displays flight information such as: arrival/departure info, canceled flights, etc. I don't know how to query the data from the website in order to display it in the app.

View 4 Replies View Related

Android :: Parse Data - Multiple Objects

Oct 29, 2010

i need to parse this response in android using the android json parser but the thing i cant find the answer to anywhere is: how do i parse the data if for example "itineraries" can contain one or sometimes more objects of the type itinerary? if it contains one than it is returned like this but if it contains more it is returned with [] with this example "itinerary" cannot be placed into a JsonArray becouse obviously it is not an array. (not placed in [] right?)

how do i parse this? any examples?
{
"plan":{
"date":"2010-10-20T00:00:00+02:00",
"from":{
"name":"Булевар Партизански Одреди",................

View 1 Replies View Related

Android :: Parse Through Xml Data From Consumed Web Service Droid?

Oct 4, 2010

I have a web service, .asmx that when consumed gives a response in the form:

<lData>
<name>...</name>
<posx>..</posx>
<posy>...</posy>
</lData>

I use Ksoap2 to consume the web service in Android, and I see the response as a string anyType {lData=anyType{name=....;posx=....;posy=....;};}

So, I get the right data from my web service, but i don't know how to parse it correctly.
I want to find a way to iterate through the different nodes.

I have tried to use a SAXParser, but can't seem to understand what I should use instead of the url. In the tutotirals I have followed the link to a xml-file on a url, but my url is only part "finished" since i need to consume the web service first. code...

Is this above something I should use, but have another openStream?

View 1 Replies View Related

Android :: How To Convert Binary String Data Into String?

Aug 4, 2010

Can anybody give me some clue that how to convert binary string into a string(english). I have tried and googled so much but couldn't find an answer.

View 1 Replies View Related

Games :: Build Structures Out Of Marshmallows / Spaghetti Noodles

Oct 10, 2010

Messing around on AppBrain I found a new game, Spaghetti Marshmallows. The idea is to build structures out of marshmallows and spaghetti noodles, to reach given points on the screen. What seems to be a very simple game on the surface, actually requires a very strategic planned out execution.

View 15 Replies View Related

General :: Rip ADB Binary Out Of CM9

Oct 5, 2012

I want't adb on my desire. I use Leedroid and there is no adb binary. So I downloaded CM9 (and other) to rip it out. But all I get if I try to start the binary on my device is:

permission denied

View 4 Replies View Related

Android :: Jpeg From Binary?

Jun 14, 2010

Does Android have a native library that can make a jpeg from binary data from say, a json object?

View 4 Replies View Related

Android :: How To Read Binary .AMF File?

Aug 2, 2010

I am new to android and I want to read a binary file extension .AMF file.I really need your help this is really urgent.

View 1 Replies View Related

Android :: Getting Double And Int Value From Binary File

Aug 5, 2010

Can anybody please tell me how to get double and int value from a binary file. I have tried alot but its giving me wrong values.

View 2 Replies View Related

Android :: Download Binary File

Feb 23, 2009

I am having problems downloading a binary file (video) in my app from the internet. In Quicktime, If I download it directly it works fine but through my app somehow it get's messed up (even though they look exactly the same in a text editor).

View 4 Replies View Related

Android :: How To Add More Words Onto Binary Dictionary?

May 19, 2009

Is there any way that i can add many words into main.dict currently used as Main Dictionary in Inputmethods package?? Please reply it's bit urgent.

View 3 Replies View Related

General :: Update-binary In Flashable Zip?

Sep 26, 2012

I noticed every flashable zip has one. If i merge to flashable zips what do I do with the update-binary? Is it important?

View 1 Replies View Related

General :: How To Update Zip File Of SU Binary

Jun 11, 2014

Update.zip file of su binary i had deleted my su binary by update.zip unroot method but now i can't get the root even i have superuser icon

View 1 Replies View Related

General :: NO SU Binary After Update To Kitkat 4.4

Nov 28, 2013

"There is no SU binary installed, and SuperSU cannot install it." after upadate my already rooted nexus 7 to kitkat 4.4

View 2 Replies View Related

Android :: How Create LatinIME's Binary Dictionary?

Mar 22, 2010

I met a big difficiult problem, i have researched more then 5 day's. Of course i read the LatinIME's algorithm for the suggestion.

View 4 Replies View Related

Android :: Binary Compatible For Emdebian And Droid?

May 27, 2010

Android ndk is hard to use for the old autoconf based code, so i employed scratchbox2/emdebian to have a complete build environment. can i build a shared library in emdebian (arch is armel) and then use it in android?

View 2 Replies View Related

Android :: Receive Binary SMS On A Specific Port?

Mar 18, 2010

Is it possible to receive a binary SMS on a specific port?

I am currently receiving SMS via Action: "android.provider.Telephony.SMS_RECEIVED" from a BroadcastReceiver.

But i have no luck with binary SMS. I only get notified for text messages.

View 2 Replies View Related

Android :: How To Remove Strings From A Compiled Binary - .so

May 20, 2010

How do I remove strings from / obfuscate a compiled binary? The goal is to avoid having people read the names of the functions/methods inside.

It is a dynamic library (.so) compiled from C++ code for Android with the NDK tools (includes GCC)

I compile with -O3 and already use arm-eabi-strip -g mylib.so to remove debugging symbols, but when I do strings mylib.so all the names of the functions/methods are still readable.

View 4 Replies View Related

General :: How To Root And Install SU Binary On LG L45C

Apr 20, 2014

I have a LG L45C and I am trying to root it and get Superuser to run, but without any luck after 2 days. I am very new to adroids and cannot figure out how to do it. It all started with Titanum Backup and the message "ROOM is not rooted" and "attempted was made using su command".

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved