RAP, the robos ad-hoc protocol, is an ad-hoc communication protocol implemented on top of the robos operating system for Lego Mindstorms. I let students in my embedded software class implement the protocol; for this reason, I do not give here the full implementation. I give here, however, some files that are helpful in the implementation.
Note: To view an attachment, for instance, a .c file, go to the Attachments page and click on View.
RAP Protocol Description
RAP Packet Structure: The packet structure for RAP, the Robos Ad-Hoc Protocol
Overview slide for the RAP protocol implementation.
How to use lnpd. This page can be edited by students, so please feel free to add here any additional useful hint you might have.
RAP Tarballs and Howtos
To start: download rap-tarball.tgz, the tarball with everything that is needed for the RAP protocol.
- Do a basic setup:
cd rap-class/robos ./configure make cd ../rap make depend make
In the file rap/applications/Makefile, there are two #define:
SWEM turns on software emulation (useful to run on the PC without a source of packets). Note that to change SWEM, you need to do consistent changes according to the instructions below:
# Undefine SWEM below to turn off software emulation CFLAGS=-O2 -DSWEM -DPC_PROTOCOL -ggdb -Wall $(CINC) # Use the lines below if SWEM is defined CINC = -I. -I../liblnp -I../include # Use the lines below if SWEM is undefined # CINC = -I. -I../liblnp -I../include # LIBS= -llnp
DEBUG turns on debugging
Moreover, PC_PROTOCOL needs to be defined to compile for the PC, and needs to be undefined to compile for the Lego. This is one of the differences between the Makefile in rap/applications and robos/rap.
Running lnpd
You don't have to be root to run lnpd, except for one reason: If your serial chip (uart) is a 16550A with builtin FIFO, this FIFO should be disabled. To do this, you have 2 options:
Before starting lnpd for the first time, run
/sbin/setserial /dev/ttyS0 uart 16450
You need root priviledge to run this command sucessfully anyways, but you can start lnpd as non-priviledged user, what might be safer. I strongly recommend this way as long as lnpd is not thoroughly tested.- Run lnpd as root or with suid-root set. In this case, lnpd will try to detect the uart type and reconfigure the uart as needed.
Like most programs that use the serial port, lnpd will try to create a lock-file in /var/lock, and terminate if it cannot create this file. In my distribution, /var/lock is only writeable by group uucp, so i had to put myself into group uucp. Another option is to start lnpd with option --nolock. In this case, lnpd will not care at all about lockfiles.
Look at the README file in the rap directory for more options.
C Files
adhoc.c This is my implementation of RAP. Well, not the whole of it
, but I am giving you #defines and main() that work both when compiled on a PC, and when compiled for the brick. In particular, this will save you the chore of figuring out exactly which include files you need on each side, and how to spawn threads on each side. babble.c This code is to be compiled for the Lego. It generates a stream of random packets formatted according to RAP, spaced 1 second apart.
rapdump.c This code is to be compiled on the PC, and prints (according to RAP, in a pretty format) all the packets that are received.
rap.h This include file is used both by babble.c and by rapdump.c, and is what I have been using to develop RAP.
Other Tarballs
There are only for the instructor's reference:
rap.tgz This is what used to be called lnpd+lnplib. It contains most of the files that are needed, including rap.h, adhoc.c, rapdump.c.
robos-and-rap.tgz This is robos, with an extra subdirectory rap where I am developing RAP. Use makelinks to make required symbolic links from this directory to rap/applications in the rap package.
