| | | | |
| |
| Hi,
I'm just getting started using LNP, read the howto and tried to play
around with the examples therein. However, somthing goes wrong. I have a
little programm on the RCX increasing a counter every second, displaying
it's value on the lCD and sending it to the PC. On the PC side this
value should be displayed as soon as it's reveived.
The RCX side seems to work, at least the counter is increased, displayed
and something is sent out the IR port. The PC side however doesn't
display anything. When I look into lnpd's log, I see that eveytime the
RCX send something, I get errors:
[...]
238738:Logical > Frame Error
239791:Integrity > Integrity reset
239791:Logical > Frame Error
239795:Integrity > Integrity reset
239795:Logical > Frame Error
239799:Integrity > Integrity reset
239799:Logical > Frame Error
239803:Integrity > Integrity reset
239803:Logical > Frame Error
239807:Integrity > Integrity reset
[...]
Looks like something is received, just not understood. I'm running
brickOS-0.2.6.09.newConf2 on a Linux system and have no problems
programming the RCX otherwise. I got lnpd from
http://legos.sourceforge.net/files/linux/LNPD/, unfortunatly there is no
version number. RCX is 2.0 and I'm using a serial IR tower.
Below is the code I used for both, RCX and PC side. Any help is
appreciated!
Thanks,
BB
RCX Code:
#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_PORT_2 0x8
#define DEST_ADDR ( DEST_HOST << 4 | DEST_PORT )
#define DEST_ADDR_2 ( DEST_HOST << 4 | DEST_PORT_2 )
void printInt(int i)
{
char buf[3];
int result;
buf[0] = 'i';
memcpy(buf + 1, &i, 2);
result = lnp_addressing_write(buf,3, 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++ );
sleep ( 1 );
}
cputs ( "done" );
return 0;
}
PC code:
#include <liblnp.h>
#include <stdio.h>
#define MY_PORT 2
#define DEST_HOST 0x8
#define DEST_PORT 0x7
#define DEST_PORT_2 0x8
#define DEST_ADDR ( DEST_HOST << 4 | DEST_PORT )
#define DEST_ADDR_2 ( DEST_HOST << 4 | DEST_PORT_2 )
void addr_handler(const unsigned char* data,unsigned char
length, unsigned char src)
{
int temp;
char *ptr;
switch(data[0])
{
case 's':
puts(data + 1);
break;
case 'i':
ptr = (char *)temp;
ptr[0] = data[2];
ptr[1] = data[1];
printf("%d", temp);
break;
}
}
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;
}
| | | | | | | | | | | | | Bodo Bauer wrote:
> ptr = (char *)temp;
What about
ptr = (char *)&temp;
Regards
Michael
| | | | | | | | | | | | | | | | | | On Sun, 2003-01-05 at 02:07, Michael Obenland wrote:
> Bodo Bauer wrote:
>
> > ptr = (char *)temp;
>
> What about
>
> ptr = (char *)&temp;
You are right, that would have probably given me a segfaut if the
handler would have ever been called, but it isn't. Even a single, static
printf in the handler doesn't work. What worries me are the error
messages lnpd reports:
30986017:Logical > Frame Error
30986021:Integrity > Integrity reset
Thanks,
BB
| | | | | | | | | | | | | | | | | | | | Bodo Bauer wrote:
> 30986017:Logical > Frame Error
> 30986021:Integrity > Integrity reset
I know that this won't help, but I tried your program (and the lnptest.c
program from the lnp distribution) and got the same errors. No message
came through, only frame errors. Will have a closer look at this.
Regards,
Michael
| | | | | | | | | | | | | | | | | | | | On Sun, 2003-01-05 at 08:27, Michael Obenland wrote:
> Bodo Bauer wrote:
>
> > 30986017:Logical > Frame Error
> > 30986021:Integrity > Integrity reset
>
> I know that this won't help, but I tried your program (and the lnptest.c
> program from the lnp distribution) and got the same errors. No message
> came through, only frame errors. Will have a closer look at this.
Thanks. Too bad it doesn't work, but at least now I know it's not me :)
Please let me know if I can be of any help.
BB
| | | | | | | | | | | | | | | |
| |
| Bodo Bauer wrote:
> [...]
> 238738:Logical > Frame Error
> 239791:Integrity > Integrity reset
> 239791:Logical > Frame Error
> 239795:Integrity > Integrity reset
> 239795:Logical > Frame Error
> 239799:Integrity > Integrity reset
> 239799:Logical > Frame Error
> 239803:Integrity > Integrity reset
> 239803:Logical > Frame Error
> 239807:Integrity > Integrity reset
> [...]
Ok. This is indeed the result if you run the original LNP package. There
are several problems with your sources, too. So try the following to get
things done:
First, go to the lnpd subdir and edit rcxtty.c. In function tty_init you
find a line with:
ios.c_cflag = CREAD | ...
it should read:
ios.c_cflag = CREAD | CLOCAL | CS8 | (highspeed ? 0 : PARENB | PARODD);
You could take a look at the rcxtty.c file in the util/dll-src subdir of
brickOS, you will find the same initialization. This will wipe out the
frame errors. But your program won't run, anyway. You should change some
things so you will get:
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;
}
-------------------------------------------------------------
| | | | | | | | | | | | | | | | | | On Sun, 2003-01-05 at 10:21, Michael Obenland wrote:
> Bodo Bauer wrote:
>
> > [...]
> > 238738:Logical > Frame Error
> > 239791:Integrity > Integrity reset
> > 239791:Logical > Frame Error
> > 239795:Integrity > Integrity reset
> > 239795:Logical > Frame Error
> > 239799:Integrity > Integrity reset
> > 239799:Logical > Frame Error
> > 239803:Integrity > Integrity reset
> > 239803:Logical > Frame Error
> > 239807:Integrity > Integrity reset
> > [...]
>
>
> Ok. This is indeed the result if you run the original LNP package. There
> are several problems with your sources, too. So try the following to get
> things done:
This works in deed! Thank you so much Michael! No way I would have found
this myself.
BB
| | | | | | | | | | | | | | | | | |
| |
| 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
| | | | | | | | | | | | | | | | |
| |
| 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
| | | | | | |