To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 2803
2802  |  2804
Subject: 
Re: lnp addressing messages
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Tue, 27 Aug 2002 11:56:03 GMT
Viewed: 
5148 times
  
nanobapt wrote:

> and how to configure address of computer ?


Martin Cornelius wrote a nice little piece on this and related isues. it can be
found at:
http://news.lugnet.com/robotics/rcx/legos/?n=788
in particular look for the sentence:
> . Can the host set its source address? If so, how?
and all shall be revealed :)


taken from luis villas legOS howto i initialize lnp on the PC with:

if(lnp_init(0,0,0,0,0)){
        perror("lnp_init\n");
        exit(1);
}else{
        fprintf(stderr,"init Ok\n");
}

thus if you want to change the address of the PC you will have to change the
third parameter to the lnp_init function call.
f.eks:
if(lnp_init(0,0,1,0,0)){
        perror("lnp_init\n");
        exit(1);
}else{
        fprintf(stderr,"init Ok\n");
}

would set the address of the PC to 0x10.

from left to right the parameters to lnp_init are:
-----------------------------------------
// parameters:
// tcp_hostname:
//      host running lnpd to connect - ascii or dotted quad
//      0 means: default to localhost
// tcp_port:
//  portnumber to connect to
//  0 means: default to 7776
// lnp_address:
//  LNP hostaddress to use
//  0 means: default to 0x80
// lnp_mask:
//  LNP hostmask to use
//  0 means: default to 0xF0
// flags:
//      bitwise or of:
//  LNP_DISCARD_WHILE_TX :
//              discard all packets received while waiting for tx result
//
// returns:
//      INIT_OK                 ok, connected to lnp-daemon
//      INIT_BAD_PARAM  bad parameters
//      INIT_ERROR      network error, errno is set
-----------------------------------


oki, guess that was it :)

kenneth


> 
> nanobapt
> ----- Original Message -----
> From: kenneth johansen <kennethj@stud.cs.uit.no>
> To: nanobapt <nanobapt@nordnet.fr>; <lugnet.robotics.rcx.legos@lugnet.com>
> Sent: Monday, August 26, 2002 3:27 AM
> Subject: Re: lnp addressing messages
> 
> > > 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 is in Reply To:
  Re: lnp addressing messages
 
(...) 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. (...) (24 years ago, 26-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
    

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR