To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 26850
26849  |  26851
Subject: 
Re: Sending spybot messages from PC?
Newsgroups: 
lugnet.robotics
Date: 
Thu, 8 Feb 2007 15:21:33 GMT
Viewed: 
3491 times
  
In lugnet.robotics, Chris Malton wrote:
To all,
I know how to send RCX messages from the PC over the IR port, but has
anyone ever tried and succeeded in sending SPYBOT messages from the PC.

I'm trying to write some cross-brick software here and so it is kind of
important that I can.  I haven't even really deciphered the protocol.

My only other option is to have an RCX relay the data, which is highly
inefficient, and battery consuming.

Anyone have any ideas on the hex code I need to send?


The NQC API for sending Spybot messages from an RCX may shed some light on what
you need to send.

#define SERIAL_PACKET_SPYBOT 0 // raw serial, no checksum, no preamble
#define SERIAL_COMM_SPYBOT 7 // 4800/76KHZ/25%

// API for interacting with Spybot and other RC components
#define MSG_BROADCAST 0x8a
#define MSG_LINKCAST 0x89
#define MSG_DIRECT 0x88

__nolist void InitSpybotComm()
{
  SetSerialPacket(SERIAL_PACKET_SPYBOT);
  SetSerialComm(SERIAL_COMM_SPYBOT);
}

__nolist void SetSpybotMessage(
const int &nMode,
const int &nMyID,
const int &nAddress,
const int &nCmd,
const int &nHiByte,
const int &nLoByte)
{
  SetSerialData(UART_BOT+0,nMode);
  SetSerialData(UART_BOT+1,nMyID);
  SetSerialData(UART_BOT+2,nAddress);
  SetSerialData(UART_BOT+3,nCmd);
  SetSerialData(UART_BOT+4,nHiByte);
  SetSerialData(UART_BOT+5,nLoByte);
  SetSerialData(UART_BOT+6,0-nMode-nMyID-nAddress-nCmd-nHiByte-nLoByte);
}

// Spybot controller commands
#define SPY_CTRL_BTN_1 0x01
#define SPY_CTRL_BTN_2 0x02
#define SPY_CTRL_BTN_3 0x03
#define SPY_CTRL_BTN_4 0x04
#define SPY_CTRL_BTN_5 0x05
#define SPY_CTRL_RCX_1 0x06 //RCX to Spybot specific
#define SPY_CTRL_RCX_2 0x07
#define SPY_CTRL_RCX_3 0x08
#define SPY_CTRL_RCX_4 0x09
#define SPY_CTRL_RCX_5 0x0a
#define SPY_CTRL_RCX_6 0x0b
#define SPY_CTRL_RCX_7 0x0c
#define SPY_CTRL_RCX_8 0x0d

#define __SPY_CTRL_CMD 0x90

__nolist void SetSpybotCtrlMessage(const int &nMyID, const int &nMsg)
{
  SetSerialData(UART_CTRL+0,__SPY_CTRL_CMD+nMyID);
  SetSerialData(UART_CTRL+1,
    (nMsg * 16) +
    ((0 - ((__SPY_CTRL_CMD+nMyID) / 16) -
          (__SPY_CTRL_CMD+nMyID) - nMsg) & 0x0f));
}

__nolist void SetSpybotCtrlPingMessage(const int &nID)
{
  SetSerialData(UART_PING+0,__SPY_CTRL_CMD+nID);
  SetSerialData(UART_PING+1,
    (0 - ((__SPY_CTRL_CMD+nID) / 16) -
         (__SPY_CTRL_CMD+nID)) & 0x0f);
}

__nolist void SetSpybotPing(
const int &nLinkID,
const int &nMyID,
const int &nInfo)
{
  SetSerialData(UART_PING+0,0x80+(nLinkID&0x7));
  SetSerialData(UART_PING+1,nMyID);
  SetSerialData(UART_PING+2,nInfo);
  SetSerialData(UART_PING+3,0-(0x80+(nLinkID&0x7))-nMyID-nInfo);
}

Based on this I think you should be able to use the LEGO USB Tower API to set
the proper Spybot comm settings (4800/76kHz/25%), construct a message using the
formats described above (depending on the type of message you want to send), and
send it by writing the message buffer to the USB Tower port.

LEGOTowerSetRange(handle, 0x03); // long range
LEGOTowerSetIRSpeed(handle, 0x10, 0x10); // 4800 baud
LEGOTowerSetCarrierFrequency(handle, 76); // 76kHz
// Range for which we set/get the duty cycle --> LT_RANGE_LONG == 0x03
// Duty cycle value, in 1/100 of usec
LEGOTowerSetCarrierDutyCycle(handle, 0x03, 25); // last param ???

byte msgBuf[7];

msgBuf[0] = MSG_BROADCAST;
msgBuf[1] = ID_BOT_MIN+1;
msgBuf[2] = 0;
msgBuf[3] = CMD_FIRE_LASER;
msgBuf[4] = 1;
msgBuf[5] = 100;
msgBuf[6] = (0-msgBuf[0]-msgBuf[1]-msgBuf[2]-msgBuf[3]-msgBuf[4]-msgBuf[5]);

// write buf to usb tower

I haven't tested this but it seems like it should work fine.  I haven't ever set
the duty cycle so I'm not sure if 25 is the correct value for a 25% duty cycle.

John Hansen



Message has 1 Reply:
  Re: Sending spybot messages from PC?
 
(...) Nice idea John, I just wish I had a USB tower! (Or not!). Handling the USB tower in VB is stupidly hard, and I can't use my existing code for the RCX. I just wish LEGO had decided on one simple protocol and speed and everything else! It is so (...) (17 years ago, 8-Feb-07, to lugnet.robotics)

Message is in Reply To:
  Sending spybot messages from PC?
 
To all, I know how to send RCX messages from the PC over the IR port, but has anyone ever tried and succeeded in sending SPYBOT messages from the PC. I'm trying to write some cross-brick software here and so it is kind of important that I can. I (...) (17 years ago, 8-Feb-07, to lugnet.robotics)

3 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