Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incoming data format #17

Open
ghost opened this issue Jun 18, 2014 · 5 comments
Open

Incoming data format #17

ghost opened this issue Jun 18, 2014 · 5 comments

Comments

@ghost
Copy link

ghost commented Jun 18, 2014

Hello.
I have been doing some research about this issue. I am doing readings with an RFID reader and some tags.

Offtopic but related (?): There is a strange behaviour with the plugin. When i start connection and run the startConnectionManager method and then i perform some readings, the plugin notifies on 2 incoming streams. The first one seems to be a random partial of the full stream. And the second stream most of the times becomes the full stream. I.e:

  1. First reading attempt from a tag:
    a. First incoming data: ":"
    b. Second incoming data: ":FXDB=001553930C123019233192"
  2. Secont reading attempt from a tag:
    a. First incoming data: ":F"
    b. Second incoming data: "FXDB=001553930C123019233192"

I figured this out with a method like this:

bluetooth.startConnectionManager(incoming_data,fail);

function incoming_data(data){
data = $.trim(data);
if(data.length < 5){ //random number, any incoming data with less than 5 chars is not valid for me
console.log("Ignoring this incoming data: " + data);
return;
}
data = data.split("=");
data = data[1] //Now i get just the number, this is worthful data for me
process_data(data);
}

Now, turns out that the real data (what is suppose to be read with the reader and be received by the application) from my tag is printed on a side of the it. i.e: 0000123
My stick reader has a led screen that shows the same number printed in the tag and this tells me that somehow the incoming data is parsed to this number.

Summing up, the plugin is receiving something like: "FXDB=13C0000C0150180000000" and what must be received is something like: "0003091"

I was looking in the BluetoothPlugin.java (line 953) at BluetoothWrapper.MSG_READ case and saw that this is where data is parsed and sent back to the plugin. I have tried to change the format on the constructor of the String 'data' object with no luck, also i have played around this case but im clueless now.

@tanelih
Copy link
Owner

tanelih commented Jun 19, 2014

Hi,

Did you try changing the encoding of the string in the MSG_READ case? It defaults to UTF-8. You can try some logging in the .java files to see what you are receiving, since the plugin simply reads the InputStream and forms a UTF-8 String from the ByteArray it receives.

@ghost
Copy link
Author

ghost commented Jun 19, 2014

Exactly, i tried using all of this http://docs.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html
Others but UTF-8 are non readable strings.

@tanelih
Copy link
Owner

tanelih commented Jun 19, 2014

Ok, that's really weird then. I'd do a double check and some logging on the data you are receiving if you know for sure that you should be receiving something specific.

@ghost
Copy link
Author

ghost commented Jun 19, 2014

What am i currently doing is returning what ever it returns from the creation of a new string with different formats back to the plugin and then back to the phonegap output. Im also using 'adb logcat' command to debug my phonegap application. How can i debug the plugin using the phonegap application?

What currently i am going to try is playing around line 936 in BluetoothWrapper.java - Here is where the message is formed from the input stream, i see the BUFFER_SIZE constant is 1024, why? I will debug this as soon as i know how to do it.

btw im using a Samsung Galaxy S4, does this matters?

@tanelih
Copy link
Owner

tanelih commented Jun 19, 2014

I don't think the device matters.

The buffer size is a magic number, it just means how many bytes the plugin will read from the InputStream in one go. If you are receiving large sets of data in one go, you can adjust it higher (maybe it should be an option).

About debugging, I have usually just used:

Log.d("debug message");

Maybe I should look into some proper debuggers...

EDIT

I discussed this issue with a colleague and he said that the data you are receiving is probably the raw RFID data, and that the printed version is already parsed somehow into a more readable format. I can't really comment on that though, since I have no experience with anything RFID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant