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 / 817
816  |  818
Subject: 
Re: using the remote control with legOS
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Wed, 9 Feb 2000 11:25:28 GMT
Viewed: 
3108 times
  
it would be nice to be able to use both LNP and remote control (advance
tactical robots)
I wrote last night a small win prog to figure out how the remote is talking
and this is it:

+++
// LEGO REMOTE CONTROL (#9738 = ~20 USD) FOR RCX MESSAGE PROTOCOL
/*
0 start              0x55    start of msg
1 nop1             0xFF   always FF
2 255 - nop1   0x00   always 00 (FF - FF)
3 nop2             0xD2   always D2
4 255 - nop2   0x2D   always 2D (FF - D2)
5 b2                 0x80    last 8 buttons state, can be any state from 0
to FF
6 255 - b2       0x7F   FF - b2
7 b1                 0x00   first 8 buttons state, can be any state from 0
to FF
8 255 - b1       0xFF   FF - b1
9 cs                 0x52    checksum = 1 + nop1 + nop2 + b2 + b1
10 255 - cs     0xAD   FF - checksum
*/
// note:
// as long as 1 or more buttons are pressed the remote control sends
continues data
// a timer should be used to reset the buttons state if one or more buttons
are still active
// (standard lego firmware seems to reset after about 500ms)
// I have 2 of these remote controls, and both send exactly the same datas
// if I use both remotes at the same time I get nothing
// With that type of checking, it is safe to use your robot in a nuclear
plant !!!

// remote control button flags
// comments are for default lego firmware behavior
#define REMOTE_MSG_1 0x0001 // send message to rcx, value = 1
#define REMOTE_MSG_2 0x0002  // value = 2
#define REMOTE_MSG_3 0x0004  // value = 3
#define REMOTE_A_FWD 0x0008 // motor on
#define REMOTE_B_FWD 0x0010 // note:
#define REMOTE_C_FWD 0x0020  // with lego firmware rev as priority
#define REMOTE_A_REV 0x0040 // when pressing fwd and rev
#define REMOTE_B_REV 0x0080
#define REMOTE_C_REV 0x0100
#define REMOTE_PRG_1 0x0200  // stop current prog and start programm 1
#define REMOTE_PRG_2 0x0400
#define REMOTE_PRG_3 0x0800
#define REMOTE_PRG_4 0x1000
#define REMOTE_PRG_5 0x2000
#define REMOTE_STOP  0x4000 // stop current prog
#define REMOTE_BIP  0x8000  // RCX says "I'm here, don't worry, sleep
well...", actually 2 shot bips

static short remote_button_state = 0;

void COnRemoteDlg::OnReceive(const unsigned char* szIn, UINT nLen)
{
static unsigned char pos = 0, cs, lb; // cs: checksum lb: lastbyte
static unsigned char B1 = 0; // first 8 buttons on remote
static unsigned char B2 = 0; // last 8 buttons on remote

for(UINT n = 0; n < nLen; n++)
{
  switch(pos++)
  {
  case 0: // start
   cs = 0x01;
   if(szIn[n] != 0x55)
    pos = 0;
   break;
  case 1: // nop1
  case 3: // nop2
   lb = szIn[n];
   cs+= lb;
   break;
  case 5: // b2
   lb = B2 = szIn[n];
   cs+=lb;
   break;
  case 7: // b1
   lb = B1 = szIn[n];
   cs+=lb;
   break;
  case 9: // cs
   lb = szIn[n];
   if(cs != lb)
    pos = 0;
   break;
  default:
/*
  case 2: // 255 - nop1
  case 4: // 255 - nop2
  case 6: // 255 - b2
  case 8: // 255 - b1
  case 10: // 255 - cs
*/
   if(lb != 0xFF - szIn[n])
    pos = 0;
    break;
  }
  if(pos == 11)
  {
   pos = 0;
   //if(remote_button_state) ResetTimer();
   if(LOBYTE(remote_button_state) != B1 || HIBYTE(remote_button_state) !=
B2)
   {
    remote_button_state = B1 + (B2 << 8);
    //if(remote_button_state == 0) KillTimer();
    //trigger remote_change
    unsigned short flag = 1;
    CString s;
    while(flag)
    {
     if(remote_button_state & flag)
      s+= '1';
     else s+= '0';
     flag<<=1;
    }
    this->SetWindowText(s);
   }
  }
}
}
+++

Martin Cornelius <cornelius@csd.de> a écrit dans le message :
389FDE4A.4E1A1693@csd.de...
Marc wrote:

the LNP stuff is neat, but it seem's that the remote control isn't using
either "integrity" or "addressing" protocol
how do I access directly the incoming IR buffer ??

with an unpatched legOS-2.3, there's no easy way to do that. The
incoming buffer is a static array inside function lnp_integrity_byte(),
it's not accessible from outside.

However, there is a hard way out (i used it during development of lnpd)
Write your own IRQ handlers for receiving and receive-errors -- you can
use the legOS-routines as a starting point -- and make the IRQ-Vectors
in RAM point to your routines. This way you can completely bypass LNP's
receive routines.

BTW, what kind of remote control are you talking about -- is it a
LEGO-part ?
Perhaps we should try to figure out what protocol this remote-control
uses and add some appropriate code to legOS.

I didn't see any source code for "lnp_integrity_set_handler" , how does • it
work ?

the function is inlined, it's trivial -- from lnp.h:
file://! set the integrity layer packet handler
extern inline void lnp_integrity_set_handler(lnp_integrity_handler_t
handler)
{
  lnp_integrity_handler = handler;
}



Message is in Reply To:
  Re: using the remote control with legOS
 
(...) with an unpatched legOS-2.3, there's no easy way to do that. The incoming buffer is a static array inside function lnp_integrity_byte(), it's not accessible from outside. However, there is a hard way out (i used it during development of lnpd) (...) (25 years ago, 8-Feb-00, to lugnet.robotics.rcx.legos)

3 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

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