To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.nxtOpen lugnet.robotics.nxt in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / NXT / 859
858  |  860
Subject: 
RE: NRLink reading RCX response w/ RobotC
Newsgroups: 
lugnet.robotics.nxt
Date: 
Fri, 3 Aug 2007 19:20:55 GMT
Reply-To: 
<dickswan@IHATESPAMsbcglobal.net>
Viewed: 
23528 times
  
I downloaded the SDK from http://mindstorms.lego.com/sdk2point5/ but

can't find any reference to the message format.  Perhaps this is the

wrong SDK?  I'velooked in all the doc .pdf files and skimmed
everything else.  I sure am having a hard time locating things.

Look at the file "RCX2 LASM Byte Codes" for a description of each of
the available opcodes.

Read http://graphics.stanford.edu/~kekoa/rcx/ coupled with the
contents of my previous email.

So what happens if the message actually begins with a header byte or

a zero, say FF or 00?  It seems to be very difficult to determine
exactly where the prefix header ends.

No valid message starts with with 'opcode' byte of '00' or 'FF'.
[Check out the above referenced description of valid opcodes.

Recall that there is a 30-msec inter-character timer. If more that 30
msec elapses in the middle of message reception then the message
reception is set to the beginning of a message.


Below is a snippet of code that implements a state machine for reading
these kinds of messages.


typedef enum
{
  serialStatusTransmitting,
  serialStatusWaitForMessage
} TSerialStatus;


typedef enum
{
  rcvMessageTransmissionInProgress        = 0,
  rcvWaitForLastEchoAfterMessageTransmit  = 1,
  rcvWaitForPreambleAndOpcode             = 2,
  rcvWaitForMessageByte                   = 3,
  rcvWaitForMessageChecksum               = 4,
} TRcvState;


//////////////////////////////////////////////////////////////////////
//
//                             receiveMessagingChar
//
// State machine for reception of a message.
//
//////////////////////////////////////////////////////////////////////

void receiveMessagingChar(ubyte nRcvdByte)
{
  if (nSerialLinkMode == serialStatusWaitForMessage)
  {
    if (interCharTimer == 0)
    {
      //
      // Too long between characters.
      // Reset to looking for start of message.
      //
      nRcvtStateMachine = rcvWaitForPreambleAndOpcode;
      nLastRcvMsgByte = (ubyte) 0xFF;
    }

    interCharTimer = 30;

    switch (nRcvtStateMachine)
    {
    case rcvMessageTransmissionInProgress:
    case rcvWaitForLastEchoAfterMessageTransmit:
      return;

    case rcvWaitForPreambleAndOpcode:
      if (   (nRcvdByte == 0x0000)
          || (nRcvdByte == 0x00FF)
          || (nRcvdByte == 0x0055))
      {
        //
        // Preamble byte. Skip it.
        //
        nLastRcvMsgByte = (TVMOpcode) nRcvdByte;
        break;
      }

      //
      // Just got an opcode byte.
      //
      // Delete any pending messages because they are going to
      // get overwritten
      //
      // Note: this cleans out the flag. It still doesn't clean
      // out the message from the buffer. So normal routines will
      // get an error the next time they try to read a message.
      //
      nSystemTaskNeedExecuting &= (ubyte) ~maskTaskMessageOpcode;
      bHasMessageWaiting = false;

      // Flush unread message from buffer.
      nCircularRcvBufferWriteIndex = nCircularRcvBufferReadIndex;

      addCharToReceiveBuffer(nRcvdByte);
      {
        ubyte nIndex;

        nIndex = (ubyte) (0xF7 & (ubyte) nRcvdByte);
        nMessageBytesLeftToReceive  = nOpcodeLengths[nIndex];
      }

      nMessageBytesLeftToReceive -= 1;
      nReceiveMsgChecksum = nLastRcvMsgByte;

      if (nMessageBytesLeftToReceive <= 0)
        nRcvtStateMachine = rcvWaitForMessageChecksum;
      else
        nRcvtStateMachine = rcvWaitForMessageByte;
      break;

    case rcvWaitForMessageByte:
      addCharToReceiveBuffer(nRcvdByte);
      nReceiveMsgChecksum += nRcvdByte;
      --nMessageBytesLeftToReceive;
      if (nMessageBytesLeftToReceive == 0)
        nRcvtStateMachine = rcvWaitForMessageChecksum;
      break;

    case rcvWaitForMessageChecksum:
      addCharToReceiveBuffer(nRcvdByte);

      if (nReceiveMsgChecksum == nLastRcvMsgByte)
      {
        bHasMessageWaiting = true;
        nSystemTaskNeedExecuting |= (ubyte) maskTaskMessageOpcode;
        nLastRcvMsgByte = (ubyte) 0x00FF;
      }
      // fall through below

    default:
      nRcvtStateMachine = rcvWaitForPreambleAndOpcode;
      nLastRcvMsgByte = (ubyte) 0x00FF;
      break;
    }
  }
  return;
}



Message is in Reply To:
  Re: NRLink reading RCX response w/ RobotC
 
(...) I downloaded the SDK from (URL) but can't find any reference to the message format. Perhaps this is the wrong SDK? I've looked in all the doc .pdf files and skimmed everything else. I sure am having a hard time locating things. (...) So what (...) (18 years ago, 3-Aug-07, to lugnet.robotics.nxt)

8 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