jmri.jmrix
Class NetMessage

java.lang.Object
  extended by jmri.jmrix.NetMessage
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
Mx1Message

public abstract class NetMessage
extends Object
implements Serializable

Represents a single general command or response.

Content is represented with ints to avoid the problems with sign-extension that bytes have, and because a Java char is actually a variable number of bytes in Unicode.

Both a set of indexed contents, an opcode, and a length field are available. Different implementations will map the opcode and length into the contents in different ways. They may not appear at all...

Author:
Bob Jacobsen Copyright (C) 2002
See Also:
Serialized Form

Constructor Summary
NetMessage(int len)
          Create a new object, representing a specific-length message.
 
Method Summary
abstract  boolean checkParity()
          check whether the message has a valid parity
 int getElement(int n)
           
 int getNumDataElements()
          Get length, including op code and error-detection byte
 int getOpCode()
           
 String getOpCodeHex()
          Get a String representation of the op code in hex
protected static int highByte(int val)
           
protected static int lowByte(int val)
           
 void setElement(int n, int v)
           
 void setOpCode(int i)
           
abstract  void setParity()
          Set parity to be correct for this implementation.
 String toString()
          Get a String representation of the entire message in hex.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NetMessage

public NetMessage(int len)
Create a new object, representing a specific-length message.

Parameters:
len - Total bytes in message, including opcode and error-detection byte.
Method Detail

setOpCode

public void setOpCode(int i)

getOpCode

public int getOpCode()

getOpCodeHex

public String getOpCodeHex()
Get a String representation of the op code in hex


getNumDataElements

public int getNumDataElements()
Get length, including op code and error-detection byte


getElement

public int getElement(int n)

setElement

public void setElement(int n,
                       int v)

toString

public String toString()
Get a String representation of the entire message in hex. This is not intended to be human-readable!

Overrides:
toString in class Object

checkParity

public abstract boolean checkParity()
check whether the message has a valid parity


setParity

public abstract void setParity()
Set parity to be correct for this implementation. Note that parity is really a stand-in for whatever error checking, etc needs to be done


lowByte

protected static int lowByte(int val)

highByte

protected static int highByte(int val)


Copyright © 1997 - 2011 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads