You are free to participate in the project by forking it, or just download the source code.
- Code: Select all
Readme from Github:
A simple and customizable bluetooth protocol for leJOS.
- Provides an object-oriented abstraction to leJOS bluetooth interface.
- Logically group data in Requests
- Easily customizable for custom needs
- Emailish request header with name, subject, module, sender...
- Answer to one individual received request
- Send follow-ups to sent requests
- Block thread execution until reply is received
I was working on a project for school with the Lego Mindstorms NXT. Because the proposed language, NXC, didn't appeal to me and I always wanted to learn a little Java, I decided to go with leJOS.
As we were planning our projects, the idea arose that we wanted to have robots that communicate with each other and send data to the computer. During our research on the web we discovered, that an NXT could not have more than one outgoing Bluetooth connection at a time. To compensate for this communication problem, we wanted our Computer to act as master between the NXTs.
I decided to abstract the NXTs raw bluetooth communication and introduce an OO approach. Soon, nxj-chat was born.
Because the project is finished, I have no longer access to the NXTs. Therefore, I am unable to extend this project any further because I lack the possibility to test code. However, feel free to open an issue on github and I will look into it.
That's why I have decided to publish the source on github, so that other people can use or fork it and add their own features.
Unfortunately I haven't been very busy documenting the source code. But I hope you can figure out how it works by looking at the sample application I have provided.
As I have mentioned, this was my first Java Experience and please excuse the complicated class hierachies...
A while ago I needed means to communicate between multiple NXTs.
I learned that an NXT can only have one incoming connection and instead of continuous reconnects, I decided to bring the computer as master into the project.
Using this library, you should be able to easily communicate between a PC and NXTs.
So how does it work?
There are three main classes, Uplink, MasterMind, and Slave
- Uplink establishes a connection from an NXT to a PC. It waits until a PC connects.
- Slave represents the NXT on the PC. It estlishes the connection from the PC to an NXT.
- MasterMind manages the Slaves on the PC
You send data between the NXTs and the PC using the Request class.
A request can be "replied" to, and you can wait until a reply is received. That is why it is called nxj-"chat".
Every request has a header, an id, a subject, sender and some other fields. An then of course, there is the data.
When sent, each field is preceded by its length, so the receiver knows how many bytes to put in that field. This is important to send strings and the custom data.
I'll write a more detailed tutorial later perhaps, but I just recently started using github, and I thought I might as well put it up there.
So here you go:
- Code: Select all
I just imported my entire nxj-chat related SVN tree into github, so the structure is awful at the moment.
Along with the code comes a little sample application that you might use to discover how the code works (sorry, I don't have much time atm)
The code structure needs some cleaning up, that is, how the repository is organized. I intend to make this bearable in the next week or so.
The code is split in two parts: PC related, and NXT related. The PC code however needs access to the NXT related code, because they derive from the same base classes.
Looking back at the code, it's not the smarted solution, but it worked for me. Also note, that this was both my first Java Project and also my first NXT one. Since this is just from an actual project of mine, there are some classes that are not complete (Broadcast for instance) and others that are just quick and dirty. The code design is also not always the smartest
Let me know what you think and please don't judge me on the folder structure yet, I know it's awful