Package jmri.jmrix.can
Interface CanFrame
- All Known Subinterfaces:
CanMutableFrame
- All Known Implementing Classes:
CanMessage,CanReply
Base interface for immutable messages in a CANbus based message/reply protocol.
It is expected that any CAN based system will be based upon basic CAN concepts such as ID/header (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
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidAppend the hex value of the data elements to a StringBuilder.default booleandataFramesEqual(CanFrame a, CanFrame b) Compare 2 CanFrame data elements for equality.default booleanCheck if the CAN Frame is extended OR RtR.intgetElement(int n) Get a single data byte in the frame.intGet the CAN Frame header.intGet number of data bytes in the frame.default StringGet formatted toString.default booleanCompare 2 CanFrames for equality.booleanGet if the CAN Frame has an extended header.booleanisRtr()Get if the CAN Frame is an RTR Frame.default StringGet formatted monitor String.
-
Method Details
-
getHeader
int getHeader()Get the CAN Frame header.- Returns:
- header value
-
isExtended
boolean isExtended()Get if the CAN Frame has an extended header.- Returns:
- true if extended, else false
-
isRtr
boolean isRtr()Get if the CAN Frame is an RTR Frame.- Returns:
- true if RTR, else false
-
getNumDataElements
int getNumDataElements()Get number of data bytes in the frame.- Returns:
- 0-8
-
getElement
Get a single data byte in the frame.- Parameters:
n- the index, 0-7- Returns:
- the data element value
-
monString
Get formatted monitor String. Includes if Frame is Extended. Header value at start. All values hex format. Only valid data elements are included.- Returns:
- eg. "(1A ext) 81 EA 83 00 12"
-
getToString
Get formatted toString. Does NOT include if Frame is Extended. All values hex format. Only valid data elements are included.- Returns:
- eg. "[12] 81 EA 83"
-
appendHexElements
Append the hex value of the data elements to a StringBuilder.- Parameters:
sb- to append the hex values to
-
isEqual
Compare 2 CanFrames for equality.- Parameters:
a- CanFrame to testb- CanFrame to test- Returns:
- true if RTR, Extended, Header and Data elements match, else false
-
dataFramesEqual
Compare 2 CanFrame data elements for equality.- Parameters:
a- CanFrame to testb- CanFrame to test- Returns:
- true if Data elements match, else false
-
extendedOrRtr
Check if the CAN Frame is extended OR RtR.- Returns:
- true if either extended or RtR, else false
-