Package jmri.jmrix
Class NetMessage
- java.lang.Object
-
- jmri.jmrix.NetMessage
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
Mx1Message
public abstract class NetMessage extends java.lang.Object implements java.io.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...
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description NetMessage(int len)Create a new object, representing a specific-length message.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract booleancheckParity()check whether the message has a valid parityintgetElement(int n)intgetNumDataElements()Get length, including op code and error-detection byteintgetOpCode()java.lang.StringgetOpCodeHex()Get a String representation of the op code in hex.protected static inthighByte(int val)protected static intlowByte(int val)voidsetElement(int n, int v)voidsetOpCode(int i)abstract voidsetParity()Set parity to be correct for this implementation.java.lang.StringtoString()Get a String representation of the entire message in hex.
-
-
-
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 java.lang.String getOpCodeHex()
Get a String representation of the op code in hex.- Returns:
- string of Opcode, 0x format.
-
getNumDataElements
public int getNumDataElements()
Get length, including op code and error-detection byte- Returns:
- total number of data elements.
-
getElement
public int getElement(int n)
-
setElement
public void setElement(int n, int v)
-
toString
public java.lang.String toString()
Get a String representation of the entire message in hex. This is not intended to be human-readable!- Overrides:
toStringin classjava.lang.Object
-
checkParity
public abstract boolean checkParity()
check whether the message has a valid parity- Returns:
- true if parity valid, else false.
-
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)
-
-