Subject:
|
Re: lnp addressing messages
|
Newsgroups:
|
lugnet.robotics.rcx.legos
|
Date:
|
Mon, 26 Aug 2002 01:27:18 GMT
|
Viewed:
|
2036 times
|
| |
| |
> I have some problem to understand the lnp addressing message. How to set
> addresse of computer. How to send a message etc ...
hmmmm..okay.......ill give it a shot.
the line below:
result = lnp_addressing_write(data,len ,DEST_ADDR,MY_PORT_1);
will send a message pointed to by data, consisting of len bytes of data to
the DEST_ADDR destination using my MY_PORT_1
port. in your case below you are sending a message to port 2 on host 0. host
0 is the default address for the PC.
DEST_ADDR is 1 byte consisting of DEST_HOST and DEST_PORT, each 4 bits. dont
know if you are aware of this, but you must
also start a lnp daemon on the PC before any messages can be received. Once
the daemon is up and running and you have created a program
on the PC that has a handler that listens on port 2 it should be able to
receive messages.
hope this helps, if you need a better walkthrough let me know and ill c what
i can do. mind you, i only know how to do this in linux :)
kenneth
kennethj@stud.cs.uit.no
> I have an example (lnpd example but i don't understand this :
>
> #define DEST_ADDR ( DEST_HOST << 4 | DEST_PORT )
> result = lnp_addressing_write(data,len ,DEST_ADDR,MY_PORT_1);
>
> here is the complete program :
>
> //
> // kleines Testprogram für linux lnp
> //
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <sys/time.h>
> #include <sys/types.h>
>
> #include "liblnp.h"
>
> #define MY_PORT_1 7
> #define MY_PORT_2 8
>
> #define DEST_HOST 0
> #define DEST_PORT 2
> #define DEST_ADDR ( DEST_HOST << 4 | DEST_PORT )
> #define LEN 253
>
> void addr_handler_1(const unsigned char* data,unsigned char length, unsigned
> char src)
> {
> char pbuf[100];
>
> sprintf(pbuf,">> Source:%2X Length:%u PacketNo:%u
> <<\n",(unsigned)src,(unsigned)length,(unsigned)data[0]);
>
> write(STDERR_FILENO,pbuf,strlen(pbuf));
> }
>
> void addr_handler_2(const unsigned char* data,unsigned char length, unsigned
> char src)
> {
> char pbuf[100];
>
> sprintf(pbuf,">> Source:%2X Length:%u PacketNo:%u
> <<\n",(unsigned)src,(unsigned)length,(unsigned)data[0]);
>
> write(STDERR_FILENO,pbuf,strlen(pbuf));
> }
>
> void int_handler(const unsigned char* data,unsigned char length)
> {
> char pbuf[100];
>
> sprintf(pbuf,">> Integrity Length:%u PacketNo:%u
> <<\n",(unsigned)length,(unsigned)data[0]);
>
> write(STDERR_FILENO,pbuf,strlen(pbuf));
> }
>
> int main(int argc, char *argv[])
> {
> char data[253];
> int i;
> lnp_tx_result result;
> unsigned char len;
> int count = 0;
>
> for (i=0;i<sizeof(data);i++) data[i] = i;
>
> if ( lnp_init(0,0,0,0,0) )
> {
> perror("lnp_init");
> exit(1);
> }
>
> else fprintf(stderr,"init OK\n");
>
> lnp_addressing_set_handler (MY_PORT_1, addr_handler_1);
> lnp_addressing_set_handler (MY_PORT_2, addr_handler_2);
> lnp_integrity_set_handler (int_handler);
>
> while (1)
> {
> file://sleep(1000);
> file://continue;
> len = LEN; file://random() % 252 + 1;
> result = lnp_addressing_write(data,len ,DEST_ADDR,MY_PORT_1);
> switch (result)
> {
> case TX_SUCCESS:
> printf("Tansmitted %d : %d\n",len,count++);
> break;
> case TX_FAILURE:
> printf("Collision\n");
> break;
> default:
> perror("Transmit error");
> exit(1);
> }
> }
>
> return 0;
> }
>
>
> thanks
>
>
> nanobapt
|
|
Message has 1 Reply: | | Re: lnp addressing messages
|
| (...) Martin Cornelius wrote a nice little piece on this and related isues. it can be found at: (URL) particular look for the sentence: (...) and all shall be revealed :) taken from luis villas legOS howto i initialize lnp on the PC with: (...) (22 years ago, 27-Aug-02, to lugnet.robotics.rcx.legos)
|
2 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|