Class CanMessage
- All Implemented Interfaces:
CanFrame,CanMutableFrame,Message
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.
The _dataChars[] and _nDataChars members refer to the data field, not the entire message.
"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. CBUS ID is set as a layout connection preference and registered by the traffic controller.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) int(package private) boolean(package private) booleanFields inherited from class jmri.jmrix.AbstractMRMessage
LONG_TIMEOUT, SHORT_TIMEOUTFields inherited from class jmri.jmrix.AbstractMessage
_dataChars, _nDataChars -
Constructor Summary
ConstructorsConstructorDescriptionCanMessage(byte[] d, int header) Create a new CanMessage from a byte arrayCanMessage(int header) Create a new CanMessage with 8 data bytesCanMessage(int[] d, int header) Create a new CanMessage from an int arrayCanMessage(int numDataBytes, int header) Create a new CanMessage of given lengthCreate a new CanMessage from an existing CanMessageCreate a new CanMessage from an existing CanReply -
Method Summary
Modifier and TypeMethodDescriptionbooleanNote that a CanMessage and a CanReply can be tested for equality.int[]getData()Get the data bytes in array form.intgetElement(int n) Get a particular element in a Message.intGet the CAN Frame header.intGet the number of data elements in a Message.inthashCode()Hash on the headerbooleanGet if the CAN Frame has an extended header.booleanisRtr()Get if the CAN Frame is an RTR Frame.booleanCheck if translation flag has been set.booleanIs a reply expected to this message?voidsetElement(int n, int v) Set a single Data Element at a particular index.voidsetExtended(boolean b) Set if the CAN Frame header is extended.voidsetHeader(int h) Set the CAN Frame header.final voidsetNumDataElements(int n) Set the number of data elements in the main CAN Frame body.voidsetRtr(boolean b) Set if the CAN Frame is an RTR Frame.voidsetTranslated(boolean translated) Tag whether translation is needed.This format matchesCanReplytoString()This format matchesCanReplyMethods inherited from class jmri.jmrix.AbstractMRMessage
addIntAsFourHex, addIntAsThree, addIntAsThreeHex, addIntAsTwoHex, getNeededMode, getOpCode, getOpCodeHex, getRetries, getTimeout, isBinary, setBinary, setNeededMode, setOpCode, setRetries, setTimeoutMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface jmri.jmrix.can.CanFrame
appendHexElements, dataFramesEqual, extendedOrRtr, getToString, isEqual, monStringMethods inherited from interface jmri.jmrix.can.CanMutableFrame
setData, setData
-
Field Details
-
_header
int _header -
_isExtended
boolean _isExtended -
_isRtr
boolean _isRtr
-
-
Constructor Details
-
CanMessage
Create a new CanMessage with 8 data bytes- Parameters:
header- The CAN Frame header value
-
CanMessage
Create a new CanMessage of given length- Parameters:
numDataBytes- number of CAN Frame data bytes, max 8header- The CAN Frame header value
-
CanMessage
Create a new CanMessage from an int array- Parameters:
d- array of CAN Frame data bytes, max 8header- The CAN Frame header value
-
CanMessage
Create a new CanMessage from a byte array- Parameters:
d- array of CAN Frame data bytes, max 8header- The CAN Frame header value
-
CanMessage
Create a new CanMessage from an existing CanMessage- Parameters:
m- The existing CanMessage
-
CanMessage
Create a new CanMessage from an existing CanReply- Parameters:
m- The existing CanReply
-
-
Method Details
-
setTranslated
Tag whether translation is needed. a "native" message has been converted already.- Parameters:
translated- true or false to set flag as required
-
isTranslated
Check if translation flag has been set.- Returns:
- false by default
-
hashCode
Hash on the header- Overrides:
hashCodein classAbstractMessage- Returns:
- hashcode from sum of elements.
-
equals
Note that a CanMessage and a CanReply can be tested for equality.- Overrides:
equalsin classAbstractMessage- Parameters:
a- CanMessage or CanReply to test against
-
toString
This format matchesCanReply- Specified by:
toStringin interfaceMessage- Overrides:
toStringin classAbstractMRMessage
-
toMonitorString
This format matchesCanReply- Specified by:
toMonitorStringin interfaceMessage- Returns:
- a human-readable representation of the message.
-
replyExpected
Is a reply expected to this message?By default, a reply is expected to every message; either a reply or a timeout is needed before the next message can be sent.
If this returns false, the transmit queue will immediately go on to transmit the next message (if any).
- Overrides:
replyExpectedin classAbstractMRMessage- Returns:
- always false
-
getNumDataElements
Get the number of data elements in a Message.- Specified by:
getNumDataElementsin interfaceCanFrame- Specified by:
getNumDataElementsin interfaceMessage- Overrides:
getNumDataElementsin classAbstractMessage- Returns:
- number elements.
-
setNumDataElements
Set the number of data elements in the main CAN Frame body.- Specified by:
setNumDataElementsin interfaceCanMutableFrame- Parameters:
n- true number of data bytes, 0-8
-
getElement
Get a particular element in a Message.- Specified by:
getElementin interfaceCanFrame- Specified by:
getElementin interfaceMessage- Overrides:
getElementin classAbstractMessage- Parameters:
n- Element Index.- Returns:
- single element of message.
-
setElement
Set a single Data Element at a particular index.- Specified by:
setElementin interfaceCanMutableFrame- Specified by:
setElementin interfaceMessage- Overrides:
setElementin classAbstractMessage- Parameters:
n- index of element.v- value of element.
-
getData
Get the data bytes in array form.- Returns:
- the actual int array
-
getHeader
Get the CAN Frame header. -
setHeader
Set the CAN Frame header.- Specified by:
setHeaderin interfaceCanMutableFrame- Parameters:
h- new header value
-
isExtended
Get if the CAN Frame has an extended header.- Specified by:
isExtendedin interfaceCanFrame- Returns:
- true if extended, else false
-
setExtended
Set if the CAN Frame header is extended.- Specified by:
setExtendedin 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:
setRtrin interfaceCanMutableFrame- Parameters:
b- true if RTR, else false
-