Subject:
|
Re: RCX to Spy messages thru IR communications route
|
Newsgroups:
|
lugnet.robotics.spybotics
|
Date:
|
Wed, 24 Mar 2004 02:23:39 GMT
|
Viewed:
|
7565 times
|
| |
| |
In lugnet.robotics.spybotics, Ed Parrent wrote:
> Yes it
> works, but SPY seems to react only to very specific code strings (message A:
> byte 0=0x92, byte1=0x23; message B: byte 0=0x92, byte1=0xab; ... etc.), and
> immediately performs the message code! (The two messages [above] are two
> separate SPY led animations). I am looking for a way to send a more general
> number code IR message from the RCX to Spy
Okay, after banging my head against this for WAY too long I think I have finally
figured out (somewhat) a few things that were previously completely lost to my
understanding.
If you want an RCX (running RCX2 firmware) to simulate a Spybot Ping you can use
the following code:
SetSerialComm(SERIAL_COMM_4800|SERIAL_COMM_76KHZ);
SetSerialPacket(SERIAL_PACKET_DEFAULT);
SetSerialData(0,0x80); // sometimes this is 0x81. I don't know why
SetSerialData(1,0xd8); // my ID
SetSerialData(2,0x00); // my ping info
SetSerialData(3,0xa8); // checksum (adjust so that sum of all 4 == 0)
SendSerial(0,4);
If you want to send a Spybot message to a Spybot using an RCX (running the RCX2
firmware) you can use the following code:
SetSerialComm(SERIAL_COMM_4800|SERIAL_COMM_76KHZ);
SetSerialPacket(SERIAL_PACKET_DEFAULT);
SetSerialData(0,0x8a); // broadcast
// SetSerialData(0,0x89); // linkcast
// SetSerialData(0,0x88); // individual message
SetSerialData(1,0xd8); // my ID
SetSerialData(2,0x04); // my ping info (when broadcasting)
// SetSerialData(2,0x04); // linkcast link-id (when linkcasting)
// SetSerialData(2,0x04); // id of a bot at an index in the relation table
SetSerialData(3,0x40); // command byte
SetSerialData(4,0x40); // hi byte
SetSerialData(5,0x40); // lo byte
SetSerialData(6,0xda); // checksum (adjust so that sum of all 7 == 0)
SendSerial(0,7);
Now we need somebody really smart to write a function for the built-in API that
works something like SendSpybotMessage in the Spybot API. Here's my feeble stab
at it:
#define MSG_BROADCAST 0x8a
#define MSG_LINKCAST 0x89
#define MSG_DIRECT 0x88
__nolist void SendSpybotMessage(const int &nMode, const int &nMyID,
const int &nAddress, const int &nCmd, const int &nHiByte, const int &nLoByte)
{
SetSerialComm(SERIAL_COMM_4800|SERIAL_COMM_76KHZ);
SetSerialPacket(SERIAL_PACKET_DEFAULT);
SetSerialData(0,nMode);
SetSerialData(1,nMyID);
SetSerialData(2,nAddress);
SetSerialData(3,nCmd);
SetSerialData(4,nHiByte);
SetSerialData(5,nLoByte);
SetSerialData(6,0x100-((nMode+nMyID+nAddress+nCmd+nHiByte+nLoByte)&0xff));
SendSerial(0,7);
}
I have tried this with broadcasting (0x8a) and the Spybot receives a message as
expected. I haven't figured out how to get linkcast or directed message to
work. It might require doing a simulated ping to get the RCX into the Spybot's
world relation table with its own ping ID. The linkcast mode also might require
knowing the Spybot's link-id.
I figured this stuff out by monitoring the IR received by the tower when I had a
Spybot send out messages using SendMessage and the Mindscript equivalent of that
built-in subroutine (which you can find in the postdemo program in the
MindStorms SDK help file). I modified my RCXTool program so that it can monitor
the Spybot IR output. I tried monitoring using the ScriptEd tool from LEGO but
I couldn't get it to work for some reason.
I also discovered that when you set the Spybot serial type (SetSerialType) using
SERIAL_TYPE_USER it just outputs the 4 raw bytes (index, cmd, hi, lo) but when
you set it to SERIAL_TYPE_SPYBOT it outputs the 7 byte sequence discussed above
on the call to SendSerial when using the Spybot NQC API. I presume something
analogous occurs when you switch to SERIAL_TYPE_RC. That doesn't seem to be the
case for SERIAL_TYPE_RCX, however.
Hopefully someone will find this useful.
John Hansen
http://bricxcc.sourceforge.net/
|
|
Message has 1 Reply:
Message is in Reply To:
10 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
|
|
|
|