java.nio.bytebuffer support in leJOS

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

java.nio.bytebuffer support in leJOS

Postby mcrosbie » Tue Apr 24, 2012 8:05 pm

Hi everyone,

I have some code I wrote in Processing (a Java wrapper) that encapsulates sending and receiving values over the Dexter NXTBee in network-independent format. This allows for communication between NXTs/PCs running either RobotC or Processing. I would like to port this class to leJOS, but it relies on the java.nio.bytebuffer class to perform network byte-ordering transformations of the data values prior to sending.

leJOS provides the EndianTools class which I could use to re-implement my own version ByteBuffer.

Does anyone know of a ByteBuffer implementation for leJOS (or one implemented in Java I could re-use)? If not then I"ll save my time searching and start re-coding my NXTBee class using EndianTools.

Thanks!
Mark
mcrosbie
Novice
 
Posts: 25
Joined: Wed Mar 24, 2010 12:27 pm
Location: Dublin, Ireland

Re: java.nio.bytebuffer support in leJOS

Postby gloomyandy » Tue Apr 24, 2012 9:02 pm

Hi,
well pretty much all of the Sun/Oracle Java implementation is now open source
http://openjdk.java.net/
and there is also the Apache Harmony project:
http://harmony.apache.org/
Both of which may have an implementation. However they may use other features of the class library that are not implemented in leJOS so you may end up having to pull in other classes, which may end up with a lot of extra code... Hard to say without looking at the actual class implementation...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4119
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: java.nio.bytebuffer support in leJOS

Postby skoehler » Wed Apr 25, 2012 12:25 pm

I would suggest, that you port your code to use byte arrays or streams. E.g. DataOutputStream also takes care of converting integers to network byte order.
If we'd add a ByteBuffer to leJOS, it would merely be a byte array. And the various methods for writing ints/longs/etc. would basically call EndianTools.
skoehler
leJOS Team Member
 
Posts: 1431
Joined: Thu Oct 30, 2008 4:54 pm

Re: java.nio.bytebuffer support in leJOS

Postby mcrosbie » Thu Apr 26, 2012 1:55 pm

Thanks everyone!

I looked into the code for ByteBuffer in Apache Harmony and it does rely on JNI native method support (as I read it). So it's probably not an easy port.

I was't aware that the DataOutputStream class wrote in network byte order, but reading the class description I see that the byte order is specified, which I can work from. My original code allowed communication between multiple NXTs using RobotC and also with multiple Windows/Macs running Processing. I should be able to achieve that using a DataOutputStream and my existing type formatting code.

Regards,
Mark
mcrosbie
Novice
 
Posts: 25
Joined: Wed Mar 24, 2010 12:27 pm
Location: Dublin, Ireland


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 0 guests

more stuff