|
Michael Marklew wrote:
>
> Does anyone have an example or two of using LNP so two RCX units can
> communicate with each other?
To get a somewhat crude explanation of how LNP works, and how to make
RCXs with different LNP-Hostaddresses, i'd suggest to read thread 'LNP
Addressing Schemes', last week in this newsgroup.
However, if you don't need addressing or several ports, just do:
on the receiving RCX:
// create a handler function that will receive broadcast packets:
void my_integrity_handler(const unsigned char *data, unsigned char len)
{
// process packet here
}
This function will be called whenever a broadcast packet arrives, and
will get passed the packet as parameters.
BE AWARE this function is called inside the IRQ-handler. It should be
reasonably short and not do anything that could block, such as waiting
for semaphores.
This means, most of the multitasking functionality ( sleep, wait, e.t.c
), and sending LNP-Packets can not be used inside the handler. However,
writing to the display, playing sounds, and switching outputs is O.K.
If you must do some really complicated processing of packets, you should
just save them inside the handler to a global array, and post a
semaphore that wakes another task to do the real work.
// activate the handler
lnp_integrity_set_handler(my_integrity_handler);
on the sending RCX there is nothing to prepare, just:
// send packet
lnp_integrity_send(packet,length);
for bidirectional communication, you have to install handlers on both
RCXs, of course.
If you have more than 2 RCXs and/or want several ports, you first have
to give the RCXs different host addresses -- read the thread cited above
for info on how to do this.
in this case, the handler function to install has one more parameter -
the originating address.
// addressing handler
void handler(const unsigned char *data, unsigned char len, unsigned char
src_address)
{
// process packet
}
//it must be activated with:
lnp_addressing_set_handler(port,handler)
The handler will be invoked whenever a packet arrives that is destined
to this host and to the port given, port is a number from 1 to 15 (0 is
reserved for dll )
//sending of an addressing packet is done via
lnp_addressing_write(data,length,dest,srcport)
// length of addressing packets MUST NOT exceed 253 bytes !
all this stuff is declared in include/lnp.h
If you want PC's to participate in communication,
- install a recent version of Linux ( kernel 2.2.x, glibc 2.x )
- get the lnpd&liblnp packet from arthurdent
- follow the instructions in the README
that´s it - hope it helps a little, Martin
|
|
Message has 1 Reply: | | Re: LNP Example please
|
| Thankyou very much Martin, that worked like a charm except for the lnp_addressing_write...t,srcport) which works as lnp_addressing_send(...t,srcport) Probably just a typo just thought I better let anyone else know who maybe interested. Now all I (...) (25 years ago, 8-Feb-00, to lugnet.robotics.rcx.legos)
|
Message is in Reply To:
| | LNP Example please
|
| Does anyone have an example or two of using LNP so two RCX units can communicate with each other? I have been searching all over the place, looking through the header files and everything for weeks. Am I missing some well hidden documentation page (...) (25 years ago, 6-Feb-00, to lugnet.robotics.rcx.legos)
|
21 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|