Package jmri.jmrix.can
Class CanReply
java.lang.Object
jmri.jmrix.AbstractMessage
jmri.jmrix.AbstractMRReply
jmri.jmrix.can.CanReply
- All Implemented Interfaces:
CanFrame
,CanMutableFrame
,Message
public class CanReply extends AbstractMRReply implements CanMutableFrame
Base class for replies in a CANbus based message/reply protocol.
It is expected that any CAN based system will be based upon basic CANbus concepts such as ID (standard or extended), Normal and RTR frames and a data field.
"header" refers to the full 11 or 29 bit header; which mode is separately set via the "extended" parameter
CBUS uses a 2-bit "Pri" field and 7-bit "ID" ("CAN ID") field, with separate accessors.
-
Field Summary
Fields Modifier and Type Field Description (package private) int
_header
(package private) boolean
_isExtended
(package private) boolean
_isRtr
-
Constructor Summary
Constructors Constructor Description CanReply()
Create a new CanReplyCanReply(int i)
Create a new CanReply of given data lengthCanReply(int[] d)
Create a new CanReply from an int arrayCanReply(int[] d, int header)
Create a new CanReply from an int array, with headerCanReply(CanMessage m)
Create a new CanReply from an existing CanMessageCanReply(CanReply m)
Create a new CanReply from an existing CanReply -
Method Summary
Modifier and Type Method Description boolean
equals(Object a)
Note that a CanMessage and a CanReply can be tested for equalityint[]
getData()
Get the data byte array.int
getElement(int n)
Get a particular element in a Message.int
getHeader()
Get the CAN Frame header.int
getNumDataElements()
Get the number of data elements in a Message.int
hashCode()
Hash on the headerboolean
isExtended()
Get if the CAN Frame has an extended header.boolean
isRtr()
Get if the CAN Frame is an RTR Frame.void
setElement(int n, int v)
Set a single Data Element at a particular index.void
setExtended(boolean b)
Set if the CAN Frame header is extended.void
setHeader(int h)
Set the CAN Frame header.void
setNumDataElements(int n)
Set the number of data elements in the main CAN Frame body.void
setRtr(boolean b)
Set if the CAN Frame is an RTR Frame.protected int
skipPrefix(int index)
String
toMonitorString()
this format matches @CanMessageString
toString()
this format matches @CanMessageMethods inherited from class jmri.jmrix.AbstractMRReply
flush, getOpCode, isBinary, isRetransmittableErrorMsg, isUnsolicited, match, maxSize, pollValue, setBinary, setOpCode, setUnsolicited, skipWhiteSpace, value
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface jmri.jmrix.can.CanFrame
appendHexElements, dataFramesEqual, extendedOrRtr, getToString, isEqual, monString
-
Field Details
-
_header
int _header -
_isExtended
boolean _isExtended -
_isRtr
boolean _isRtr
-
-
Constructor Details
-
CanReply
public CanReply()Create a new CanReply -
CanReply
Create a new CanReply of given data length- Parameters:
i
- number of data bytes, 0-8
-
CanReply
Create a new CanReply from an int array- Parameters:
d
- array of CAN Frame data bytes, max 8
-
CanReply
Create a new CanReply from an int array, with header- Parameters:
d
- array of CAN Frame data bytes, max 8header
- the Frame header value
-
CanReply
Create a new CanReply from an existing CanReply- Parameters:
m
- The existing CanReply
-
CanReply
Create a new CanReply from an existing CanMessage- Parameters:
m
- The existing CanMessage
-
-
Method Details
-
hashCode
Hash on the header- Overrides:
hashCode
in classAbstractMessage
- Returns:
- hashcode from sum of elements.
-
equals
Note that a CanMessage and a CanReply can be tested for equality- Overrides:
equals
in classAbstractMessage
-
skipPrefix
- Specified by:
skipPrefix
in classAbstractMRReply
-
getNumDataElements
Get the number of data elements in a Message.- Specified by:
getNumDataElements
in interfaceCanFrame
- Specified by:
getNumDataElements
in interfaceMessage
- Overrides:
getNumDataElements
in classAbstractMessage
- Returns:
- number elements.
-
setNumDataElements
Set the number of data elements in the main CAN Frame body.- Specified by:
setNumDataElements
in interfaceCanMutableFrame
- Parameters:
n
- true number of data bytes, 0-8
-
getElement
Get a particular element in a Message.- Specified by:
getElement
in interfaceCanFrame
- Specified by:
getElement
in interfaceMessage
- Overrides:
getElement
in classAbstractMessage
- Parameters:
n
- Element Index.- Returns:
- single element of message.
-
setElement
Set a single Data Element at a particular index.- Specified by:
setElement
in interfaceCanMutableFrame
- Specified by:
setElement
in interfaceMessage
- Overrides:
setElement
in classAbstractMRReply
- Parameters:
n
- index of element.v
- value of element.
-
getData
Get the data byte array.- Returns:
- the actual byte array, not a Copy Of
-
getHeader
Get the CAN Frame header. -
setHeader
Set the CAN Frame header.- Specified by:
setHeader
in interfaceCanMutableFrame
- Parameters:
h
- new header value
-
isExtended
Get if the CAN Frame has an extended header.- Specified by:
isExtended
in interfaceCanFrame
- Returns:
- true if extended, else false
-
setExtended
Set if the CAN Frame header is extended.- Specified by:
setExtended
in interfaceCanMutableFrame
- Parameters:
b
- true if extended, else false
-
isRtr
Get if the CAN Frame is an RTR Frame. -
setRtr
Set if the CAN Frame is an RTR Frame.- Specified by:
setRtr
in interfaceCanMutableFrame
- Parameters:
b
- true if RTR, else false
-
toString
this format matches @CanMessage- Specified by:
toString
in interfaceMessage
- Overrides:
toString
in classAbstractMRReply
-
toMonitorString
this format matches @CanMessage- Specified by:
toMonitorString
in interfaceMessage
-