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 / 1363
1362  |  1364
Subject: 
Re: legOS Addressing - Packet Handler
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Fri, 11 Aug 2000 22:19:42 GMT
Viewed: 
1014 times
  
I have a very simple RCX legos program (which I've attached), that I'm having
difficulty with. I have compiled legOS with the default host address of 0 (0x00).
I am using WinLNP to send data to the RCX (simple short strings), but the RCX
will not recieve it.

The IR icon on the LCD illuminates, but the LCP display does not change. I have
simplified my program to just write a simple string to the LCD upon recieving
data,
but this does not work either.. Can anyone tell me if my attached code is
incorrect,
I am addressing my packet to host id 0 (as compiled) and port 1 (according to my
handler).


Take the sleep(1) out of the code!

The function addressHandlerPortOne() is called from an interrupt, so
you must not call any function which might cause a reschedule (which
sleep() definitely does).

You can do all this by having a separate task waiting for packets
which is woken up by addressHandlerPortOne() with some semaphore.
Look at legOS/kernel/program.c how this is done.

Sleeping inside an interrupt will cause the legOS kernel to hang, this
is why you don't see the change in the LCD. If you remove the sleep,
all is well, and the program correctly listens at port 1 for packets.

Hope this helps,

Thanks in advance,

Colin Ryan.

----------------Code Begins--------------- (short and sweet)


#include <conio.h>
#include <unistd.h>
#include <string.h>
#include <lnp.h>

#define PORT_ONE 1

static int quit = 0; /*end program button*/


/*------------------------------ LNP Handling functions
-----------------------------*/


/*Packet Handler for packets addresses to local port number 1*/
void addressHandlerPortOne(const unsigned char* data, unsigned char length,
unsigned char src) {

     cputs("prt1");
     sleep(1);
    /*I did have code here to write out the recieved data, but even this simpe
code won't work*/
     if (data[0] == 'q') quit = 1;
}


/*-----------------------------------------------------------------------------------*/

/*------------------------------ Main Body of Execution
-----------------------------*/
/*-----------------------------------------------------------------------------------*/

int main()
{

//Assign a handling function to a particular port number:
lnp_addressing_set_handler(PORT_ONE, addressHandlerPortOne);

cputs("Begin");

while(!quit)
{
   msleep(200);
  }
return 0;
}



Eddie C. Dost
ecd@skynet.be



Message has 1 Reply:
  Re: legOS Addressing - Packet Handler
 
Thanks Eddie, Sorry for posting a message I should have known the answer to. I'll have a look at the semaphore example. If anyone knows of a good refence for semaphore programming could they please let me know?Its taken me a while to get into the (...) (24 years ago, 11-Aug-00, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  legOS Addressing - Packet Handler
 
Hi All I have a very simple RCX legos program (which I've attached), that I'm having difficulty with. I have compiled legOS with the default host address of 0 (0x00). I am using WinLNP to send data to the RCX (simple short strings), but the RCX will (...) (24 years ago, 11-Aug-00, to lugnet.robotics.rcx.legos)

9 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