EDU.cmu.cs.coral.cye
Class JCyeMsg

java.lang.Object
  |
  +--EDU.cmu.cs.coral.cye.JCyeMsg

public class JCyeMsg
extends java.lang.Object

JCyeMsg implements the message protocol used by the Cye robot. This class should NOT be used by a end-user of the JavaCye package.


Field Summary
static byte CMD_ACK_REQUEST
           
static byte CMD_ASTART
           
static byte CMD_BUZZER_FREQUENCY
           
static byte CMD_BUZZER_ON
           
static byte CMD_GO_STRAIGHT_VELOCITY
           
static byte CMD_ISTART
           
static byte CMD_POLL_REQUEST
           
static byte CMD_POWER_OFF
           
static byte CMD_REQUEST_POSITION
           
static byte CMD_REQUEST_STATE
           
static byte CMD_SET_DEST
           
static byte CMD_SET_HANDLE_LENGTH
           
static byte CMD_SET_HEADING
           
static byte CMD_SET_HEADING_CORRECT_FACTOR
           
static byte CMD_SET_HEADING_DEST
           
static byte CMD_SET_MAXPWM
           
static byte CMD_SET_MAXSPEED
           
static byte CMD_SET_MOTION_CONTROL_CONSTANTS
           
static byte CMD_SET_MOTORS_PWM
           
static byte CMD_SET_MOTORS_VELOCITY
           
static byte CMD_SET_POSITION
           
static byte CMD_SET_POSITIONVELOCITY_DEST
           
static byte CMD_SET_SENSITIVE_OBS
           
static byte CMD_SET_TURN
           
static byte CMD_SET_VELOCITY_DIRECTION
           
static byte CMD_STOP_MOTORS
           
static byte ESC
           
static byte ESC_ETX
           
static byte ESC_STX
           
static byte ETX
           
static byte FLAG
           
static int FLAG_NUM
           
static int MAX_MSG_LEN
           
static byte PC_SRC_ADDR
           
static byte REPLY_AT_HOME
           
static byte REPLY_CHARGE
           
static byte REPLY_OBSTACLE
           
static byte REPLY_SOFTWARE_REV
           
static byte REPLY_STATUS_UPDATE
           
static byte STX
           
 
Constructor Summary
protected JCyeMsg(byte d)
          JCyeMsg constructor
 
Method Summary
protected  void Add(byte b)
          Adds a byte to the message buffer.
protected  int CalcCRC(byte[] a, int len)
          Calculates the CRC value for a byte array.
protected  byte CombineBytes(byte b1, byte b2)
          Combine two four-bit values into a single byte.
protected  byte GetBufByte(int i)
          Gets a particular buffer byte.
protected  int GetDestAddr()
          Gets the message destination address.
protected  byte[] GetMsgBuf()
          Returns the raw buffer data.
protected  int GetMsgID()
          Gets the message ID number.
protected  int GetMsgLen()
          Returns the message length.
protected  int GetRxMsgNum()
          Gets the message RX number.
protected  int GetSrcAddr()
          Gets the message source address.
protected  int GetTxMsgNum()
          Gets the TX message number.
protected  void ParseReply()
          Extract address, message number, and message type from a freshly-received JCyeMsg.
protected  void Print()
          Pretty-prints a JCyeMsg object to System.out.
protected  void SetBufByte(int i, byte b)
          Sets a particular buffer byte to a specified value.
protected  void SetDestAddr(int Addr)
          Sets the message destination address.
protected  void SetMsgID(int ID)
          Sets the message ID number.
protected  void SetRxMsgNum(int Num)
          Sets the message RX number.
protected  void SetSrcAddr(int Addr)
          Sets the message source address.
protected  void SetTxMsgNum(int Num)
          Sets the TX message number.
protected  byte[] SplitByte(byte b)
          Split a byte into two four-bit values.
protected  JCyeMsg toTransmitArray()
          Converts all of the ugly protocol information into a pretty byte array ready to be pushed through the serial port.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_MSG_LEN

public static final int MAX_MSG_LEN

PC_SRC_ADDR

public static final byte PC_SRC_ADDR

CMD_SET_DEST

public static final byte CMD_SET_DEST

CMD_SET_HEADING_DEST

public static final byte CMD_SET_HEADING_DEST

CMD_SET_TURN

public static final byte CMD_SET_TURN

CMD_SET_MOTORS_PWM

public static final byte CMD_SET_MOTORS_PWM

CMD_SET_MAXPWM

public static final byte CMD_SET_MAXPWM

CMD_SET_MAXSPEED

public static final byte CMD_SET_MAXSPEED

CMD_SET_MOTORS_VELOCITY

public static final byte CMD_SET_MOTORS_VELOCITY

CMD_SET_HEADING_CORRECT_FACTOR

public static final byte CMD_SET_HEADING_CORRECT_FACTOR

CMD_SET_POSITIONVELOCITY_DEST

public static final byte CMD_SET_POSITIONVELOCITY_DEST

CMD_STOP_MOTORS

public static final byte CMD_STOP_MOTORS

CMD_REQUEST_POSITION

public static final byte CMD_REQUEST_POSITION

CMD_SET_HEADING

public static final byte CMD_SET_HEADING

CMD_SET_POSITION

public static final byte CMD_SET_POSITION

CMD_GO_STRAIGHT_VELOCITY

public static final byte CMD_GO_STRAIGHT_VELOCITY

CMD_SET_SENSITIVE_OBS

public static final byte CMD_SET_SENSITIVE_OBS

CMD_SET_MOTION_CONTROL_CONSTANTS

public static final byte CMD_SET_MOTION_CONTROL_CONSTANTS

CMD_SET_HANDLE_LENGTH

public static final byte CMD_SET_HANDLE_LENGTH

CMD_BUZZER_ON

public static final byte CMD_BUZZER_ON

CMD_BUZZER_FREQUENCY

public static final byte CMD_BUZZER_FREQUENCY

CMD_SET_VELOCITY_DIRECTION

public static final byte CMD_SET_VELOCITY_DIRECTION

CMD_REQUEST_STATE

public static final byte CMD_REQUEST_STATE

CMD_POWER_OFF

public static final byte CMD_POWER_OFF

CMD_POLL_REQUEST

public static final byte CMD_POLL_REQUEST

CMD_ISTART

public static final byte CMD_ISTART

CMD_ASTART

public static final byte CMD_ASTART

CMD_ACK_REQUEST

public static final byte CMD_ACK_REQUEST

REPLY_STATUS_UPDATE

public static final byte REPLY_STATUS_UPDATE

REPLY_OBSTACLE

public static final byte REPLY_OBSTACLE

REPLY_CHARGE

public static final byte REPLY_CHARGE

REPLY_SOFTWARE_REV

public static final byte REPLY_SOFTWARE_REV

REPLY_AT_HOME

public static final byte REPLY_AT_HOME

FLAG

public static final byte FLAG

FLAG_NUM

public static final int FLAG_NUM

ESC

public static final byte ESC

STX

public static final byte STX

ETX

public static final byte ETX

ESC_STX

public static final byte ESC_STX

ESC_ETX

public static final byte ESC_ETX
Constructor Detail

JCyeMsg

protected JCyeMsg(byte d)
JCyeMsg constructor
Parameters:
d, - the destination address.
Method Detail

Print

protected void Print()
Pretty-prints a JCyeMsg object to System.out.

GetMsgBuf

protected byte[] GetMsgBuf()
Returns the raw buffer data.
Returns:
the byte array of raw data

GetMsgLen

protected int GetMsgLen()
Returns the message length.
Returns:
the message length

toTransmitArray

protected JCyeMsg toTransmitArray()
Converts all of the ugly protocol information into a pretty byte array ready to be pushed through the serial port. Implements CRC on transmit end. Adds flag bytes to start and end of packet.
Returns:
a JCyeMsg object with the raw data buffer full of nicely-processed bytes

Add

protected void Add(byte b)
Adds a byte to the message buffer.
Parameters:
b - the byte to add

SetBufByte

protected void SetBufByte(int i,
                          byte b)
Sets a particular buffer byte to a specified value.
Parameters:
i - the buffer index
b - the byte

GetBufByte

protected byte GetBufByte(int i)
Gets a particular buffer byte.
Parameters:
i - the buffer index
Returns:
b the desired byte

SetDestAddr

protected void SetDestAddr(int Addr)
Sets the message destination address.
Parameters:
Addr - the address

GetDestAddr

protected int GetDestAddr()
Gets the message destination address.
Returns:
the address

SetSrcAddr

protected void SetSrcAddr(int Addr)
Sets the message source address.
Parameters:
Addr - the address

GetSrcAddr

protected int GetSrcAddr()
Gets the message source address.
Returns:
the address

SetRxMsgNum

protected void SetRxMsgNum(int Num)
Sets the message RX number.
Parameters:
Num - the RX number

GetRxMsgNum

protected int GetRxMsgNum()
Gets the message RX number.
Returns:
the RX number

SetTxMsgNum

protected void SetTxMsgNum(int Num)
Sets the TX message number.
Parameters:
Num - the TX number

GetTxMsgNum

protected int GetTxMsgNum()
Gets the TX message number.
Returns:
the TX number

SetMsgID

protected void SetMsgID(int ID)
Sets the message ID number.
Parameters:
ID - the number

GetMsgID

protected int GetMsgID()
Gets the message ID number.
Returns:
the number

CalcCRC

protected int CalcCRC(byte[] a,
                      int len)
Calculates the CRC value for a byte array.
Parameters:
a - the byte array
len - the length of the array

ParseReply

protected void ParseReply()
Extract address, message number, and message type from a freshly-received JCyeMsg.

SplitByte

protected byte[] SplitByte(byte b)
Split a byte into two four-bit values.
Parameters:
b - the byte to split
Returns:
a byte array with the two four-bit values

CombineBytes

protected byte CombineBytes(byte b1,
                            byte b2)
Combine two four-bit values into a single byte.
Parameters:
b1 - the first four-bit value
b2 - the second four-bit value
Returns:
the combined byte