[Suggestion] Use gnaerator to create JNA mapping class

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

Moderators: roger, gloomyandy, skoehler

[Suggestion] Use gnaerator to create JNA mapping class

Postby topikachu » Thu Sep 19, 2013 1:34 pm

How about to use gnaerator https://code.google.com/p/jnaerator/ to create all JNA mapping class from ev3 head file?
As I test, the generated java classes exactly map the c structure memory layout.
It's more easier than compute the structure size and filed offset by hand.

Please see the generated class at https://github.com/topikachu/lejosc
And I use a modified gnaerator which create addition constructor for each class https://github.com/topikachu/nativelibs ... onstructor
Code: Select all
public XXX(Pointer address) {
    super(address);
}
topikachu
Novice
 
Posts: 32
Joined: Wed Sep 18, 2013 3:27 am

Re: [Suggestion] Use gnaerator to create JNA mapping class

Postby gloomyandy » Thu Sep 19, 2013 2:27 pm

Hi,
this looks interesting but at the moment I just don't have the time to look at it. Please feel free when you get your EV3 to try using this and report back with how well it works. Having said that the main problem is not with the one or two items that use Structures but with the much larger memory mapped items. My main concern there with attempting to use the JNA Structure to access the data is that to read a value from the structure requires you to update all of the structure data and there is rather a lot of it in some of these data structures. Copying a large volume of data just to check a single byte status value seems over the top to me. If you can find an efficient way to replace the offsets etc use to access those then that would be very useful.

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

Re: [Suggestion] Use gnaerator to create JNA mapping class

Postby topikachu » Thu Sep 19, 2013 2:41 pm

there's a readField method to update single field. https://jna.java.net/nonav/javadoc/com/ ... ang.String)
I'd like to try this after I receive my ev3.
:)
topikachu
Novice
 
Posts: 32
Joined: Wed Sep 18, 2013 3:27 am

Re: [Suggestion] Use gnaerator to create JNA mapping class

Postby skoehler » Thu Sep 19, 2013 2:50 pm

I had heard about this generatetor. Now it seems to generate lots of get/set methods which we probably don't need since the structures are hidden behind a proper API. The generator would be useful if we'd expect Lego's API to change often - if is probably not going to happen. Andy has pretty much done the work already - so why switch to using the generator?

Also, as Andy says, JNA might not be the best performance wise. So what working out what could be done to improve the performance here seems like an important part to me. It might involve using JNI. Note, that you should target the the stuff in a performance critical path first, i.e. everything that might be executed in a loop (like readin sensor values etc.).
skoehler
leJOS Team Member
 
Posts: 1350
Joined: Thu Oct 30, 2008 4:54 pm


Return to EV3 Software

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests

more stuff