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 / 3134
Subject: 
Re: LNP problem
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Tue, 28 Jan 2003 20:03:17 GMT
Viewed: 
3915 times
  
Hi everyone,

I have to say I have found these messages very interesting, and was wanting
to use lnp myself but i do not know where to write and make my programs. And
I would also like to find out more about how you write the pc code and the
rcx code below, and how this works and where it goes?

I have a good understanding of programming, it's just this is a very new
area to me, and is truly very interesting,

PC PROGRAM:
===========================================================
#include <liblnp.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <string.h>

#define MY_PORT 7

void addr_handler(const unsigned char* data,unsigned char length,
unsigned char src)
{
   switch(data[0]) {
      case 's':
         printf( "%s\n", &data[1] );
         break;
      case 'i':
         printf( "%d\n", data[1] * 256 +  data[2] );
         break;
      default:
         printf( "unknown type\n" );
      }
      fflush( stdout );
   }

int main ( int argc, char **argv ) {

   if ( lnp_init ( 0, 0, 0, 0, 0 ) ) {
      perror ( "lnp_init" );
      exit(1);
   } else {
      printf ( "init OK\n" );
   }

   lnp_addressing_set_handler (MY_PORT, addr_handler );

   while ( 1 ) {
   };

   return 0;
}

----------------------------------------------------------
RCX PROGRAM:
==========================================================
#include <lnp.h>
#include <conio.h>
#include <string.h>
#include <lnp-logical.h>
#include <dkey.h>

#define MY_PORT 2
#define DEST_HOST 0x8
#define DEST_PORT 0x7
#define DEST_ADDR ( DEST_HOST << 4 | DEST_PORT )

unsigned char buf[3];
unsigned char len = 3;

void printInt(int i)
{
int result;

   buf[0] = 'i';
   memcpy(buf + 1, &i, 2);
   result = lnp_addressing_write( buf, len, DEST_ADDR, MY_PORT);
}

wakeup_t prgmKeyCheck(wakeup_t data)
{
   return dkey == KEY_PRGM;
}

int main ( int argc, char **argv )
{
int c=0;

   lnp_logical_range ( 0 );
   while( 1 ) {
      if( prgmKeyCheck( 0 ) ) break;
      printInt( c );
      cputw( c++ );
      msleep ( 200 );
   }
   cputs ( "done" );
   return 0;
}
-------------------------------------------------------------

Does anyone one know of any good books or websites for this topic?

So far I have BrickOS configured and running in cygwin, and I also have
winLNP downloaded and placed it in my brickOS directory like the site i was
reading told me to. But as for what to do now I am stuck.

If anyone could help with the above questions I would be most grateful.

Thanks

Andrew


Subject: 
Re: LNP problem
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Wed, 29 Jan 2003 04:10:59 GMT
Viewed: 
3919 times
  
On Tue, 2003-01-28 at 12:03, Andrew Tait wrote:
Hi everyone,

I have to say I have found these messages very interesting, and was wanting
to use lnp myself but i do not know where to write and make my programs. And
I would also like to find out more about how you write the pc code and the
rcx code below, and how this works and where it goes?

I have a good understanding of programming, it's just this is a very new
area to me, and is truly very interesting,


I don't know anything about Windows, but I started using LNP on Linux
with good results lately. It really isn't that hard once you get your
first programm running ... :)

I wrote a little remote-control/monitor app based on LNP. While for
Gnome (Linux), the LNP stuff is very general and may give you a point to
start. You find the project at http://brickrc.sourceforge.net Or just
look at the source in the CVS browser at
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/brickrc/brickRC/ . Of
interest for you will be src/rcx.[ch] and rcx/remote.c. The first file
handles sending/receiving messages on the PC side. There is nothing
Linux or gnome specific in this file at all, you should be able to use
it as is in your own project. The other file is the RCX application
sending sensor state and controlling the output ports.

Let me know if you have any questions about this code, I'm happy to
help.

BB


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