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 / 2092
2091  |  2093
Subject: 
Re: legOS codeI need example code of rcx2rcx communication.
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Wed, 24 Oct 2001 01:32:56 GMT
Viewed: 
1765 times
  
Hi Chris,

I just started experimenting with brick-to-brick rcx communication.  This is
some code that I got working.  It doesn't do a whole lot, but it
demonstrates the basics of what you need to do.

There are two bricks involved.  Hostmask is 0xf0. The first brick is
compiled with network address 0x10, and the second brick uses 0x20

brick 1 has receiving code built into it.  It demonstrates how to set up an
address handler and how to wait and block for input from the IR port.  You
would probably spawn a new thread / process to do the actual waiting.

I assume you already know how to build the legOS kernel images for each
brick, and that you need different Makefiles for each brick (the Makefile
must point to the kernel with which the brick was built, otherwise undefined
behavior results)

There may be some small typos, as I made small modifications to the code I
posted (to simplify it)

hope this helps,
-Albert

---------------------- brick1.c ------------------------------
#include <lnp.h>
#include <string.h>
#include <conio.h>
#include <dlcd.h>
#include <dsound.h>

char address_buf[255];
int buf_len = 0;

note_t notes_short[] = { { PITCH_C4, EIGHTH },
    { PITCH_END, EIGHTH } };

note_t notes_reject[] = { { PITCH_C3, EIGHTH },
     { PITCH_END, EIGHTH } };

/*  This function gets called asynchronously by the OS when a valid packet
     is received on the IR port.
  */
static void port_handler(const unsigned char *data,
    unsigned char length,
    unsigned char src)
{
  memcpy(address_buf, data, length);
  buf_len = length;
}

static wakeup_t havepack(wakeup_t w)
{
  return buf_len;
}

/*  This function blocks and waits until a valid packet has been received
*  on the IR port.
*/
int read_from_ir(const unsigned char *data)
{
  int ret;
  wait_event(havepack, 0);
  memcpy(data, address_buf, buf_len);
  ret = buf_len;
  buf_len = 0;
  return ret;
}

int main(int argc, char *argv[])
{
  char buf[256];
  int i, len;

  // set the handler / callback function for port 1
  lnp_addressing_set_handler(1, port_handler);

  while(1)
    {
      len = read_from_ir(data);
      if (data[0] == '!')
         {
            dsound_play(notes_short);
         }
      else
         {
             dsound_play(notes_reject);
         }
       msleep(100);
    }
}

----------------------- brick2.c ------------------------------
#include <lnp.h>
#include <string.h>

#define BRICK1_ADDR 0x10
#define BRICK1_PORT 0x01

int main(int argc, char *argv[])
{
    char *msg = "!";

    // send the msg to brick1, telling it that port 1 is the originating
source port.
   // The originating source port doesn't mean a whole lot here, cause this
brick doesn't
   // listen for incoming messages

    lnp_addressing_write(msg, strlen(msg), BRICK1_ADDR | BRICK1_PORT, 1);

}



"Chris Daniel" <ldaniel2@Prodigy.net> wrote in message
news:GLHoMr.J72@lugnet.com...
Hello, I want to use one RCX with 2 rotation sensors as a remote to • control
a second rcx. I own Extreme Mindstorms,have read the legOS howto,and • checked
the cvs at http://sourceforge.net/projects/legos/. Any and all help would • be
appreciated.                           ldaiel2@prodigy.net



Message has 2 Replies:
  Re: legOS codeI need example code of rcx2rcx communication.
 
Albert, Thanks for responding to my post! I had trouble compileing the code maybe you could help or e-mail me the original.Thanks here is the error report: brick1.c: In function `read_from_ir': brick1.c:40: warning: passing arg 1 of `memcpy' di rget (...) (23 years ago, 29-Oct-01, to lugnet.robotics.rcx.legos)
  corect me please
 
Thanks Bill with your help the code Albert gave me compiles nicely! Now i (...) //This is what I tried in LegOS/boot/config.h: #define CONF_LNP_HOSTMASK 0xf0 #define CONF_LNP_HOSTADDR 0x10 //Then in a cygnus window I created a kernal make realclean (...) (23 years ago, 4-Nov-01, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  legOS codeI need example code of rcx2rcx communication.
 
Hello, I want to use one RCX with 2 rotation sensors as a remote to control a second rcx. I own Extreme Mindstorms,have read the legOS howto,and checked the cvs at (URL) Any and all help would be appreciated. ldaiel2@prodigy.net (23 years ago, 20-Oct-01, to lugnet.robotics.rcx.legos)

7 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
    

Custom Search

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