roboforum.ruТехнический форум по робототехнике. |
|
|
Make your own
To use uJ in your own project, you'll need to provide a few pieces of code. First, you'll want to figure out where to store the class files, and how to get them there. That part is completely up to you, though you can use uc_loader.c as an exaple of storing classes in the flash of the microcontroller and putting them there from the SD card. You are responsible for, at boot, calling ujInit() to initialize uJ. At this point you can inject your own native classes, if you so wish. This is where you provide access to your hardware to java. Feel free to use uc_main.c as an example of doing that. After this, you should start loading java classes. Call ujLoadClass() on each, and remember the ones that fail with UJ_ERR_DEPENDENCY_MISSING. Re-try them later - you may have just not yet loaded their dependencies. After you're all done with that, and all classes loaded without errors, it is time to initialize all classes. Use ujInitAllClasses() for this. Now you can start the VM. Create the main thread via a call to ujThreadCreate() and have it start running main, or whatever your entry point is via a call to ujThreadGoto(). As previously, uc_main.c can be used as an example of doing this. At this point everything is ready, and you can let the VM go. Code like this is what you need now: [while(ujCanRun() && EJ_ERR_NONE == (err = ujInstr()));]. If that loop ever exits, it means your code finished or an error occured. Examine the value of err for details. Of course you'll also need to implement ujReadClassByte() that actually reads bytes from whereever you store your class files.
The current state of the code can be had via a download from [HERE]
Вернуться в Разработка модулей
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 15