Class CanMessage

  • All Implemented Interfaces:
    CanFrame, CanMutableFrame, Message

    public class CanMessage
    extends AbstractMRMessage
    implements CanMutableFrame
    Base class for messages 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.

    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.

    • Constructor Detail

      • CanMessage

        public CanMessage​(int header)
        Create a new CanMessage with 8 data bytes
        Parameters:
        header - The CAN Frame header value
      • CanMessage

        public CanMessage​(int numDataBytes,
                          int header)
        Create a new CanMessage of given length
        Parameters:
        numDataBytes - number of CAN Frame data bytes, max 8
        header - The CAN Frame header value
      • CanMessage

        public CanMessage​(int[] d,
                          int header)
        Create a new CanMessage from an int array
        Parameters:
        d - array of CAN Frame data bytes, max 8
        header - The CAN Frame header value
      • CanMessage

        public CanMessage​(byte[] d,
                          int header)
        Create a new CanMessage from a byte array
        Parameters:
        d - array of CAN Frame data bytes, max 8
        header - The CAN Frame header value
      • CanMessage

        public CanMessage​(@Nonnull
                          CanMessage m)
        Create a new CanMessage from an existing CanMessage
        Parameters:
        m - The existing CanMessage
      • CanMessage

        public CanMessage​(@Nonnull
                          CanReply m)
        Create a new CanMessage from an existing CanReply
        Parameters:
        m - The existing CanReply
    • Method Detail

      • setTranslated

        public void setTranslated​(boolean translated)
        Tag whether translation is needed. a "native" message has been converted already.
        Parameters:
        translated - true or false to set flag as required
      • isTranslated

        public boolean isTranslated()
        Check if translation flag has been set.
        Returns:
        false by default
      • equals

        public boolean equals​(java.lang.Object a)
        Note that a CanMessage and a CanReply can be tested for equality.
        Overrides:
        equals in class AbstractMessage
        Parameters:
        a - CanMessage or CanReply to test against
      • replyExpected

        public boolean 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:
        replyExpected in class AbstractMRMessage
        Returns:
        always false
      • getData

        public int[] getData()
        Get the data bytes in array form.
        Returns:
        the actual int array
      • getHeader

        public int getHeader()
        Get the CAN Frame header.
        Specified by:
        getHeader in interface CanFrame
        Returns:
        header value
      • isExtended

        public boolean isExtended()
        Get if the CAN Frame has an extended header.
        Specified by:
        isExtended in interface CanFrame
        Returns:
        true if extended, else false
      • setExtended

        public void setExtended​(boolean b)
        Set if the CAN Frame header is extended.
        Specified by:
        setExtended in interface CanMutableFrame
        Parameters:
        b - true if extended, else false
      • isRtr

        public boolean isRtr()
        Get if the CAN Frame is an RTR Frame.
        Specified by:
        isRtr in interface CanFrame
        Returns:
        true if RTR, else false
      • setRtr

        public void setRtr​(boolean b)
        Set if the CAN Frame is an RTR Frame.
        Specified by:
        setRtr in interface CanMutableFrame
        Parameters:
        b - true if RTR, else false