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

Java Port #55

Closed
wants to merge 10 commits into from
Closed

Java Port #55

wants to merge 10 commits into from

Conversation

fommil
Copy link

@fommil fommil commented Dec 28, 2012

(let's leave this pull request open until it's fully implemented)

Access in Java (and Scala) to Emotive EEG devices.

@fommil
Copy link
Author

fommil commented Dec 28, 2012

@bschumacher @qdot @daeken @openyou

Could one of you please provide me with an example array of raw input data and the corresponding unencrypted? I'd like to use it for a unit test of the Java decryption. (Also, I'll need the serial number)

If you could also give me the final data structure too, that would be great because it means I could also use it in unit tests of the frame objects.

@fommil
Copy link
Author

fommil commented Dec 28, 2012

I have AES decryption running, but I'm not sure if it's working - the decrypted bytes 29/30 (gyro) seem to be coming out randomly. Without a test input/output I'm a bit buggered.

@ozancaglayan
Copy link

Just check the first byte which counts from 0 to 127 consecutively and then
reports the battery level.

@fommil
Copy link
Author

fommil commented Dec 28, 2012

@ozancaglayan I'll do that.

BTW, what the C code is doing (to extract keys) and what is written here https://github.com/openyou/emokit/blob/master/doc/emotiv_protocol.asciidoc don't agree – at all!

@qdot
Copy link
Member

qdot commented Dec 28, 2012

I'd rather not bring a java port not maintained by me into the main repo. I recommend making your own repo, or else if you want it hosted under openyou to centralize things, I'd be happy to make a repo there and add you as a commiter.

I'm probably going to split the C and python at some point too (the python was only Proof of Concept until recently, and I prefer reference implementations in C). I really prefer one repo per language (see reasoning about this at signal11/hidapi#87), with the library as a submodule, and I can put a link in the README. This is much easier to maintain for all parties, and makes sure that API upgrades don't break language bindings.

@fommil
Copy link
Author

fommil commented Dec 28, 2012

@qdot whatever you think is easiest. I'll do all that admin stuff once I've written it. Let's leave this pull request open though as it serves as an adhoc QA.

@fommil
Copy link
Author

fommil commented Dec 28, 2012

@ozancaglayan hmm, I'm not getting the right first byte, whether I use the "research" or "consumer" key from my code. I'll need to do some debugging.

@fommil
Copy link
Author

fommil commented Dec 28, 2012

ok, now I can't even build the C code – think I was using qdot's branch when I last built it.


[100%] Building C object CMakeFiles/emokit.dir/emokit.o
/Users/samuel/Documents/Projects/emokit/src/emokit.c:20:27: error: emokit/emokit.h: No such file or directory
/Users/samuel/Documents/Projects/emokit/src/emokit.c:22:20: error: mcrypt.h: No such file or directory

@qdot's branch works though. Not sure what's different between them.

@fommil
Copy link
Author

fommil commented Dec 28, 2012

W00T!!!! Got decryption working. The docs are totally up the left – the C code is the best reference.

I think this deserves a short break to have a wee dram of a single malt...

@fommil
Copy link
Author

fommil commented Dec 29, 2012

@bschumacher you recommended doing the decryption in a separate thread.

In Java the reading takes about 8 milliseconds and it sometimes takes as much as 1 millisecond to do the decryption. I think it makes sense to do the decryption in the same thread as the USB reading as this thread is suffering from a lot of blockage otherwise.

@fommil
Copy link
Author

fommil commented Dec 29, 2012

@bschumacher just did a nanosecond analysis: reading takes 7.5 milliseconds, decryption takes 0.058 milliseconds.

@ghost
Copy link

ghost commented Dec 29, 2012

Depends on platform I guess, I'm using this on a Raspberry Pi. It doesn't decrypt the packets fast enough to keep up with the flow(in Python). Although I haven't tested Java performance vs Python on the Pi.

From: Sam Halliday [mailto:notifications@github.com]
Sent: Friday, December 28, 2012 6:16 PM
To: openyou/emokit
Cc: Bill Schumacher
Subject: Re: [emokit] Java Port (#55)

@bschumacherhttps://github.com/bschumacher you recommended doing the decryption in a separate thread.

In Java the reading takes about 8 milliseconds and it sometimes takes as much as 1 millisecond to do the decryption. I think it makes sense to do the decryption in the same thread as the USB reading as this thread is suffering from a lot of blockage otherwise.


Reply to this email directly or view it on GitHubhttps://github.com//pull/55#issuecomment-11744989.

@fommil
Copy link
Author

fommil commented Dec 29, 2012

@bschumacher I'm actually hoping to run this on a blackberry pi too – I'll leave the timing debugging in here so that maybe you can run it and give me the numbers :-P

@fommil
Copy link
Author

fommil commented Dec 29, 2012

@bschumacher yes, what I'll do is put in an if statement to spit out a log message if decryption took longer than 5 milliseconds and a severe log message if it takes longer than 7. The sampling rate is about 7 or 8 milliseconds (127Hz) so that is about right.

@ghost
Copy link

ghost commented Dec 29, 2012

I'll pull your code down and see how it does.

From: Sam Halliday [mailto:notifications@github.com]
Sent: Friday, December 28, 2012 6:21 PM
To: openyou/emokit
Cc: Bill Schumacher
Subject: Re: [emokit] Java Port (#55)

@bschumacherhttps://github.com/bschumacher I'm actually hoping to run this on a blackberry pi too – I'll leave the timing debugging in here so that maybe you can run it and give me the numbers :-P


Reply to this email directly or view it on GitHubhttps://github.com//pull/55#issuecomment-11745063.

@fommil
Copy link
Author

fommil commented Dec 29, 2012

@bschumacher try commit #0fd66fc as it has special debugging in it just for you.

@fommil
Copy link
Author

fommil commented Dec 29, 2012

@bschumacher one of the Java dependencies uses JNI which targets 32/64 bit linux/osx/windows. Is that going to be a problem for the raspberry?

@ghost
Copy link

ghost commented Dec 29, 2012

We shall see.

From: Sam Halliday [mailto:notifications@github.com]
Sent: Friday, December 28, 2012 6:29 PM
To: openyou/emokit
Cc: Bill Schumacher
Subject: Re: [emokit] Java Port (#55)

@bschumacherhttps://github.com/bschumacher one of the Java dependencies uses JNI which targets 32/64 bit linux/osx/windows. Is that going to be a problem for the raspberry?


Reply to this email directly or view it on GitHubhttps://github.com//pull/55#issuecomment-11745187.

@fommil
Copy link
Author

fommil commented Dec 29, 2012

@bschumacher I don't think it will work actually – give it a try but I think we might have to use the ARM binary from https://github.com/mirkojahn/net.mjahn.hid.driver (or similar).

@fommil
Copy link
Author

fommil commented Dec 29, 2012

OK, I'm happy with the state of this now.

Tomorrow I'll look into creating a little GUI for obtaining data (and showing a graphic with the quality of connections) in a format that is easily parsed into R.

@ghost
Copy link

ghost commented Dec 29, 2012

I've almost got this running on the Pi I believe.

From: Sam Halliday [mailto:notifications@github.com]
Sent: Friday, December 28, 2012 8:02 PM
To: openyou/emokit
Cc: Bill Schumacher
Subject: Re: [emokit] Java Port (#55)

OK, I'm happy with the state of this now.

Tomorrow I'll look into creating a little GUI for obtaining data (and showing a graphic with the quality of connections) in a format that is easily parsed into R.


Reply to this email directly or view it on GitHubhttps://github.com//pull/55#issuecomment-11746194.

@fommil
Copy link
Author

fommil commented Dec 29, 2012

@bschumacher that quite amazes me because the USB backend doesn't have an ARM binary. There is one floating around, but I'm not sure if it it works.

@ghost
Copy link

ghost commented Dec 29, 2012

Let me rephrase that, I got the maven to build successful.

From: Sam Halliday [mailto:notifications@github.com]
Sent: Friday, December 28, 2012 8:04 PM
To: openyou/emokit
Cc: Bill Schumacher
Subject: Re: [emokit] Java Port (#55)

@bschumacherhttps://github.com/bschumacher that quite amazes me because the USB backend doesn't have an ARM binary. There is one floating around, but I'm not sure if it it works.


Reply to this email directly or view it on GitHubhttps://github.com//pull/55#issuecomment-11746215.

@fommil
Copy link
Author

fommil commented Dec 29, 2012

@bschumacher My money is on an UnsatisfiedLinkException :-D

How much Java do you know? If you want you could try the ARM binary listed above, comment out the following line from EmotiveHid

            ClassPathLibraryLoader.loadNativeHIDLibrary();

and load the ARM binary manually.

@fommil
Copy link
Author

fommil commented Dec 29, 2012

@bschumacher @qdot @daeken @openyou

does anyone have a graphic with the names of the sensors and their location on the device? I want to create a user friendly GUI that points out which probes are not sitting correctly.

@ghost
Copy link

ghost commented Dec 29, 2012

@fommil
Copy link
Author

fommil commented Dec 29, 2012

@bschumacher lol - that'll do. :-D

@ghost
Copy link

ghost commented Dec 29, 2012

Yeah I'll make it work, unfortunately my girlfriend wants me to be social tonight and I have to leave in a bit.

From: Sam Halliday [mailto:notifications@github.com]
Sent: Friday, December 28, 2012 8:08 PM
To: openyou/emokit
Cc: Bill Schumacher
Subject: Re: [emokit] Java Port (#55)

@bschumacherhttps://github.com/bschumacher My money is on an UnsatisfiedLinkException :-D

How much Java do you know? If you want you could try the ARM binary listed above, comment out the following line from EmotiveHid

        ClassPathLibraryLoader.loadNativeHIDLibrary();

and load the ARM binary manually.


Reply to this email directly or view it on GitHubhttps://github.com//pull/55#issuecomment-11746250.

@ghost
Copy link

ghost commented Dec 29, 2012

Yeah I was never very good at writing. I'm left handed so everything comes out like crap.

From: Sam Halliday [mailto:notifications@github.com]
Sent: Friday, December 28, 2012 8:14 PM
To: openyou/emokit
Cc: Bill Schumacher
Subject: Re: [emokit] Java Port (#55)

@bschumacherhttps://github.com/bschumacher lol - that'll do. :-D


Reply to this email directly or view it on GitHubhttps://github.com//pull/55#issuecomment-11746313.

@fommil
Copy link
Author

fommil commented Dec 29, 2012

@bschumacher the test subjects are controlling the mind readers?? This will never do! Have fun! :-D I'm GMT so I'm already well past my bedtime.

@fommil
Copy link
Author

fommil commented Dec 29, 2012

@bschumacher four of these sensors still have question marks on them – have you worked them out yet?

@ghost
Copy link

ghost commented Dec 29, 2012

Yeah they do not return a value, unless it is related to the last bit that is still unknown, like a meditation value or something. I know that if they do not have good quality the other sensors will not report quality. The emotiv docs say there are only 14 sensors on the headset also. I'm supposed to be able to run this jar file right?

I've tried all sorts of different combinations for the main class.

java -cp emokit-1.0-SNAPSHOT.jar Emotiv
java -cp emokit-1.0-SNAPSHOT.jar org.openyou.Emotiv
java -cp emokit-1.0-SNAPSHOT.jar java.org.openyou.Emotiv
java -cp emokit-1.0-SNAPSHOT.jar main.java.org.openyou.Emotiv

@fommil
Copy link
Author

fommil commented Dec 29, 2012

@bschumacher

if you grab the latest you should be able to just run

mvn exec:java

the main method is org.openyou.Emotive. (sorry, maybe I've put an extra "e")

@fommil
Copy link
Author

fommil commented Dec 29, 2012

I've fixed the typo now: everything should be "Emotiv".

@fommil
Copy link
Author

fommil commented Dec 29, 2012

@bschumacher apologies, the jar didn't have the main class or dependencies – I forget Maven didn't do this automatically.

now a

mvn package

will create a jar in target which will work if you also bring the dependency folder with it.

java -jar emokit-1.0-SNAPSHOT.jar

You might find the following logging setup to be a bit prettier

java -ea -Djava.util.logging.config.file=../logging.properties -jar emokit-1.0-SNAPSHOT.jar 

@fommil
Copy link
Author

fommil commented Dec 29, 2012

Following @qdot's recommendation, I'm going to close this Pull Request and set it up as a separate project here https://github.com/fommil/emokit-java

@qdot, please feel free to fork to @openyou and I'll close the wiki / issue tracker on my repo with a note in the README to point to the "communal central".

@fommil fommil closed this Dec 29, 2012
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

Successfully merging this pull request may close these issues.

3 participants